Package: django-proxypay
django-proxypayDjango Proxypay is aDjango Frameworkapplication/library that facilitates the integration of your Django project with theProxypayAPI. Allowing to generate referrals, recognize payments and look through Proxypay's webhooks.If you are looking for a Python alternative that doesn't use any framework, maybeproxypay-pycould be useful.proxypay-pyis the official Proxypay library maintained byTimeBoxedSome FeaturesThe Django Proxypay really comes to facilitate the integration to the Proxypay API, leaving all interaction with Proxypay totally out of the box. Letting you focus more on data validation and / or the FrontendGenerate references and store them in the databaseVerify payment directly from a reference instanceAcknowledge paymentRecognize payments automatically using Proxypay webhooksMock Payment, for development testsOf course, Signals, notifying you when a payment is recognized or a reference is created or updated.InstallationSimpledjango-proxypaycan be installed withpip:pip install django-proxypayOr from this repository:pip install -e git+https://github.com/txiocoder/django-proxypay.git@master#egg=django-proxypayRequirementsPython3.8;Django3.0;requests2.23django-admin-displayThese are the officially supported python and package versions. Other versions will probably workConfigurationsAs stated above, Django Proxypay is a Django Application. To configure your project you simply need to addproxypayto yourINSTALLED_APPSand configure thePROXYPAYvariable in thesettings.pyfilefor more details on how to configure the PROXYPAY variable, access the proxypay.conf fileLike the example below, filesettings.py:# Your project applicationsINSTALLED_APPS=['proxypay',]# Proxypay ConfigurationsPROXYPAY={# (str) Your Proxypay authorization token key'PRIVATE_KEY':os.environ.get('PP_PRIVATE_KEY'),# (int) Your Proxypay Entity ID'ENTITY':os.environ.get('PP_ENTITY'),# (int) Optional, Default: 1# days to expire a reference'REFERENCE_LIFE_TIME_IN_DAYS':os.environ.get('PP_REFERENCE_LIFE_TIME_IN_DAYS'),# (bool) Optional, default: False# If True, proxypay.payments.watch will return status 200# if a payment confirmation is sent whose reference has not been registered'ACCEPT_UNRECOGNIZED_PAYMENT':os.environ.get('PP_ACCEPT_UNRECOGNIZED_PAYMENT'),# (bool) Optional, default: True# If true, in sandbox env mode fictitious payments will be processed automatically without the proxypay webhook.# Useful if you want to test local payments without configuring the endpoint watch payments on proxypay'ACKNOWLEDGE_MOCK_PAYMENT_LOCALLY_AUTOMATICALLY':os.environ.get('PP_ACKNOWLEDGE_MOCK_PAYMENT_LOCALLY_AUTOMATICALLY')# (str) Optional, the proxypay api environment to use# If not set, by default Proxypay will use the sandbox environment if settings.DEBUG is True# and produnction if is False# If set, the value must be sandbox or production'ENV':os.environ.get('PP_ENV'),# (tuple) Optional# fees# fee must be a tuple in this order: Fee Name, Fee Percent, Min Amount, Max Amount'PROXYPAY_FEE':('Proxypay',0.25,50,1000),'BANK_FEE':(None,0,0,0),}Note: That's all, make sure to run the database migrations. Using the commandspython manage.py makemigrationsandpython manage.py migrateto generate a table of References in the databaseBasic useCreating references and verifying paymentsUse theproxypay.references.createmethod to create new references. This method will return an instance ofproxypay.models.Reference. Which you can use to verify payment and other data such as related entity, reference id and morefromproxypay.referencesimportcreate##### Creating References## simple like thatreference=create(1780.78)# orreference2=create(# the reference amountamount=3500,# (dict) Optional, custom_fields to add to refence instance and proxypay payment data# Make sure to use just stringsfields={'product':'some','service':'some service name'},# (int) Optional, Number of days to expire the referencedays=3,)# Check if a reference was paid / Acknowledge Payment for this reference# will return False or the payment data from Proxypay API in a dict structurepayment=reference.check_payment()Proxypay Webhooks, watching for paymentsYou can avoid manually checking for paid references. Django Proxypay comes with a view ready to keep an eye on the Proxypay API Webhooks. This view will check the signature, find the relatedproxypay.models.Referenceinstance and update as paid. At the end it will trigger thereference_paidsignal.To use, you only need to add the endpoint that will be used by the Proxypay API. As in the example below. In yoururls.pyfile:# django stuffsfromdjango.urlsimportpathfromdjango.contribimportadmin# proxypay watch payments viewfromproxypay.viewsimportwatch_paymentsurlpatterns=[path("admin/",admin.site.urls),# Note, the URL name can be whatever you wantpath('proxypay-payments',watch_payments),]Note: Don't forget to configure the endpoint in your Proxypay accountWorking with SignalsSignals are the best way to keep an eye on new reference or new payments. So, in yoursignals.pyfile:fromdjango.dispatchimportreceiverfromproxypay.signalsimportreference_paid,reference_created# receive a paid reference@receiver(reference_paid)defhandle_paid_reference(sender,reference,**kwargs):# will print out the referenceprint(f"Reference{reference.reference}was paid!")# You can also check the payment data received  from Proxypayprint('(dict) Payment Data: ',reference.payment)# receive a created reference@receiver(reference_created)defhandle_created_reference(sender,reference,**kwargs):print(f"Reference{reference.reference}was created!")Mock PaymentIn development mode, you can create fictitious payments to test your application. Using Django'smanage.pyin your terminal like below:# reference ID or keypythonmanage.pyproxypaypay123902092This command will search for the reference in the database, if found and has not yet been paid, it will make the payment. This time, the signal will be triggered, and you will be able to simulate it as if the payment confirmation came from Proxypay's Webhooks. To perform desired operationsAPI ReferenceOkay, let's see how far django-proxypay can help you...