88
99class CreateTransactionControllerTest extends ApiCoreTestBase
1010{
11+ /*
1112 public function testCreateTransactionCreditCard()
1213 {
1314 $merchantAuthentication = new apiContract\MerchantAuthenticationType();
@@ -33,6 +34,7 @@ public function testCreateTransactionCreditCard()
3334 $response = $controller->getApiResponse();
3435
3536 // Handle and validate the response
37+ self::displayMessages( $response);
3638 $this->assertNotNull($response, "null response");
3739 $this->assertNotNull($response->getMessages());
3840 file_put_contents(self::$log_file, sprintf("\n%s: Controller Response ResultCode: '%s'.", \net\authorize\util\Helpers::now() ,$response->getMessages()->getResultCode()), FILE_APPEND);
@@ -45,45 +47,42 @@ public function testCreateTransactionCreditCard()
4547 $this->assertEquals("Successful.", $response->getText());
4648 }
4749 }
48- /*
50+ */
51+
4952 public function testCreateTransactionPayPal ()
5053 {
51- $this->markTestSkipped('Ignoring for Travis. Will fix after release.'); //TODO
52-
53- $name = (defined('AUTHORIZENET_API_LOGIN_ID') && ''!=AUTHORIZENET_API_LOGIN_ID) ? AUTHORIZENET_API_LOGIN_ID : getenv("api_login_id");
54- $transactionKey = (defined('AUTHORIZENET_TRANSACTION_KEY') && ''!=AUTHORIZENET_TRANSACTION_KEY) ? AUTHORIZENET_TRANSACTION_KEY : getenv("transaction_key");
55-
56- $name ="9q2yWeA3J3Q";
57- $transactionKey="7KTb8aThMJ35y879";
58- if (!defined('AUTHORIZENET_LOG_FILE'))
59- {
60- define( "AUTHORIZENET_LOG_FILE", "./authorize-net.log");
61- }
62-
63- $merchantAuthentication = new MerchantAuthenticationType();
64- $merchantAuthentication->setName($name);
65- $merchantAuthentication->setTransactionKey($transactionKey);
54+ $ merchantAuthentication = new apiContract \MerchantAuthenticationType ();
55+ $ merchantAuthentication ->setName (self ::$ LoginName );
56+ $ merchantAuthentication ->setTransactionKey (self ::$ TransactionKey );
6657
67- $paymentType = new PaymentType();
58+ $ paymentType = new apiContract \ PaymentType ();
6859 $ paymentType ->setPayPal ($ this ->payPalOne );
6960
7061 //create a transaction
71- $transactionRequestType = new TransactionRequestType();
62+ $ transactionRequestType = new apiContract \ TransactionRequestType ();
7263 $ transactionRequestType ->setTransactionType ( "authOnlyTransaction " ); // TODO Change to Enum
7364 $ transactionRequestType ->setAmount ( $ this ->setValidAmount ( $ this ->counter ));
7465 $ transactionRequestType ->setPayment ( $ paymentType );
7566
76- $request = new CreateTransactionRequest();
67+ $ request = new apiContract \ CreateTransactionRequest ();
7768 $ request ->setMerchantAuthentication ($ merchantAuthentication );
7869 $ request ->setTransactionRequest ( $ transactionRequestType );
7970
80- $controller = new CreateTransactionController($request);
81- $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::CUSTOM );
71+ $ controller = new apiController \ CreateTransactionController ($ request );
72+ $ response = $ controller ->executeWithApiResponse ( self :: $ TestEnvironment );
8273
8374 // Handle the response.
8475 $ this ->assertNotNull ($ response , "null response " );
8576 $ this ->assertNotNull ($ response ->getMessages ());
8677
78+ self ::displayMessages ( $ response );
79+ if ( "Ok " != $ response ->getMessages ()->getResultCode ())
80+ {
81+ $ this ->displayTransactionMessages ( $ response );
82+ $ this ->assertTrue ( false , "Should not reach here. " );
83+ }
84+ $ this ->assertEquals ("Ok " , $ response ->getMessages ()->getResultCode ());
85+
8786 $ this ->assertEquals ("Ok " , $ response ->getMessages ()->getResultCode ());
8887 $ this ->assertTrue (0 < count ($ response ->getMessages ()));
8988 foreach ($ response ->getMessages () as $ message )
@@ -92,5 +91,45 @@ public function testCreateTransactionPayPal()
9291 $ this ->assertEquals ("Successful. " , $ response ->getText ());
9392 }
9493 }
95- */
94+
95+ function displayTransactionMessages ( apiContract \CreateTransactionResponse $ response )
96+ {
97+ if ( null != $ response )
98+ {
99+ $ logMessage = sprintf ("\n%s: Displaying Transaction Response. " , \net \authorize \util \Helpers::now ());
100+ echo $ logMessage ; file_put_contents (self ::$ log_file , $ logMessage , FILE_APPEND );
101+
102+ if ( null != $ response ->getTransactionResponse ())
103+ {
104+ $ logMessage = sprintf ("\n%s: Transaction Response Code: '%s'. " , \net \authorize \util \Helpers::now (), $ response ->getTransactionResponse ()->getResponseCode ());
105+ echo $ logMessage ; file_put_contents (self ::$ log_file , $ logMessage , FILE_APPEND );
106+
107+ $ allMessages = $ response ->getTransactionResponse ()->getMessages ();
108+ $ allErrors = $ response ->getTransactionResponse ()->getErrors ();
109+ $ errorCount = 0 ;
110+ if ( null != $ allErrors )
111+ {
112+ foreach ( $ allErrors as $ error )
113+ {
114+ $ errorCount ++;
115+ $ logMessage = sprintf ("\n%s: %d - Error: Code:'%s', Text:'%s' " , \net \authorize \util \Helpers::now (), $ errorCount , $ error ->getErrorCode (), $ error ->getErrorText ());
116+ echo $ logMessage ; file_put_contents (self ::$ log_file , $ logMessage , FILE_APPEND );
117+ }
118+ }
119+ $ messageCount = 0 ;
120+ if ( null != $ allMessages )
121+ {
122+ foreach ( $ allMessages as $ message )
123+ {
124+ $ messageCount ++;
125+ //$logMessage = sprintf("\n%s: %d - Message: Code:'%s', Description:'%s'", \net\authorize\util\Helpers::now(), $errorCount, $message->getCode(), $message->getDescription());
126+ $ logMessage = sprintf ("\n%s: %d - Message: " , \net \authorize \util \Helpers::now (), $ messageCount );
127+ echo $ logMessage ; file_put_contents (self ::$ log_file , $ logMessage , FILE_APPEND );
128+ }
129+ }
130+ $ logMessage = sprintf ("\n%s: Transaction Response, Errors: '%d', Messages: '%d'. " , \net \authorize \util \Helpers::now (), $ errorCount , $ messageCount );
131+ echo $ logMessage ; file_put_contents (self ::$ log_file , $ logMessage , FILE_APPEND );
132+ }
133+ }
134+ }
96135}
0 commit comments