Understanding of payment gateway(Razorpay)
In this article, I am going to explain how I implemented Razorpay in my application and describe what it taught me.
At the beginning of this article, I confess I am not familiar with this concept. If I am wrong in any area please correct me.
What is the payment gateway
A payment gateway is a merchant service provided by an e-commerce application service provider that authorizes credit card or direct payments processing for e-businesses, online retailers, bricks and clicks, or traditional brick and mortar. — Wikipedia
The payment gateway is a third-party between merchants and customers that securely take the money from customers and send it to the merchant’s bank account.
Razorpay is one of the payment gateways. There are many of the payment gateways is there.
How does it work?
Easy understanding
We can easily understand from the above picture.
For deep understanding please go through their official document it's explaining about flow. Click here.
How I used it in my project.
The above two images are the flow of my project. If you do not understand both pictures do not worry read further.
I am going to split into a two-part mobile-side and server-side.
From mobile-side user make payment only. There is one process is there before making the payment that is called order.
But I did not create any order. Though I can make the payment without creating order.
Once payment gets success it state changed in the dashboard to ‘Authorized’. If payment fails then the state should be ‘failed’.
Earlier I assume if Authorized is the end of the process. But it is not so. Authorized means payment gateway get authorized with the bank. But this is not the final step. There is another on step is called ‘Capture’.
We should call capture API.
Take the above picture as an example. If payment_id and the amount are matched with transaction then state changed to ‘Captured’ in the dashboard. If its fail it returns an error message.
We can call the capture method only which transaction state is ‘Authorized’.
Once the transaction state changed ‘Capture’ then the amount will settle in your bank account.
Then we can Refund to users. Refund method can call only after the state changed to captured.
So far I discussed only positive flow. If some situation that arises when a payment is interrupted by external factors such as network issues or technical errors at customer’s or bank’s end. In such cases, funds may or may not get debited from the customer’s bank account and Razorpay does not receive a payment status from the bank.
In such a case, we can handle by Late Authorization.
Late Authorization
Late authorization is a situation that arises when a payment is interrupted by external factors such as network issues or technical errors at customer’s or bank’s end. In such cases, funds may or may not get debited from the customer’s bank account and Razorpay does not receive a payment status from the bank.
Razorpay will poll the bank at various intervals within 5 days. If at the time if our transaction is changed to success then our dashboard also changed failed to authorized.
If late authorization happens we can two ways.
It depends on your business needs.
1. Communicate with your customer
When customers reach out to you about a payment that was debited from their bank accounts before the successful order completion, ensure that you have clearly communicated about the status of the payment and how you will be handling it. You can choose to send out a message such as the following: “If your order has failed and the amount has been debited, the debited amount will be auto-refunded in 5 working days (without taking into account the processing time of your bank).”
If state change to ‘Authorized’ if you are not called capture function the amount auto-refunded.
2.Track payment
If you wish to provide the service later, there are ways in which you can keep a close track of these payments and fulfil the order when it is authorized.
For example, you, as an online marketplace merchant, who sell clothes and accessories can mark the order as ‘pending’ in your system and deliver the order when the payment gets authorized.
We can handle Late Authorization using webhooks.
Webhooks
In webhooks, we set a URL and set actions. Whenever actions triggered it send a notification to URL.
For more understanding please read the document.
Thanks for reading!
Have a great day!
Reference link: