Sèlman pou HTG 850💸 - Aprann kreye sitwèb ak Django . Rezève plas ou... Learn more.

Implement Moncashify Sdk In Your Python Projects

Last update: Dec. 9, 2020, 5:24 p.m.
Tags : Web development , Programming , Mobile Development
Duration : 2 min
Views : 243
Available in : English

In this tutorial, I will teach you how to implement the moncashify sdk to accept payments from your customers using the Moncash API. This tutorial can be used in any python project.

This package is compatible with python 2 or 3, so you don't really need to worry about which version you are using. In my case, I am using Python 3.7.

Moncashify can be installed with pip - go to your terminal or cmd and type the command below:

pip install moncashify

Once you have installed it, you can open your project to start using the sdk.

I have a customer who bought in my store, a shoe that costs 1500 HTG. This shoe has a unique ID in my database which is SH023. The objective here is to charge the customer, 1,500 HTG from his Moncash account.

Set up your Moncash dashboard

To configure your Moncash dashboard, you must have an account. Click on this link to create your own account. Once in the dashboard, go to the General info section to add your business info

enter image description here

After saving all of your business information, you will have client_id and client_secret

Make sure you have these credentials somewhere, as you will need them.

Client Id: f443363451e40d926edd8ff3eb59ca7
Client Secret: fqCEN-jbcK9K_iterjkkjgdUusd1i64cfFg4-LOnqPeS6PO6tDP2KmXwsYjBAt6C

Initialize the process

To start the process, just import the package

import moncashify

Note that I will use the name secret_key instead of client_secret.

client_id = "f443363451e40d926edd8ff3eb59ca7"
secret_key = "fqCEN-jbcK9K_iterjkkjgdUusd1i64cfFg4-LOnqPeS6PO6tDP2KmXwsYjBAt6C"

order_id = 'SH023'
amount = 1500 # HTG

moncash = moncashify.API(client_id, secret_key, True)

The third argument is for debugging, when I set it to True, it means I am testing the gateway. When you are in development, MonCash will not debit the account and will also use a different URL to make the payment.

The variable moncash is the instance to use to make the payment

payment = moncash.payment(order_id, amount)
# Payment object - Order ID: SH023, Amount: 1500

And there you are, you've made your first payment. Use the redirect_url attribute of the instance, to get the redirect URL that the client will use to pay.

url = payment.redirect_url
# https://sandbox.moncashbutton.digicelgroup.com/Moncash-middleware/Payment/Redirect?token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjQ1NzgiLCJyZWYiOiJTSDAyMyIsImNydCI6MTU5MTgwNTA0MzQ2NCwiZXh0IjoxNTkxODA1NjQzNDY0LCJhcGkiOnRydWV9.t82yPlU7lk8qEDbVIu_py1dNW89LXsjwkxzcOUm7hvHFbaat3qauiPt30_dBEjhnGt_G-7YuwwdlKhhmWMRFh6HbaRWrDtHwsWripq2If27AOlFsa5TOY8AygEIu79u-QzvOv2u_7rR6VNAejhflPMc5UuK4NJuzcsFR4Z5vy0hI_ZSCrSlz1clZMEqtUtfzshQT4tIQWIG8Vco2DTNMZ9lQmyFqQ2BkXIp19WTS61ot0BAdDxatE7ApF8L4o3KA76wMizIOdNyGA6XH4xMqa6VCU-JoQcH2K56BOUFU9oNLBQwAjh46e5AWy2TCsIE52pYsg4pnFq5HFiIalUGdww

The token in the url as query parameter, is generated by the Moncash API. Actually, the API sends more information, and to get all of it, just call payment.get_response().

Open a browser, visit the link and fill out the form with your test account. If you don't have a test number yet, go to the MonCash dashboard and click Add Test Account to create it. By filling this form, you are acting as a customer.

With this test number, you can proceed to the payment test. Once you're done with everything, the MonCash API will redirect you to the link provided in Return Url when you were filling the business form.

You can also get the transaction details with the order_id

transaction = moncash.transaction_details(order_id=order_id)
# or 
transaction = moncash.transaction_details_by_order_id(order_id)

I built this SDK to help you as a pythonist benefiting from the MonCash API. I hope this tutorial will help you implement the SDK very well. If you want to know more about all the features, go to the official documentation

's avatar

by Lub Lorry Lamysère on Jun. 10, 2020

Software Developer | Entrepreneur

Comments (2)
's avatar
Desir Renaldo 1 month, 3 weeks ago

Salut,mp devlope yon app ak kivymd m pa wei kote nan api a,pou mw mete numewo cliyan an,edem svp

Like 1 Dislike Reply

Replyies (2)

's avatar
Lub Lorry Lamysère 1 month, 2 weeks ago

Nimewo kliyan, wap jwenn li sou Dashboard moncash la. Ou ka anrejistre nimewo sa kote w vle, depi l sekirize. Pou w itilisyalize koneksyon ak Moncash la, ou kapab fe l la `moncash = moncashify.API(client_id, secret_key, True)`

Like Dislike Reply
's avatar
Desir Renaldo 1 month, 1 week ago

Yah m jwenn yn fason m fel mute,nan yon WebView

Like Dislike Reply
's avatar
Lub Lorry Lamysère 1 year, 3 months ago

Ah! email me at lemayzeur@code9haiti.com for further details

Like 1 Dislike Reply