PHP SDK
The PayU SDK for PHP enables you to easily work with the APIs of PayU by integrating this SDK within your base system. With our SDK, you do not need to worry about low-level details for API integration and with a few lines of code and a function call, get started within a few minutes. To install PHP Web SDK, refer to Install PHP Web SDK.
Features Supported
The following features are supported in the PHP SDK:
- Create a Payment form.
- Verify the transaction or check the transaction status.
- Initiate/cancel refunds and check the status of a refund.
- Retrieve settlement details that the bank has to settle you.
- Get information on eligible payment options and PG/BANK downtime details.
- Check the customer’s eligibility for EMI and get the amount according to the EMI interest.
- Create/Expire invoice link through the function.
Prerequistes
- PHP version >= 7
- Enable the payment methods that you want to offer to your customers from Dashboard > Settings > Payment methods. We enable Cards, UPI, and other payment methods by default, and PayU recommends that you enable other payment methods that are relevant to you.
Steps to Integrate
Create a PayU account
First, create a PayU account. See Register for a Merchant Account.
Download php SDKYou can download the php web SDK from the following github link: https://github.com/payu-intrepos/web-sdk-php
Build PayU object
Use the following code snippet to create the instance of the PayU class object:
namespace <namespace_name>;
require_once('PayU.php');
$payu_obj = new PayU();
Set the credentials data and URL using the following code sample:
$payu_obj->env_prod = 0; // 1 for Live Environment/ 0 for SandBox Environment
$payu_obj->key = '<key>';
$payu_obj->salt = '<salt>';
$res = $payu_obj->initGateway();
Initiate a payment
This method can be used to submit HTML form code with the required parameters.
public function showPaymentForm($params) {
?>
<form action="<?= $this->url; ?>" id="payment_form_submit" method="post">
<input type="hidden" id="surl" name="surl" value="<?= self::SUCCESS_URL; ?>" />
<input type="hidden" id="furl" name="furl" value="<?= self::FAILURE_URL; ?>" />
<input type="hidden" id="key" name="key" value="<?= $this->key; ?>" />
<input type="hidden" id="txnid" name="txnid" value="<?= $params['txnid'] ?>" />
<input type="hidden" id="amount" name="amount" value="<?= $params['amount']; ?>" />
<input type="hidden" id="productinfo" name="productinfo" value="<?= $params['productinfo']; ?>" />
<input type="hidden" id="firstname" name="firstname" value="<?= $params['firstname']; ?>" />
<input type="hidden" id="lastname" name="lastname" value="<?= $params['lastname']; ?>" />
<input type="hidden" id="zipcode" name="zipcode" value="<?= $params['zipcode']; ?>" />
<input type="hidden" id="email" name="email" value="<?= $params['email']; ?>" />
<input type="hidden" id="phone" name="phone" value="<?= $params['phone']; ?>" />
<input type="hidden" id="address1" name="address1" value="<?= $params['address1']; ?>" />
<input type="hidden" id="city" name="city" value="<?= $params['city']; ?>" />
<input type="hidden" id="state" name="state" value="<?= $params['state']; ?>" />
<input type="hidden" id="country" name="country" value="<?= $params['country']; ?>" />
<input type="hidden" id="hash" name="hash" value="<?= $this->getHashKey($params); ?>" />
</form>
<script type="text/javascript">
document.getElementById("payment_form_submit").submit();
</script>
<?php
return null;
}
private function getHashKey($params) {
return hash('sha512', $this->key . '|' . $params['txnid'] . '|' . $params['amount'] . '|' . $params['productinfo'] . '|' . $params['firstname'] . '|' . $params['email'] . '|' . $params['udf1'] . '|' . $params['udf2'] . '|' . $params['udf3'] . '|' . $params['udf4'] . '|' . $params['udf5'] . '||||||' . $this->salt);
}
Verify payment
This method can be used to fetch the status/details of a transaction using txnid or payuid.
public function verifyPayment($params) {
if(!empty($params['txnid'])){
$transaction = $this->getTransactionByTxnId($params['txnid']);
}
else{
$transaction = $this->getTransactionByPayuId($params['payuid']);
}
return $transaction;
}
Get transaction details
This method This method can be used to fetch the details of the transactions within a date and time range.
public function getTransaction($params) {
$command = ($params['type'] == 'time') ? self::GET_TRANSACTION_INFO_API : self::GET_TRANSACTION_DETAILS_API;
$this->params['data'] = ['var1' => $params['from'], 'var2' => $params['to'], 'command' => $command];
return $this->execute();
}
Validate VPA
This method can be used to validate VPA of a user.
public function validateUpi($params) {
$this->params['data'] = ['var1' => $params['vpa'], 'var2' => $params['auto_pay_vpa'], 'command' => self::VALIDATE_UPI_HANLE_API];
return $this->execute();
}
Cencel refund transaction
This method can be used to initiate refunds for a specific transaction.
public function cancelRefundTransaction($params) {
$this->params['data'] = ['var1' => $params['payuid'], 'var2' => $params['txnid'], 'var3' => $params['amount'], 'command' => self::CANCEL_REFUND_API];
return $this->execute();
}
Check action status
This method can be used to check the status of a refund.
public function checkRefundStatus($params) {
$this->params['data'] = ['var1' => $params['request_id'], 'command' => self::CHECK_ACTION_STATUS];
return $this->execute();
}
public function checkRefundStatusByPayuId($params) {
$this->params['data'] = ['var1' => $params['payuid'], 'var2' => 'payuid', 'command' => self::CHECK_ACTION_STATUS];
return $this->execute();
}
Get net banking status
This method can be used to check status (down/up) of PGs.
public function getTransaction($params) {
$this->params['data'] = ['var1' => $params['netbanking_code'], 'command' => self::GET_NETBANKING_STATUS_API];
return $this->execute();
}
Get issuing bank status
This method can be used to check downtime through bin number.
public function getIssuingBankStatus($params) {
$this->params['data'] = ['var1' => $params['cardnum'], 'command' => self::GET_ISSUING_BANK_STATUS_API];
return $this->execute();
}
Check bin type
This method can be used to check the bin information.
public function getCardBin($params) {
$this->params['data'] = ['var1' => $params['cardnum'], 'command' => self::GET_CARD_BIN_API];
return $this->execute();
}
Create invoice
This method can be used to create email and SMS invoice ( Pay by link ).
public function createPaymentInvoice($params) {
$this->params['data'] = ['var1' => $params['details'], 'command' => self::CREATE_INVOICE_API];
return $this->execute();
}
Expire invoice
This method can be used to expire email and SMS invoice ( Pay by link ).
public function expirePaymentInvoice($params) {
$this->params['data'] = ['var1' => $params['txnid'], 'command' => self::EXPIRE_INVOICE_API];
return $this->execute();
}
Elligible bins for EMI
This method can be used to check the card eligibilty for EMI through the bin number.
public function checkEligibleEMIBins($params) {
$this->params['data'] = ['var1' => $params['bin'], 'var2' => $params['card_num'], 'var3' => $params['bank_name'], 'command' => self::CHECK_ELIGIBLE_BIN_FOR_EMI_API];
return $this->execute();
}
Get EMI amount according to interest
This method can be used to fetch EMI interest amount according to Banks and tenure.
public function getEmiAmount($params) {
$this->params['data'] = ['var1' => $params['amount'], 'command' => self::GET_EMI_AMOUNT_ACCORDING_TO_INTEREST_API];
return $this->execute();
}
Get settlement details
This method can be used to fetch settlement details for a particular date or UTR number.
public function getSettlementDetails($params) {
$this->params['data'] = ['var1' => $params['data'], 'command' => self::GET_SETTLEMENT_DETAILS_API];
return $this->execute();
}
Get checkout detail
This method can be used to fetch payment options, eligibility, recommendations, and downtime details.
public function getCheckoutDetails($params) {
$this->params['data'] = ['var1' => $params['data'], 'command' => self::GET_CHECKOUT_DETAILS_API];
return $this->execute();
}
Test and Go-live
Test your integration
After the integration is complete, you must test the integration before you go live and start collecting payment. You can start accepting actual payments from your customers once the test is successful.
You can make test payments using one of the payment methods configured at the Checkout.
Configure setIsProduction()
Set the value of the setIsProduction()
to false in the payment integration code. This enables the integration to accept live payments.
Test credentials
Following are the payment methods supported in PayU Test mode.
Test credentials for Net Banking
Use the following credentials to test the Net Banking integration:
- user name: payu
- password: payu
- OTP: 123456
Test VPA for UPI
You can use either of the following VPAs to test your UPI-related integration:
- anything@payu
- [email protected]
CalloutThe UPI in-app and UPI intent flow is not available in the Test mode.
Test cards for EMI
You can use the following Debit and Credit cards to test Emi integration.
Kotak DC EMI |
|
AXIS DC EMI |
|
HDFC CC EMI |
|
ICICI CC EMI |
|
Test Wallets
You can use the following wallets and their corresponding credentials to test wallet integration.
Wallet | Mobile Number | OTP |
---|---|---|
PayTM | 7777777777 | 888888 |
PhonePe | Use the Phonepe Pre-Prod app for testing purposes as described in the following PhonePe doc. location: https://developer.phonepe.com/v1/docs/setting-up-test-account Download the app and register your mobile number and follow the instructions as described in the above PhonePe docs. | NA |
AmazonPay | You can test using your original Amazon account details. |
Go-live Checklist
Ensure these steps before you deploy the integration in a live environment.
Collect Live Payments
After testing the integration end-to-end, once you are confident that the integration is working as expected, you can switch to live mode to start accepting payments from your customers.
Watch Out!Ensure that you are using the production merchant key and salt generated in the live mode.
Checklist 2: Configure environment() parameter
Set the value of the environment()
to 0
in the payment integration code. This enables the integration to accept live payments.
Checklist 4:- Remove/comment meta -data code from manifest file :-
For Android
You must be comment/remove the below metadata code from the manifest file to use the UPI Collect flow on Production env:-
<application>
<meta-data android:name="payu_debug_mode_enabled" android:value="true" /> // set the value to false for production environment
<meta-data android:name="payu_web_service_url" android:value="https://test.payu.in" /> //Comment in case of Production-->
<meta-data android:name="payu_post_url" android:value="https://test.payu.in"/> //Comment in case of Production-->
</appliction>
Checklist 5: Configure verify payment method
Configure the Verify payment method to fetch the payment status. We strongly recommend that you use this as a back up method to handle scenarios where the payment callback is failed due to technical error.
Checklist 6: Configure Webhook
We recommend that you configure Webhook to receive payment responses on your server. For more information, refer to Webhooks.
Updated 3 days ago