Integrate Stripe payment with a card in python

Mishraranjeet
2 min readAug 29, 2020

--

Although there is well documentation provided by stripe for all features in various programming languages. I have to spend some time to integrate stripe payment through card details. There is a lot in detail description in documentation and sections which we don’t want to go through.

Here, I concise those steps that need to do for payment integration with Stripe using python. Here you will learn to integrate stripe payment to your application.

I assume you have stripe access keys already if you have not you can generate API keys going through steps in this link API KEYS.

Basically, the steps involved in payment integration are as follows.

  1. Create a card token from card information.
  2. Create a payment charge using the obtained card token.

1. Create a card token from card information

The card token generated can be used only once at a time. to generate a card token following card details required.

  1. 16 digit card number
  2. card expiry month and year
  3. card CVV number

Here at last the script contains a python function that will generate card token using above mentioned card details and return a token response which consists of a token id and other parameters in JSON format. we extract token id only and use that to create a payment charge.

2. Create a payment charge using the obtained card token

To create a charge from card token we need to pass the token id and amount in cents. The payment amount can be in different currencies like US dollars or the Australian dollar but the amount needs to be converted in cents.

Here the script contains the two python functions one to create card token and one to create payment charge which creates the payment.

Conclusion

Here we set up stripe payment within two steps in python. if you want more detail on payment integrations you can visit the stripe API documentation. You can get complete integration including frontend with all the codes and files in my Github repo [ LINK ]

Thanks for your time. do write comments and suggestions if any thank you.

--

--

Mishraranjeet

Software Engineer | Web Developer | Enthusiastic to learn and teach new technology