1. Integration Steps
Before you start with the integration, 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 we recommend that you enable other payment methods that are relevant to you.
Create a PayU account
First, create a PayU account. See Register for a Merchant Account.
Download php SDK
You 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();
}
Updated 11 months ago