<?php
function createTotalPayOrder($apiUrl, $apiKey, $orderData) {
// Initialize cURL
// Set cURL options
curl_setopt($ch, CURLOPT_URL
, $apiUrl . '/create-order'); // Adjust the endpoint as necessary 'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey,
]);
// Execute the request
// Check for cURL errors
if ($response === false) {
return null;
}
// Close cURL session
// Decode the response
}
// Usage example
$apiUrl = 'https://c...content-available-to-author-only...y.global'; // TotalPay API URL
$apiKey = '26581a8f244c2b2f16fc80caa2d7a58b'; // Your API key from TotalPay
// Prepare order data
$orderData = [
'merchant_id' => '072f3aa2-1cfd-11ef-b318-7a03a3b9dc8b', // Your merchant ID
'amount' => 1000, // Amount in the smallest currency unit (e.g., cents)
'currency' => 'USD',
'order_id' => uniqid(), // Unique order ID 'description' => 'Order description here',
'redirect_url' => 'https://b...content-available-to-author-only...t.com/thank-you', // URL to redirect after payment
'cancel_url' => 'https://b...content-available-to-author-only...t.com/cancel', // URL for cancel action
];
// Create order
$orderResponse = createTotalPayOrder($apiUrl, $apiKey, $orderData);
// Check the response
if ($orderResponse) {
if ($orderResponse['status'] === 'success') {
// Redirect the user to the payment page
header('Location: ' . $orderResponse['payment_url']); } else {
echo 'Order creation failed: ' . $orderResponse['message'];
}
} else {
echo 'Failed to create order.';
}
?>
PD9waHAKCmZ1bmN0aW9uIGNyZWF0ZVRvdGFsUGF5T3JkZXIoJGFwaVVybCwgJGFwaUtleSwgJG9yZGVyRGF0YSkgewogICAgLy8gSW5pdGlhbGl6ZSBjVVJMCiAgICAkY2ggPSBjdXJsX2luaXQoKTsKCiAgICAvLyBTZXQgY1VSTCBvcHRpb25zCiAgICBjdXJsX3NldG9wdCgkY2gsIENVUkxPUFRfVVJMLCAkYXBpVXJsIC4gJy9jcmVhdGUtb3JkZXInKTsgLy8gQWRqdXN0IHRoZSBlbmRwb2ludCBhcyBuZWNlc3NhcnkKICAgIGN1cmxfc2V0b3B0KCRjaCwgQ1VSTE9QVF9SRVRVUk5UUkFOU0ZFUi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