Skip to main content

mobilPy

mobilPy helps you with everything you need to implement mobilPay’s online payment solution. Steps: - create an account - get approved - create a merchant - download keys (private and public) - copy the signature (just a string)

NOTE You will have two private keys: for testing and production. The public key is the same.

Install

To install the library, run:

pip install mobilpy

Usage

from mobilpy import Client

# the signature for your account
signature = 'DLAN-1R5V-19EN-XXXX-NFJA'
# the path to the public key
public_key = "./sandbox.DLAN-1R5V-19EN-XXXX-NFJA.public.cer"
# the private_key
private_key = "./sandbox.DLAN-1R5V-19EN-XXXX-NFJA.private.key"

client = Client(signature=signature, public_key=public_key, private_key=private_key)

# optional dict containing details about the customer
# if they are sent, the customer will have a short checkout by skipping the second step in the payment flow
billing_details = {
    "first_name": "",
    "last_name": "",
    "address": "",
    "phone": "",
    "email": ""
}
# optional dict with details that you would need internally
# these are returned when the webhook is called
params = {
    "subscription_id": "",
    "basket_id": "",
    etc.
}

options = {
    "order_id": "" # int/string, max 64 length
    "currency": "RON", # string, RON or other
    "amount": 1, # float, between 0.10 and 99999
    "customer_id": "", # int/string
    "details": "",  # string, description for this transaction
    "billing": billing_details, # dict, OPTIONAL
    "params": params, # dict, OPTIONAL,

    # the webhook where the response from mobilPay will be sent
    "confirm_url": "",
    # the url where the user will be redirected
    "return_url": ""
}
response = client.create_payment_data(**options)

The response is an dict that has two keys: env_key and data. These need to be used in the front end and make the request to mobilPay.

For example, the HTML might look like this:

<form action="http://sandboxsecure.mobilpay.ro" method="post">
    <input type="hidden" name="env_key" value="{{ env_key }}">
    <input type="hidden" name="data" value="{{ data }}">

    <input type="submit" value="Send">
</form>

The POST urls for the form are:

testing:

http://sandboxsecure.mobilpay.ro

production:

https://secure.mobilpay.ro

Webhook

mobilPay will make a POST request to the url you set as confirm_url. mobilPy has methods to help you parse it and offer a response.

post = # get the post data
env_key = post.get('env_key')
data = post.get('data')

client = Client(signature=signature, public_key=public_key, private_key=private_key)

request_xml = client.decrypt_message(env_key, data)
request_object = client.parse_webhook_request(request_xml)

# do some magic

In order to check if the transaction was successful you need to check error_code AND action:

transaction_successful = request_object.get('error_code') == '0' and request_object.get('action') == 'confirmed'
if transaction_successful:
  # everything is ok

Creating a response

You need to let mobilPay know if everything is ok on your end or if something weird happened. If everything is ok you can create a response like this:

message = "All good captain"
response_xml = client.create_reponse(message=message)

If you had an error:

# message that will help you debug. it will appear in your dashboard
message = "Everything is on fire"
# this can be "1" (temporary error) or "2" (permanent error)
error_type = "1"
# your internal error code. a number maybe. OPTIONAL
error_code = ''
response_xml = client.create_reponse(message=message, error_type=error_type, error_code=error_code)

The response doesn’t need to be encrypted. Just respond with the xml.

Crediting

If a transaction was credited from the Dashboard, mobilPay will make a new webhook POST. You can check for that:

# if the transaction was credited from mobilpay
if request_object.get('action') == 'credit':
  # do something
  # return a reponse

TODO

Some things that still need to be done:

  • tests

  • add support for: instalements, recurrence

  • maybe add prefilled credit card data payments?

Disclaimer

This library is not associated in any way with mobilPay

Metadata

Release files for mobilpy 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mobilpy 0.4.1
File Size Uploaded
mobilpy-0.4.1.tar.gz 6.4 kB Details

Release files / mobilpy-0.4.1.tar.gz

Download URL mobilpy-0.4.1.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e593f2384759b09178e0e07f81ce20a3d775a7f514c443d411e2f19b0a824a9a
BLAKE2b-256 checksum
How to use checksums
177cdacdc6bceb89e01ad0bc8dfa0d8bc6efe472cfcdbfd82679fea3d9213e22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release history Release notifications | RSS feed

This release

0.4.1 This release

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page