django/commerce/paypal: keeping track of user transactions - django

currently I wish to integrate paypal payment into my application, so I downloaded django-paypal (dcramer) to test it out with the paypal sandbox. I tried the WPP express checkout payment as my primary payment flow, and have no problems with payment process, worked smoothly.
However like all e-commerce, I am aware that I should keep track of user transactions/payments in my application. This is where I am lost. I've checked the model table paypal_nvp in django-paypal, and there's no field that resembles a transaction-id with Paypal.
If so, how should I keep track of users' payments? Can I use the datetime + user as hash for my transaction id? How can I reference a particular transaction to a paypal transaction?
Anyone who used django-paypal or have experience with e-commerce in django please feel free to offer valuable suggestions.

In your database you should have a "paypal_ipn" table with the detailed transactions. You can use that table or you can create your own model for your transactions and link them together. There you will find the transaction-id under the name "txn_id". If you want to fire up a script when a transaction occurs you can use the #receiver(payment_was_successful) signal from djano-paypal. Hope this helps.

Related

How to differentiate Basic/Premium plan users for premium-only features in Django REST?

I am working on a beta-stage writing tool SaaS that is built with NextJS, React, and Django REST. As I’m gaining some user base, I am starting to research on introducing a premium plan to the mix using Stripe.
As most other SaaSs, I will have a subscription-based premium plan which grants access to premium-only features. However, even after days of research, I am still lost how this is commonly implemented in Django/Backend. Here is what I’ve thought of so far, but again, I am not sure if it’s the best/common way to accomplish this.
User model has a ‘premium’ field which is either True or False
Whenever user clicks on a premium-only API call, Django will check if user is premium or not to decide whether to make the actual API call. I currently have a '/user/me/' route which returns basic user information as API GET call.
Upon successful stripe payment, stripe redirects user to the success_url. Then, somehow I will detect when user lands on success_url and then set that user’s premium field to True.
I know this is not the ideal way, because I already see lots of issues/hurdles:
How will I set ‘premium’ field back to False after user’s payment stops
How can I ‘detect’ stripe’s payment to set user’s premium field
Is this feature supposed to be implemented with Stripe customer objects instead? I would appreciate any guidance on where I should be looking for solutions.
If you use subscription on Checkout Session (low code solution), you can add additional key-value pair data such as premium: true in metadata and subscription_data.metadata fields when creating a subscription.
Once the payment is completed, those metadata will appear in checkout.session.completed and customer.subscription.updated webhook events, which you can then set the user as premium in your own database.
A customer object in Stripe can have multiple subscriptions, so this feature will be implemented on subscription object instead.

How to connect a payment system in django?

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?
So, you need to answer yourself a few questions like:
What payment provider I need? It need to be paypal, stripe or...?
If I know what payment provider I need, is there package for django (or python) for it?
If yes, it is up-to-date?
If no, were there updates to API or solutions described in payment provider documentation?
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.

Django paypal checkout for WHOLE cart

I made a Django online-store site and I need to include paypal checkout system for the cart, but solutions I found online either just for one item only(Buy Now buttons) or something like django-paypal-cart, which is not well-documented and I can't figure out how to make it to the checkout.
Please, give me some hint, maybe good article about how to make your cart items go to the checkout, anything will be highly appreciated, I don't know what else to google now
There are numerous options for tying PayPal into your website or app. Depending on exactly what you're doing or how good you are with web service API's you may choose one or another.
If you want to keep things simple, you can stick with Payments Standard. This is basically what you're referring to about the one item only buy now button, but you can use the cart upload command method to build a form that includes multiple items and pass it all over to PayPal at once.
If you prefer web service API's I'd recommend using Express Checkout. This consists of SetExpressCheckout, GetExpressCheckoutDetails, and DoExpressCheckoutPayment. Read through that general EC documentation to get familiar with the calls and how it all flows.
Another thing I would highly recommend utilizing is Instant Payment Notification (IPN). This is a feature where PayPal will POST transaction data to a listener script that you have sitting on your server any time a transaction occurs on your PayPal account. This includes payments, refunds, disputes, cleared payments that were pending, etc. This allows you to automate tasks like updating your database, sending out custom email notifications, hitting 3rd party web services, etc. and it happens in real-time, so it's very powerful.

PayPal After checkout handling

I have a web service at which users can buy reports made on the fly using PayPals Express checkout process. I want to make sure that no matter how the user returns to the site (through paypals callback or by himself) he could download the report he payed for. For that I need to keep the report ID he has bought somewhere. Where and how would it be best to do that? (Cookies? Sessions Parameters?)
I am using ASP .Net C#.
Thanks,
Wess
Do the users have logins that are managed by you in your database? If so and you want the user to be able to return at any time to your page and download the report, then you'll need to use a PayPal callback to store in your database what report ID the user has purchased.
If you don't manage your users then I'm not sure how this can be accomplished because cookies are limited (and can be disabled by users) and sessions expire.

setup payment for django satchmo

this is a newbie satchmo question...so I've implemented satchmo for a django e-shop I am building. I have setup sathcmo following the tutorials, created some products, tested that I can make an order, and then switched to 'real mode', on http://site/settings, clicking on 'accept real payments'. The question is how I can setup the payments to be made on my bank account (a bank in Greece)?
I have not found any reference on this, so please help!
btw, on the checkout page, I get this
You'll need to fill out at least the fields with a *
How do you want to pay?
Payment method*
Payment test module
Gift Certificate
so what does payment test module means? Do I have to install another application? Currently setting.py contains
'payment',
'payment.modules.dummy',
'payment.modules.giftcertificate',
Thanks a lot for any help!
Satchmo has multiple payment methods. I am not sure exactly what payment methods would support interacting with your Greek bank account. Typically people use something like Authorize.net, paypal or google to collect payments.
Once you decide which processor you want to use, then we can help you decide if there's a processor available or if you'll need to build one.