Pre-requisites #
- Create an account on Payunit as a merchant. Click to create an account.
- Get the merchant Api User, merchant API key, and merchant API Password from the merchant dashboard under the credentials section.
Installation #
Usage #
Now, proceed to creating a payment instance with payUnit( ) .
from payUnit import payUnit
from flask import Flask,render_template,request
app = Flask(__name__)
payment = payUnit({
"apiUsername":'',
"apiPassword":'',
"api_key":'',
"return_url": "",
"notify_url":"",
"mode": "",
"name": "",
"description": "",
"purchaseRef": "",
"currency": "",
"transaction_id": ""
})
# main driver function
if __name__ == '__main__':
app.run()
That set, payments can now be done by using makePayment( ) method, with the transaction amount as parameter.
payment.makePayment(5000)
Configuration
- To Test Visa/Master Card in the Sandbox environment use the following information :
- Card Number: 4242 4224 2424 2424 or 2223 0000 4840 0011
- To test PayPal in the Sandbox environment use the following credential :
Attribute | Description | Mandatory |
apiUsername | Merchant Api Username gotten from merchant dashboard under credentials section | yes |
apiPassword | Merchant Api Password gotten from merchant dashboard under credentials section | yes |
api_key | Merchant Api Key gotten from merchant dashboard under credentials section | yes |
mode | The current mode operation. Can either be “test” when testing in sandbox or “live” when ready for production. | yes |
return_url | The url or endpoint to be called upon payment completion | yes |
notify_url | The url or endpoint to submit a transaction response to.
This url or endpoint accepts a POST request of format: { “transaction_id:”6465464”, “transaction_amount”:”5000″, “transaction_status”:”SUCCESS”, “error”:null, “message”:”Transaction of 5000 XAF was successfully completed” } | no |
purchaseRef | A reference which you can give from your end to a particular transaction | no |
total_amount | The amount or price of the product/products to be paid for. | yes |
description | A description you can give to this type of transaction | no |
name | Name of the merchant | yes |
currency | Can be XAF, USD or any currently supported currency | yes |
transaction_id | id that uniquely identifies the transaction and I must be unique for a transaction. This id should be alpha numeric and less than 20 characters | yes |
Recommendations #
For security concerns, make sure you read your Api key, Api password and Api user from a config file.
Consider saving your API credentials in environment variables for an extra layer of security. You can find a Flask demo app using payunit on github here
https://gitlab.com/sevencommonfactor/payunit-python_demo.git