PhonePe Payment Gateway Integration Guide
Today, we are going to learn how to integrate the PhonePe Payment Gateway. This tutorial will guide you through the integration process and highlight common errors you may encounter.
At the start of this year, I learnt how to integrate the PhonePe payment gateway into a website. This guide not only shares that experience but also provides a roadmap for anyone looking to integrate PhonePe into their Android or iOS apps. The process and challenges are similar across all platforms. So, lets dive deep in how to integrate PhonePe Payment Gateway.
Why businesses choose PhonePe Payment Gateway?
Before diving into the integration, let’s address why businesses choose PhonePe over competitors like Stripe or Razorpay. While Stripe and Razorpay are popular, the question is: why PhonePe? The answer is simple — lower service charges. Currently, PhonePe does not charge its clients, making it an economical choice. However, this could change at any time in the future. I hope this answers your question.
Please refer to this article for Payment Gateway Charges. PhonePe is at last
A little about PhonePe Admin Panel
On the flip side, the PhonePe admin panel falls short compared to its competitors. You (as a developer) may got frustrated while integrating payment gateway. Because it lacks functionalities like creating test credentials or regenerate API keys directly. Frustration is common, especially during the testing phase and a little on Production.
Setting Up Your PhonePe Account
To begin, ensure you have an account on PhonePe Business and some programming expertise. Now, let’s tackle the first challenge — generating test credentials.
Test vs. Production Credentials
PhonePe’s Developer Settings inside Admin Panel only display production credentials. For test credentials or regenerate Production API keys, you must contact their customer support. Here’s how:
- Raise a Ticket: Navigate to the “Help” section in the admin panel. Under the relevant error category, select Contact Us to raise a ticket and then describe your concern.
- Call Support: If the ticket system fails, call PhonePe’s business support team for assistance.
Pro Tip: Avoid using Google’s suggested email (“merchant-pgsupport@phonepe.com”). It’s outdated and will redirect you to the ticketing process.
You can’t create new production API keys and can’t regenerate current one by own from admin panel. For all, you just need to “Contact Support” team.
Test Credential Components
After contacting support, you’ll receive the following test credentials:
- Merchant ID: Test IDs usually start with “test”.
- Salt Index: A unique random number (e.g., 1 for testing).
- Salt Key: A key provided by PhonePe (e.g., “b80c575a-a6b6–4c42–8e6b-9b22d35d894c”).
- Environment: Use
Env.UAT
for testing andEnv.PROD
for production.
Integration Process
Now that you have the credentials, let’s integrate PhonePe using React and Django as an example. We are not here for show integration at code level. But this can give you an idea, how you can integrate.
PhonePe Documentation for python integration
Backend Integration
- Initialize Payment: Create a backend API to initialize payments. Pass parameters like
merchant_transaction_id
,amount
,merchant_user_id
,callback_url
, andredirect_url
to PhonePe’s SDK. - Generate Payment URL: Use the
pay_page_pay_request_builder
function to get a payment URL. - Redirect User: Redirect users to the payment URL, letting PhonePe handle the payment process.
Verify Payment
After payment:
- Use the
merchant_transaction_id
to verify the payment via PhonePe’scheck_status
function. - Handle statuses like
SUCCESS
,PENDING
, orFAILED
.
Note: Avoid using local storage or sessions to handle
merchant_transaction_id
for unauthenticated users.
Supported Payment Methods
PhonePe supports specific methods during testing. Refer to their UAT testing docs for details.
Common Pitfalls and Solutions
Domain Mismatch Errors:
- Ensure the domain used for payment requests matches the one whitelisted during account creation.
- Verify that your callback and redirect URLs share the same domain.
Example: If PhonePe whitelisted
www.example.com
, ensure all URLs usewww.
.
Ticketing Issues:
- Follow up with customer support if tickets don’t open correctly.
Next Steps
This guide focused on the integration process and common challenges. In future articles, I’ll dive deeper into code-level implementations using React and Django.
Conclusion
In the end, PhonePe payment gateway offers a cost-effective solution for businesses, especially those conscious of service charges. Despite its admin panel limitations the gateway’s economic advantage and functionality make it a compelling choice. By following this guide, you can overcome common integration challenges and unlock seamless transactions for your platform. With proper domain configurations, API handling, and support follow-ups, integrating PhonePe can be a smooth and rewarding experience.
As PhonePe evolves, its potential for businesses will likely grow. Stay updated with their official documentation and make the most of this robust payment gateway.