Site icon Learn Web Development & Programming, Artificial Intelligence, WordPress, Shopify Articles

How to Integrate PhonePe Payment Gateway in Laravel

PhonePe Payment Gateway Integration in Laravel

If you want to integrate PhonePe payment gateway on your php laravel website/application, it’s not just about Laravel code. You need to get a merchant account for handling payments, grab some API credentials, and set up how the payment function works.

Let’s start php laravel PhonePe payment gateway Integration into your website/application.

Suggested Read: How to Integrate PhonePe Payment Gateway in PHP

There is no need to worry about creating an account for testing the PhonePe payment gateway – the test credentials are open to everyone. But when you’re ready to take the live / production keys for real payments, log in or register on PhonePe Business Solutions.

Suppose you already have a merchant account and API credentials for your PhonePe gateway.

PhonePe API Credentials

Merchant ID : PGTESTPAYUAT
Salt Key: 099eb0cd-02cf-4e2a-8aca-3e6c6aff0399

Card: 4242 4242 4242 4242
Expiry: 12/25 (any future date)
CVV: 357
OTP: 987654

Are you want to get implementation help, or modify or extend the functionality of this script?

A Tutorialswebsite Expert can do it for you.

Step 1: Create a controller

Step 2: Let’s Build Your Payment Form

Next up, we’re going to create a user-friendly payment form. This form will enable you to request the necessary details and receive the confirmation. Let’s get started!

Now create a payment form at the location: resources/views/payment-form.blade.php

Copy and Paste the below code on the above file.

Step 3: Create Routes in web.php

Let’s create 3 routes in your web.php file. The 1st route will load a Phonepe request, 2nd route will handle the submitted payment form request, 3rd route will handle the response from the Phonepe server in the form of a “SUCCESS” response or “FAILED” response.

Step 4: Create a Model to Insert Data into a Table

To insert data into a table in Laravel, If you don’t already have a model for your table, you can create one using the following command:

Open the generated model file (located in the app directory) and define the model class and the associated table name:

Step 5: Create a Payment Function

Now create a function named index in PaymentController.php

Now create a function named submitPaymentForm in PaymentController.php

PhonePe Checkout Page

Step 6: Setting Up the Callback Function

Now, let’s make a function called “confirmPayment” in PaymentController.php. In this function, we’ll handle and receive PhonePe transaction details like code, merchantId, transactionId, amount, providerReferenceId, checksum, and more.

Now create a response view page at the location: resources/views/confirm_payment.blade.php and and display providerReferenceId and transactionId.

Step 7: Exclude callback URL

As PhonePe’s payment callback works with the POST method and doesn’t include a CSRF token from their side. So we need to exclude CSRF verification for the PhonePe callback URL.

To achieve this, add the callback URL to a middleware located in app/Http/Middleware/VerifyCsrfToken.php.

👍

UAT OR SANDBOX API

UAT Host URL: https://api-preprod.phonepe.com/apis/pg-sandbox
API End Point: /pg/v1/pay

UAT PAY API URL: https://api-preprod.phonepe.com/apis/pg-sandbox/pg/v1/pay

Are you want to get implementation help, or modify or extend the functionality of this script?

A Tutorialswebsite Expert can do it for you.

Wrapping Words

These are the simple and easy steps to Integrate PhonePe Payment Gateway in PHP. You can modify and customize code as per your requirements.

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

Related Article

Integrate Recurring Stripe Subscription Payment with PHP

Integrate Blockonomics bitcoin payment gateway in PHP

FAQs

How to get the PhonePe PG test environment API details?

You will get test/sandbox API details from this link: https://developer.phonepe.com/v1/docs/uat-testing

Test Credentials :
Merchant ID : PGTESTPAYUAT
Salt Key: 099eb0cd-02cf-4e2a-8aca-3e6c6aff0399

Test Card Details:
Card: 4242 4242 4242 4242
Expiry: 12/25 (any future date)
CVV: 357
OTP: 987654

Can I integrate PhonePe Payment Gateway in PHP?

Yes, You can integrate PhonePe Payment Gateway API In PHP. Please follow this link

How to hire a PhonePe Payment Gateway Integration developer?

You just need to call or Whatsapp at: +91-8218920611

How to get PhonePe PG live Salt Key and Salt Index?

You will receive an email with live Salt Key and Salt Index from the PhonePe PG team. When your account is verified and activated to accept online payment.

Exit mobile version