<?php

$serviceURL = 'https://api-cert.payeezy.com/v1/transactions';
$apiKey = "bfvCs2v0BlGr2GlKn55b5iDeRDcX0AMs";
$apiSecret = "4012faf411afc618b77f0703ad1c37be8eff8d8337e8e7571364d35c49edf003";
$token = "fdoa-a480ce8951daa73262734cf102641994c1e55e7cdf4c02b6";
$nonce = strval(hexdec(bin2hex(openssl_random_pseudo_bytes(4, $cstrong))));
$timestamp = strval(time() * 1000);
//time stamp in milli seconds
$payload = getPayload(setPrimaryTxPayload());
function processInput($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return strval($data);
}
function setPrimaryTxPayload()
{
    $card_holder_name = $card_number = $card_type = $card_cvv = $card_expiry = $currency_code = $merchant_ref = "";
    $card_holder_name = processInput("John Smith");
    $card_number = processInput("4788250000028291");
    $card_type = processInput("visa");
    $card_cvv = processInput("123");
    $card_expiry = processInput("1218");
    $amount = processInput("1200");
    $currency_code = processInput("USD");
    $merchant_ref = processInput("Astonishing-Sale");
    $primaryTxPayload = array("amount" => $amount, "card_number" => $card_number, "card_type" => $card_type, "card_holder_name" => $card_holder_name, "card_cvv" => $card_cvv, "card_expiry" => $card_expiry, "merchant_ref" => $merchant_ref, "currency_code" => $currency_code);
    return $primaryTxPayload;
}
// $payeezy->setApiKey("EHMenTH0KF1aN7KQpjGDsj7V9r5fxaaB");
// $payeezy->setApiSecret("243a48b691a3b8f62b4f496e67ae2a58c333729aa58dafa074f211f3eaefe4b5");
// $payeezy->setMerchantToken("fdoa-a480ce8951daa73262734cf102641994c1e55e7cdf4c02b6");
//test account provided in sample code
$payeezy->setApiKey("y6pWAJNyJyjGv66IsVuWnklkKUPFbb0a");
$payeezy->setApiSecret("86fbae7030253af3cd15faef2a1f4b67353e41fb6799f576b5093ae52901e6f7");
$payeezy->setMerchantToken("fdoa-a480ce8951daa73262734cf102641994c1e55e7cdf4c02b6");
$payeezy->setTokenUrl("https://api-cert.payeezy.com/v1/transactions/tokens");
$payeezy->setUrl("https://api-cert.payeezy.com/v1/transactions");
echo "-------------------- Testing authorize 1----------";
$response = $payeezy->authorize(setTokenPayload());
echo $response;
echo "<br>";
echo "<br>";
echo "-------------------- Testing authorize 2 ---------- </br> ";
$response = $payeezy->authorize(setPrimaryTxPayload());
echo $response;
function setTokenPayload()
{
    $card_holder_name = $amount = $transaction_type = $auth = $card_number = $ta_token = $card_type = $card_cvv = $card_expiry = $currency_code = $merchant_ref = "";
    $transaction_type = processInput("FDToken");
    $auth = processInput("false");
    $ta_token = processInput("NOIW");
    $card_holder_name = processInput("PHP Client");
    $card_number = processInput("4788250000028291");
    $card_type = processInput("visa");
    $card_cvv = processInput("123");
    $card_expiry = processInput("1230");
    $currency_code = processInput("USD");
    $amount = processInput("1000");
    $merchant_ref = processInput("Astonishing-Sale");
echo "<br><br> ";
echo "<div class='datagrid1'>";
echo "<table><thead><tr><th>authorize-capture Credit card </th></thead></tr>";
echo "<tbody><tr><td>capture Request: ";
$secondaryTxResponse_JSON = $payeezy->capture(setSecondaryTxPayload($authr->transaction_id, $authr->transaction_tag, $authr->amount));
echo "</td></tr>";
echo "<tr class='alt'><td>authorize-capture Response :";
echo $secondaryTxResponse_JSON;
echo "</td></tr><tbody></table>";
echo "</div>";
echo "<br><br> ";
echo "<h1> Purchase-void Transactions </h1>";
echo "<div class='datagrid2'>";
echo "<table><thead><tr><th>Purchase credit card transaction ' </th></tr></thead>";
echo "<tbody><tr><td>Request for Purchase: ";
$purchaseresponse = $payeezy->purchase(setPrimaryTxPayload());
echo "</td></tr>";
echo "<tr class='alt'><td>Purchase Response :";
echo $purchaseresponse;
echo "</td></tr></tbody> </table>";
echo "</div>";
echo "<br><br> ";
echo "<div class='datagrid2'>";
echo "<table><thead><tr><th> transaction_id and transaction_tag from previous transaction</th></tr></thead><tbody><tr><td> ";
$purchasetr = json_decode($purchaseresponse);
echo "transaction_id: " . $purchasetr->transaction_id;
echo "<br>";
echo "transaction_tag: " . $purchasetr->transaction_tag;
echo "</td></tr></tbody> </table>";
echo "</div>";
echo "<br><br> ";