Package: django-moncash
Digicel Moncash API SDK for DJANGODigicel MonCash - MonCash is a mobile wallet that facilitates reliable, safe and convenient financial transactions to reduce the distance between people regardless of their location in Haiti. While providing its services to its customer base of over 1.5 million people, MonCash maintains its goal of expanding its range of available services.Define: SDKSDK stands for “Software Development Kit”, which is a great way to think about it — a kit.
Think about putting together a model car or plane. When constructing this  model, a whole kit of items is needed, including the kit pieces themselves, the tools needed to put them together, assembly instructions, and so forth.FeaturesCreate paymentConsume paymentVerify paymentInstallationMoncash requiresDJANGOv2.2+ to run.Install the the SDK and start using it.Install using pip with:pipinstalldjango_moncashAdd django_moncash app to INSTALLED_APPS in your django settings.py:INSTALLED_APPS=(...,'django_moncash',)Run the migrations:pythonmanage.pymakemigrationspythonmanage.pymigrateConfiguring the clientDigicel Moncash APIDashboard.Each business has it's ownclientIdclientSecretpairs.Add credentials in your django settings.py:MONCASH={'CLIENT_ID':'YOUR_CLIENT_ID','SECRET_KEY':'YOUR_SECRET_KEY','ENVIRONMENT':'sandbox or production'}Include django_moncash.urls in your django project urls.py:fromdjango.contribimportadminfromdjango.urlsimportpath,includeurlpatterns=[path('admin/',admin.site.urls),path('payment/',include('django_moncash.urls')),path('',include('test_app.urls'))]On the Digicel Moncash APIDashboardsetup the business return url to be "https://yoursite.com/payment/moncash"Note that "payment" is the base route you chose when your urls.py (path('payment/',include('django_moncash.urls')))Create PaymentThe only supported currency is 'HTG'.With the configue above.fromdjango.shortcutsimportredirectfromdjango_moncash.utilsimportinit_payment#viewsdefbuy(request):"""params:request,                  # django views requestamount: float,            # amount to payreturn_url: str = None,   # custom return_url, default to current vieworder_id: str = None,     # unique order_id, default uuidV4meta_data: dict = None    # meta_data associated to the request"""payment=init_payment(request,50)print(payment)returnredirect(payment['payment_url'])""" output:{"payment_url":https://'<sandbox|"">'.moncashbutton.digicelgroup.com/Moncash-middleware/Payment/Redirect?token='<token>',"transaction":Transaction<object>}"""Verify PaymentTwo way to do so.By moncash_transaction_id or request if on the "return_url" view.fromdjango.httpimportHttpResponsefromdjango_moncash.utilsimportverify_payment#viewsdefverify(request):"""params:request,                             # django views requestmoncash_transaction_id: str = None   # custom moncash_transaction_id, default to "request.GET.get("transactionId",None)""""payment=verify_payment(request)print(payment)returnHttpResponse("payment succeed.")""" output:{"transaction": Transaction<object>,"transactionId":"XXXXXXXXXX"}"""Consume PaymentTwo way to do so.By moncash_transaction_id or request if on the "return_url" view.fromdjango.httpimportHttpResponsefromdjango_moncash.utilsimportconsume_payment#viewsdefconsume(request):"""params:request,                             # django views requestmoncash_transaction_id: str = None   # custom moncash_transaction_id, default to "request.GET.get("transactionId",None)""""result=consume_payment(request)print(result)ifresult["success"]:returnHttpResponse("payment successfuly consume.")returnHttpResponse("payment failed to be consumed.")""" output:# if already consume{"success":False,"error":"USED","payment":{"transaction": Transaction<object>,"transactionId":"XXXXXXXXXX"}}# if not found{"success":False,"error":"NOT_FOUND"}# if consume successfuly{"success":True,"payment":{"transaction": Transaction<object>,"transactionId":"XXXXXXXXXX"}}"""The difference between verify_payment and consume is that verify_payment didn't change the status of the transaction#Possible transaction statusfromdjango_moncash.modelsimportTransactionTransaction.Status.PENDING# before paymentTransaction.Status.COMPLETE# after paymentTransaction.Status.CONSUME# after consumeError handlingList of errors in moncash.exceptionsfrommoncash.exceptionsimportNotFoundErrorfromdjango.dbimportIntegrityErrorfromdjango_moncash.modelsimportTransactionList of errorsFrom moncashAuthenticationErrorAuthorizationErrorGatewayTimeoutErrorConnectionErrorInvalidResponseErrorConnectTimeoutErrorReadTimeoutErrorTimeoutErrorNotFoundErrorRequestTimeoutErrorServerErrorServiceUnavailableErrorTooManyRequestsErrorUnexpectedErrorUpgradeRequiredErrorFrom djangoIntegrityErrorTransaction.DoesNotExistCurrent Transaction modelclassTransaction(models.Model):classStatus(models.TextChoices):PENDING='PENDING',_("Pending")COMPLETE='COMPLETE',_("Complete")CONSUME='CONSUME',_("Consume")user=models.ForeignKey(User,on_delete=models.SET_NULL,null=True,blank=True)order_id=models.CharField(_("Order id"),max_length=50,default=uuid.uuid4,unique=True,editable=False)amount=models.DecimalField(_("Amount"),max_digits=11,decimal_places=2,blank=False,null=False)status=models.CharField(_('Status'),max_length=25,choices=Status.choices,default=Status.PENDING,blank=False)return_url=models.TextField(_("Return URL"),blank=False,null=False)meta_data=models.JSONField(_("Meta data"),null=True,blank=True)created_at=models.DateTimeField(auto_now_add=True)updated_at=models.DateTimeField(auto_now=True)DevelopmentRun all tests.pythonload_tests.pyDonate to support usScan and donate using the Moncash AppOr Tranfer to:(+509) 48-02-0151LicenseGNU GENERAL PUBLIC LICENSEVersion 3, 29 June 2007Useful linksPypi package linkDigicel Moncash API DashboardRestAPI_MonCash_doc.pdfLow level SDK for python