Skip to content

Commit cb2d1ae

Browse files
author
akankari
committed
Changes for proper error handling in create Transaction requests
1 parent 4a4d422 commit cb2d1ae

23 files changed

Lines changed: 783 additions & 241 deletions

MobileInappTransactions/create-an-accept-transaction.php

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,48 @@ function createAnAcceptTransaction(){
3434

3535
if ($response != null)
3636
{
37+
if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK)
38+
{
3739
$tresponse = $response->getTransactionResponse();
38-
39-
if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )
40+
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
41+
if ($tresponse != null && $tresponse->getMessages() != null)
42+
{
43+
echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n";
44+
echo " TRANS ID : " . $tresponse->getTransId() . "\n";
45+
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
46+
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
47+
}
48+
else
4049
{
41-
echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n";
42-
echo " TRANS ID : " . $tresponse->getTransId() . "\n";
50+
echo "Transaction Failed \n";
51+
if($tresponse->getErrors() != null)
52+
{
53+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
54+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
55+
}
56+
}
57+
}
58+
else
59+
{
60+
echo "Transaction Failed \n";
61+
$tresponse = $response->getTransactionResponse();
62+
if($tresponse != null && $tresponse->getErrors() != null)
63+
{
64+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
65+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
4366
}
4467
else
4568
{
46-
echo "ERROR : Invalid response\n";
47-
$errorMessages = $response->getMessages()->getMessage();
48-
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
69+
echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
70+
echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
4971
}
72+
}
5073
}
5174
else
5275
{
53-
echo "Null response";
76+
echo "No response returned \n";
5477
}
78+
5579
return $response;
5680
}
5781

MobileInappTransactions/create-an-android-pay-transaction.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,48 @@ function createAnAndroidPayTransaction(){
3434

3535
if ($response != null)
3636
{
37+
if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK)
38+
{
3739
$tresponse = $response->getTransactionResponse();
38-
39-
if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )
40+
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
41+
if ($tresponse != null && $tresponse->getMessages() != null)
4042
{
4143
echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n";
4244
echo " TRANS ID : " . $tresponse->getTransId() . "\n";
45+
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
46+
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
47+
}
48+
else
49+
{
50+
echo "Transaction Failed \n";
51+
if($tresponse->getErrors() != null)
52+
{
53+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
54+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
55+
}
56+
}
57+
}
58+
else
59+
{
60+
echo "Transaction Failed \n";
61+
$tresponse = $response->getTransactionResponse();
62+
if($tresponse != null && $tresponse->getErrors() != null)
63+
{
64+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
65+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
4366
}
4467
else
4568
{
46-
echo "ERROR : Invalid response\n";
47-
$errorMessages = $response->getMessages()->getMessage();
48-
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
69+
echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
70+
echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
4971
}
72+
}
5073
}
5174
else
5275
{
53-
echo "Null response";
76+
echo "No response returned \n";
5477
}
78+
5579
return $response;
5680
}
5781

MobileInappTransactions/create-an-apple-pay-transaction.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,51 @@ function createAnApplePayTransaction(){
3232
$controller = new AnetController\CreateTransactionController($request);
3333
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
3434

35+
3536
if ($response != null)
3637
{
38+
if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK)
39+
{
3740
$tresponse = $response->getTransactionResponse();
38-
39-
if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )
41+
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
42+
if ($tresponse != null && $tresponse->getMessages() != null)
4043
{
4144
echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n";
4245
echo " TRANS ID : " . $tresponse->getTransId() . "\n";
46+
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
47+
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
4348
}
4449
else
4550
{
46-
echo "ERROR : Invalid response\n";
47-
$errorMessages = $response->getMessages()->getMessage();
48-
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
51+
echo "Transaction Failed \n";
52+
if($tresponse->getErrors() != null)
53+
{
54+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
55+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
56+
}
57+
}
58+
}
59+
else
60+
{
61+
echo "Transaction Failed \n";
62+
$tresponse = $response->getTransactionResponse();
63+
if($tresponse != null && $tresponse->getErrors() != null)
64+
{
65+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
66+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
4967
}
68+
else
69+
{
70+
echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
71+
echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
72+
}
73+
}
5074
}
5175
else
5276
{
53-
echo "Null response";
77+
echo "No response returned \n";
5478
}
79+
5580
return $response;
5681
}
5782

