Integrating a Payment Gateway, an easy way.

Zaid Shaikh
4 min readMar 27, 2021
Photo by Mika Baumeister on Unsplash

When living in a Digital Age, all sorts of tasks have become easy after being Automated and switched to Online platforms. From shopping your favourite pair of sneakers Online on an E-Commerce website, or transferring amount to your Family, digital payments have played a vital role being a part of our day to day lives. Digital payments come in many forms, such as NEFT, Debit, Credits etc. But while making cash transfers, the Service owner of any business would ensure that the process is smooth without any Vulnerability. To accomplish this, we have a special type of Internet Banking Service known as a Payment Gateway.

Payment Gateways partner up with potential Banks to accomplish the task of Fund transfer. This reduces the burden of Handling Digital payments entirely from the Businesses where the Payment Service Provider takes care of the entire infrastructure.

Today we’ll be looking at an Overview from a Customer’s Point of view as well as a Developers Point of view on how the Payment process is carried out by the Gateway.

Note :- We will be taking Instamojo Payment Gateway as a Reference in this story, but other Gateways also work in the same way & have almost a similar approach.

Customer

Remember that while performing Online Transactions, you as a Consumer never make payments to the Business owner directly. When making purchases online on any E-Commerce website for any product, the website owner redirects the details of the payment, such as the product details which is called as a Purpose and the Payment itself. This process is called as a Payment Request. From here, the further task is carried by the Developer which we will discuss later in the Post.

The payment is made to the Payment Gateway which then further processes the request to the Bank where your account details are associated with. The request is then Authorized back with the consumer whether he/she has initiated the Payment or not by verifying the OTP.

The outcomes are either credit or a failure which redirect you accordingly. A failure leads to reattempt the payment whereas a credit leads to completion of the order. Now that this task is complete, let’s take a look at Developers POV to the entire process.

Developer

Each & every Business or site owner has to enroll himself/herself for the Payment service on the Gateway Portals itself. After signing up & listing your business, each owner is associated with Unique API keys for his/her Payments. These keys are important & unique to everyone.

The Development files can be downloaded from the official documentations itself. Almost all Gateways provide the versatility of choosing a Scripting Language of your own like Python, PHP, Java, JavaScript, Go etc.

The developer’s task begins when the user makes an order on the E-Commerce site. Order details must be collected via a form and passed using POST. The details associated to the order are then passed to the Payment Gateway API where the API initiates a step of processes as follows:-

  • The API generates a payment request unique to the product. In this 1st step, your unique API authentication Keys must be passed as well.
  • 2 necessary parameters such as a Payment purpose(string) & Amount(int) are mandatory for initiating a request. There are more parameters such as Email(string), Phone(int) & repeated payments(bool) that can be passed to a request.
  • The Request once completed should be redirected to some other page via redirect URL.
Passing order parameters.
  • The redirected page is passed with HTTP GET parameters such as the payment_id, payment_request_id & payment_status. These parameters are unique to the Orders made and can be verified at the time of Delivering a product or cross checking a Transaction.
  • The payment_id is also used for payment refunds after Orders are cancelled.
handling the Payment by accessing payment request id & payment id.

Here’s a difference between payment_id & payment_request_id.

A payment request is an instrument to collect money for a specific purpose and amount from one or many customers. A payment request ID is generated when a new payment request is created. It is a random string of 32 characters like this.

4ce986c9d9614224bd044d1331c531ff

A payment ID is generated when a customer makes an actual payment against a payment request. There could be multiple payments (and hence multiple payment IDs) against a single payment request. A payment ID is a 20 character string prefixed with MOJO, for example.

MOJO6c09000J31957837

Here are some of the popular Gateways that also have easy to understand Documentation.

  1. Stripe.
  2. Razorpay.
  3. Paypal.
  4. Paytm.
  5. Instamojo.
  6. Square.

If you are getting started out integrating one of these gateways then the best way is to test them on the Testing environment provided by these Gateways.

If you enjoyed Reading this article, then consider clicking the clap icon down below.👏

Also follow for more such Tech Blogs ahead.👨‍💻

LinkedIn :- https://www.linkedin.com/in/zaid-shaikh-10a286194

GitHub :- https://github.com/Zaid-Shaikh333/php-payment-gateway

--

--

Zaid Shaikh

Converting my thoughts into Words 📖💻🖋️📝