How to Integrate PhonePe Payment Gateway: A Step-by-Step Guide

How to Integrate PhonePe Payment Gateway: A Step-by-Step Guide

Integrating a reliable payment gateway is crucial for any online business to offer a seamless and secure payment experience to customers. PhonePe, one of India’s most popular digital payment platforms, provides a secure and efficient payment gateway for online transactions. This guide will walk you through the process of integrating PhonePe’s payment gateway into your website or mobile app.

Why Choose PhonePe Payment Gateway?

Before diving into the integration process, it’s essential to understand why PhonePe is an excellent choice:

  1. Wide User Base: PhonePe has millions of active users in India, making it a preferred payment method.
  2. Secure Transactions: It follows PCI-DSS compliance, ensuring a secure payment environment.
  3. Multiple Payment Options: Supports UPI, credit/debit cards, and wallet payments.
  4. Easy Integration: Provides a comprehensive developer portal and documentation.
  5. Fast Settlements: Quick fund settlements to merchants.

Prerequisites for PhonePe Integration

Before you start integrating the PhonePe payment gateway, ensure the following:

  1. PhonePe Merchant Account: You need to register as a merchant on PhonePe’s platform.
  2. API Keys: Obtain the required API keys (Merchant ID, Secret Key) from the PhonePe dashboard.
  3. Server Requirements:
    • HTTPS enabled on your website for secure transactions.
    • Compatible backend technology (like PHP, Node.js, Java, or Python).
  4. Development Environment: Set up a development environment for testing the integration.

Step 1: Register as a Merchant

  1. Visit the PhonePe Merchant Portal and sign up.
  2. Complete the KYC process by submitting the necessary documents.
  3. Once verified, you’ll receive API credentials including:
    • Merchant ID
    • Secret Key
    • Salt Key (used for creating checksum)

Step 2: Choose the Integration Method

PhonePe provides two primary methods for integration:

  1. Redirect Integration: Users are redirected to PhonePe’s secure page for payment and then redirected back to your website.
  2. Seamless Integration (API-based): Payments happen within your application using PhonePe’s APIs.

For beginners, the Redirect Integration is simpler, but if you want a seamless experience, go for the API-based integration.

Step 3: Integrate Payment Request API

To initiate a payment request:

  1. Endpoint URL:

    bash
    https://api.phonepe.com/v3/transaction/initiate
  2. Request Parameters:

    • merchantId: Your PhonePe Merchant ID
    • amount: Payment amount in paisa (e.g., ₹100 = 10000 paisa)
    • transactionId: Unique transaction identifier
    • redirectUrl: URL to redirect after payment success/failure
    • callbackUrl: Backend URL to receive payment status updates
  3. Create Checksum: PhonePe requires a checksum to be sent along with the request. This is created using:

  4. Send the Payment Request: Example in PHP:

 

Step 4: Handle Payment Response

  • PhonePe will redirect users to the redirectUrl after payment.

  • The payment status can be:

    • SUCCESS
    • FAILED
    • PENDING
  • Verify Payment Status: Use the following endpoint to verify the payment:

  • Send the transaction ID and checksum to verify the payment status.

Step 5: Implement Webhook for Payment Notifications

PhonePe supports webhooks to notify you about the payment status in real-time.

  1. Set Callback URL: Register your callback URL in the PhonePe merchant dashboard.
  2. Handle Notification: Ensure your backend is ready to handle payment notifications and update the order status accordingly.

Step 6: Test Your Integration

  • Sandbox Environment: PhonePe provides a sandbox environment for testing. Use test credentials to simulate payments.
  • Test Scenarios:
    • Successful Payment
    • Failed Payment
    • Payment Cancellation
    • Timeout Scenario

Step 7: Go Live

Once the testing is successful:

  1. Replace sandbox URLs with live production URLs.
  2. Use live API credentials.
  3. Perform a live transaction test to ensure everything is functioning as expected.

Tips for Secure Integration

  1. Always use HTTPS to secure payment data.
  2. Validate all inputs to avoid security vulnerabilities.
  3. Store API keys securely (e.g., in environment variables).
  4. Implement logging for transaction tracking and error debugging.

Common Issues and Troubleshooting

  1. Invalid Checksum:

    • Ensure the checksum is calculated correctly using the right sequence and keys.
  2. Payment Not Reflected:

    • Check the webhook implementation and ensure your server is reachable.
  3. Transaction Failed:

    • Verify API keys and transaction details.
    • Check for any downtime on the PhonePe server.

Conclusion

Integrating the PhonePe payment gateway enhances the user experience by providing a secure and reliable payment option. By following this guide, you can seamlessly integrate PhonePe into your website or mobile app, ensuring smooth transactions for your customers.

Need Help?

If you need professional assistance with integrating PhonePe or any other payment gateway, feel free to reach out to our team of experienced developers. We are here to help you build a secure and scalable payment solution tailored to your business needs.

Recent Posts

Categories

Quick Links