PaymentTransactions/authorize-credit-card.php

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,51 @@ function authorizeCreditCard($amount){
3737

3838
if ($response != null)
3939
{
40-
$tresponse = $response->getTransactionResponse();
41-
42-
if (($tresponse != null) && ($tresponse->getResponseCode()== \SampleCode\Constants::RESPONSE_OK) )
40+
if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK)
4341
{
44-
echo " AUTH CODE : " . $tresponse->getAuthCode() . "\n";
45-
echo " TRANS ID : " . $tresponse->getTransId() . "\n";
42+
$tresponse = $response->getTransactionResponse();
43+
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
44+
if ($tresponse != null && $tresponse->getMessages() != null)
45+
{
46+
echo " Successfully created a transaction with Auth code : " . $tresponse->getAuthCode() . "\n";
47+
echo " TRANS ID : " . $tresponse->getTransId() . "\n";
48+
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
49+
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
50+
}
51+
else
52+
{
53+
echo "Transaction Failed \n";
54+
if($tresponse->getErrors() != null)
55+
{
56+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
57+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
58+
}
59+
}
4660
}
4761
else
4862
{
49-
echo "ERROR : " . $tresponse->getResponseCode() . "\n";
50-
}
51-
63+
echo "Transaction Failed \n";
64+
$tresponse = $response->getTransactionResponse();
65+
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
66+
if($tresponse != null && $tresponse->getErrors() != null)
67+
{
68+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
69+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
70+
}
71+
else
72+
{
73+
echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
74+
echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
75+
}
76+
}
5277
}
5378
else
5479
{
55-
echo "No response returned";
80+
echo "No response returned \n";
5681
}
82+
5783
return $response;
5884
}
5985
if(!defined('DONT_RUN_SAMPLES'))
60-
authorizeCreditCard( \SampleCode\Constants::SAMPLE_AMOUNT);
86+
authorizeCreditCard( 23.32);
6187
?>

PaymentTransactions/capture-funds-authorized-through-another-channel.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ function captureFundsAuthorizedThroughAnotherChannel($amount){
2727
//Auth code of the previously authorized amount
2828
$transactionRequestType->setAuthCode("ROHNFQ");
2929

30-
3130
$request = new AnetAPI\CreateTransactionRequest();
3231
$request->setMerchantAuthentication($merchantAuthentication);
3332
$request->setTransactionRequest( $transactionRequestType);
@@ -37,25 +36,50 @@ function captureFundsAuthorizedThroughAnotherChannel($amount){
3736

3837
if ($response != null)
3938
{
39+
if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK)
40+
{
4041
$tresponse = $response->getTransactionResponse();
41-
if (($tresponse != null) && ($tresponse->getResponseCode()== \SampleCode\Constants::RESPONSE_OK) )
42+
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
43+
if ($tresponse != null && $tresponse->getMessages() != null)
4244
{
4345
echo "Successful." . "\n";
4446
echo "Capture funds authorized through another channel TRANS ID : " . $tresponse->getTransId() . " Amount : $amount \n";
47+
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
48+
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
49+
}
50+
else
51+
{
52+
echo "Transaction Failed \n";
53+
if($tresponse->getErrors() != null)
54+
{
55+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
56+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
57+
}
58+
}
59+
}
60+
else
61+
{
62+
echo "Transaction Failed \n";
63+
$tresponse = $response->getTransactionResponse();
64+
if($tresponse != null && $tresponse->getErrors() != null)
65+
{
66+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
67+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
4568
}
4669
else
4770
{
48-
echo "Capture funds authorized through another channel ERROR: Invalid response\n";
49-
$errorMessages = $response->getMessages()->getMessage();
50-
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
71+
echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
72+
echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
5173
}
74+
}
5275
}
5376
else
5477
{
55-
echo "Capture funds authorized through another channel, NULL Response Error\n";
78+
echo "No response returned \n";
5679
}
80+
5781
return $response;
5882
}
5983
if(!defined('DONT_RUN_SAMPLES'))
60-
captureFundsAuthorizedThroughAnotherChannel((rand(1, 99999)/12*12));
84+
captureFundsAuthorizedThroughAnotherChannel((rand(1, 999)/12*12));
6185
?>

PaymentTransactions/capture-previously-authorized-amount.php

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,50 @@ function capturePreviouslyAuthorizedAmount($transactionid){
2828

2929
if ($response != null)
3030
{
31-
$tresponse = $response->getTransactionResponse();
32-
if (($tresponse != null) && ($tresponse->getResponseCode()== \SampleCode\Constants::RESPONSE_OK) )
31+
if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK)
3332
{
34-
echo "Successful." . "\n";
35-
echo "Capture Previously Authorized Amount, Trans ID : " . $tresponse->getRefTransId() . "\n";
33+
$tresponse = $response->getTransactionResponse();
34+
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
35+
if ($tresponse != null && $tresponse->getMessages() != null)
36+
{
37+
echo "Successful." . "\n";
38+
echo "Capture Previously Authorized Amount, Trans ID : " . $tresponse->getRefTransId() . "\n";
39+
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
40+
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
41+
}
42+
else
43+
{
44+
echo "Transaction Failed \n";
45+
if($tresponse->getErrors() != null)
46+
{
47+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
48+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
49+
}
50+
}
3651
}
3752
else
3853
{
39-
echo " Capture Previously Authorized Amount: Invalid response\n";
40-
}
54+
echo "Transaction Failed \n";
55+
$tresponse = $response->getTransactionResponse();
56+
if($tresponse != null && $tresponse->getErrors() != null)
57+
{
58+
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
59+
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
60+
}
61+
else
62+
{
63+
echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
64+
echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
65+
}
66+
}
4167
}
4268
else
4369
{
44-
echo "Capture Previously Authorized Amount, NULL Response Error\n";
70+
echo "No response returned \n";
4571
}
72+
4673
return $response;
4774
}
4875
if(!defined('DONT_RUN_SAMPLES'))
49-
capturePreviouslyAuthorizedAmount(2249839471);
76+
capturePreviouslyAuthorizedAmount(60007076002);
5077
?>

0 commit comments

Comments
 (0)