define(‘INTEGRATION_KEY’, ‘xyzxyz’);
define(‘MERCHANT_ID’, ‘123123’);
// Define functions
function CreateHash($values) {
$string = “”;
foreach ($values as $key => $value) {
if (strtoupper($key) != “HASH”) {
$string .= $value;
}
}
echo $string;
$string .= INTEGRATION_KEY;
echo $string;
$hash = hash("sha512", $string);
return strtoupper($hash);
}
function initiatePayment($amount, $reference) {
// Define base URL
$baseUrl = ‘https://pay.xyz.com’;
// Define the URLs where Paynow ZW will redirect the user after payment
$returnUrl = $baseUrl . '/success.php?ref=xyz';
$resultUrl = $baseUrl . '/result.php';
$data = [
'id' => MERCHANT_ID,
'reference' => $reference,
'amount' => $amount,
'additionalinfo' => 'A test ticket transaction',
'returnurl' => $returnUrl,
'resulturl' => $resultUrl,
'status' => 'Message', // Initial status
'authemail' => 'raj@gmail.com'
];
$hash = CreateHash($data);
//$data['hash'] = $hash;
// Send data to Paynow ZW API
// You need to implement this part based on your preferred HTTP client (e.g., cURL, Guzzle)
$response = sendRequest('https://www.paynow.co.zw/interface/initiatetransaction', $data);
// Process response
if (!empty($response['status']) && $response['status'] == 'ok') {
// Redirect user to payment page
header('Location: ' . $response['browserurl']);
exit;
} else {
// Handle error
echo 'Error initiating payment: ' . print_r($response, true);
die(); // Terminate script execution
}
}
function sendRequest($url, $data) {
// You need to implement this part based on your preferred HTTP client (e.g., cURL, Guzzle)
// This is a placeholder function
// Example using cURL:
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
return json_decode($response, true);
}
// Example usage
$amount = 100.00; // Amount to be paid (in ZWL)
$reference = ‘ORDER hj’; // Your unique order/reference ID
try {
initiatePayment($amount, $reference);
} catch (Exception $e) {
// If payment fails, redirect to failure page with error message
header(‘Location: failure.php?error=’ . urlencode($e->getMessage()));
exit;
}
i am getting this error
status=Error&error=Invalid+Hash.++Hash+should+start+with%3a+E43D78