Stripe integration with Django rest and Angular/Cli - django

I want to create a stripe payment integration using Django Rest Framework as backend and Angular/Cli as frontend. And also I want to confirm the payment using stripe webhooks. I could not able to find Angular documentation just for the only frontend. And also the Stripe docs are generally has written for flask and not for the rest framework. Any help will be appreciated. Thank you in advance.

I've found a library and some newer docs that I think will solve your issues: https://richnologies.gitbook.io/ngx-stripe/core-concepts/checkout
Using the ngx-stripe library as a wrapper, you can setup the publishable key on your front end. The library then offers a StripeService.
If you setup some custom endpoints on your backend to handle the dirty work (accept payments, create customers, etc), you can have then have the StripeService listen for the response and react accordingly (create a checkout session, display payment successful message, etc.)

Related

Implementing Stripe with React-native and Django

I am using React-native for mobile app and Django as server. How to implement stripe payment gateway? How I can make a payment and send the response to the backend so that in backend I can handle which user is now subscribed?
In web we can do that using stripe-session url. We can hit the url and after successful payment it's return an id, I have to just post the id to the server.
How can I do that with react-native because by doing so I am kicked out from my app and the session url opens in the browser, i can make the payment successfully but cannot redirect to the app.
How to successfully I can implement this with react-native and django?
According to the Docs, React Native provides the Fetch API. You should be able to make POST requests to your Django back-end that way.
You may run into issues with authentication (since Django POST request require CSRF tokens). There are many docs about this topic and you should be able to find a solution that meets your needs with a few searches.
As for how to implement your Stripe payment flow, that depends on how you want to collect payment details for your subscriptions. Stripe public docs have many useful examples from using a Stripe hosted Checkout page, using Stripe Payment Elements, or using the basic Quickstart example to get you started. The Python back-end uses Flask instead of Django but it is not difficult to understand how to translate the functionality from one framework to another.
As a back-up and general best practice, consider utilizing webhooks to ensure your back-end is aware of changes to Stripe records. Financial networks include many asynchronous processes and it's a good idea to not just rely on the Request <-> Response loop.

Django rest framework and frontend

I want to use Django Rest Framework to create RESTAPI to integrate with the payment gateway API like stripe. For the frontend part I can only see project using React for the frontend. Cant i use Django as a frontend?
Looking for suggestions if i really just need to use React or Vue. Or is it possible to use django as frontend as well.
Looking for your suggestions. Thank you.
To use Stripe in Django, you may refer to this package https://github.com/dj-stripe/dj-stripe which supports Stripe out-of-the box specific for Django
For replacing React with Django for front-end, it is possible and you can use Django template, however, it depends on your use-case.

Django REST authentication with React/ Redux

I am building a web app with a Django backend and React/Redux frontend running on separate servers. I have begun to try and start working on authentication and I cannot find a tutorial that suits my needs. Every tutorial either uses deprecated modules like drf-jwt (as opposed to simple-jwt) or has a simple mono-server that houses both the backend and the frontend in one directory. The former is useless and I do not want to do the latter as I like having the two separate servers for when I move on to deployment. Now can someone direct me to a good source of knowledge for getting this done? It doesn't have to be a tutorial it can be anything. I am really lost and I do not know how to begin.
you can use 3rd party packages djoser: Provides a set of views to handle basic actions such as registration, login, logout, password reset and account activation. for more information: https://pypi.org/project/djoser/
I'm using token authentication from Django Rest Framework so, after a login/password verification, the token on response can be used on any DRF endpoint.

Flutter app with Django backend and google authentication

i would like to create a flutter app, with social authentication (Facebook & Google) connected to a Django DRF backend.
I could not find any examples for handling the social authentication at the back-end coming from a flutter app, i only found firebase based tutorials.
Any libraries that work this way? in case there aren't, how could i send the required social account from the phone to my backend?
Thanks!!
I suggest you to use the Google Auth Library for Ruby (because you are using Django) and expose a service that wrap the API and consume the google libraries.
With your API created you can create a Provider / BLoC or whatever State Management you use in Flutter using the Dart Package Http to consume your own Django backend API
If you have any trouble using HTTP Dart/flutter package let me now to create and example

Where should stripe be integrated in single page application with django backend

I am new to stripe integration. I've looked at couple of examples but I'm unsure where I should integrate stripe in my application. My front-end is in Angular and the backend is in django. Should I integrate stripe in Angular code base or django code base?
Both. Front-end: either use Checkout (Embedded Form) or their Custom Form. This will spit out a token that you must process on the server side. If you are using routing or have a complex app, then you probably want a library to abstract away from Stripe's default behaviors, as it uses a simple form action. This will cause a reload or redirection from the page which could be a problem if you don't want to leave the app. I prefer this lightweight wrapper, though others exist: https://github.com/tobyn/angular-stripe-checkout
Server: You include their library for your language (Python if you want) in a script written to process the token. This is what actually sends the charge to Stripe. Just doing the front-end side only sends them a token which shows up in the logs but does nothing. This is where you create a new customer, charge, subscription, etc. according to the API for your language.
Once you've got that set up, then you'll probably want to listen for their webhooks, save the user that is created in your backend with its created from the initial payment, etc.
You can integrate it both in the front-end and back-end, but if it's a single page app and the backend is REST-ful it makes sense to do it in Angular
See this article for example: https://www.airpair.com/javascript/integrating-stripe-into-angular-app