App Development

How to integrate Phonepe payment gateway in PHP [2024]

AAdminDecember 23, 20237 min read
How to integrate Phonepe payment gateway in PHP [2024]

require DIR . '/vendor/autoload.php';

$config = new PhonePe('PHONEPE_MERCHANTID','PHONEPE_SALTKEY',PHONEPE_SALTINDEX);//merchantId,SaltKey,SaltIndex after onboarding PhonePe Payment gateway you will got this. $merchantTransactionId='MUID' . substr(uniqid(), -6);// Uqique Randoe transcation Id $merchantOrderId='Order'.mt_rand(1000,99999);// orderId $amount=100;// Amount in Paisa or amount*100 $redirectUrl="/success.php";// Redirect Url after Payment success or fail $mode="PRODUCTION"; // MODE or PAYMENT UAT(test) or PRODUCTION(production) $callbackUrl="/success.php";//Callback Url after Payment success or fail get response $mobileNumber=9876543210;//Mobile No $data=$config->PaymentCall("$merchantTransactionId","$merchantOrderId","$amount","$redirectUrl","$callbackUrl","$mobileNumber","$mode");// call function to get response form phonepe like url,msg,status //header('Location:'. $data['url']);//use when you directly want to redirect to phonepe gateway echo $data['url']; // here you get url after initiated PhonePe gateway

<!-- User Email -->
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>

<!-- User Phone -->
<label for="phone">Phone:</label>
<input type="tel" id="phone" name="phone" pattern="[0-9]{10}" required>

<!-- Amount -->
<label for="amount">Amount:</label>
<input type="number" id="amount" name="amount" required>

<!-- Submit Button -->
<button type="submit">Submit</button>

</form>

Need help with your project?

Talk to the Papaya Coders team for a free consultation.

Contact Us