From 87dda67bcbe4beb048c543ee7814afac41d70f94 Mon Sep 17 00:00:00 2001 From: Derek Caswell Date: Thu, 2 Mar 2017 16:55:05 -0700 Subject: [PATCH 1/7] Refactored some of the code to centralize the sendData function and simplify some of the code. Implemented the Capture, Refund, and Void functions. Expanded the ConvergeGatewayTest class to include tests for the new functions and created a mesage test for the Capture request. Still need to create message tests for Refund and Void. --- src/ConvergeGateway.php | 30 +++++++ src/Message/ConvergeAbstractRequest.php | 9 ++ src/Message/ConvergeAuthorizeRequest.php | 13 --- src/Message/ConvergeCaptureRequest.php | 82 +++++++++++++++++ src/Message/ConvergeGenerateTokenRequest.php | 9 -- src/Message/ConvergePurchaseRequest.php | 7 +- src/Message/ConvergeRefundRequest.php | 82 +++++++++++++++++ src/Message/ConvergeTransactionManage.php | 36 ++++++++ src/Message/ConvergeVoidRequest.php | 92 ++++++++++++++++++++ tests/ConvergeGatewayTest.php | 51 +++++++++++ tests/Message/ConvergeCaptureRequestTest.php | 52 +++++++++++ tests/Mock/ConvergeCaptureResponse.txt | 19 ++++ 12 files changed, 454 insertions(+), 28 deletions(-) create mode 100644 src/Message/ConvergeCaptureRequest.php create mode 100644 src/Message/ConvergeRefundRequest.php create mode 100644 src/Message/ConvergeTransactionManage.php create mode 100644 src/Message/ConvergeVoidRequest.php create mode 100644 tests/Message/ConvergeCaptureRequestTest.php create mode 100644 tests/Mock/ConvergeCaptureResponse.txt diff --git a/src/ConvergeGateway.php b/src/ConvergeGateway.php index 91076bb..6e88ae3 100644 --- a/src/ConvergeGateway.php +++ b/src/ConvergeGateway.php @@ -214,6 +214,16 @@ public function authorize(array $parameters = array()) return $this->createRequest('\Omnipay\Elavon\Message\ConvergeAuthorizeRequest', $parameters); } + /** + * @param array $parameters + * + * @return \Omnipay\Elavon\Message\ConvergeCaptureRequest + */ + public function capture(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Elavon\Message\ConvergeCaptureRequest', $parameters); + } + /** * @param array $parameters * @return \Omnipay\Elavon\Message\ConvergePurchaseRequest @@ -223,6 +233,26 @@ public function purchase(array $parameters = array()) return $this->createRequest('\Omnipay\Elavon\Message\ConvergePurchaseRequest', $parameters); } + /** + * @param array $parameters + * + * @return \Omnipay\Elavon\Message\ConvergeRefundRequest + */ + public function refund(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Elavon\Message\ConvergeRefundRequest', $parameters); + } + + /** + * @param array $parameters + * + * @return \Omnipay\Elavon\Message\ConvergeVoidRequest + */ + public function void(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Elavon\Message\ConvergeVoidRequest', $parameters); + } + /** * @param array $parameters * @return \Omnipay\Elavon\Message\ConvergePurchaseRequest diff --git a/src/Message/ConvergeAbstractRequest.php b/src/Message/ConvergeAbstractRequest.php index 2d9cdb8..01f4fe3 100644 --- a/src/Message/ConvergeAbstractRequest.php +++ b/src/Message/ConvergeAbstractRequest.php @@ -332,4 +332,13 @@ protected function getBaseData() return $data; } + + public function sendData($data) + { + $httpResponse = $this->httpClient->post($this->getEndpoint() . '/process.do', null, http_build_query($data)) + ->setHeader('Content-Type', 'application/x-www-form-urlencoded') + ->send(); + + return $this->createResponse($httpResponse->getBody()); + } } diff --git a/src/Message/ConvergeAuthorizeRequest.php b/src/Message/ConvergeAuthorizeRequest.php index 62c2378..4deaaff 100644 --- a/src/Message/ConvergeAuthorizeRequest.php +++ b/src/Message/ConvergeAuthorizeRequest.php @@ -96,10 +96,6 @@ * $transaction->setSslResultFormat('ASCII'); * * - * This gateway supports authorize() but does not support capture() so there is no way to capture - * a previous authorization. I am guessing that the standard procedure is to abandon the previous - * authorize and issue a purchase() request in its place. - * * @link https://www.myvirtualmerchant.com/VirtualMerchant/ * @link https://resourcecentre.elavonpaymentgateway.com/index.php/download-developer-guide * @see \Omnipay\Elavon\ConvergeGateway @@ -148,13 +144,4 @@ public function getData() return array_merge($this->getBaseData(), $data); } - - public function sendData($data) - { - $httpResponse = $this->httpClient->post($this->getEndpoint() . '/process.do', null, http_build_query($data)) - ->setHeader('Content-Type', 'application/x-www-form-urlencoded') - ->send(); - - return $this->createResponse($httpResponse->getBody()); - } } diff --git a/src/Message/ConvergeCaptureRequest.php b/src/Message/ConvergeCaptureRequest.php new file mode 100644 index 0000000..0f9d99f --- /dev/null +++ b/src/Message/ConvergeCaptureRequest.php @@ -0,0 +1,82 @@ + + * // + * // Put your gateway credentials here. + * // + * $credentials = array( + * 'merchantId' => '000000', + * 'username' => 'USERNAME', + * 'password' => 'PASSWORD' + * 'testMode' => true, // Or false if you want to test production mode + * ); + * + * // Create a gateway object + * // (routes to GatewayFactory::create) + * $gateway = Omnipay::create('Elavon_Converge'); + * + * // Initialise the gateway + * $gateway->initialize($credentials); + * + * + * #### Direct Credit Card Completion + * + * + * try { + * $transaction = $gateway->capture(array( + * 'amount' => '10.00', + * 'transactionReference' => '123456' + * )); + * $response = $transaction->send(); + * $data = $response->getData(); + * echo "Gateway capture response data == " . print_r($data, true) . "\n"; + * + * if ($response->isSuccessful()) { + * echo "Capture transaction was successful!\n"; + * } + * } catch (\Exception $e) { + * echo "Exception caught while attempting capture.\n"; + * echo "Exception type == " . get_class($e) . "\n"; + * echo "Message == " . $e->getMessage() . "\n"; + * } + * + * + * @link https://www.myvirtualmerchant.com/VirtualMerchant/ + * @link https://resourcecentre.elavonpaymentgateway.com/index.php/download-developer-guide + * @see \Omnipay\Elavon\ConvergeGateway + */ +class ConvergeCaptureRequest extends ConvergeTransactionManage +{ + + protected $transactionType = 'cccomplete'; + + protected function manageValidate() + { + $this->validate('transactionReference', 'amount'); + } +} \ No newline at end of file diff --git a/src/Message/ConvergeGenerateTokenRequest.php b/src/Message/ConvergeGenerateTokenRequest.php index d9d55c8..9c6d0a6 100644 --- a/src/Message/ConvergeGenerateTokenRequest.php +++ b/src/Message/ConvergeGenerateTokenRequest.php @@ -133,13 +133,4 @@ public function getData() return array_merge($this->getBaseData(), $data); } - - public function sendData($data) - { - $httpResponse = $this->httpClient->post($this->getEndpoint() . '/process.do', null, http_build_query($data)) - ->setHeader('Content-Type', 'application/x-www-form-urlencoded') - ->send(); - - return $this->createResponse($httpResponse->getBody()); - } } diff --git a/src/Message/ConvergePurchaseRequest.php b/src/Message/ConvergePurchaseRequest.php index bd6c97a..58f2404 100644 --- a/src/Message/ConvergePurchaseRequest.php +++ b/src/Message/ConvergePurchaseRequest.php @@ -102,10 +102,5 @@ */ class ConvergePurchaseRequest extends ConvergeAuthorizeRequest { - public function getData() - { - $this->transactionType = 'ccsale'; - - return parent::getData(); - } + protected $transactionType = 'ccsale'; } diff --git a/src/Message/ConvergeRefundRequest.php b/src/Message/ConvergeRefundRequest.php new file mode 100644 index 0000000..bdc6091 --- /dev/null +++ b/src/Message/ConvergeRefundRequest.php @@ -0,0 +1,82 @@ + + * // + * // Put your gateway credentials here. + * // + * $credentials = array( + * 'merchantId' => '000000', + * 'username' => 'USERNAME', + * 'password' => 'PASSWORD' + * 'testMode' => true, // Or false if you want to test production mode + * ); + * + * // Create a gateway object + * // (routes to GatewayFactory::create) + * $gateway = Omnipay::create('Elavon_Converge'); + * + * // Initialise the gateway + * $gateway->initialize($credentials); + * + * + * #### Direct Credit Card Completion + * + * + * try { + * $transaction = $gateway->refund(array( + * 'amount' => '10.00', + * 'transactionReference' => '123456' + * )); + * $response = $transaction->send(); + * $data = $response->getData(); + * echo "Gateway capture response data == " . print_r($data, true) . "\n"; + * + * if ($response->isSuccessful()) { + * echo "Capture transaction was successful!\n"; + * } + * } catch (\Exception $e) { + * echo "Exception caught while attempting capture.\n"; + * echo "Exception type == " . get_class($e) . "\n"; + * echo "Message == " . $e->getMessage() . "\n"; + * } + * + * + * @link https://www.myvirtualmerchant.com/VirtualMerchant/ + * @link https://resourcecentre.elavonpaymentgateway.com/index.php/download-developer-guide + * @see \Omnipay\Elavon\ConvergeGateway + */ +class ConvergeRefundRequest extends ConvergeTransactionManage +{ + + protected $transactionType = 'ccreturn'; + + protected function manageValidate() + { + $this->validate('transactionReference', 'amount'); + } +} \ No newline at end of file diff --git a/src/Message/ConvergeTransactionManage.php b/src/Message/ConvergeTransactionManage.php new file mode 100644 index 0000000..6bf35cc --- /dev/null +++ b/src/Message/ConvergeTransactionManage.php @@ -0,0 +1,36 @@ +manageValidate(); + + $data = array( + 'ssl_transaction_type'=>$this->transactionType, + 'ssl_txn_id'=>$this->getTransactionReference(), + 'ssl_amount'=>$this->getAmount() + ); + + return array_merge($this->getBaseData(), $data); + } + + protected abstract function manageValidate(); +} \ No newline at end of file diff --git a/src/Message/ConvergeVoidRequest.php b/src/Message/ConvergeVoidRequest.php new file mode 100644 index 0000000..ccf4ec2 --- /dev/null +++ b/src/Message/ConvergeVoidRequest.php @@ -0,0 +1,92 @@ + + * // + * // Put your gateway credentials here. + * // + * $credentials = array( + * 'merchantId' => '000000', + * 'username' => 'USERNAME', + * 'password' => 'PASSWORD' + * 'testMode' => true, // Or false if you want to test production mode + * ); + * + * // Create a gateway object + * // (routes to GatewayFactory::create) + * $gateway = Omnipay::create('Elavon_Converge'); + * + * // Initialise the gateway + * $gateway->initialize($credentials); + * + * + * #### Direct Credit Card Completion + * + * + * try { + * $transaction = $gateway->void(array( + * 'transactionReference' => '123456' + * )); + * $response = $transaction->send(); + * $data = $response->getData(); + * echo "Gateway capture response data == " . print_r($data, true) . "\n"; + * + * if ($response->isSuccessful()) { + * echo "Capture transaction was successful!\n"; + * } + * } catch (\Exception $e) { + * echo "Exception caught while attempting capture.\n"; + * echo "Exception type == " . get_class($e) . "\n"; + * echo "Message == " . $e->getMessage() . "\n"; + * } + * + * + * @link https://www.myvirtualmerchant.com/VirtualMerchant/ + * @link https://resourcecentre.elavonpaymentgateway.com/index.php/download-developer-guide + * @see \Omnipay\Elavon\ConvergeGateway + */ +class ConvergeVoidRequest extends ConvergeTransactionManage +{ + protected $transactionType = 'ccvoid'; + + protected function manageValidate() + { + $this->validate('transactionReference'); + } + + public function getData() + { + $this->manageValidate(); + + $data = array( + 'ssl_transaction_type'=>$this->transactionType, + 'ssl_txn_id'=>$this->getTransactionReference() + ); + + return array_merge($this->getBaseData(), $data); + } +} \ No newline at end of file diff --git a/tests/ConvergeGatewayTest.php b/tests/ConvergeGatewayTest.php index 440c4d3..464554a 100644 --- a/tests/ConvergeGatewayTest.php +++ b/tests/ConvergeGatewayTest.php @@ -4,6 +4,11 @@ class ConvergeGatewayTest extends GatewayTestCase { + /** @var ConvergeGateway */ + protected $gateway; + /** @var array */ + protected $options; + public function setUp() { parent::setUp(); @@ -79,5 +84,51 @@ public function testPurchaseChargeCard() $this->assertSame('USD', $request->getCurrency()); } + public function testCapture() + { + $request = $this->gateway->capture( + array( + 'amount'=>10.00, + 'transactionReference'=>100001 + ) + ); + + $this->assertInstanceOf('Omnipay\Elavon\Message\ConvergeCaptureRequest', $request); + $this->assertSame('10.00', $request->getAmount()); + $this->assertSame(false, $request->getSslShowForm()); + $this->assertSame('ASCII', $request->getSslResultFormat()); + $this->assertSame(100001, $request->getTransactionReference()); + } + + public function testRefund() + { + $request = $this->gateway->refund( + array( + 'amount'=>10.00, + 'transactionReference'=>100001 + ) + ); + + $this->assertInstanceOf('Omnipay\Elavon\Message\ConvergeRefundRequest', $request); + $this->assertSame('10.00', $request->getAmount()); + $this->assertSame(false, $request->getSslShowForm()); + $this->assertSame('ASCII', $request->getSslResultFormat()); + $this->assertSame(100001, $request->getTransactionReference()); + } + + public function testVoid() + { + $request = $this->gateway->void( + array( + 'amount'=>10.00, + 'transactionReference'=>100001 + ) + ); + $this->assertInstanceOf('Omnipay\Elavon\Message\ConvergeVoidRequest', $request); + $this->assertSame('10.00', $request->getAmount()); + $this->assertSame(false, $request->getSslShowForm()); + $this->assertSame('ASCII', $request->getSslResultFormat()); + $this->assertSame(100001, $request->getTransactionReference()); + } } diff --git a/tests/Message/ConvergeCaptureRequestTest.php b/tests/Message/ConvergeCaptureRequestTest.php new file mode 100644 index 0000000..9fb6832 --- /dev/null +++ b/tests/Message/ConvergeCaptureRequestTest.php @@ -0,0 +1,52 @@ +request = new ConvergeCaptureRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize( + array( + 'transactionReference'=>'00000000-0000-0000-0000-00000000000', + 'amount'=>10.00 + ) + ); + } + + public function testTransactionReference() + { + $this->assertEquals('00000000-0000-0000-0000-00000000000', $this->request->getTransactionReference()); + $this->assertSame($this->request, $this->request->setTransactionReference('test')); + $this->assertEquals('test', $this->request->getTransactionReference()); + $this->request->setTransactionReference('00000000-0000-0000-0000-00000000000'); + } + + public function testAmount() + { + $this->assertEquals('10.00', $this->request->getAmount()); + $this->assertSame($this->request, $this->request->setAmount(15.00)); + $this->assertEquals('15.00', $this->request->getAmount()); + $this->request->setAmount(10.00); + } + + public function testCaptureSuccess() + { + $this->setMockHttpResponse('ConvergeCaptureResponse.txt'); + + $response = $this->request->send(); + $this->assertTrue($response->isSuccessful()); + $this->assertSame('APPROVED', $response->getMessage()); + $this->assertSame('0', $response->getCode()); + $this->assertSame('00000000-0000-0000-0000-00000000000', $response->getTransactionReference()); + } + +} \ No newline at end of file diff --git a/tests/Mock/ConvergeCaptureResponse.txt b/tests/Mock/ConvergeCaptureResponse.txt new file mode 100644 index 0000000..55b8038 --- /dev/null +++ b/tests/Mock/ConvergeCaptureResponse.txt @@ -0,0 +1,19 @@ +HTTP/1.1 200 OK +Date: Wed, 20 Feb 2013 13:55:50 GMT +Server: Apache +Content-Length: 214 +Connection: close +Content-Type: text/plain; charset=utf-8 + +ssl_status=TEST MODE +ssl_card_number=41**********1111 +ssl_amount=10.00 +ssl_invoice_number=1 +ssl_result=0 +ssl_result_message=APPROVED +ssl_txn_id=00000000-0000-0000-0000-00000000000 +ssl_approval_code=123456 +ssl_cvv2_response=P +ssl_avs_response=X +ssl_account_balance=0.00 +ssl_txn_time=05/13/2015 07:50:40 PM \ No newline at end of file From 0f5bad5911d4b558b769f180b2e04ffc298a79f2 Mon Sep 17 00:00:00 2001 From: Derek Caswell Date: Fri, 3 Mar 2017 15:28:21 -0700 Subject: [PATCH 2/7] Created tests for the refund and void messages --- tests/Message/ConvergeCaptureRequestTest.php | 2 - tests/Message/ConvergeRefundRequestTest.php | 50 ++++++++++++++++++++ tests/Message/ConvergeVoidRequestTest.php | 41 ++++++++++++++++ tests/Mock/ConvergeRefundResponse.txt | 19 ++++++++ tests/Mock/ConvergeVoidResponse.txt | 13 +++++ 5 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 tests/Message/ConvergeRefundRequestTest.php create mode 100644 tests/Message/ConvergeVoidRequestTest.php create mode 100644 tests/Mock/ConvergeRefundResponse.txt create mode 100644 tests/Mock/ConvergeVoidResponse.txt diff --git a/tests/Message/ConvergeCaptureRequestTest.php b/tests/Message/ConvergeCaptureRequestTest.php index 9fb6832..5abc9a5 100644 --- a/tests/Message/ConvergeCaptureRequestTest.php +++ b/tests/Message/ConvergeCaptureRequestTest.php @@ -2,8 +2,6 @@ namespace Omnipay\Elavon\Message; - -use Omnipay\Elavon\ConvergeGateway; use Omnipay\Tests\TestCase; class ConvergeCaptureRequestTest extends TestCase diff --git a/tests/Message/ConvergeRefundRequestTest.php b/tests/Message/ConvergeRefundRequestTest.php new file mode 100644 index 0000000..1b14579 --- /dev/null +++ b/tests/Message/ConvergeRefundRequestTest.php @@ -0,0 +1,50 @@ +request = new ConvergeRefundRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize( + array( + 'transactionReference'=>'00000000-0000-0000-0000-00000000000', + 'amount'=>10.00 + ) + ); + } + + public function testTransactionReference() + { + $this->assertEquals('00000000-0000-0000-0000-00000000000', $this->request->getTransactionReference()); + $this->assertSame($this->request, $this->request->setTransactionReference('test')); + $this->assertEquals('test', $this->request->getTransactionReference()); + $this->request->setTransactionReference('00000000-0000-0000-0000-00000000000'); + } + + public function testAmount() + { + $this->assertEquals('10.00', $this->request->getAmount()); + $this->assertSame($this->request, $this->request->setAmount(15.00)); + $this->assertEquals('15.00', $this->request->getAmount()); + $this->request->setAmount(10.00); + } + + public function testCaptureSuccess() + { + $this->setMockHttpResponse('ConvergeRefundResponse.txt'); + + $response = $this->request->send(); + $this->assertTrue($response->isSuccessful()); + $this->assertSame('APPROVED', $response->getMessage()); + $this->assertSame('0', $response->getCode()); + $this->assertSame('00000000-0000-0000-0000-00000000000', $response->getTransactionReference()); + } +} \ No newline at end of file diff --git a/tests/Message/ConvergeVoidRequestTest.php b/tests/Message/ConvergeVoidRequestTest.php new file mode 100644 index 0000000..d70b08b --- /dev/null +++ b/tests/Message/ConvergeVoidRequestTest.php @@ -0,0 +1,41 @@ +request = new ConvergeVoidRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize( + array( + 'transactionReference'=>'00000000-0000-0000-0000-00000000000' + ) + ); + } + + public function testTransactionReference() + { + $this->assertEquals('00000000-0000-0000-0000-00000000000', $this->request->getTransactionReference()); + $this->assertSame($this->request, $this->request->setTransactionReference('test')); + $this->assertEquals('test', $this->request->getTransactionReference()); + $this->request->setTransactionReference('00000000-0000-0000-0000-00000000000'); + } + + public function testCaptureSuccess() + { + $this->setMockHttpResponse('ConvergeVoidResponse.txt'); + + $response = $this->request->send(); + $this->assertTrue($response->isSuccessful()); + $this->assertSame('APPROVED', $response->getMessage()); + $this->assertSame('0', $response->getCode()); + $this->assertSame('00000000-0000-0000-0000-00000000000', $response->getTransactionReference()); + } +} \ No newline at end of file diff --git a/tests/Mock/ConvergeRefundResponse.txt b/tests/Mock/ConvergeRefundResponse.txt new file mode 100644 index 0000000..55b8038 --- /dev/null +++ b/tests/Mock/ConvergeRefundResponse.txt @@ -0,0 +1,19 @@ +HTTP/1.1 200 OK +Date: Wed, 20 Feb 2013 13:55:50 GMT +Server: Apache +Content-Length: 214 +Connection: close +Content-Type: text/plain; charset=utf-8 + +ssl_status=TEST MODE +ssl_card_number=41**********1111 +ssl_amount=10.00 +ssl_invoice_number=1 +ssl_result=0 +ssl_result_message=APPROVED +ssl_txn_id=00000000-0000-0000-0000-00000000000 +ssl_approval_code=123456 +ssl_cvv2_response=P +ssl_avs_response=X +ssl_account_balance=0.00 +ssl_txn_time=05/13/2015 07:50:40 PM \ No newline at end of file diff --git a/tests/Mock/ConvergeVoidResponse.txt b/tests/Mock/ConvergeVoidResponse.txt new file mode 100644 index 0000000..e363526 --- /dev/null +++ b/tests/Mock/ConvergeVoidResponse.txt @@ -0,0 +1,13 @@ +HTTP/1.1 200 OK +Date: Wed, 20 Feb 2013 13:55:50 GMT +Server: Apache +Content-Length: 214 +Connection: close +Content-Type: text/plain; charset=utf-8 + +ssl_invoice_number=1 +ssl_result=0 +ssl_result_message=APPROVED +ssl_txn_id=00000000-0000-0000-0000-00000000000 +ssl_approval_code=123456 +ssl_txn_time=05/13/2015 07:50:40 PM \ No newline at end of file From 5a3c1682f2ea6468f4833beccd38fa118645a8e2 Mon Sep 17 00:00:00 2001 From: Derek Caswell Date: Fri, 3 Mar 2017 16:25:54 -0700 Subject: [PATCH 3/7] Started creating integration tests --- .gitignore | 1 + tests/ConvergeIntegrationTest.php | 80 +++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 tests/ConvergeIntegrationTest.php diff --git a/.gitignore b/.gitignore index 8a282a5..9af5c19 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.lock composer.phar phpunit.xml +/tests/Mock/myCredentials.json \ No newline at end of file diff --git a/tests/ConvergeIntegrationTest.php b/tests/ConvergeIntegrationTest.php new file mode 100644 index 0000000..b583dea --- /dev/null +++ b/tests/ConvergeIntegrationTest.php @@ -0,0 +1,80 @@ +", + * "username":"", + * "password":"" + * } + * + * If that file does not exist or is not formatted in this way, all tests in this class will be skipped. + * + * Beware that test accounts on Elavon are temporary so if it has been a while since you setup your account you might need + * to setup a new one or remove your credentials from the myCredentials file so the variables are empty and these tests + * will be skipped. + * + * @package Omnipay\Elavon + */ +class ConvergeIntegrationTest extends TestCase +{ + /** @var ConvergeGateway */ + protected $gateway; + + /** + * Check the myCredentials file to make sure it exists and has the needed data. If there are any problems skip the tests. + * If there are not, instantiate the object. + */ + public function setUp() + { + $merchantId = ''; + $username = ''; + $password = ''; + $credentialsFilePath = dirname(__FILE__) . '/Mock/myCredentials.json'; + + if(file_exists($credentialsFilePath)) { + $credentialsJson = file_get_contents($credentialsFilePath); + if($credentialsJson) { + $credentials = json_decode($credentialsJson); + $merchantId = $credentials->merchantId; + $username = $credentials->username; + $password = $credentials->password; + } + } + + if(empty($merchantId) || empty($username) || empty($password)) { + $this->markTestSkipped(); + } else { + $this->gateway = new ConvergeGateway(); + $this->gateway->setMerchantId($merchantId); + $this->gateway->setUsername($username); + $this->gateway->setPassword($password); + $this->gateway->setTestMode(true); + } + } + + public function testAuthCapture() + { + $authResponse = $this->gateway->authorize( + array( + 'amount'=>'10.00', + 'card'=>$this->getValidCard(), + 'ssl_invoice_number'=>'1' + ) + )->send(); + $this->assertTrue($authResponse->isSuccessful()); + echo '
';
+        print_r($authResponse->getData());
+        echo '
'; + } +} \ No newline at end of file From acc6c9403406af00ecd1417c2895babd4589c57a Mon Sep 17 00:00:00 2001 From: Derek Caswell Date: Tue, 7 Mar 2017 13:14:16 -0700 Subject: [PATCH 4/7] Finished the creation of integration tests --- src/Message/ConvergeAbstractRequest.php | 26 ++++++- tests/ConvergeIntegrationTest.php | 95 +++++++++++++++++++++++-- 2 files changed, 116 insertions(+), 5 deletions(-) diff --git a/src/Message/ConvergeAbstractRequest.php b/src/Message/ConvergeAbstractRequest.php index 01f4fe3..890b5f0 100644 --- a/src/Message/ConvergeAbstractRequest.php +++ b/src/Message/ConvergeAbstractRequest.php @@ -310,6 +310,30 @@ public function setSslLastName($value) return $this->setParameter('ssl_last_name', $value); } + /** + * Get the IntegrationTesting boolean value. If this is true, you can run test transactions that actually create a + * transaction in an Elavon account so you can then run tests like a refund. + * + * @return bool + */ + public function getIntegrationTesting() + { + return $this->getParameter('integrationTesting'); + } + + /** + * Set the IntegrationTesting boolean value. If this is true, you can run test transactions that actually create a + * transaction in an Elavon account so you can then run tests like a refund. + * + * @param bool $value + * + * @return ConvergeAbstractRequest provides a fluent interface + */ + public function setIntegrationTesting($value) + { + return $this->setParameter('integrationTesting', $value); + } + protected function createResponse($response) { return $this->response = new ConvergeResponse($this, $response); @@ -324,7 +348,7 @@ protected function getBaseData() 'ssl_merchant_id' => $this->getMerchantId(), 'ssl_user_id' => $this->getUsername(), 'ssl_pin' => $this->getPassword(), - 'ssl_test_mode' => ($this->getTestMode()) ? 'true' : 'false', + 'ssl_test_mode' => ($this->getTestMode() && !$this->getIntegrationTesting()) ? 'true' : 'false', 'ssl_show_form' => ($this->getSslShowForm() && ($this->getSslShowForm() != 'false')) ? 'true' : 'false', 'ssl_result_format' => $this->getSslResultFormat(), 'ssl_invoice_number' => $this->getSslInvoiceNumber(), diff --git a/tests/ConvergeIntegrationTest.php b/tests/ConvergeIntegrationTest.php index b583dea..f0e7c9a 100644 --- a/tests/ConvergeIntegrationTest.php +++ b/tests/ConvergeIntegrationTest.php @@ -63,18 +63,105 @@ public function setUp() } } + /** + * Test an authorization only followed by the capture of that transaction + */ public function testAuthCapture() { $authResponse = $this->gateway->authorize( array( 'amount'=>'10.00', 'card'=>$this->getValidCard(), - 'ssl_invoice_number'=>'1' + 'ssl_invoice_number'=>'1', + 'integrationTesting'=>true ) )->send(); $this->assertTrue($authResponse->isSuccessful()); - echo '
';
-        print_r($authResponse->getData());
-        echo '
'; + $this->assertEquals('APPROVAL', $authResponse->getMessage()); + + $captureResponse = $this->gateway->capture( + array( + 'amount'=>'10.00', + 'transactionReference'=>$authResponse->getTransactionReference(), + 'integrationTesting'=>true + ) + )->send(); + + $this->assertTrue($captureResponse->isSuccessful()); + $this->assertEquals('APPROVAL', $captureResponse->getMessage()); + } + + /** + * Test a purchase followed by a refund of that purchase + */ + public function testPurchaseRefund() + { + $purchaseResponse = $this->gateway->purchase( + array( + 'amount'=>'20.00', + 'card'=>$this->getValidCard(), + 'ssl_invoice_number'=>2, + 'integrationTesting'=>true + ) + )->send(); + + $this->assertTrue($purchaseResponse->isSuccessful()); + $this->assertEquals('APPROVAL', $purchaseResponse->getMessage()); + + $refundResponse = $this->gateway->refund( + array( + 'amount'=>'20.00', + 'transactionReference'=>$purchaseResponse->getTransactionReference(), + 'integrationTesting'=>true + ) + )->send(); + + $this->assertTrue($refundResponse->isSuccessful()); + $this->assertEquals('APPROVAL', $refundResponse->getMessage()); + } + + + /** + * Test a purchase followed by a void of that purchase + */ + public function testPurchaseVoid() + { + $purchaseResponse = $this->gateway->purchase( + array( + 'amount'=>'30.00', + 'card'=>$this->getValidCard(), + 'ssl_invoice_number'=>3, + 'integrationTesting'=>true + ) + )->send(); + + $this->assertTrue($purchaseResponse->isSuccessful()); + $this->assertEquals('APPROVAL', $purchaseResponse->getMessage()); + + $voidResponse = $this->gateway->void( + array( + 'transactionReference'=>$purchaseResponse->getTransactionReference(), + 'integrationTesting'=>true + ) + )->send(); + + $this->assertTrue($voidResponse->isSuccessful()); + $this->assertEquals('APPROVAL', $voidResponse->getMessage()); + } + + /** + * This allows for the usage of Elavon's test card data instead of using the default data from Omnipay + * + * @return array + */ + public function getValidCard() + { + $card = parent::getValidCard(); + $card['number'] = '4124939999999990'; + $card['expiryMonth'] = '12'; + $card['expiryYear'] = '19'; + + return $card; + } } \ No newline at end of file From 4230c569d796df5b1ad47bc10f1d43168fced879 Mon Sep 17 00:00:00 2001 From: Derek Caswell Date: Tue, 7 Mar 2017 13:20:46 -0700 Subject: [PATCH 5/7] Added a test for the new IntegrationTesting setter and getter. --- tests/Message/ConvergeAuthorizeRequestTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Message/ConvergeAuthorizeRequestTest.php b/tests/Message/ConvergeAuthorizeRequestTest.php index 3d836a9..27584c6 100644 --- a/tests/Message/ConvergeAuthorizeRequestTest.php +++ b/tests/Message/ConvergeAuthorizeRequestTest.php @@ -4,6 +4,9 @@ class ConvergeAuthorizeRequestTest extends TestCase { + /** @var ConvergeAuthorizeRequest */ + protected $request; + public function setUp() { $this->request = new ConvergeAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); @@ -43,6 +46,12 @@ public function testGetLiveEndpoint() $this->assertSame('https://www.myvirtualmerchant.com/VirtualMerchant', $this->request->getEndpoint()); } + public function testIntegrationTesting() + { + $this->assertSame($this->request, $this->request->setIntegrationTesting(false)); + $this->assertFalse($this->request->getIntegrationTesting()); + } + public function testGetData() { $data = $this->request->getData(); From 8e1236d418fd7ceddfd56da233a54dd6f30f9c25 Mon Sep 17 00:00:00 2001 From: Derek Caswell Date: Tue, 7 Mar 2017 14:03:43 -0700 Subject: [PATCH 6/7] Made some formatting changes to be PSR2 compliant. --- src/Message/ConvergeCaptureRequest.php | 2 +- src/Message/ConvergeRefundRequest.php | 2 +- src/Message/ConvergeTransactionManage.php | 4 ++-- src/Message/ConvergeVoidRequest.php | 2 +- tests/Message/ConvergeCaptureRequestTest.php | 2 +- tests/Message/ConvergeRefundRequestTest.php | 2 +- tests/Message/ConvergeVoidRequestTest.php | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Message/ConvergeCaptureRequest.php b/src/Message/ConvergeCaptureRequest.php index 0f9d99f..9769116 100644 --- a/src/Message/ConvergeCaptureRequest.php +++ b/src/Message/ConvergeCaptureRequest.php @@ -79,4 +79,4 @@ protected function manageValidate() { $this->validate('transactionReference', 'amount'); } -} \ No newline at end of file +} diff --git a/src/Message/ConvergeRefundRequest.php b/src/Message/ConvergeRefundRequest.php index bdc6091..cf18af8 100644 --- a/src/Message/ConvergeRefundRequest.php +++ b/src/Message/ConvergeRefundRequest.php @@ -79,4 +79,4 @@ protected function manageValidate() { $this->validate('transactionReference', 'amount'); } -} \ No newline at end of file +} diff --git a/src/Message/ConvergeTransactionManage.php b/src/Message/ConvergeTransactionManage.php index 6bf35cc..a5febe7 100644 --- a/src/Message/ConvergeTransactionManage.php +++ b/src/Message/ConvergeTransactionManage.php @@ -32,5 +32,5 @@ public function getData() return array_merge($this->getBaseData(), $data); } - protected abstract function manageValidate(); -} \ No newline at end of file + abstract protected function manageValidate(); +} diff --git a/src/Message/ConvergeVoidRequest.php b/src/Message/ConvergeVoidRequest.php index ccf4ec2..c5db4de 100644 --- a/src/Message/ConvergeVoidRequest.php +++ b/src/Message/ConvergeVoidRequest.php @@ -89,4 +89,4 @@ public function getData() return array_merge($this->getBaseData(), $data); } -} \ No newline at end of file +} diff --git a/tests/Message/ConvergeCaptureRequestTest.php b/tests/Message/ConvergeCaptureRequestTest.php index 5abc9a5..90a1e8b 100644 --- a/tests/Message/ConvergeCaptureRequestTest.php +++ b/tests/Message/ConvergeCaptureRequestTest.php @@ -47,4 +47,4 @@ public function testCaptureSuccess() $this->assertSame('00000000-0000-0000-0000-00000000000', $response->getTransactionReference()); } -} \ No newline at end of file +} diff --git a/tests/Message/ConvergeRefundRequestTest.php b/tests/Message/ConvergeRefundRequestTest.php index 1b14579..757396e 100644 --- a/tests/Message/ConvergeRefundRequestTest.php +++ b/tests/Message/ConvergeRefundRequestTest.php @@ -47,4 +47,4 @@ public function testCaptureSuccess() $this->assertSame('0', $response->getCode()); $this->assertSame('00000000-0000-0000-0000-00000000000', $response->getTransactionReference()); } -} \ No newline at end of file +} diff --git a/tests/Message/ConvergeVoidRequestTest.php b/tests/Message/ConvergeVoidRequestTest.php index d70b08b..2ff3820 100644 --- a/tests/Message/ConvergeVoidRequestTest.php +++ b/tests/Message/ConvergeVoidRequestTest.php @@ -38,4 +38,4 @@ public function testCaptureSuccess() $this->assertSame('0', $response->getCode()); $this->assertSame('00000000-0000-0000-0000-00000000000', $response->getTransactionReference()); } -} \ No newline at end of file +} From e3497dfebbb6770e871305129d1af3a9b1d3a174 Mon Sep 17 00:00:00 2001 From: Derek Caswell Date: Wed, 22 Mar 2017 12:13:10 -0600 Subject: [PATCH 7/7] Minor change so I have something to commit and hopefully get the ci to run the tests again. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9d0caa2..127389d 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ The following gateways are provided by this package: For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) repository. + ## Support If you are having general issues with Omnipay, we suggest posting on