Package: django-vpos
Django vPOSDjango vPOS is aDjango Frameworkapplication/library that facilitates the integration of your Django project with thevPOSAPI Payment Gateway.Some FeaturesThe Django vPOS really comes to facilitate the integration to the vPOS API, leaving all interaction with vPOS totally out of the box. Letting you focus more on data validation and/or your business logic.Verify payment directly from a transaction instanceRecognize confirmed transaction automatically using vPOS callback urlSignals, to get dynamically confirmed transactions instancesInstallationSimpledjango-vposcan be installed withpip:pip install django-vposOr from this repository:pip install -e git+https://github.com/txiocoder/django-vpos.git@main#egg=vposThese are the officially supported python and package versions. Other versions will probably workConfigurationAs stated above, Django vPOS is a django Application. To configure on your project you simply need to addvposto yourINSTALLED_APPSand configure theVPOSvariable in thesettings.pyfile. More details about how to configure theVPOSvariable below.INSTALLED_APPS:list=['vpos',]VPOS:dict={'TOKEN':'your-vpos-token','POS_ID':1234,# the base callback url without slash at end'URL':'https://youproject.com/path/to/confirm','MODE':'production'}Then, addvpos.urlsto your URL configuration to route and handle all transaction confirmation coming from vPOS API callback.In yourproject.urls:fromdjango.urlsimportpath,includeurlpatterns:list=[path('path/to/confirm/',include('vpos.urls'))]Here the details about all attributes accpeted inVPOSAttributeTypeRequiredDescriptionTOKENstrTruevPOS API Authorization TokenPOS_IDintTrueThe Point of Sale ID provided by EMISURLstrTrueBase Callback URL to handle transaction confirmation from vPOS APIMODEstrFalseThe vPOS environment:production(default) orsandboxVPOS_SUPERVISOR_CARDsrtTrueThe Supervisor card ID provided by EMISVPOS_BASE_URLstrFalsevPOS API base URL.https://vpos.ao/api/v1(default)VPOS_TEST_SUPERVISOR_CARDstrFalseThe Supervisor card for test, provided by vPOSWorking with TransactionsUse thevpos.references.createmethod to create new payment or refund transactions. This method will return an instance ofvpos.models.Transaction, which you can use to request payment/refund, check payment confirmation, get transaction data fromvPOS APIand more.fromvpos.transactionsimport(Transaction,create)# first, create payment transaction instancet1:Transaction=create(mobile='900000000',amount='34500.45')# then, request the paymentt1.request()To create refund transaction, only specify the payment transaction to be refunded in create method. As shown below. Parent transaction must be an accepted payment transaction instancefromvpos.transactionsimport(Transaction,create)# first, get the payment transactiont1:Transaction=Transaction.objects.get(id='transanction-id')# second, create refund transaction instancet2:Transaction=create(parent=t1)# then, request the refundt2.request()If you prefer to use polling communication to manually check the transaction confirmation, instead of callback url. Just setpolling=Trueastransaction.requestargumentt1:Transaction=create(mobile='900000000',amount='34500.45')t1.request(polling=True)# then, check the paymentt1.check_payment()# You can also wait some time until the confirmation.# This will wait at maximum 90 seconds. But first it will try to use the estimate time provided by vpos ETA.# see: https://developer.vpos.ao/?shell#requestst1.check_payment(wait=True)Callback URL (Watch Payments)To dynamically receive transaction confirmations from vPOS API, you only need to setup theURLkey inVPOSvariable configured in yoursettings.py.VPOS:dict={# other configurations...# the base callback url without slash at end'URL':'https://youproject.com/path/to/confirm'}Django vPOS will automaticaly recognize the related transaction and update the transaction data. To dynamiacly catch confirmed transactions see the session below about signals. And enjoy real-time payments update.Signals, Getting Dynamically Confirmed TransactionsSignals are the best way to keep an eye on transactions confirmations. Let's imagine the following simple scenario. Activating a service after confirming payments.First, the user need to request the service and payment. In your views you could do something like below:fromservice.modesimportServicefromvpos.transactionsimport(Transaction,create)defadd_service(request)->Response:# after validation and some business logic...# prepare the transactiont:Transaction=create(mobile=request.user.mobile,amount='1500')# create the service and add related transactionservice:Service=Service.objects.create(owner=request.user,is_active=False,payment=t)# request user to payt.request()returnResponse(status=201)Yeah, I know... but just keep it simple. Then, we can use signals to activate the service when the user pay the requested payment transaction. Django vPOS has thevpos.signals.transaction_completedsignal witch we can use to receive confirmed or completed transactions.fromdjango.dispatchimportreceiverfromservice.modesimportServicefromvpos.modelsimportTransactionfromvpos.signalsimporttransaction_completed@receiver(transaction_completed)defactive_service(sender,transaction:Transaction,**kwargs):if(transaction.acceptedandtransaction.is_payment):ifhasattr(transaction,'service'):service:Service=transaction.serviceservice.is_active=Trueservice.save()# publish the event...That's it, I hope this module can be useful for you. Feel free to contribute and help me improve this module.