0

I've created a sample script utilising Securepay's direct post api documentation provided at https://www.securepay.com.au/wp-content/uploads/2017/06/Direct_Post_Integration_Guide.pdf

Here is the script code:

$test_url = "https://test.api.securepay.com.au/directpost/authorise";
$EPS_MERCHANTID = "ABC0001"; //manual id
$Transaction_Password = "abc123"; // manual password
$EPS_TXNTYPE = 0; //sending default
$EPS_REFERENCEID = "1234"; //manual order id
$EPS_AMOUNT = "20.77";
$EPS_TIMESTAMP = gmdate('Ymdhis');
$hash_string = "$EPS_MERCHANTID|$Transaction_Password|$EPS_TXNTYPE|$EPS_REFERENCEID|$EPS_AMOUNT|$EPS_TIMESTAMP";
$sha_256_string = hash('SHA256',$hash_string);

//card details
$EPS_CARDNUMBER = "4444333322221111";
$EPS_EXPIRYMONTH = "01";
$EPS_EXPIRYYEAR = "2020";
$EPS_CCV = 123;
$EPS_CURRENCY = "AUD";

$post_data = "EPS_MERCHANT=".$EPS_MERCHANTID
."&EPS_TXNTYPE=".$EPS_TXNTYPE
."&EPS_AMOUNT=".$EPS_AMOUNT
."&EPS_REFERENCEID=".$EPS_REFERENCEID
."&EPS_TIMESTAMP=".$EPS_TIMESTAMP
."&EPS_CARDNUMBER=".$EPS_CARDNUMBER
."&EPS_EXPIRYMONTH=".$EPS_EXPIRYMONTH
."&EPS_EXPIRYYEAR=".$EPS_EXPIRYYEAR
."&EPS_CCV=".$EPS_CCV
."&EPS_RESULTURL="."https://mydomain.com.au/pay.php" //custom url form - mydomain.com.au is replaced with personal domain
."&EPS_CURRENCY=".$EPS_CURRENCY
."&EPS_FINGERPRINT=".$sha_256_string;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $test_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$ch_result = curl_exec($ch);
print_r($ch_result);

This script outputs to error "Invalid Fingerprint".

Any help to resolve this will be greatly appreciated.

Vatsh Patel
  • 101
  • 7

1 Answers1

1

The issue is now resolved with help of secure pay support and a bit of research.

The above code has two errors:

  1. The Fingerprint should be encrypted with HMAC and transaction password should be used as a secret.

    $sha_256_string = hash_hmac('SHA256',$hash_string,$Transaction_Password);

  2. GMT Timestamp should use a 24hr format

    $EPS_TIMESTAMP = gmdate('YmdGis', time());

Vatsh Patel
  • 101
  • 7