2 posts / 0 new
Last post
jakegarrison9294
PHP API Error Handling (Returning Code)

Using the Payeezy PHP library, I have a transaction inside a "try" block:
______________
$client = new Payeezy_Client();
$client->setApiKey(****);
$client->setApiSecret(****);
$client->setMerchantToken(****);
$client->setUrl("https://api-cert.payeezy.com/v1/transactions");
$authorize_card_transaction = new Payeezy_Token($client);
try {
$authorize_response = $authorize_card_transaction->purchase(
[
"merchant_ref" => "Payment",
"transaction_type" => "purchase",
"method" => "token",
"amount" => "$amount",
"currency_code" => "USD",
"token" => array(
"token_type" => "FDToken",
"token_data" => $cardData
)
]
);
} catch (Payeezy_Error $e) {
$error = $e->getMessage();
$errorType = $e->getCode();
$success = false;
$gatewayToken = false;
$result = array();
}

---------

This returns $error ("the api equivalent of "description") without a problem. But, i can't seem to get the actual error code (API equivalent "Error": {"messages": [{"code"}]}). I was guessing the proper way would be "$errorType = $e->getCode()" based on my IDE's autofill. Am I on the right track?

Thanks,

-Jake


rohitrajagopal3538
Re: PHP API Error Handling (Returning Code)

Does this help - https://github.com/payeezy/payeezy-php/blob/master/src/Payeezy/Error.php?