Introduction

Have you ever wanted to create an app in which the users would have to pay a few one-time fees and have a periodic subscription as well? On the one hand, you’d like to keep as much information as needed to have control over your customers and their payments. On the other hand, credit cards data are really sensitive, and storing them in your database would be very risky.

Fortunately, there’s a very interesting solution. Integrating your app with Stripe will save you time and provide a really clean and safe payment process. With its extensive API, you’ll be able to implement any type of money transaction you can imagine, and, moreover, all sensitive data will be secure in the Stripe cloud.


Our Goal

For the purpose of this article, we’ll create a simple app using the Django REST framework for our API back end and React for the front-end side.

Main flow of our app

  1. The user provides his email and credit/debit card data.
  2. We create a new Stripe customer based on the data the user provided.
  3. The user will be charged with a one-time fee for creating an account.
  4. The user will also be signed up for the monthly subscription to keep his account active.

Seems quite simple, doesn’t it? So let’s start!


Set Up the Django API

Assume we’ve already created a Django project called StripeApp with the Django REST framework library installed.

Let’s create a new app in our StripeAppproject root

python manage.py startapp payments

Our project structure should look like that (make sure you have the files with bolded names, and create missing ones, if needed):

- StripeApp/
  - payments
    - migrations/
    - __init.py__
    - admin.py
    - apps.py
    - models.py
    - tests.py
    - urls.py
    - views.py
  - stripeapp/
    - __init.py__
    - settings.py
    - urls.py

Install the Stripe library

pip install --upgrade stripe

#stripe #react #python #javascript #programming

Add Stripe Payments to Your Your Django and React App
26.95 GEEK