Payment integration with Juspay in php. This Code helps you to integrate with Juspay and process payments for your customers.
To integrate Juspay payment gateway with PHP, you can follow the steps below:
1. Sign up for a Juspay account and create a merchant ID to get the API keys required for the integration.
2. Download the Juspay PHP SDK from the official website and include it in your PHP project.
3.Create a PHP script that will handle the payment request. Here's an example code snippet that uses the Juspay PHP SDK to create a new payment request:
<?php
$api_key="YOUR API KEY";
$secret_key="YOUR SECRET KEY";
$paymentURL="https://axisbank.juspay.in/order/create";
$returnURL="YOUR RETURN URL";
$pay=1;
if($pay==1)
{
$aid=1;
$applicant_email="dipankar@gmail.com";
$transaction_number=1;
$app_fees=10;
$txID='001';
$txID="APP-".date("Y")."-".str_pad($transaction_number,6,"0",STR_PAD_LEFT);
$ch = curl_init($paymentURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $api_key);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('customer_id' => str_pad($aid,6,"0",STR_PAD_LEFT) , 'customer_email' => $applicant_email , 'amount' => $app_fees , 'order_id' => $txID , 'return_url' => $returnURL ));
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($s,CURLOPT_TIMEOUT, 15);
$response = curl_exec($ch);
$response_json=json_decode($response);
$payment_link="";
foreach($response_json as $key=>$val)
{
if($key=="payment_links")
{
foreach($val as $one_val)
{
if($payment_link=="")
{
$payment_link=$one_val;
}
}
}
}
header("Location: ".$payment_link);
}
else
{
$error_msg="There was an error with your application. Please try again.";
}
?>
This code creates a new PaymentRequest object and sets various parameters such as the order ID, amount, currency, customer details, and description. It then calls the createPaymentRequest() method of the Juspay PHP SDK to create a new payment request and obtain the payment page URL. If the request is successful, the code redirects the user to the payment page.
Get the latest news and updates by signing up to our daily newsletter.We won't sell your email or spam you !