Stripe Implementation Part I | Payment Gateway Integration | Postman Collection

Ravi Shankar Singh
DevMins
Published in
4 min readMar 2, 2019

Nowadays more and more people prefer not wasting their time in physical shopping trips, & otp, instead prefer to buy things or services online right from the comfort of their own home. It means that every merchant aims to increase their sale by integrating the online payment gateway.

As a developer integrating the payment gateway on the first attempt is not quite easy, sometimes without any knowledge of the flow of how the payment gateway works and how the customer can be charged. Payment gateway API docs are good but not enough to understand the exact flow to get started the implementation. I have also faced many problems understanding the flow in the starting and decided to write this blog to help the developer community not to face the same problem. Hope this will help you a lot and will give a basic understanding.

Before we begin…

Let us know something about Stripe.

Stripe is a payment gateway provider company that provides services to accept payments and manage businesses online. Whether you’re looking to bill customers on a recurring basis, set up a marketplace, or simply accept payments, It supports online and in-person payments.

To get started with this tutorial you need to have a stripe account just go to STRIPE OFFICIAL SITE and signup for a new account. Once you are registered you need to verify your registered email in order to use the API and test them by charging the customer.

On the Stripe Dashboard, you will get two keys :

  1. Publishable key e.g (pk_test_xxxxxxxxxxxxxxxxxxxx)
  2. Secret key e.g(sk_test_xxxxxxxxxxxxxxxxxxxx)

Do not share these keys with anyone these secret key are used to authorize for accessing the Stripe API.

Let's begin

Now you have a verified stripe account to get started with stripe implementation. We will be exploring the Stripe API doc and creating a Postman collection for the testing and later used for easy implementation on the mobile application or web application end.

Charging a customer on your end requires a card token that will be sent to stripe API on the basis of which customer will be charged and a success response will be returned. Creating a card token is simple and the very first step in charging the customer.

Customers can be of two type one who is a regular one and want their card information to be stored by payment gateway and managed on your end so that next time they do not need to enter the same information. Another one is who just want to purchase and not sure to store their card information at that time.

We will discuss both the ways of charging on by one.

You need to hit all the API of the stripe with headers:

  1. Authorization:Bearer sk_test_xxxxxxxxxxxxxxxxxxxxxx(Your secret key)
  2. Content-Type:application/x-www-form-urlencoded

1. Charge customer without saving their card information.

The very first step is to create a card token on the basis of valid card information entered by the user.

Use the Stripe API Create Card Token which is a post request to create a card token by entering some basic pieces of information like

  1. card[number]
  2. card[exp_month]
  3. card[exp_year]
  4. card[cvc]

Note: Do not forget to add the Headers with keys mentioned above, to your API request else you will end up with error and wondering why your approach is not working.Hope you will take care of this.

#1 Create a card token

As you can see the screenshot of the postman, you will also get a similar response too if you have followed everything correctly.

Now you have a card token for a particular card of customer and now you can charge the customer for some item with this card token.

To charge the customer use this Stripe API Charge which is a POST request to charge a customer with its card token by sending form-urlencoded data request:

  1. amount
  2. currency
  3. description
  4. source
Charge a customer with stripe card token

You can refer to the above screenshots that customer is charged without saving its card information.

That's all for this part of blog i.e charging the customer without saving the customer card information. In the next part of the blog, we will save the card information and then charge customer with saved card token.

Did I get something wrong? Mention it in the comments. I would love to improve.

If you liked what you read, please leave some claps!

Follow me:

Twitter : https://twitter.com/imRaviSSingh

Facebook : https://www.facebook.com/itsravishankarsingh

Instagram : https://www.instagram.com/itsravishankarsingh/

Github : https://github.com/ravishankarsingh1996

LinkedIn : https://www.linkedin.com/in/itsravishankarsingh/

About.me :https://about.me/itsravishankarsingh

--

--