In the process of verifying payments, CinetPay implements a notification mechanism that consists in contacting the partner on a Webhook, in order to send him the information of a payment whose status has changed. For security purposes, an HMAC token has been implemented in the header of this notification to allow verification on the partner's side.
The purpose of this turorial is to describe the process for verifying the HMAC token.
Before proceeding to go, you need to retrieve your Secret Key in your merchant account:
Secret Key
thereThe server executes a POST request on your notification url containing :
Headers:
Form values:
The token is constituted by concatenation of the information received in the body of the request. Thus, you must formulate a character string by respecting the diagram below presented:
cpm_site_id + cpm_trans_id + cpm_trans_date + cpm_amount + cpm_currency + signature +
payment_method + cel_phone_num + cpm_phone_prefixe + cpm_language + cpm_version
+ cpm_payment_config + cpm_page_action + cpm_custom + cpm_designation + cpm_error_message
$data = $cpm_site_id . $cpm_trans_id . $cpm_trans_date . $cpm_amount . $cpm_currency .
$signature . $payment_method . $cel_phone_num . $cpm_phone_prefixe .
$cpm_language . $cpm_version . $cpm_payment_config . $cpm_page_action . $cpm_custom . $cpm_designation . $cpm_error_message;
Create the token following the HMAC technique by applying the SHA256 algorithm with the secret key (which will be communicated to you).
$token = hash_hmac(‘SHA256’, $data, $secretKey);
The step consists in checking that the token received in the header corresponds to that which you will have generated.
if(hash_equals($received_token, $generated_token))
{
// Valid Token
}