diff --git a/src/Message/RapidSharedCreateCardRequest.php b/src/Message/RapidSharedCreateCardRequest.php new file mode 100644 index 0000000..8c097ee --- /dev/null +++ b/src/Message/RapidSharedCreateCardRequest.php @@ -0,0 +1,39 @@ +validate('returnUrl'); + + $data = $this->getBaseData(); + $data['Method'] = 'CreateTokenCustomer'; + $data['TransactionType'] = 'Purchase'; + $data['RedirectUrl'] = $this->getReturnUrl(); + + // Shared page parameters (optional) + $data['CancelUrl'] = $this->getCancelUrl(); + $data['LogoUrl'] = $this->getLogoUrl(); + $data['HeaderText'] = $this->getHeaderText(); + $data['Language'] = $this->getLanguage(); + $data['CustomerReadOnly'] = $this->getCustomerReadOnly(); + $data['CustomView'] = $this->getCustomView(); + + $data['Payment'] = array(); + $data['Payment']['TotalAmount'] = 0; + + return $data; + } +} diff --git a/src/Message/RapidSharedUpdateCardRequest.php b/src/Message/RapidSharedUpdateCardRequest.php new file mode 100644 index 0000000..b1d42ed --- /dev/null +++ b/src/Message/RapidSharedUpdateCardRequest.php @@ -0,0 +1,41 @@ +validate('returnUrl', 'cardReference'); + + $data = $this->getBaseData(); + $data['Method'] = 'UpdateTokenCustomer'; + $data['TransactionType'] = 'Purchase'; + $data['RedirectUrl'] = $this->getReturnUrl(); + + // Shared page parameters (optional) + $data['CancelUrl'] = $this->getCancelUrl(); + $data['LogoUrl'] = $this->getLogoUrl(); + $data['HeaderText'] = $this->getHeaderText(); + $data['Language'] = $this->getLanguage(); + $data['CustomerReadOnly'] = $this->getCustomerReadOnly(); + $data['CustomView'] = $this->getCustomView(); + + $data['Payment'] = array(); + $data['Payment']['TotalAmount'] = 0; + + $data['Customer']['TokenCustomerID'] = $this->getCardReference(); + + return $data; + } +} diff --git a/src/RapidSharedGateway.php b/src/RapidSharedGateway.php index 33d2ee7..5f5696a 100644 --- a/src/RapidSharedGateway.php +++ b/src/RapidSharedGateway.php @@ -73,4 +73,14 @@ public function refund(array $parameters = array()) { return $this->createRequest('\Omnipay\Eway\Message\RefundRequest', $parameters); } + + public function createCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Eway\Message\RapidSharedCreateCardRequest', $parameters); + } + + public function updateCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Eway\Message\RapidSharedUpdateCardRequest', $parameters); + } } diff --git a/tests/Message/RapidSharedCreateCardRequestTest.php b/tests/Message/RapidSharedCreateCardRequestTest.php new file mode 100644 index 0000000..38d4681 --- /dev/null +++ b/tests/Message/RapidSharedCreateCardRequestTest.php @@ -0,0 +1,123 @@ +request = new RapidSharedCreateCardRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'returnUrl' => 'https://www.example.com/return', + )); + } + + public function testGetData() + { + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'returnUrl' => 'https://www.example.com/return', + 'card' => array( + 'title' => 'Mr', + 'firstName' => 'Patrick', + 'lastName' => 'Collison', + 'country' => 'AU', + ), + )); + + $data = $this->request->getData(); + + $this->assertSame('Purchase', $data['TransactionType']); + $this->assertSame('CreateTokenCustomer', $data['Method']); + $this->assertSame('https://www.example.com/return', $data['RedirectUrl']); + $this->assertSame(0, $data['Payment']['TotalAmount']); + $this->assertSame('Mr', $data['Customer']['Title']); + $this->assertSame('Patrick', $data['Customer']['FirstName']); + $this->assertSame('Collison', $data['Customer']['LastName']); + $this->assertSame('au', $data['ShippingAddress']['Country']); + } + + public function testSendSuccess() + { + $this->setMockHttpResponse('RapidSharedCreateCardRequestSuccess.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertTrue($response->isRedirect()); + $this->assertSame('GET', $response->getRedirectMethod()); + $this->assertSame('https://secure.ewaypayments.com/sharedpayment?AccessCode=F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL', $response->getRedirectUrl()); + $this->assertNull($response->getRedirectData()); + $this->assertNull($response->getTransactionReference()); + $this->assertNull($response->getMessage()); + $this->assertNull($response->getCode()); + $this->assertNotNull($response->getCardReference()); + } + + public function testSendFailure() + { + $this->setMockHttpResponse('RapidSharedCreateCardRequestFailure.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertNull($response->getRedirectUrl()); + $this->assertNull($response->getRedirectData()); + $this->assertNull($response->getCardReference()); + $this->assertNull($response->getTransactionReference()); + $this->assertSame('V6042,V6043,V6044', $response->getCode()); + } + + public function testCancelUrl() + { + $this->assertSame($this->request, $this->request->setCancelUrl('http://www.example.com')); + $this->assertSame('http://www.example.com', $this->request->getCancelUrl()); + } + + public function testLogoUrl() + { + $this->assertSame($this->request, $this->request->setLogoUrl('https://www.example.com/logo.jpg')); + $this->assertSame('https://www.example.com/logo.jpg', $this->request->getLogoUrl()); + } + + public function testHeaderText() + { + $this->assertSame($this->request, $this->request->setHeaderText('Header Text')); + $this->assertSame('Header Text', $this->request->getHeaderText()); + } + + public function testLanguage() + { + $this->assertSame($this->request, $this->request->setLanguage('EN')); + $this->assertSame('EN', $this->request->getLanguage()); + } + + public function testCustomerReadOnly() + { + $this->assertSame($this->request, $this->request->setCustomerReadOnly('true')); + $this->assertSame('true', $this->request->getCustomerReadOnly()); + } + + public function testCustomView() + { + $this->assertSame($this->request, $this->request->setCustomView('Bootstrap')); + $this->assertSame('Bootstrap', $this->request->getCustomView()); + } + + public function testVerifyCustomerPhone() + { + $this->assertSame($this->request, $this->request->setVerifyCustomerPhone('true')); + $this->assertSame('true', $this->request->getVerifyCustomerPhone()); + } + + public function testVerifyCustomerEmail() + { + $this->assertSame($this->request, $this->request->setVerifyCustomerEmail('true')); + $this->assertSame('true', $this->request->getVerifyCustomerEmail()); + } + +} diff --git a/tests/Message/RapidSharedUpdateCardRequestTest.php b/tests/Message/RapidSharedUpdateCardRequestTest.php new file mode 100644 index 0000000..1cdc316 --- /dev/null +++ b/tests/Message/RapidSharedUpdateCardRequestTest.php @@ -0,0 +1,126 @@ +request = new RapidSharedUpdateCardRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'returnUrl' => 'https://www.example.com/return', + 'cardReference' => '123456789' + )); + } + + public function testGetData() + { + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'returnUrl' => 'https://www.example.com/return', + 'cardReference' => '123456789', + 'card' => array( + 'title' => 'Mr', + 'firstName' => 'Patrick', + 'lastName' => 'Collison', + 'country' => 'AU', + ), + )); + + $data = $this->request->getData(); + + $this->assertSame('Purchase', $data['TransactionType']); + $this->assertSame('UpdateTokenCustomer', $data['Method']); + $this->assertSame('https://www.example.com/return', $data['RedirectUrl']); + $this->assertSame(0, $data['Payment']['TotalAmount']); + $this->assertSame('Mr', $data['Customer']['Title']); + $this->assertSame('Patrick', $data['Customer']['FirstName']); + $this->assertSame('Collison', $data['Customer']['LastName']); + $this->assertSame('au', $data['ShippingAddress']['Country']); + $this->assertSame('123456789', $data['Customer']['TokenCustomerID']); + } + + public function testSendSuccess() + { + $this->setMockHttpResponse('RapidSharedUpdateCardRequestSuccess.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertTrue($response->isRedirect()); + $this->assertSame('GET', $response->getRedirectMethod()); + $this->assertSame('https://secure.ewaypayments.com/sharedpayment?AccessCode=F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL', $response->getRedirectUrl()); + $this->assertNull($response->getRedirectData()); + $this->assertNull($response->getTransactionReference()); + $this->assertNull($response->getMessage()); + $this->assertNull($response->getCode()); + $this->assertNotNull($response->getCardReference()); + } + + public function testSendFailure() + { + $this->setMockHttpResponse('RapidSharedUpdateCardRequestFailure.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertNull($response->getRedirectUrl()); + $this->assertNull($response->getRedirectData()); + $this->assertNull($response->getCardReference()); + $this->assertNull($response->getTransactionReference()); + $this->assertSame('V6040', $response->getCode()); + } + + public function testCancelUrl() + { + $this->assertSame($this->request, $this->request->setCancelUrl('http://www.example.com')); + $this->assertSame('http://www.example.com', $this->request->getCancelUrl()); + } + + public function testLogoUrl() + { + $this->assertSame($this->request, $this->request->setLogoUrl('https://www.example.com/logo.jpg')); + $this->assertSame('https://www.example.com/logo.jpg', $this->request->getLogoUrl()); + } + + public function testHeaderText() + { + $this->assertSame($this->request, $this->request->setHeaderText('Header Text')); + $this->assertSame('Header Text', $this->request->getHeaderText()); + } + + public function testLanguage() + { + $this->assertSame($this->request, $this->request->setLanguage('EN')); + $this->assertSame('EN', $this->request->getLanguage()); + } + + public function testCustomerReadOnly() + { + $this->assertSame($this->request, $this->request->setCustomerReadOnly('true')); + $this->assertSame('true', $this->request->getCustomerReadOnly()); + } + + public function testCustomView() + { + $this->assertSame($this->request, $this->request->setCustomView('Bootstrap')); + $this->assertSame('Bootstrap', $this->request->getCustomView()); + } + + public function testVerifyCustomerPhone() + { + $this->assertSame($this->request, $this->request->setVerifyCustomerPhone('true')); + $this->assertSame('true', $this->request->getVerifyCustomerPhone()); + } + + public function testVerifyCustomerEmail() + { + $this->assertSame($this->request, $this->request->setVerifyCustomerEmail('true')); + $this->assertSame('true', $this->request->getVerifyCustomerEmail()); + } + +} diff --git a/tests/Mock/RapidSharedCreateCardRequestFailure.txt b/tests/Mock/RapidSharedCreateCardRequestFailure.txt new file mode 100644 index 0000000..3a0a461 --- /dev/null +++ b/tests/Mock/RapidSharedCreateCardRequestFailure.txt @@ -0,0 +1,17 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Thu, 27 Jun 2013 05:22:52 GMT +Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D00F53B19AA8D0E66C1AD34691F2170CBA3CC4FEE8666E2FB3C85D3B0E238FA2E93B31AAC1C98DFF4D0639139359FE706;PATH=/;MAX-AGE=86400 +X-EWAY-VIA: api-au.sandbox.ewaypayments.com/ +X-EWAY-VIA-FROM: http://api.sandbox.ewaypayments.com/CreateAccessCodeShared.json +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/CreateAccessCodeShared.json +X-ID: AM-131 +X-Powered-By: eWAY +X-Staging: AU +Content-Length: 649 +Connection: keep-alive + +{"AccessCode":null,"Customer":{"TokenCustomerID":null,"Reference":null,"Title":null,"FirstName":null,"LastName":null,"CompanyName":null,"JobDescription":null,"Street1":null,"Street2":null,"City":null,"State":null,"PostalCode":null,"Country":null,"Email":null,"Phone":null,"Mobile":null,"Comments":null,"Fax":null,"Url":null,"CardNumber":null,"CardStartMonth":null,"CardStartYear":null,"CardIssueNumber":null,"CardName":null,"CardExpiryMonth":null,"CardExpiryYear":null,"IsActive":false},"Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},"FormActionURL":null,"Errors":"V6042,V6043,V6044"} diff --git a/tests/Mock/RapidSharedCreateCardRequestSuccess.txt b/tests/Mock/RapidSharedCreateCardRequestSuccess.txt new file mode 100644 index 0000000..ecc6f39 --- /dev/null +++ b/tests/Mock/RapidSharedCreateCardRequestSuccess.txt @@ -0,0 +1,16 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Wed, 26 Jun 2013 13:11:50 GMT +Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D00F53B19AA8D0E66C1AD34691F2170CB4C6B4D750DDAD028ED5C0787DEB1569F57CC58B5923AA0229EC5B49BD7647A57;PATH=/;MAX-AGE=86400 +X-EWAY-VIA: api-au.sandbox.ewaypayments.com/ +X-EWAY-VIA-FROM: http://api.sandbox.ewaypayments.com/CreateAccessCodeShared.json +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/CreateAccessCodeShared.json +X-ID: AM-143 +X-Powered-By: eWAY +Content-Length: 1112 +Connection: keep-alive + +{"SharedPaymentUrl":"https://secure.ewaypayments.com/sharedpayment?AccessCode=F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL","AccessCode":"F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL","Customer":{"TokenCustomerID":"","Reference":"","Title":"","FirstName":"","LastName":"","CompanyName":"","JobDescription":"","Street1":"","Street2":"","City":"","State":"","PostalCode":"","Country":"","Email":"","Phone":"","Mobile":"","Comments":"","Fax":"","Url":"","CardNumber":"","CardStartMonth":"","CardStartYear":"","CardIssueNumber":"","CardName":"","CardExpiryMonth":"","CardExpiryYear":"","IsActive":false},"Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},"FormActionURL":"https://secure.ewaypayments.com/AccessCode/F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL","Errors":null} \ No newline at end of file diff --git a/tests/Mock/RapidSharedUpdateCardRequestFailure.txt b/tests/Mock/RapidSharedUpdateCardRequestFailure.txt new file mode 100644 index 0000000..f093c58 --- /dev/null +++ b/tests/Mock/RapidSharedUpdateCardRequestFailure.txt @@ -0,0 +1,17 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Thu, 27 Jun 2013 05:22:52 GMT +Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D00F53B19AA8D0E66C1AD34691F2170CBA3CC4FEE8666E2FB3C85D3B0E238FA2E93B31AAC1C98DFF4D0639139359FE706;PATH=/;MAX-AGE=86400 +X-EWAY-VIA: api-au.sandbox.ewaypayments.com/ +X-EWAY-VIA-FROM: http://api.sandbox.ewaypayments.com/CreateAccessCodeShared.json +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/CreateAccessCodeShared.json +X-ID: AM-131 +X-Powered-By: eWAY +X-Staging: AU +Content-Length: 649 +Connection: keep-alive + +{"AccessCode":null,"Customer":{"TokenCustomerID":null,"Reference":null,"Title":null,"FirstName":null,"LastName":null,"CompanyName":null,"JobDescription":null,"Street1":null,"Street2":null,"City":null,"State":null,"PostalCode":null,"Country":null,"Email":null,"Phone":null,"Mobile":null,"Comments":null,"Fax":null,"Url":null,"CardNumber":null,"CardStartMonth":null,"CardStartYear":null,"CardIssueNumber":null,"CardName":null,"CardExpiryMonth":null,"CardExpiryYear":null,"IsActive":false},"Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},"FormActionURL":null,"Errors":"V6040"} diff --git a/tests/Mock/RapidSharedUpdateCardRequestSuccess.txt b/tests/Mock/RapidSharedUpdateCardRequestSuccess.txt new file mode 100644 index 0000000..ecc6f39 --- /dev/null +++ b/tests/Mock/RapidSharedUpdateCardRequestSuccess.txt @@ -0,0 +1,16 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Wed, 26 Jun 2013 13:11:50 GMT +Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D00F53B19AA8D0E66C1AD34691F2170CB4C6B4D750DDAD028ED5C0787DEB1569F57CC58B5923AA0229EC5B49BD7647A57;PATH=/;MAX-AGE=86400 +X-EWAY-VIA: api-au.sandbox.ewaypayments.com/ +X-EWAY-VIA-FROM: http://api.sandbox.ewaypayments.com/CreateAccessCodeShared.json +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/CreateAccessCodeShared.json +X-ID: AM-143 +X-Powered-By: eWAY +Content-Length: 1112 +Connection: keep-alive + +{"SharedPaymentUrl":"https://secure.ewaypayments.com/sharedpayment?AccessCode=F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL","AccessCode":"F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL","Customer":{"TokenCustomerID":"","Reference":"","Title":"","FirstName":"","LastName":"","CompanyName":"","JobDescription":"","Street1":"","Street2":"","City":"","State":"","PostalCode":"","Country":"","Email":"","Phone":"","Mobile":"","Comments":"","Fax":"","Url":"","CardNumber":"","CardStartMonth":"","CardStartYear":"","CardIssueNumber":"","CardName":"","CardExpiryMonth":"","CardExpiryYear":"","IsActive":false},"Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},"FormActionURL":"https://secure.ewaypayments.com/AccessCode/F9802j0-O7sdVLnOcb_3IPryTxHDtKY8u_0pb10GbYq-Xjvbc-5Bc_LhI-oBIrTxTCjhOFn7Mq-CwpkLDja5-iu-Dr3DjVTr9u4yxSB5BckdbJqSA4WWydzDO0jnPWfBdKcWL","Errors":null} \ No newline at end of file diff --git a/tests/RapidSharedGatewayTest.php b/tests/RapidSharedGatewayTest.php index 78802c0..0b1b040 100644 --- a/tests/RapidSharedGatewayTest.php +++ b/tests/RapidSharedGatewayTest.php @@ -28,4 +28,20 @@ public function testPurchaseReturn() $this->assertInstanceOf('Omnipay\Eway\Message\RapidCompletePurchaseRequest', $request); $this->assertSame('10.00', $request->getAmount()); } + + public function testCreateCard() + { + $request = $this->gateway->createCard(array('amount' => '10.00')); + + $this->assertInstanceOf('\Omnipay\Eway\Message\RapidSharedCreateCardRequest', $request); + $this->assertSame('10.00', $request->getAmount()); + } + + public function testUpdateCard() + { + $request = $this->gateway->updateCard(array('amount' => '10.00')); + + $this->assertInstanceOf('\Omnipay\Eway\Message\RapidSharedUpdateCardRequest', $request); + $this->assertSame('10.00', $request->getAmount()); + } }