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


<?php
// Unique Order ID
$invoiceid = floor(microtime(true) * 1000);

// Order Total Amount and Currency
$amount = 123;
$currency = 'usd';

// Billing User Info
$billing_fname = 'First name';
$billing_lname = 'Last name';
$billing_email = '[email protected]';

// Redirection URLs after payment
$redirect_to = 'http://localhost/pt/payerurl_payment_success.php';
$notify_url = 'https://mydomain.com/payerurl_payment_response.php';
$cancel_url = 'http://localhost/pt/payerurl_payment_cancel.php';

// Payerurl API Credentials
$payerurl_public_key = 'de1e85e8a087fed83e4a3ba9dfe36f08';
$payerurl_secret_key = '0a634fc47368f55f1f54e472283b3acd';

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

// API Parameters
$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 Payment Request to API
$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 the payment page
if ($httpCode === 200 && isset($response->redirectTO) && !empty($response->redirectTO)) {
header('Location: ' . $response->redirectTO);
}
exit();
?>

</div>

Step 2: Receive response from payerurl after payment successful

</pre>
<?php
// Payerurl API Credentials
$payerurl_public_key = 'de1e85e8a087fed83e4a3ba9dfe36f08';
$payerurl_secret_key = '0a634fc47368f55f1f54e472283b3acd';

// Retrieve and Validate Authorization
$headers = getallheaders();
$authStr_post = base64_decode($_POST['authStr'] ?? '');
$auth = $authStr_post ? explode(':', $authStr_post) : [];

if ($payerurl_public_key != $auth[0]) {
echo json_encode(['status' => 2030, 'message' => 'Public key doesn\'t match']);
exit();
}

// Retrieve and Validate Transaction Data
$GETDATA = [
'order_id' => $_POST['order_id'],
'transaction_id' => $_POST['transaction_id'],
'status_code' => $_POST['status_code'],
];

// Perform Additional Security Checks (Optional)
// ksort($GETDATA);
// $signature = hash_hmac('sha256', http_build_query($GETDATA), $payerurl_secret_key);
// if (!hash_equals($signature, $auth[1])) {
// echo json_encode(['status' => 2030, 'message' => 'Signature not matched']);
// exit();
// }

// Respond Based on Payment Status
if ($GETDATA['status_code'] == 200) {
// Order successful
echo json_encode(['status' => 200, 'message' => "Payment successful"]);
} elseif ($GETDATA['status_code'] == 20000) {
// Order cancelled
echo json_encode(['status' => 20000, 'message' => "Order cancelled"]);
} else {
// Payment not completed
echo json_encode(['status' => 2050, 'message' => "Order not complete"]);
}
?>
<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