Signature generation and verification
Overview
The data communication between the merchant's web service and the Orchid payment platform is protected by using the TLS (Transport Layer Security) protocol version 1.2 or later. This ensures the confidentiality of the data being transmitted, although the protocol cannot guarantee the message integrity and ensure that the message author possesses the secret key. Therefore, every message must be digitally signed using the secret key issued by Orchid for the merchant and known only to the merchant and the Orchid payment platform.
Regardless of the interface that is used for working with the payment platform, digital signatures must be included in all requests, callbacks, and certain responses exchanged between the merchant's web service and the payment platform. Thus, before sending any request to the platform, generate and include a signature in the request to be sent; and when receiving responses and callbacks from the platform, verify the received data by comparing the signatures to the ones generated on the merchant side. To implement the digital signature generation and verification, you can use either your own solutions or the SDKs available from Orchid (details).
This section describes the algorithms for the digital signature generation and the data integrity verification, including examples with the use of these algorithms and interactive forms for testing the workflows using signatures.
Signature generation
Signing algorithm
The algorithm input includes the following:
- Data to sign.
As a rule, it is a request body: all request parameters without the signature or the configObj JavaScript object with parameters that do not include the
signature
parameter. - A signing key.Note: For working with the Data API, it is necessary to use keys generated via the Dashboard interface together with tokens (for more information, see the Data access model section.)
For the purposes of debugging and testing your signing algorithm implementation, you are free to use any signing key. For signing requests in production environment, you are required to use your production secret key.
Depending on the algorithm implementation, its output may be either a signature or signed data. Generally, the algorithm output consists of an object or a request body in the JSON format with the signature
parameter.
The algorithm description, the examples, and test forms below include the most common algorithm implementation relevant for use when working with the Payment Page API, the Gate API, and the Data API.
The algorithm includes the following steps:
-
Validating input. Make sure the following requirements are met:
- The structure of data to be signed must correspond to the JSON format. In case of using Payment Page, JavaScript objects are also allowed.
- Data to sign does not contain any
signature
parameter even if it is empty. - The signing key is readily available.
- Transforming data to meet the nesting depth requirements.
Depending on which interface of the payment platform you need to send the request to, this step requires different actions:
- When working via Payment Page, encode those parameters that contain nested objects using Base64 or URL encoding, as per the requirements that can be found in the list of parameters for opening the payment form.
- When working via the Gate API, you do not have to transform data because there are no nesting depth restrictions.
- When working via the Data API, replace values of all parameters nested at level four or deeper with empty strings.
-
Converting all strings to UTF-8 with parameters sorted in natural order. Complete the following steps:
- Encode any Boolean values as follows: replace
false
with0
, replacetrue
with1
. Mind that this rule applies only to Boolean values. If any string parameter contains"false"
or"true"
string value, the value is not replaced with0
or1
but is treated as any other string value (for example therecurring: "{type: \"U\",register: true}"
parameter does not require replacingtrue
with1
). -
Convert each parameter into a string that contains the full path to the parameter (with all its parents), parameter name, and parameter value:
<parent_1>:...:<parent_n>:<parameter_name>:<parameter_value>
where parents are the object(s) and/or arrays in which the parameter is contained. Parents are ordered by the embedding level starting with the topmost one. The parent names, parameter name, and parameter value are delimited by colon (:); delete any commas between key-value pairs and any quotation marks that delimit string values.
- Leave any empty parameter values empty. In other words, do not replace any empty values with blank space or
null
. For instance,"payment_description":""
is replaced withpayment_description:
. - Add index numbers to array elements starting with zero, for example,
["alpha", "beta", "gamma"]
is replaced with three strings:0:alpha
,1:beta
, and2:gamma
. - Empty arrays are ignored and are not included in the string set used to generate the signature.
- Convert all strings to UTF-8.
- Sort the strings in natural sort order and join them into a single string by using semicolon (;) as a delimiter.
- Encode any Boolean values as follows: replace
- Calculating the HMAC code by using the key and the SHA-512 hash function. Calculate the HMAC code for the string by using the SHA-512 hash function and secret key. The HMAC code must be calculated as raw binary data.
- Encoding the HMAC code by using the Base64 scheme. Encode the HMAC code using Base64 to obtain the signature for the initial data.
- Adding signature. Add the
signature
parameter to the request body using the signature from the previous step as its value.
Example of a purchase request via Payment Page
Suppose that you need to generate a signature for a Payment Page request in the following scenario:
- The secret key obtained from the Orchid technical support:
secret
. - The configObj object that does not yet contain the signature parameter is the following:
{ "project_id": 12345, "payment_id": "X03936", "payment_amount": 2035, "payment_currency": "USD", "payment_description": "Guyliner purchase", "customer_first_name": "Jack", "customer_id": "user007", "customer_last_name": "Sparrow", "customer_phone": "02081234567", "close_on_missclick": true, "signature": "<signature that needs to be generated>" }
The task is to generate the signature; in other words, you need to compute the value for the signature
parameter. The signature is generated as follows:
- Make sure there is no
signature
parameter in your request even it is empty:{ "project_id": 12345, "payment_id": "X03936", "payment_amount": 2035, "payment_currency": "USD", "payment_description": "Guyliner purchase", "customer_first_name": "Jack", "customer_id": "user007", "customer_last_name": "Sparrow", "customer_phone": "02081234567", "close_on_missclick": true, "signature": "<signature that needs to be generated>" }
- Convert all strings to UTF-8 as per algorithm description:
project_id:12345 payment_id:X03936 payment_amount:2035 payment_currency:USD payment_description:Guyliner purchase customer_first_name:Jack customer_id:user007 customer_last_name:Sparrow customer_phone:02081234567 close_on_missclick:1
- Sort the strings in natural sort order:
close_on_missclick:1 customer_first_name:Jack customer_id:user007 customer_last_name:Sparrow customer_phone:02081234567 payment_amount:2035 payment_currency:USD payment_description:Guyliner purchase payment_id:X03936 project_id:12345
- Join all strings into a single string by using semicolon (;) as a delimiter:
close_on_missclick:1;customer_first_name:Jack;customer_id:user007;customer_last_name:Sparrow;customer_phone:02081234567;payment_amount:2035;payment_currency:USD;payment_description:Guyliner purchase;payment_id:X03936;project_id:12345
- Calculate the HMAC code for the string by using the SHA-512 hash function and secret key, and then encode the HMAC code by using the Base64 scheme:
SyA3cx/dmFrwjRcpbnwEK9zaklWKR9buIfTctQob/EHUTutFLpI0zWpSDFEWEwbZt/04i83395RCdEhtUMw83A==
- Add the resulting signature to the configObj object:
{ "project_id": 12345, "payment_id": "X03936", "payment_amount": 2035, "payment_currency": "USD", "payment_description": "Guyliner purchase", "customer_first_name": "Jack", "customer_id": "user007", "customer_last_name": "Sparrow", "customer_phone": "02081234567", "close_on_missclick": true, "signature": "SyA3cx/dmFrwjRcpbnwEK9zaklWKR9buIfTctQob/EHUTutFLpI0zWpSDFEWEwbZt/04i83395RCdEhtUMw83A==" }
Signature verification form for Payment Page
Below you can find an interactive form that allows you to test signature generation when sending requests for opening Payment Page.
Example of a purchase request via Gate
Suppose that you need to generate the signature for the Gate API request in the following scenario:
- Signing key :
secret
. - Preliminary request body version where the value for the
signature
is not yet added:{ "general": { "project_id": 3254, "payment_id": "id_38202316", "signature": "<signature that needs to be generated>" }, "customer": { "id": "585741", "email": "johndoe@mycompany.com", "first_name": "John", "last_name": "Doe", "address": "Downing str., 23", "identify": { "doc_number": "54122312544" }, "ip_address": "111.222.333.444" }, "payment": { "amount": 10800, "currency": "USD", "description": "Computer keyboards" }, "receipt_data": { "positions": [ { "quantity": "10", "amount": "108", "description": "Computer keyboard" } ] }, "return_url": { "success": "https://paymentpage.mycompany.com/complete-redirect?id=success", "decline": "https://paymentpage.mycompany.com/complete-redirect?id=decline" } }
The task is to generate the signature; in other words, you need to compute the value for the signature
parameter and add it to the request. Complete the following steps:
- Make sure there is no
signature
parameter in your request even if it is empty:{ "general": { "project_id": 3254, "payment_id": "id_38202316", "signature": "<signature that needs to be generated>" }, "customer": { "id": "585741", "email": "johndoe@mycompany.com", "first_name": "John", "last_name": "Doe", "address": "Downing str., 23", "identify": { "doc_number": "54122312544" }, "ip_address": "111.222.333.444" }, "payment": { "amount": 10800, "currency": "USD", "description": "Computer keyboards" }, "receipt_data": { "positions": [ { "quantity": "10", "amount": "108", "description": "Computer keyboard" } ] }, "return_url": { "success": "https://paymentpage.mycompany.com/complete-redirect?id=success", "decline": "https://paymentpage.mycompany.com/complete-redirect?id=decline" } }
- Convert all strings to UTF-8 as per algorithm description:
general:project_id:3254 general:payment_id:id_38202316 customer:id:585741 customer:email:johndoe@mycompany.com customer:first_name:John customer:last_name:Doe customer:address:Downing str., 23 customer:identify:doc_number:54122312544 customer:ip_address:111.222.333.444 payment:amount:10800 payment:currency:USD payment:description:Computer keyboards receipt_data:positions:0:quantity:10 receipt_data:positions:0:amount:108 receipt_data:positions:0:description:Computer keyboard return_url:success:https://paymentpage.mycompany.com/complete-redirect?id=success return_url:decline:https://paymentpage.mycompany.com/complete-redirect?id=decline
- Sort the strings in natural sort order:
customer:address:Downing str., 23 customer:email:johndoe@mycompany.com customer:first_name:John customer:id:585741 customer:identify:doc_number:54122312544 customer:ip_address:111.222.333.444 customer:last_name:Doe general:payment_id:id_38202316 general:project_id:3254 payment:amount:10800 payment:currency:USD payment:description:Computer keyboards receipt_data:positions:0:amount:108 receipt_data:positions:0:description:Computer keyboard receipt_data:positions:0:quantity:10 return_url:decline:https://paymentpage.mycompany.com/complete-redirect?id=decline return_url:success:https://paymentpage.mycompany.com/complete-redirect?id=success
- Join all strings into a single string by using semicolon (;) as a delimiter:
customer:address:Downing str., 23;customer:email:johndoe@mycompany.com;customer:first_name:John;customer:id:585741;customer:identify:doc_number:54122312544;customer:ip_address:111.222.333.444;customer:last_name:Doe;general:payment_id:id_38202316;general:project_id:3254;payment:amount:10800;payment:currency:USD;payment:description:Computer keyboards;receipt_data:positions:0:amount:108;receipt_data:positions:0:description:Computer keyboard;receipt_data:positions:0:quantity:10;return_url:decline:https://paymentpage.mycompany.com/complete-redirect?id=decline;return_url:success:https://paymentpage.mycompany.com/complete-redirect?id=success
- Calculate the HMAC code for the string by using the SHA-512 hash function and secret key, and then encode the HMAC code by using the Base64 scheme:
VLLZzVNGevQNhr1b4TEhbC4qqHD17Kyn/M6FPNN93ttyk/amJgD/R6dayTKVvW6/QCRdq4hOf8R2w/xbUa8f2w==
- Add the resulting signature to the request body:
{ "general": { "project_id": 3254, "payment_id": "id_38202316", "signature": "VLLZzVNGevQNhr1b4TEhbC4qqHD17Kyn/M6FPNN93ttyk/amJgD/R6dayTKVvW6/QCRdq4hOf8R2w/xbUa8f2w==" }, "customer": { "id": "585741", "email": "johndoe@mycompany.com", "first_name": "John", "last_name": "Doe", "address": "Downing str., 23", "identify": { "doc_number": "54122312544" }, "ip_address": "111.222.333.444" }, "payment": { "amount": 10800, "currency": "USD", "description": "Computer keyboards" }, "receipt_data": { "positions": [ { "quantity": "10", "amount": "108", "description": "Computer keyboard" } ] }, "return_url": { "success": "https://paymentpage.mycompany.com/complete-redirect?id=success", "decline": "https://paymentpage.mycompany.com/complete-redirect?id=decline" } }
Signature verification form for the Gate API
Below you can find an interactive form that allows you to test signature generation when sending the Gate API requests.
Example of a data request via the Data API
Suppose that you need to generate a signature for a Dashboard request in the following scenario:
- Signing key :
secret
. - Preliminary request body version where the value for the
signature
is not yet added:{ "token": "WKiarERJ5pcceNerpM9R5TNnyPTQMl", "interval": { "from": "2020-01-01 14:53:55", "to": "2020-01-30 13:53:59" }, "project_id": [ 183 ], "limit": 3, "offset": 0, "tz": "Asia/Singapore", "signature": "<signature that needs to be generated>" }
The task is to generate the signature; in other words, you need to compute the value for the signature
parameter and add it to the request. Complete the following steps:
- Make sure there is no
signature
parameter in your request even it is empty:{ "token": "WKiarERJ5pcceNerpM9R5TNnyPTQMl", "interval": { "from": "2020-01-01 14:53:55", "to": "2020-01-30 13:53:59" }, "project_id": [ 183 ], "limit": 3, "offset": 0, "tz": "Asia/Singapore", "signature": "<signature that needs to be generated>" }
- Convert all strings to UTF-8 as per algorithm description:
token:WKiarERJ5pcceNerpM9R5TNnyPTQMl interval:from:2020-01-01 14:53:55 interval:to:2020-01-30 13:53:59 project_id:0:183 limit:3 offset:0 tz:Asia/Singapore
- Sort the strings in natural sort order:
interval:from:2020-01-01 14:53:55 interval:to:2020-01-30 13:53:59 limit:3 offset:0 project_id:0:183 token:WKiarERJ5pcceNerpM9R5TNnyPTQMl tz:Asia/Singapore
- Join all strings into a single string by using semicolon (;) as a delimiter:
interval:from:2020-01-01 14:53:55;interval:to:2020-01-30 13:53:59;limit:3;offset:0;project_id:0:183;token:WKiarERJ5pcceNerpM9R5TNnyPTQMl;tz:Asia/Singapore
- Calculate the HMAC code for the string by using the SHA-512 hash function and secret key, and then encode the HMAC code by using the Base64 scheme:
Ini3aKje6aZskajTuRS761YOzVqierlVRafZdxIz48wmVnL7yxgy9vDsp7T2/LGPGHJ/DHoKOgP7VqObJALrUA==
- Add the resulting signature to the request body:
{ "token": "WKiarERJ5pcceNerpM9R5TNnyPTQMl", "interval": { "from": "2020-01-01 14:53:55", "to": "2020-01-30 13:53:59" }, "project_id": [ 183 ], "limit": 3, "offset": 0, "tz": "Asia/Singapore", "signature": "Ini3aKje6aZskajTuRS761YOzVqierlVRafZdxIz48wmVnL7yxgy9vDsp7T2/LGPGHJ/DHoKOgP7VqObJALrUA==" }
Signature verification form for Data API
Below you can find an interactive form that allows you to test signature generation when sending the Data API requests.
Signature verification
Verification algorithm
The algorithm input includes the following:
- Signed data to verify.
As a rule, it is a callback or response body in the JSON format with the
signature
parameter. - Verification key. It must be the same key that was previously used for signing the data to verify.
Depending on the algorithm implementation, its output may be either a generated signature or the information whether the generated signature matches the one included in the response or callback.
The algorithm description, the examples, and test forms below use the most common algorithm implementation that includes a callback or response body in the JSON format as input (without the signature
parameter) and the result of signature verification as output (with the signature
parameter).
Thus, the algorithm includes the following steps:
-
Validating input. Make sure the following requirements are met:
- Data conforms to the JSON format.
- Data to verify contains a
signature
parameter with the signature value. - The signing key is readily available.
- Extracting the signature from the data to verify. Store the value of the
signature
parameter value for further reference and remove the parameter from the input data. -
When working with the responses received from the platform via the Data API, at this step you need to replace values of all parameters nested at level four and deeper with empty strings. For example, in the response with operation information for a specified time period you need to remove key-value pairs of the following object:
"sum_initial": {"amount": 2000, "currency": "EUR"}
. Next, you need to replace the value of the parameter with an empty string"sum_initial": ""
and then generate the signature. As for responses and callbacks received from other interfaces of the platform, there are no nesting depth restrictions, and, therefore, no actions to remove data are required. - Generating a signature for the data to verify.
- Converting all strings to UTF-8 with parameters sorted in natural order. Complete the following steps:
- Encode any Boolean values as follows: replace
false
with0
, replacetrue
with1
. Mind that this rule applies only to Boolean values. If any string parameter contains"false"
or"true"
string value, the value is not replaced with0
or1
but is treated as any other string value (for example therecurring: "{type: \"U\",register: true}"
parameter does not require replacingtrue
with1
). -
Convert each parameter into a string that contains the full path to the parameter (with all its parents), parameter name, and parameter value:
<parent_1>:...:<parent_n>:<parameter_name>:<parameter_value>
where parents are the object(s) and/or arrays in which the parameter is contained. Parents are ordered by the embedding level starting with the topmost one. The parent names, parameter name, and parameter value are delimited by colon (:); delete any commas between key-value pairs and any quotation marks that delimit string values.
- Leave any empty parameter values empty. In other words, do not replace any empty values with blank space or
null
. For instance,"payment_description":""
is replaced withpayment_description:
. - Add index numbers to array elements starting with zero, for example,
["alpha", "beta", "gamma"]
is replaced with three strings:0:alpha
,1:beta
, and2:gamma
. - Empty arrays are ignored and not included in the string set used to generate the signature.
- Convert all strings to UTF-8.
- Sort the strings in natural sort order and join them into a single string by using semicolon (;) as a delimiter.
- Encode any Boolean values as follows: replace
- Calculating the HMAC code by using the key and the SHA-512 hash function. Calculate the HMAC code for the string by using the SHA-512 hash function and secret key. The HMAC code must be calculated as raw binary data.
- Encoding the HMAC code by using the Base64 scheme. Encode the HMAC code using Base64 to obtain the signature for the initial data.
- Converting all strings to UTF-8 with parameters sorted in natural order. Complete the following steps:
- Signature matching. Compare the generated signature with the signature you have previously stored. If the signatures match, the data is authentic and its integrity is considered confirmed; otherwise, the data is considered compromised and cannot be used for production purposes.
Example of callback verification
Suppose that you need to verify the signature of a callback in the following scenario:
- Signing key :
secret
. - The callback body contains the following information:
Figure 1. Callback body { "customer": { "id": "782572" }, "account": { "number": "424242******4242", "token": "c8175453f68ec7c8fb3f052b8d786c661261efebcb91155327a6c7b8f8e66359", "type": "visa", "card_holder": "TEST TEST", "expiry_month": "01", "expiry_year": "2025" }, "project_id": 28051, "payment": { "id": "5242723", "type": "purchase", "status": "success", "date": "2023-03-10T12:26:17+0000", "method": "card", "sum": { "amount": 5200, "currency": "EUR" }, "description": "" }, "operation": { "sum_initial": { "amount": 5200, "currency": "EUR" }, "sum_converted": { "amount": 5200, "currency": "EUR" }, "code": "0", "message": "Success", "provider": { "id": 6, "payment_id": "16784511766816", "auth_code": "563253", "endpoint_id": 6, "date": "2023-03-10T10:26:17+0000" }, "id": 5028800010128225, "type": "sale", "status": "success", "date": "2023-03-10T12:26:17+0000", "created_date": "2023-03-10T12:26:15+0000", "request_id": "1f6d3ac37444142f5bd27e7491faa360633fd5a2-fc98e73d475fa4cd6ee02fc6340c964f0267b3d8-05028801" }, "signature": "IszjSnH+UqFp88DF0giI/jUTDHOnfPxc83j2VD/jN4loB9wbHwiO5+KvHfdFE4nBPHhhxD6TXbOkGnRINFTTmg==" }
The signature is verified as follows:
- Remove the
signature
parameter and its value from the callback:{ "customer": { "id": "782572" }, "account": { "number": "424242******4242", "token": "c8175453f68ec7c8fb3f052b8d786c661261efebcb91155327a6c7b8f8e66359", "type": "visa", "card_holder": "TEST TEST", "expiry_month": "01", "expiry_year": "2025" }, "project_id": 28051, "payment": { "id": "5242723", "type": "purchase", "status": "success", "date": "2023-03-10T12:26:17+0000", "method": "card", "sum": { "amount": 5200, "currency": "EUR" }, "description": "" }, "operation": { "sum_initial": { "amount": 5200, "currency": "EUR" }, "sum_converted": { "amount": 5200, "currency": "EUR" }, "code": "0", "message": "Success", "provider": { "id": 6, "payment_id": "16784511766816", "auth_code": "563253", "endpoint_id": 6, "date": "2023-03-10T10:26:17+0000" }, "id": 5028800010128225, "type": "sale", "status": "success", "date": "2023-03-10T12:26:17+0000", "created_date": "2023-03-10T12:26:15+0000", "request_id": "1f6d3ac37444142f5bd27e7491faa360633fd5a2-fc98e73d475fa4cd6ee02fc6340c964f0267b3d8-05028801" }, "signature": "IszjSnH+UqFp88DF0giI/jUTDHOnfPxc83j2VD/jN4loB9wbHwiO5+KvHfdFE4nBPHhhxD6TXbOkGnRINFTTmg==" }
- Convert all parameter strings to UTF-8 as per algorithm description:
customer:id:782572 account:number:424242******4242 account:token:c8175453f68ec7c8fb3f052b8d786c661261efebcb91155327a6c7b8f8e66359 account:type:visa account:card_holder:TEST TEST account:expiry_month:01 account:expiry_year:2025 project_id:28051 payment:id:5242723 payment:type:purchase payment:status:success payment:date:2023-03-10T12:26:17+0000 payment:method:card payment:sum:amount:5200 payment:sum:currency:EUR payment:description: operation:sum_initial:amount:5200 operation:sum_initial:currency:EUR operation:sum_converted:amount:5200 operation:sum_converted:currency:EUR operation:code:0 operation:message:Success operation:provider:id:6 operation:provider:payment_id:16784511766816 operation:provider:auth_code:563253 operation:provider:endpoint_id:6 operation:provider:date:2023-03-10T10:26:17+0000 operation:id:5028800010128225 operation:type:sale operation:status:success operation:date:2023-03-10T12:26:17+0000 operation:created_date:2023-03-10T12:26:15+0000 operation:request_id:1f6d3ac37444142f5bd27e7491faa360633fd5a2-fc98e73d475fa4cd6ee02fc6340c964f0267b3d8-05028801
- Sort the strings in natural sort order:
account:card_holder:TEST TEST account:expiry_month:01 account:expiry_year:2025 account:number:424242******4242 account:token:c8175453f68ec7c8fb3f052b8d786c661261efebcb91155327a6c7b8f8e66359 account:type:visa customer:id:782572 operation:code:0 operation:created_date:2023-03-10T12:26:15+0000 operation:date:2023-03-10T12:26:17+0000 operation:id:5028800010128225 operation:message:Success operation:provider:auth_code:563253 operation:provider:date:2023-03-10T10:26:17+0000 operation:provider:endpoint_id:6 operation:provider:id:6 operation:provider:payment_id:16784511766816 operation:request_id:1f6d3ac37444142f5bd27e7491faa360633fd5a2-fc98e73d475fa4cd6ee02fc6340c964f0267b3d8-05028801 operation:status:success operation:sum_converted:amount:5200 operation:sum_converted:currency:EUR operation:sum_initial:amount:5200 operation:sum_initial:currency:EUR operation:type:sale payment:date:2023-03-10T12:26:17+0000 payment:description: payment:id:5242723 payment:method:card payment:status:success payment:sum:amount:5200 payment:sum:currency:EUR payment:type:purchase project_id:28051
- Join all strings into a single string by using semicolon (;) as a delimiter:
account:card_holder:TEST TEST;account:expiry_month:01;account:expiry_year:2025;account:number:424242******4242;account:token:c8175453f68ec7c8fb3f052b8d786c661261efebcb91155327a6c7b8f8e66359;account:type:visa;customer:id:782572;operation:code:0;operation:created_date:2023-03-10T12:26:15+0000;operation:date:2023-03-10T12:26:17+0000;operation:id:5028800010128225;operation:message:Success;operation:provider:auth_code:563253;operation:provider:date:2023-03-10T10:26:17+0000;operation:provider:endpoint_id:6;operation:provider:id:6;operation:provider:payment_id:16784511766816;operation:request_id:1f6d3ac37444142f5bd27e7491faa360633fd5a2-fc98e73d475fa4cd6ee02fc6340c964f0267b3d8-05028801;operation:status:success;operation:sum_converted:amount:5200;operation:sum_converted:currency:EUR;operation:sum_initial:amount:5200;operation:sum_initial:currency:EUR;operation:type:sale;payment:date:2023-03-10T12:26:17+0000;payment:description:;payment:id:5242723;payment:method:card;payment:status:success;payment:sum:amount:5200;payment:sum:currency:EUR;payment:type:purchase;project_id:28051
- Calculate the HMAC code for the string by using the SHA-512 hash function and secret key, and then encode the HMAC code by using the Base64 scheme:
Y0qjN9dDnPTdddkVvXKS1pGp2z8ZpIl60P1CocND3YRxuBNx05ZMnhUaGFt90fPzgwsI/UpLw0q2RR/XTiDQBg==
- Compare the generated signature and the one included in the callback.
In our case, the signatures differ which means that the callback is invalid and must be ignored.
Signature verification form for callbacks
Below you can find an interactive form that allows you to test signature verification.
Example of verifying a response via the Gate API
Suppose that you need to verify the signature of a response in the following scenario:
- Signing key :
secret
. - The response body contains the following information:
Figure 2. Response body { "project_id": 200, "payment": { "id": "abc12345", "type": "purchase", "status": "success", "date": "2025-04-23T10:54:37+0000", "method": "card", "sum": { "amount": 45000, "currency": "EUR" }, "description": "" }, "account": { "number": "425000******0000", "token": "13n121******4991", "type": "visa", "card_holder": "****************", "expiry_month": "**", "expiry_year": "****" }, "customer": { "id": "customer_007" }, "operations": [ { "id": 9529253065607, "type": "auth", "status": "success", "date": "2025-04-23T10:54:27+0000", "created_date": "2025-04-23T10:53:48+0000", "request_id": "a7B9kLmQwP2X8rTg-uV3n6Zc1RbEyHd", "sum_initial": { "amount": 45000, "currency": "EUR" }, "sum_converted": { "amount": 45000, "currency": "EUR" }, "code": "0", "message": "Success", "eci": "05", "provider": { "id": 3651, "payment_id": "00000000123456", "auth_code": "070707", "endpoint_id": 0000, "date": "2025-04-23T10:54:26+0000" } } ], "signature": "EksxDdDygDQ30JKsfK6QSvubpNRSj3wtLI5FzWDJuNY0nEhLXt65Y77dtKMJRcd39NegA7YK1eojA2EB1hIbnQ==" }
The signature is verified as follows:
-
Remove the
signature
parameter and its value.{ "project_id": 200, "payment": { "id": "abc12345", "type": "purchase", "status": "success", "date": "2025-04-23T10:54:37+0000", "method": "card", "sum": { "amount": 45000, "currency": "EUR" }, "description": "" }, "account": { "number": "425000******0000", "token": "13n121******4991", "type": "visa", "card_holder": "****************", "expiry_month": "**", "expiry_year": "****" }, "customer": { "id": "customer_007" }, "operations": [ { "id": 9529253065607, "type": "auth", "status": "success", "date": "2025-04-23T10:54:27+0000", "created_date": "2025-04-23T10:53:48+0000", "request_id": "a7B9kLmQwP2X8rTg-uV3n6Zc1RbEyHd", "sum_initial": { "amount": 45000, "currency": "EUR" }, "sum_converted": { "amount": 45000, "currency": "EUR" }, "code": "0", "message": "Success", "eci": "05", "provider": { "id": 3651, "payment_id": "00000000123456", "auth_code": "070707", "endpoint_id": 0000, "date": "2025-04-23T10:54:26+0000" } } ], "signature": "EksxDdDygDQ30JKsfK6QSvubpNRSj3wtLI5FzWDJuNY0nEhLXt65Y77dtKMJRcd39NegA7YK1eojA2EB1hIbnQ==" }
- Convert all parameter strings to UTF-8 as per algorithm description:
project_id:200 payment:id:abc12345 payment:type:purchase payment:status:success payment:date:2025-04-23T10:54:37+0000 payment:method:card payment:sum:amount:45000 payment:sum:currency:EUR payment:description: account:number:425000******0000 account:token:13n121******4991 account:type:visa account:card_holder:**************** account:expiry_month:** account:expiry_year:**** customer:id:customer_007 operations:0:id:9529253065607 operations:0:type:auth operations:0:status:success operations:0:date:2025-04-23T10:54:27+0000 operations:0:created_date:2025-04-23T10:53:48+0000 operations:0:request_id:a7B9kLmQwP2X8rTg-uV3n6Zc1RbEyHd operations:0:sum_initial:amount:45000 operations:0:sum_initial:currency:EUR operations:0:sum_converted:amount:45000 operations:0:sum_converted:currency:EUR operations:0:code:0 operations:0:message:Success operations:0:eci:05 operations:0:provider:id:3651 operations:0:provider:payment_id:00000000123456 operations:0:provider:auth_code:070707 operations:0:provider:endpoint_id:0 operations:0:provider:date:2025-04-23T10:54:26+0000
- Sort the strings in natural sort order:
account:card_holder:**************** account:expiry_month:** account:expiry_year:**** account:number:425000******0000 account:token:13n121******4991 account:type:visa customer:id:customer_007 operations:0:code:0 operations:0:created_date:2025-04-23T10:53:48+0000 operations:0:date:2025-04-23T10:54:27+0000 operations:0:eci:05 operations:0:id:9529253065607 operations:0:message:Success operations:0:provider:auth_code:070707 operations:0:provider:date:2025-04-23T10:54:26+0000 operations:0:provider:endpoint_id:0 operations:0:provider:id:3651 operations:0:provider:payment_id:00000000123456 operations:0:request_id:a7B9kLmQwP2X8rTg-uV3n6Zc1RbEyHd operations:0:status:success operations:0:sum_converted:amount:45000 operations:0:sum_converted:currency:EUR operations:0:sum_initial:amount:45000 operations:0:sum_initial:currency:EUR operations:0:type:auth payment:date:2025-04-23T10:54:37+0000 payment:description: payment:id:abc12345 payment:method:card payment:status:success payment:sum:amount:45000 payment:sum:currency:EUR payment:type:purchase project_id:200
- Join all strings into a single string by using semicolon (;) as a delimiter:
account:card_holder:****************;account:expiry_month:**;account:expiry_year:****;account:number:425000******0000;account:token:13n121******4991;account:type:visa;customer:id:customer_007;operations:0:code:0;operations:0:created_date:2025-04-23T10:53:48+0000;operations:0:date:2025-04-23T10:54:27+0000;operations:0:eci:05;operations:0:id:9529253065607;operations:0:message:Success;operations:0:provider:auth_code:070707;operations:0:provider:date:2025-04-23T10:54:26+0000;operations:0:provider:endpoint_id:0;operations:0:provider:id:3651;operations:0:provider:payment_id:00000000123456;operations:0:request_id:a7B9kLmQwP2X8rTg-uV3n6Zc1RbEyHd;operations:0:status:success;operations:0:sum_converted:amount:45000;operations:0:sum_converted:currency:EUR;operations:0:sum_initial:amount:45000;operations:0:sum_initial:currency:EUR;operations:0:type:auth;payment:date:2025-04-23T10:54:37+0000;payment:description:;payment:id:abc12345;payment:method:card;payment:status:success;payment:sum:amount:45000;payment:sum:currency:EUR;payment:type:purchase;project_id:200
- Calculate the HMAC code for the string by using the SHA-512 hash function and secret key, and then encode the HMAC code by using the Base64 scheme:
qUVvwChGUOSWRXwKQI6ZIkKvvWJsvx2luS8cYvN+M7iRiBAKkGE+WwfgAztgGU+vZNMr2bd4Lnn0J0KkhwYS1A==
- Compare the generated signature and the one included in the response.
In our case, the signatures differ which means that the response is invalid and must be ignored.
Signature verification form for responses via the Gate API
Below you can find an interactive form that allows you to test signature verification.
Example of verifying a response via the Data API
Suppose that you need to verify the signature of a response in the following scenario:
- Signing key :
secret
. - The response body contains the following information:
Figure 3. Response body { "operations": [ { "project_id": "183", "operation_id": "9048253065548", "payment_id": "EP834a-40521580376090593", "operation_type": "cancel", "operation_status": "success", "account_number": "431422******0056", "customer_ip": "192.0.0.255", "payment_method_name": "visa", "payment_method_type": "visa", "payment_description": null, "operation_created_at": "2020-01-30T12:29:03+03:00", "operation_completed_at": "2020-01-30T12:29:04+03:00", "provider_date": null, "shipment_date": "", "mid": "3416123", "sum_initial": { "amount": 2000, "currency": "EUR" }, "sum_converted": { "amount": 2000, "currency": "EUR" }, "provider_name": "Dashboard Provider Card", "fee_currency": null, "fee_amount": 0, "arn": null, "rrn": null } ], "signature": "EksxDdDygDQ30JKsfK6QSvubpNRSj3wtLI5FzWDJuNY0nEhLXt65Y77dtKMJRcd39NegA7YK1eojA2EB1hIbnQ==" }
The signature is verified as follows:
-
Remove the
signature
parameter and its value.{ "operations": [ { "project_id": "183", "operation_id": "9048253065548", "payment_id": "EP834a-40521580376090593", "operation_type": "cancel", "operation_status": "success", "account_number": "431422******0056", "customer_ip": "192.0.0.255", "payment_method_name": "visa", "payment_method_type": "visa", "payment_description": null, "operation_created_at": "2020-01-30T12:29:03+03:00", "operation_completed_at": "2020-01-30T12:29:04+03:00", "provider_date": null, "shipment_date": "", "mid": "3416123", "sum_initial": { "amount": 2000, "currency": "EUR" }, "sum_converted": { "amount": 2000, "currency": "EUR" }, "provider_name": "Dashboard Provider Card", "fee_currency": null, "fee_amount": 0, "arn": null, "rrn": null } ], "signature": "EksxDdDygDQ30JKsfK6QSvubpNRSj3wtLI5FzWDJuNY0nEhLXt65Y77dtKMJRcd39NegA7YK1eojA2EB1hIbnQ==" }
- Replace the data nested at the fourth level with an empty string:
{ "operations": [ { "project_id": "183", "operation_id": "9048253065548", "payment_id": "EP834a-40521580376090593", "operation_type": "cancel", "operation_status": "success", "account_number": "431422******0056", "customer_ip": "192.0.0.255", "payment_method_name": "visa", "payment_method_type": "visa", "payment_description": null, "operation_created_at": "2020-01-30T12:29:03+03:00", "operation_completed_at": "2020-01-30T12:29:04+03:00", "provider_date": null, "shipment_date": "", "mid": "3416123", "sum_initial": { "amount": 2000, "currency": "EUR" }, "sum_initial":"", "sum_converted": { "amount": 2000, "currency": "EUR" }, "sum_converted":"", "provider_name": "Dashboard Provider Card", "fee_currency": null, "fee_amount": 0, "arn": null, "rrn": null } ] }
- Convert all parameter strings to UTF-8 as per algorithm description:
operations:0:project_id:183 operations:0:operation_id:9048253065548 operations:0:payment_id:EP834a-40521580376090593 operations:0:operation_type:cancel operations:0:operation_status:success operations:0:account_number:431422******0056 operations:0:customer_ip:192.0.0.255 operations:0:payment_method_name:visa operations:0:payment_method_type:visa operations:0:payment_description: operations:0:operation_created_at:2020-01-30T12:29:03+03:00 operations:0:operation_completed_at:2020-01-30T12:29:04+03:00 operations:0:provider_date: operations:0:shipment_date: operations:0:mid:3416123 operations:0:sum_initial: operations:0:sum_converted: operations:0:provider_name:Dashboard Provider Card operations:0:fee_currency: operations:0:fee_amount:0 operations:0:arn: operations:0:rrn:
- Sort the strings in natural sort order:
operations:0:account_number:431422******0056 operations:0:arn: operations:0:customer_ip:192.0.0.255 operations:0:fee_amount:0 operations:0:fee_currency: operations:0:mid:3416123 operations:0:operation_completed_at:2020-01-30T12:29:04+03:00 operations:0:operation_created_at:2020-01-30T12:29:03+03:00 operations:0:operation_id:9048253065548 operations:0:operation_status:success operations:0:operation_type:cancel operations:0:payment_description: operations:0:payment_id:EP834a-40521580376090593 operations:0:payment_method_name:visa operations:0:payment_method_type:visa operations:0:project_id:183 operations:0:provider_date: operations:0:provider_name:Dashboard Provider Card operations:0:rrn: operations:0:shipment_date: operations:0:sum_converted: operations:0:sum_initial:
- Join all strings into a single string by using semicolon (;) as a delimiter:
operations:0:account_number:431422******0056;operations:0:arn:;operations:0:customer_ip:192.0.0.255;operations:0:fee_amount:0;operations:0:fee_currency:;operations:0:mid:3416123;operations:0:operation_completed_at:2020-01-30T12:29:04+03:00;operations:0:operation_created_at:2020-01-30T12:29:03+03:00;operations:0:operation_id:9048253065548;operations:0:operation_status:success;operations:0:operation_type:cancel;operations:0:payment_description:;operations:0:payment_id:EP834a-40521580376090593;operations:0:payment_method_name:visa;operations:0:payment_method_type:visa;operations:0:project_id:183;operations:0:provider_date:;operations:0:provider_name:Dashboard Provider Card;operations:0:rrn:;operations:0:shipment_date:;operations:0:sum_converted:;operations:0:sum_initial:
- Calculate the HMAC code for the string by using the SHA-512 hash function and secret key, and then encode the HMAC code by using the Base64 scheme:
F58IW7JCqHsUthlmgQ/i1plf6lRPfdSVTGMXeEfhUMpdmwDMHKlO/rbtTy+V8cmQtvPNBjvuyQnl/rWxT7gPGg==
- Compare the generated signature and the one included in the response.
In our case, the signatures differ which means that the response is invalid and must be ignored.
Signature verification form for responses via the Data API
Below you can find an interactive form that allows you to test signature verification.