5 posts / 0 new
Last post
sanjaychaudhary7022
Problem with "Recurring Payments" on Direct API.

Hi,

I am getting following error while testing sample data for Recurring payments.

Error :

Error: call to URL https://api-cert.payeezy.com/v1/transactions/ET118212 failed with status 400, response {"correlation_id":"228.1452862801596","Error":{"messages":[{"code":"400","description":"Processed"}]},"transaction_status":"Not Processed"}, curl_error , curl_errno 0
---------------------------------------------------------------

Here is my code :

<?php

//require_once('..PayeezyCheckLink.php');

$serviceURL = 'https://api-cert.payeezy.com/v1/transactions/ET157455';
$apiKey = "66YB7AVwaWgSjIAQcNTJ0GR6Hyhur4dC";
$apiSecret = "d7f8ed92c424ee460581d2a7f1b892d027264942c9a52922eb36184543432f4f";
$token = "fdoa-a480ce8951daa73262734cf102641994c1e55e7cdf4c02b6";

$nonce = strval(hexdec(bin2hex(openssl_random_pseudo_bytes(4, $cstrong))));
$timestamp = strval(time() * 1000); //time stamp in milli seconds

function processInput($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return strval($data);
}

function setSecondaryTxPayload() {

$merchant_ref = processInput("Astonishing-Sale");
// $transaction_id = processInput("ET157455");
$transaction_tag = processInput("1726410");
$transaction_type = processInput("recurring");
$amount = processInput("100");
$currency_code = processInput("USD");

$secondaryTxPayload = array(
"merchant_ref" => $merchant_ref,
// "transaction_id" => $transaction_id,
"transaction_tag" => $transaction_tag,
"transaction_type" => $transaction_type,
"amount" => $amount,
"currency_code" => $currency_code,
);

return $secondaryTxPayload;
}

//$payload = getPayload(setPrimaryTxPayload());

/**
* Payeezy
*
* Generate Payload
*/
function getPayload($args = array()) {
$args = array_merge(array(
"merchant_ref" => "",
// "transaction_id" => "",
"transaction_tag" => "",
"transaction_type" => "",
"amount" => "",
"currency_code" => "",
), $args);

$data = "";

$data = array(
'merchant_ref' => $args['merchant_ref'],
// 'transaction_id' => $args['transaction_id'],
'transaction_tag' => $args['transaction_tag'],
'transaction_type' => $args['transaction_type'],
'amount' => $args['amount'],
'currency_code' => $args['currency_code'],
);

return json_encode($data, JSON_FORCE_OBJECT);
}

$payload = getPayload(setSecondaryTxPayload());

echo " Request JSON Payload :";

echo $payload;

echo " Authorization :";

$data = $apiKey . $nonce . $timestamp . $token . $payload;

$hashAlgorithm = "sha256";

### Make sure the HMAC hash is in hex -->
$hmac = hash_hmac($hashAlgorithm, $data, $apiSecret, false);

### Authorization : base64 of hmac hash -->
$hmac_enc = base64_encode($hmac);

echo " ";

echo $hmac_enc;

echo "";

$curl = curl_init('https://api-cert.payeezy.com/v1/transactions/ET157455');

$headers = array(
'Content-Type: application/json',
'apikey:' . strval($apiKey),
'token:' . strval($token),
'Authorization:' . $hmac_enc,
'nonce:' . $nonce,
'timestamp:' . $timestamp,
);

curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);

curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$json_response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

$response = json_decode($json_response, true);

echo " ";

if ($status != 201) {
die("Error: call to URL $serviceURL failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}

curl_close($curl);

echo "Response is: \n";
print_r($response);

echo "JSON response is: " . $json_response . "\n" . $status;
?>
------------------------------------------------------------------

Please help me out. Thanks !

Regards,
Sanjay Chaudhary.


rohitrajagopal3538
Re: Problem with "Recurring Payments" on Direct API.

Hi Sanjay,

I tested your code and it works fine. Please try the following - 

1. Run a test credit card authorization for $2. I have created the code for it already. You can run it here - http://goo.gl/3LMcZZ

2. Run a recurring transaction of $2 to capture the amount. You can run it here and check out the code - http://goo.gl/wh3ODL

Please note that for now the recurring feature is limited to Apple pay only. You can submit transactions in an incremental manner upto a limit of 200% of the initial authorization value, after which the transactions will fail. Example: If the initial authorization amount is for $100, the recurring payments will start failing when the total captured payment exceeds $200. 

Regards,

Payeezy team


sanjaychaudhary7022
Re: Problem with "Recurring Payments" on Direct API.

Hi,

I tested the code given by you. For authorization its working fine, but when I go for recurring payment, it is still giving the same error.
-----------------

Error: call failed with status 400, response {"correlation_id":"228.1453099912685","Error":{"messages":[{"code":"400","description":"Processed"}]},"transaction_status":"Not Processed"}, curl_error , curl_errno 0

Are you saying that we cannot integrate the recurring payment to a website developed in PHP Script or so ?
Is it for mobile development only ?

Thanks !

Warm Regards,
Sanjay Chaudhary.


rohitrajagopal3538
Re: Problem with "Recurring Payments" on Direct API.

Sanjay - After executing the authorization transaction, you will need to copy the transaction tag and transaction id from the response and use it in the recurring transaction. Transaction id and transaction tag are what idenify the primary transaction when executing a secondary transaction such as void, capture, refund, recurring, etc.

Yes, the recurring payments are limited to Apple Pay only and only works until the total recurring payments less than 2x of the initial authorization amount.

Regards,

Payeezy team


sanjaychaudhary7022
Re: Problem with "Recurring Payments" on Direct API.

Hey,

Thanks ! Got it.

Regards,
Sanjay Chaudhary.