Below are those steps to generate the first phase payment signature:
/* given $params contains the parameters you would like to sign */
$fields_for_sign = array('mid', 'order_id', 'payment_type', 'amount', 'ccy');
$aggregated_field_str = "";
foreach ($fields_for_sign as $f) {
$aggregated_field_str .= trim($params[$f]);
}
Code example (in PHP):
$aggregated_field_str .= payer_id;
Code example (in PHP):
$aggregated_field_str .= substr(card_no,0,6).substr(card_no,-4);
$aggregated_field_str .= exp_date;
$aggregated_field_str .= substr(cvv2,-1);
If cvv2 is not available, you can proceed to concatenate the card_no and exp_date only.
Code example (in PHP):
$aggregated_field_str .= payer_id;
$aggregated_field_str .= substr(cvv2,-1);
If cvv2 is not available, you can proceed to concatenate the payer_id only.
$secret_key=
"D716A4188569B68AB1B6DFAC178E570114CDF0EA3A1CC0E31486C3E41241BC6A76424E8C37AB26F096FC85EF9886C8CB634187F4FDDFF645FB099F1FF54C6B8C";
$aggregated_field_str .= $secret_key;
$signature = hash ('sha512', $aggregated_field_str);
Other than the first phase request, the algorithm for other generated signature should follow the Generic Signature algorithm mentioned in this section.
The algorithm is applicable for this following process or steps:
Here are the step by step procedures to generate the generic signature:
$rp = array(
'mid' => '1000089029',
'transaction_id' => $_GET['transaction_id'] );
Sample code for authentication response (in PHP):
$response_array = json_decode($json_response, true);
if (isset($response_array['payment_response']) {
unset($response_array['payment_response']['signature'])
$rp = $response_array['payment_response'];
}
$data_to_sign = "";
// at the end of the function call $data_to_sign contains the String required for step 3
recursive_generic_array_sign($rp, $data_to_sign);
/* RECURSIVE FUNCTION DEFINITION */
// use reference-passing to update the variable directly
function recursive_generic_array_sign(&$params, &$data_to_sign) {
// sort the parameters based on its key
ksort($params);
// Traverse through each component
// And generate the concatenated string to sign
foreach ($params as $v) {
if (is_array($v)) {
// In case of array traverse inside
// And build further the string to sign
recursive_generic_array_sign($v, $data_to_sign);
}
else {
// Not an array means this is a key=>value map,
// Concatenate the value to data to sign
$data_to_sign .= $v;
}
}
}
$data_to_sign .= $secret_key;
$signature = hash('sha512', $data_to_sign);
function sign_generic($secret_key, $params)
{
// a copy-passing, so it's not altering the original
unset($params['signature']);
$data_to_sign = "";
recursive_generic_array_sign($params, $data_to_sign);
$data_to_sign .= $secret_key;
return hash('sha512', $data_to_sign);
}
function recursive_generic_array_sign(&$params, &$data_to_sign)
{
// sort the parameters based on its key
ksort($params);
// Traverse through each component
// And generate the concatenated string to sign
foreach ($params as $v) {
if (is_array($v)) {
// in case of array traverse inside
// and build further the string to sign
recursive_generic_array_sign($v, $data_to_sign);
}
else {
// Not an array means this is a key=>value map,
// Concatenate the value to data to sign
$data_to_sign .= $v;
}
}
}
Please take note that the ‘signature’ field or parameter will not always be available or exist inside RDP response message; and might only be available or exist for these following response codes:
Response Code | Description |
---|---|
0 | OK or successful. |
-1 | Bank or acquirer rejection. |
-01 | The transaction is on pending status. Merchant need to continue with either polling query API or waiting for push notification (if there is 'notify_url' parameter at request phase). |