Package: django-spgateway
Write Django and your store as usual, and letdjango-spgatewayhandle your transactions with SpgatewayRequirementsPython 3.7Django 2.1pycrypto 2.6.1We only tested on environment as belowInstallationInstall using pip or pipenv:pip installdjango-spgagewayAlternatively, you can install download or clone this repo and callpip install-e..Add to INSTALLED_APPS in yoursettings.py:'spgateway',Add settings in yoursettings.py:SPGATEWAY_PROFILE={'YOUR_MerchantID':{'MerchantID':'YOUR_MerchantID','HashKey':'YOUR_HashKey','HashIV':'YOUR_HashIV',},}SPGATEWAY_MERCHANTID='YOUR_MerchantID'SPGATEWAY_ORDERMODEL='yourapp.Order'Add urlpattern into yoururls.py:path('spgateway/',include('spgateway.urls')),for Django 2url(r'^spgateway/',include('spgateway.urls')),for Django 1Importfrom spgateway.models import SpgatewayOrderMixinand inherit from it with your order model.Runpython manage.py makemigrationsandpython manage.py migrateas usual.Get form from your order by callinggenerate_credit_formin view:credit_form = order_object.generate_credit_form(request)And use it in your template:<form action="{{credit_form.action}}" method="POST">{{credit_form.as_p}}<input type="submit">
</form>AddSpgatewaySameSiteCookieMiddlewarebeforeSessionMiddlewareto avoid SameSite cookie while return from payment gateway:MIDDLEWARE=['django.middleware.security.SecurityMiddleware','spgateway.middleware.SpgatewaySameSiteCookieMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware',...]Example modelfromspgateway.modelsimportSpgatewayOrderMixinclassOrder(SpgatewayOrderMixin,models.Model):total=models.IntegerField(default=0,verbose_name='Total Price')user=models.ForeignKey(User,verbose_name='Order by user')is_paid=models.BooleanField(default=False)# Add this parameter to let django-spgateway know which field is amount of priceSpgatewayAmtFieldName='total'# Add this parameter to let django-spgateway set item descriptionSpgatewayItemDesc='Items descriptions'# Add this method to let django-spgateway retrieve emaildefget_SpgatewayEmail(self,**kwargs):returnself.user.email# Add this method let django-spgateway call when notify from Spgateway server# Change your order with this methoddefspgateway_notify(self,request,trade_info):status=trade_info['Status']status_msg=trade_info['Message']ifstatus=='SUCCESS':self.is_paid=Trueself.save()else:# TODO: Handle error# Add this method let django-spgateway call when client return from Spgateway server# Never trust data from client. Display messages onlydefspgateway_return(self,request,trade_info):status=trade_info['Status']status_msg=trade_info['Message']ifstatus=='SUCCESS':# TODO: Display success message to userelse:# TODO: Display error message to user# django-spgateway will call this method to redirect user after user return from Spgateway serverdefget_absolute_url(self):returnreverse('ORDER_DETAIL_VIEW_NAME_HERE')Bugs and suggestionsIf you have found a bug or if you have a request for additional functionality, please use the issue tracker on GitHub.https://github.com/cjltsod/django-spgateway/issuesLicenseYou can use this under MIT. SeeLICENSEfile for details.AuthorDeveloped and maintained byCJLTSOD.Thanks to everybody that has contributed pull requests, ideas, issues, comments and kind words.Please see AUTHORS.rst for a list of contributors.