diff --git a/src/ConvergeGateway.php b/src/ConvergeGateway.php index d6d6f10..5058110 100644 --- a/src/ConvergeGateway.php +++ b/src/ConvergeGateway.php @@ -70,4 +70,13 @@ public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\Elavon\Message\ConvergePurchaseRequest', $parameters); } + + /** + * @param array $parameters + * @return \Omnipay\Elavon\Message\PurchaseRequest + */ + public function createCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Elavon\Message\ConvergeGenerateTokenRequest', $parameters); + } } diff --git a/src/Message/ConvergeAuthorizeRequest.php b/src/Message/ConvergeAuthorizeRequest.php index 5cbaf6c..93e5f7a 100644 --- a/src/Message/ConvergeAuthorizeRequest.php +++ b/src/Message/ConvergeAuthorizeRequest.php @@ -6,26 +6,41 @@ class ConvergeAuthorizeRequest extends ConvergeAbstractRequest public function getData() { - $this->validate('amount', 'card'); - $this->getCard()->validate(); + if ($this->getCard() != null) { + $this->validate('amount', 'card'); + $this->getCard()->validate(); - $data = array( - 'ssl_amount' => $this->getAmount(), - 'ssl_salestax' => $this->getSslSalesTax(), - 'ssl_transaction_type' => $this->transactionType, - 'ssl_card_number' => $this->getCard()->getNumber(), - 'ssl_exp_date' => $this->getCard()->getExpiryDate('my'), - 'ssl_cvv2cvc2' => $this->getCard()->getCvv(), - 'ssl_cvv2cvc2_indicator' => ($this->getCard()->getCvv()) ? 1 : 0, - 'ssl_first_name' => $this->getCard()->getFirstName(), - 'ssl_last_name' => $this->getCard()->getLastName(), - 'ssl_avs_address' => $this->getCard()->getAddress1(), - 'ssl_address2' => $this->getCard()->getAddress2(), - 'ssl_city' => $this->getCard()->getCity(), - 'ssl_state' => $this->getCard()->getState(), - 'ssl_country' => $this->getCard()->getCountry(), - 'ssl_avs_zip' => $this->getCard()->getPostcode() - ); + $data = array( + 'ssl_amount' => $this->getAmount(), + 'ssl_salestax' => $this->getSslSalesTax(), + 'ssl_transaction_type' => $this->transactionType, + 'ssl_card_number' => $this->getCard()->getNumber(), + 'ssl_exp_date' => $this->getCard()->getExpiryDate('my'), + 'ssl_cvv2cvc2' => $this->getCard()->getCvv(), + 'ssl_cvv2cvc2_indicator' => ($this->getCard()->getCvv()) ? 1 : 0, + 'ssl_first_name' => $this->getCard()->getFirstName(), + 'ssl_last_name' => $this->getCard()->getLastName(), + 'ssl_avs_address' => $this->getCard()->getAddress1(), + 'ssl_address2' => $this->getCard()->getAddress2(), + 'ssl_city' => $this->getCard()->getCity(), + 'ssl_state' => $this->getCard()->getState(), + 'ssl_country' => $this->getCard()->getCountry(), + 'ssl_customer_code' => $this->getDescription(), + 'ssl_avs_zip' => $this->getCard()->getPostcode() + ); + } elseif ($this->getCardReference() != null) { + $this->validate('amount'); + + $data = array( + 'ssl_show_form' => 'false', + 'ssl_result_format' => 'ASCII', + 'ssl_amount' => $this->getAmount(), + 'ssl_salestax' => $this->getSslSalesTax(), + 'ssl_transaction_type' => $this->transactionType, + 'ssl_token' => $this->getCardReference(), + 'ssl_customer_code' => $this->getDescription(), + ); + } return array_merge($this->getBaseData(), $data); } diff --git a/src/Message/ConvergeGenerateTokenRequest.php b/src/Message/ConvergeGenerateTokenRequest.php new file mode 100644 index 0000000..0533198 --- /dev/null +++ b/src/Message/ConvergeGenerateTokenRequest.php @@ -0,0 +1,45 @@ + $this->transactionType, + 'ssl_amount' => $this->getAmount(), + 'ssl_salestax' => $this->getSslSalesTax(), + + 'ssl_card_number' => $this->getCard()->getNumber(), + 'ssl_exp_date' => $this->getCard()->getExpiryDate('my'), + 'ssl_cvv2cvc2' => $this->getCard()->getCvv(), + 'ssl_cvv2cvc2_indicator' => ($this->getCard()->getCvv()) ? 1 : 0, + + 'ssl_verify' => 'N', + + 'ssl_first_name' => $this->getCard()->getFirstName(), + 'ssl_last_name' => $this->getCard()->getLastName(), + 'ssl_avs_address' => $this->getCard()->getAddress1(), + 'ssl_address2' => $this->getCard()->getAddress2(), + 'ssl_city' => $this->getCard()->getCity(), + 'ssl_state' => $this->getCard()->getState(), + 'ssl_country' => $this->getCard()->getCountry(), + 'ssl_add_token' => 'Y', + + 'ssl_show_form' => 'false', + 'ssl_result_format' => 'ASCII', + ); + + 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/ConvergeResponse.php b/src/Message/ConvergeResponse.php index 5d485cf..6f28a40 100644 --- a/src/Message/ConvergeResponse.php +++ b/src/Message/ConvergeResponse.php @@ -38,4 +38,9 @@ public function getCode() return $this->data['ssl_result']; } + + public function getCardToken() + { + return (isset($this->data['ssl_token'])) ? $this->data['ssl_token'] : null; + } } diff --git a/tests/ConvergeGatewayTest.php b/tests/ConvergeGatewayTest.php index e597779..440c4d3 100644 --- a/tests/ConvergeGatewayTest.php +++ b/tests/ConvergeGatewayTest.php @@ -54,4 +54,30 @@ public function testPurchase() $this->assertSame('testpassword1', $request->getPassword()); $this->assertSame('USD', $request->getCurrency()); } + + public function testPurchaseChargeCard() + { + $request = $this->gateway->purchase(array( + 'amount' => 10.00, + 'token' => '7595301425001111', + 'ssl_show_form' => 'false', + 'ssl_result_format' => 'ASCII', + 'merchantId' => 'testmerchant1', + 'username' => 'testusername1', + 'password' => 'testpassword1', + 'currency' => 'USD' + )); + + $this->assertInstanceOf('Omnipay\Elavon\Message\ConvergePurchaseRequest', $request); + $this->assertSame('10.00', (string) $request->getAmount()); + $this->assertSame('false', (string) $request->getSslShowForm()); + $this->assertSame('ASCII', (string) $request->getSslResultFormat()); + $this->assertSame('testmerchant1', $request->getMerchantId()); + $this->assertSame('testusername1', $request->getUsername()); + $this->assertSame('testpassword1', $request->getPassword()); + $this->assertSame('testpassword1', $request->getPassword()); + $this->assertSame('USD', $request->getCurrency()); + } + + } diff --git a/tests/Message/ConvergeGenerateTokenRequestTest.php b/tests/Message/ConvergeGenerateTokenRequestTest.php new file mode 100644 index 0000000..ef6b1d9 --- /dev/null +++ b/tests/Message/ConvergeGenerateTokenRequestTest.php @@ -0,0 +1,28 @@ +request = new ConvergeGenerateTokenRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize( + array( + 'card' => $this->getValidCard(), + 'ssl_show_form' => 'false', + 'ssl_result_format' => 'ASCII', + ) + ); + } + + public function testCreateCardSuccess() + { + $this->setMockHttpResponse('ConvergeCreateCardResponse.txt'); + $response = $this->request->send(); + $this->assertTrue($response->isSuccessful()); + $this->assertSame('7595301425001111', $response->getCardToken()); + } + +} + diff --git a/tests/Message/ConvergePurchaseRequestTest.php b/tests/Message/ConvergePurchaseRequestTest.php index 4954dd9..4051dcc 100644 --- a/tests/Message/ConvergePurchaseRequestTest.php +++ b/tests/Message/ConvergePurchaseRequestTest.php @@ -81,4 +81,31 @@ public function testPurchaseNoPIN() $this->assertSame('The PIN was not supplied in the authorization request.', $response->getMessage()); $this->assertSame('4013', $response->getCode()); } + + public function testPurchaseChargeCardToken() + { + $this->setMockHttpResponse('ConvergePurchaseCreditCardToken.txt'); + + $request = new ConvergePurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); + $request->initialize( + array( + 'amount' => 10.00, + 'token' => '7595301425001111', + 'cardReference' => '7595301425001111', + 'ssl_show_form' => 'false', + 'ssl_result_format' => 'ASCII', + 'merchantId' => 'testmerchant1', + 'username' => 'testusername1', + 'password' => 'testpassword1', + 'currency' => 'USD' + ) + ); + + $response = $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()); + } + } diff --git a/tests/Mock/ConvergeCreateCardResponse.txt b/tests/Mock/ConvergeCreateCardResponse.txt new file mode 100644 index 0000000..cb57c11 --- /dev/null +++ b/tests/Mock/ConvergeCreateCardResponse.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_status=TEST MODE +ssl_result=0 +ssl_token=7595301425001111 +ssl_card_number=41**********1111 +ssl_token_response=SUCCESS +ssl_add_token_response=Card Updated diff --git a/tests/Mock/ConvergePurchaseCreditCardToken.txt b/tests/Mock/ConvergePurchaseCreditCardToken.txt new file mode 100644 index 0000000..2373b0c --- /dev/null +++ b/tests/Mock/ConvergePurchaseCreditCardToken.txt @@ -0,0 +1,31 @@ +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_exp_date=0117 +ssl_amount=10.00 +ssl_salestax=1.23 +ssl_invoice_number=1 +ssl_departure_date= +ssl_completion_date= +ssl_issue_points= +ssl_promo_code= +ssl_enrollment= +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:21:58 PM +ssl_loyalty_account_balance= +ssl_loyalty_program= +ssl_access_code= +ssl_tender_amount= +ssl_account_status= \ No newline at end of file