Home > Software design >  How to connect a payment system in django?
How to connect a payment system in django?

Time:09-07

I'm new to the Django framework and I don't quite understand how to connect the payment system to the site, at the same time, so that part of the payment for the product goes to the balance of the user who exposed it, and 10%-20% of the amount goes to the balance of the service. And what is the best way to connect a payment system for individuals.faces?

CodePudding user response:

So, you need to answer yourself a few questions like:

  1. What payment provider I need? It need to be paypal, stripe or...?
  2. If I know what payment provider I need, is there package for django (or python) for it?
  3. If yes, it is up-to-date?
  4. If no, were there updates to API or solutions described in payment provider documentation?
  5. Are they better in any term?

Depending on these answers, you could go straightforward to implementing payments using external library (for e.g. https://django-paypal.readthedocs.io/en/latest/) or just implement it yourself. In my situation when I implemented paypal payments in e_commerce store I just went with paypal buttons because they were looking better, and they, so far work more nicely.

What also you must mostly implement is something that Paypal calls IPN (instant payment notifications). Stripe, and for example TPay also has IPN-like mechanisms. The IPN is simply an view (functional or generic) that handles payments using data with usually md5 verification, where you update status of order to COMPLETED or et cetera.

The lack of security validation can make endpoint vulnerable to custom requests made by postman, curl or any kind of HTTP-testing tool.

For models - you should write them yourself or use provided by package. This usually means that with multiple payments you store one model per provider with ForeignKey to Order global model that collects all the data. You could use also abstract models for implementing multiple models with similar fields, but this causes some database query issues for additional logic handling (you can't query abstract models, so you need to parse stuff using forloops when you need it instead of using filters).

Frontend is also depending what you will use, but remember about not having price as hidden input :)

The thread is much bigger as it seems, but I hope I gave you point-of-view of the topic.

  • Related