Payerurl API Integration using PHP

Deal Score+1

Payerurl API Integration using PHP with sandbox payment testing

GITHUB LINK:
https://github.com/muhitmonsur/payerurl_api_integration_by_php

#1 PHP

Step 1: Send payment request

</pre>
<?php
/**
* unique order ID, this order number must be unique.
*/
$invoiceid = floor(microtime(true) * 1000);

/**
* Order Total Amount
*/
$amount = 123;

/**
* Order amount currency
*/
$currency = 'usd';

/**
* Billing user info
*/
$billing_fname = 'First name';
$billing_lname = 'Last name';
$billing_email = '[email protected]';

/**
* After successful payment customer will redirect to this url.
*/
$redirect_to = 'http://localhost/pt/payerurl_payment_success.php';

&nbsp;

/*****
**** THIS IS VERY IMPORTANT VARIABLE *******************
* Response URL/cancel URL/ Callback URL/ our system will only send response to this url
*****/
$notify_url = 'https://mydomain.com/payerurl_payment_response.php';
//Note: It is the web address where payerurl_payment_response.php file would be located.

/**
* If you user cancel any payment, user will redirect to cancel url
*/
$cancel_url = 'http://localhost/pt/payerurl_payment_cancel.php';

/**
* Payerurl API credentials
* Do not share the credentials
* Get your API key : https://dashboard.payerurl.com/profile/api-management
*/

$payerurl_public_key = 'de1e85e8a087fed83e4a3ba9dfe36f08'; // this credencials open for public
$payerurl_secret_key = '0a634fc47368f55f1f54e472283b3acd'; // this credencials open for public

/**
* Order items
*/
$items = [
[
'name' => 'Order item name',
'qty' => 'Order item quantity',
'price' => '123',
]
];

/**
* API params
*/
$args = [
'order_id' => $invoiceid,
'amount' => $amount,
'items' => $items,
'currency' => $currency,
'billing_fname' => $billing_fname,
'billing_lname' => $billing_lname,
'billing_email' => $billing_email,
'redirect_to' => $redirect_to,
'notify_url' => $notify_url,
'cancel_url' => $cancel_url,
'type' => 'php',
];

/**
* Generate signature
*/
ksort($args);
$args = http_build_query($args);
$signature = hash_hmac('sha256', $args, $payerurl_secret_key);
$authStr = base64_encode(sprintf('%s:%s', $payerurl_public_key, $signature));

/**
* Send API response
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api-v2.payerurl.com/api/payment');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type:application/x-www-form-urlencoded;charset=UTF-8',
'Authorization:' . sprintf('Bearer %s', $authStr),
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$response = json_decode($response);

/**
* Redirect user to payerurl payment page
*/
if ($httpCode === 200 && isset($response->redirectTO) && !empty($response->redirectTO)) {
header('Location: ' . $response->redirectTO);
}
exit();
?>
<pre>

Step 2: Receive response from payerurl after payment successful

