PhonePe Standard Checkout – Authorization Token Generation in PHP

Authorization Token Generation in PHP - PhonePe Standard Checkout

If you’re integrating PhonePe’s payment gateway into your application, you must ensure that communication between your server and PhonePe’s backend is secure. To achieve this, you must first generate an Auth Token, which is used to authorize all coming API requests. This article will walk you through the process of generating an authentication token with PHP.

What is an authorization token in PhonePe?

An auth token is a security signature that authorizes requests from your backend to PhonePe. It is generated based on your client_id, client_version, client_secret, and grant_type.

Also Read: Integrating Razorpay Payment Gateway in PHP

How to get client_id, client_version, client_secret, and grant_type?

To get this details:

  • Login to your PhonePe Business Account
  • Go To “Developer Settings” -> API Keys
PhonePe Standard Checkout - Authorization Token Generation

Generate and Fetch Authorization Token using API

Host Details:

Environment:

UAT: https://api-preprod.phonepe.com/apis/pg-sandbox/v1/oauth/token

Endpoint

/v1/oauth/token – Endpoint is common for UAT and Production.

We will use above UAT api url and test credentials to generate Auth Token. Please follow the below code snippets:

Looking for a Website Developer in Delhi NCR?

Get a professionally designed and developed website tailored to your needs.
As an experienced website developer based in Delhi NCR, I offer customized solutions to build responsive, SEO-friendly, and user-friendly websites. Whether it’s for a personal blog, business site, or e-commerce store, I ensure your online presence stands out.

Response Body

Phonepe Authorization Token
  • access_token – The token required for making API requests to PhonePe
  • expires_at – The validity of the Generated TOKEN (in seconds)

Token Reusability & Expiry

PhonePe gives you a token that works for a limited time. You can check when it expires using the ‘expires_at’ field. After it expires, you need to get a new one using the same API.

Do you want to get implementation help, or modify or extend the functionality of this script? Submit a paid service request

Conclusion

Creating and managing an authorization token is an important part of your PhonePe integration. Always keep the token securely stored, reused efficiently, and refreshed before it expires. This not only secures your integration, but also ensures that your users have a smooth payment experience.

When you understand the signing process, you can easily generate the PhonePe authentication token in PHP. By securing your API calls with this token, you ensure a reliable and safe integration with PhonePe’s backend.

Related Article:

Related posts

Leave a Comment