Skip to content

Commit a8a8841

Browse files
authored
clean up responses
1 parent a39b081 commit a8a8841

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

PaymentTransactions/create-an-accept-payment-transaction.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function createAnAcceptPaymentTransaction($amount){
1212
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
1313
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
1414
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
15+
16+
// Set the transaction's refId
1517
$refId = 'ref' . time();
1618

1719
// Create the payment object for a payment nonce
@@ -63,8 +65,8 @@ function createAnAcceptPaymentTransaction($amount){
6365
// Assemble the complete transaction request
6466
$request = new AnetAPI\CreateTransactionRequest();
6567
$request->setMerchantAuthentication($merchantAuthentication);
66-
$request->setRefId( $refId);
67-
$request->setTransactionRequest( $transactionRequestType);
68+
$request->setRefId($refId);
69+
$request->setTransactionRequest($transactionRequestType);
6870

6971
// Create the controller and get response
7072
$controller = new AnetController\CreateTransactionController($request);
@@ -82,19 +84,19 @@ function createAnAcceptPaymentTransaction($amount){
8284

8385
if ($tresponse != null && $tresponse->getMessages() != null)
8486
{
85-
echo " Transaction Response Code : " . $tresponse->getResponseCode() . "\n";
86-
echo " Successfully created an authCapture transaction with Auth Code : " . $tresponse->getAuthCode() . "\n";
87-
echo " Transaction ID : " . $tresponse->getTransId() . "\n";
88-
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
89-
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
87+
echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "\n";
88+
echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n";
89+
echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n";
90+
echo " Auth Code: " . $tresponse->getAuthCode() . "\n";
91+
echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n";
9092
}
9193
else
9294
{
9395
echo "Transaction Failed \n";
9496
if($tresponse->getErrors() != null)
9597
{
96-
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
97-
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
98+
echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
99+
echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
98100
}
99101
}
100102
}
@@ -106,13 +108,13 @@ function createAnAcceptPaymentTransaction($amount){
106108

107109
if($tresponse != null && $tresponse->getErrors() != null)
108110
{
109-
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
110-
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
111+
echo " Error Code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
112+
echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
111113
}
112114
else
113115
{
114-
echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
115-
echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
116+
echo " Error Code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
117+
echo " Error Message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
116118
}
117119
}
118120
}
@@ -123,6 +125,7 @@ function createAnAcceptPaymentTransaction($amount){
123125

124126
return $response;
125127
}
128+
126129
if(!defined('DONT_RUN_SAMPLES'))
127130
CreateAnAcceptPaymentTransaction(\SampleCode\Constants::SAMPLE_AMOUNT);
128131
?>

0 commit comments

Comments
 (0)