</pre></pre>
<div><?php</div>
<div></div>
<div>/**</div>
<div> * Pyerurl will send a POST request to notify_url from payment request</div>
<div> * Add this below code to your callback page</div>
<div> */</div>
<div></div>
<div>/**</div>
<div> * Payerurl API credentials</div>
<div> */</div>
<div></div>
<div>$payerurl_public_key = 'de1e85e8a087fed83e4a3ba9dfe36f08';  // this credencials open for public</div>
<div>$payerurl_secret_key = '0a634fc47368f55f1f54e472283b3acd'; // this credencials open for public</div>
<div></div>
<div>$headers = getallheaders();</div>
<div>$auth ="";</div>
<div></div>
<div>if ($headers === false || !array_key_exists('Authorization', $headers)) {</div>
<div>    /////////////  YOUR CODE HERE   ///////////////////////////</div>
<div></div>
<div>$authStr_post = base64_decode($_POST['authStr']);</div>
<div>    $auth = explode(':', $authStr_post);</div>
<div></div>
<div>} else</div>
<div>{</div>
<div>$authStr = str_replace('Bearer ', '', $headers['Authorization']);</div>
<div>$authStr = base64_decode($authStr);</div>
<div>$auth = explode(':', $authStr);</div>
<div>}</div>
<div></div>
<div></div>
<div></div>
<div></div>
<div>if ($payerurl_public_key != $auth[0]) {</div>
<div>    /////////////  YOUR CODE HERE   ///////////////////////////</div>
<div>    $data = ['status' => 2030, 'message' => 'Public key doesn\'t match'];</div>
<div>    header('Content-Type: application/json; charset=utf-8');</div>
<div>    echo json_encode($data);</div>
<div>    exit();</div>
<div>}</div>
<div></div>
<div></div>
<div></div>
<div>$GETDATA = [</div>
<div>    'order_id' => $_POST['order_id'],</div>
<div>    'ext_transaction_id' => $_POST['ext_transaction_id'],</div>
<div>    'transaction_id' => $_POST['transaction_id'],</div>
<div>    'status_code' => $_POST['status_code'],</div>
<div>    'note' => $_POST['note'],</div>
<div>    'confirm_rcv_amnt' => $_POST['confirm_rcv_amnt'],</div>
<div>    'confirm_rcv_amnt_curr' => $_POST['confirm_rcv_amnt_curr'],</div>
<div>    'coin_rcv_amnt' => $_POST['coin_rcv_amnt'],</div>
<div>    'coin_rcv_amnt_curr' => $_POST['coin_rcv_amnt_curr'],</div>
<div>    'txn_time' => $_POST['txn_time']</div>
<div>];</div>
<div></div>
<div>if (!isset($GETDATA['transaction_id']) || empty($GETDATA['transaction_id'])) {</div>
<div>    /////////////  YOUR CODE HERE   ///////////////////////////</div>
<div>    $data = ['status' => 2050, 'message' => "Transaction ID not found"];</div>
<div>    header('Content-Type: application/json; charset=utf-8');</div>
<div>    echo json_encode($data);</div>
<div>    exit();</div>
<div>}</div>
<div></div>
<div>if (!isset($GETDATA['order_id']) || empty($GETDATA['order_id'])) {</div>
<div>    /////////////  YOUR CODE HERE   ///////////////////////////</div>
<div>    $data = ['status' => 2050, 'message' => "Order ID not found"];</div>
<div>    header('Content-Type: application/json; charset=utf-8');</div>
<div>    echo json_encode($data);</div>
<div>    exit();</div>
<div>}</div>
<div></div>
<div>if ($GETDATA['status_code'] == 20000) {</div>
<div>    /////////////  YOUR CODE HERE   ///////////////////////////</div>
<div>    $data = ['status' => 20000, 'message' => "Order Cancelled"];</div>
<div>    header('Content-Type: application/json; charset=utf-8');</div>
<div>    echo json_encode($data);</div>
<div>    exit();</div>
<div>}</div>
<div></div>
<div>if ($GETDATA['status_code'] != 200) {</div>
<div>    /////////////  YOUR CODE HERE   ///////////////////////////</div>
<div>    $data = ['status' => 2050, 'message' => "Order not complete"];</div>
<div>    header('Content-Type: application/json; charset=utf-8');</div>
<div>    echo json_encode($data);</div>
<div>    exit();</div>
<div>}</div>
<div></div>
<div></div>
<div>//****************** ADVANCE SECURITY CHECK  ***********************//</div>
<div>//ksort($GETDATA);</div>
<div>//$args = http_build_query($GETDATA);</div>
<div>//$signature = hash_hmac('sha256', $GETDATA, $payerurl_secret_key);</div>
<div>//if (!hash_equals($signature, $auth[1])) {</div>
<div>//    $data = ['status' => 2030, 'message' => "Signature not matched"];</div>
<div>//    header('Content-Type: application/json; charset=utf-8');</div>
<div>//    echo json_encode($data);</div>
<div>//    exit();</div>
<div>//}</div>
<div>//********************** ADVANCE SECURITY CHECK  *******************//</div>
<div></div>
<div></div>
<div></div>
<div>$data = ['status' => 2040, 'message' => $GETDATA];</div>
<div></div>
<div>/////////////  YOUR CODE HERE   ///////////////////////////</div>
<div>//</div>
<div>//</div>
<div>//</div>
<div>//</div>
<div>//</div>
<div>//</div>
<div>// change your order status</div>
<div>// all the security check is done</div>
<div>//</div>
<div>//</div>
<div>//</div>
<div>//</div>
<div>//</div>
<div>///////////// YOUR CODE HERE ///////////////////////////</div>
<div></div>
<div></div>
<div>$filename = "payerurl.log";</div>
<div>$fh = fopen($filename, "a");</div>
<div>fwrite($fh, json_encode($data));</div>
<div>fclose($fh);</div>
<div></div>
<div>header('Content-Type: application/json; charset=utf-8');</div>
<div>echo json_encode($data);</div>
<div>exit();</div>
<div></div>
<div>?></div>
<pre><pre>

Step 3:  Customer redirect to success page after payment

</pre>
<?php

echo "PAYMENT SUCCESS";

?>
<pre>

Step 3:  Customer redirect to cancel page if payment is not paid or cancel

</pre>
<?php

echo "PAYMENT CANCEL";

?>
<pre>

GITHUB repository:  https://github.com/muhitmonsur/payerurl_api_integration_by_php

What is as API key?

An API key or application programming interface key is a code that gets passed in by computer applications. The program or application then calls the API or application programming interface to identify its user, developer or calling program to a website. API keys are the credentials used to connect user’s payments account to any external systems you’re using to accept payments from. These keys can be found on the payment gateway’s dashboard. Payment gateway APIs allows user to maintain control of the user experience.

Benefits Of API Keys

If user use Payerurl, they will have the facilities of API keys which help user’s business to interact with customers in more than one place. API will increase the number of places users can interact with their customers exponentially. Imagine the possibilities for contextual payments, way beyond simple web checkout!

User’s business will have real-time purchasing data to inform smarter marketing decisions. Forget about once-a-month check-ins to decipher your transaction patterns. Payerurl with API provides a ton of data beyond simple payment information and the real-time data feeds can be used immediately to help any user understand and act on buyer behaviors. Easy access to this actionable data is key to driving anyone’s business forward. Since Payerurl has the API key facility, it can offer users many methods of payments and they are free to choose their desired ones. .Ideally, user should be able to accept any number of payment types, including all types of credit cards, alternative payment options and international currencies and payment methods. It’s possible with the right API. Our customers will have all the advantages of the flexibility and sales won’t be limited by geographical area or specific payment types.

Last but not the least which is customer’s safety. Our customer data remains safe and secure and API keys will remain only in between user and clients. Payerurl’s APIs are sophisticated enough that user can build their own purchasing experience and take it all the way out to the edge of the payment process—while the API provider remains responsible for PCI data by securing the sensitive credit card fields. The API customer choose will give them the flexibility to handle all types of transactions (mobile, mobile apps, eCommerce, and others) while still providing the security.

Payerurl
Logo