• PHP
  • Python

# Signature generate

<?php
//Concatenate all parameters field values into single string.
$dataString = $amount.$cardId.$currency.$merchantId.$reference.$type;

//Read the private key
$pkeyid = openssl_pkey_get_private("file:///private_key.pem");

//Generate signature
$signResult = openssl_sign($dataString, $signature, $pkeyid, OPENSSL_ALGO_SHA256);

//Base64 encode the signature
$signature = base64_encode($signature);

//Free the key from memory
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# Signature generate and send API request

<?php

$priKey = '-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA1Jc9tLbi1OIxpFzJX0DEsMh8J9VyVV67Rqp/qb8YJfK6QOSl
7r0/6eOXhemxjGsXzs6RyaJ8Iqn4xr4H0jJs1kEIWyr0s2pOzyb
-----END RSA PRIVATE KEY-----';

$mId = "xxxxxx";
$type = "REFUND";
$trnId = "875";
$note = "transaction refund.";
$amount = 500.00;

$dataString = $mId.$type.$trnId.$note.$amount;
print($dataString . "\n");
$pkeyid = openssl_get_privatekey($pri_key);
$signResult = openssl_sign($dataString, $signature, $priKey, OPENSSL_ALGO_SHA256);
$signature = base64_encode($signature);
print($signature . "\n");

$curl = curl_init();

//key order must be same order generate signature dataString
$requestBody = [
"merchantId" => "xxxxxx",
"type" => "REFUND",
"transactionId" => "875",
"note" => "transaction refund.",
"amount" => 500.00
];

curl_setopt_array($curl, array(
CURLOPT_URL => "http://refundPayment",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($requestBody),
CURLOPT_HTTPHEADER => array(
"Signature: ".$signature,
"x-api-key: dnfo8743ythbf9n7cr8yh473n",
"Content-Type: application/json"
),
));

$response = curl_exec($curl);

curl_close($curl);
print_r($response);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52