diff --git a/README.md b/README.md index 231846d..21c17bf 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -# Omnipay: eWay +# Omnipay: eWAY -**eWay driver for the Omnipay PHP payment processing library** +**eWAY driver for the Omnipay PHP payment processing library** [![Build Status](https://travis-ci.org/thephpleague/omnipay-eway.png?branch=master)](https://travis-ci.org/thephpleague/omnipay-eway) [![Latest Stable Version](https://poser.pugx.org/omnipay/eway/version.png)](https://packagist.org/packages/omnipay/eway) [![Total Downloads](https://poser.pugx.org/omnipay/eway/d/total.png)](https://packagist.org/packages/omnipay/eway) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment -processing library for PHP 5.3+. This package implements eWay support for Omnipay. +processing library for PHP 5.3+. This package implements eWAY support for Omnipay. ## Installation @@ -33,6 +33,7 @@ The following gateways are provided by this package: * Eway_Rapid * Eway_RapidShared +* Eway_RapidDirect * Eway_Direct For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) @@ -44,7 +45,7 @@ If you are having general issues with Omnipay, we suggest posting on [Stack Overflow](http://stackoverflow.com/). Be sure to add the [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found. -If you want to keep up to date with release anouncements, discuss ideas for the project, +If you want to keep up to date with release announcements, discuss ideas for the project, or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which you can subscribe to. diff --git a/src/DirectGateway.php b/src/DirectGateway.php index cbb8eaf..5c8cd4b 100644 --- a/src/DirectGateway.php +++ b/src/DirectGateway.php @@ -1,11 +1,20 @@ getParameter('transactionType'); + if ($this->getParameter('transactionType')) { + return $this->getParameter('transactionType'); + } + return 'Purchase'; } /** @@ -86,6 +95,7 @@ protected function getBaseData() $data['Customer'] = array(); $card = $this->getCard(); if ($card) { + $data['Customer']['Title'] = $card->getTitle(); $data['Customer']['FirstName'] = $card->getFirstName(); $data['Customer']['LastName'] = $card->getLastName(); $data['Customer']['CompanyName'] = $card->getCompany(); diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php index b8094b4..5798cc3 100644 --- a/src/Message/AbstractResponse.php +++ b/src/Message/AbstractResponse.php @@ -1,13 +1,23 @@ 'Transaction Approved', 'A2008' => 'Honour With Identification', diff --git a/src/Message/RapidCaptureRequest.php b/src/Message/RapidCaptureRequest.php new file mode 100644 index 0000000..bf12366 --- /dev/null +++ b/src/Message/RapidCaptureRequest.php @@ -0,0 +1,68 @@ + + * // Once the transaction has been authorized, we can capture it for final payment. + * $transaction = $gateway->capture(array( + * 'amount' => '10.00', + * 'currency' => 'AUD', + * )); + * $transaction->setTransactionReference($txn_id); + * $response = $transaction->send(); + * + * + * @link https://eway.io/api-v3/#pre-auth + * @see RapidDirectAuthorizeRequest + */ +class RapidCaptureRequest extends AbstractRequest +{ + public function getData() + { + $this->validate('amount', 'transactionReference'); + + $data = array(); + + $data['Payment'] = array(); + $data['Payment']['TotalAmount'] = $this->getAmountInteger(); + $data['Payment']['InvoiceNumber'] = $this->getTransactionId(); + $data['Payment']['InvoiceDescription'] = $this->getDescription(); + $data['Payment']['CurrencyCode'] = $this->getCurrency(); + $data['Payment']['InvoiceReference'] = $this->getInvoiceReference(); + + $data['TransactionId'] = $this->getTransactionReference(); + + return $data; + } + + public function getEndpoint() + { + return $this->getEndpointBase().'/CapturePayment'; + } + + public function sendData($data) + { + // This request uses the REST endpoint and requires the JSON content type header + $httpResponse = $this->httpClient->post( + $this->getEndpoint(), + array('content-type' => 'application/json'), + json_encode($data) + ) + ->setAuth($this->getApiKey(), $this->getPassword()) + ->send(); + + return $this->response = new RapidResponse($this, $httpResponse->json()); + } +} diff --git a/src/Message/RapidCompletePurchaseRequest.php b/src/Message/RapidCompletePurchaseRequest.php index 2f5a519..54a27f1 100644 --- a/src/Message/RapidCompletePurchaseRequest.php +++ b/src/Message/RapidCompletePurchaseRequest.php @@ -1,9 +1,14 @@ $this->httpRequest->query->get('AccessCode')); } - public function getEndpoint() + protected function getEndpoint() { return $this->getEndpointBase().'/GetAccessCodeResult.json'; } diff --git a/src/Message/RapidDirectAbstractRequest.php b/src/Message/RapidDirectAbstractRequest.php new file mode 100644 index 0000000..fa628c2 --- /dev/null +++ b/src/Message/RapidDirectAbstractRequest.php @@ -0,0 +1,107 @@ +getParameter('encryptedCardNumber'); + } + + /** + * Sets the encrypted card number, for use when submitting card data + * encrypted using eWAY's client side encryption. + * + * @param string $value + * @return RapidDirectAbstractRequest + */ + public function setEncryptedCardNumber($value) + { + return $this->setParameter('encryptedCardNumber', $value); + } + + public function getEncryptedCardCvv() + { + return $this->getParameter('encryptedCardCvv'); + } + + /** + * Sets the encrypted card cvv, for use when submitting card data + * encrypted using eWAY's client side encryption. + * + * @param string $value + * @return RapidDirectAbstractRequest + */ + public function setEncryptedCardCvv($value) + { + return $this->setParameter('encryptedCardCvv', $value); + } + + protected function getBaseData() + { + + $data = parent::getBaseData(); + $data['TransactionType'] = $this->getTransactionType(); + + if ($this->getCardReference()) { + $data['Customer']['TokenCustomerID'] = $this->getCardReference(); + } else { + $this->validate('card'); + } + + if ($this->getCard()) { + $data['Customer']['CardDetails'] = array(); + $data['Customer']['CardDetails']['Name'] = $this->getCard()->getName(); + $data['Customer']['CardDetails']['ExpiryMonth'] = $this->getCard()->getExpiryDate('m'); + $data['Customer']['CardDetails']['ExpiryYear'] = $this->getCard()->getExpiryDate('y'); + $data['Customer']['CardDetails']['CVN'] = $this->getCard()->getCvv(); + + if ($this->getEncryptedCardNumber()) { + $data['Customer']['CardDetails']['Number'] = $this->getEncryptedCardNumber(); + } else { + $data['Customer']['CardDetails']['Number'] = $this->getCard()->getNumber(); + } + + if ($this->getEncryptedCardCvv()) { + $data['Customer']['CardDetails']['CVN'] = $this->getEncryptedCardCvv(); + } else { + $data['Customer']['CardDetails']['CVN'] = $this->getCard()->getCvv(); + } + + if ($this->getCard()->getStartMonth() and $this->getCard()->getStartYear()) { + $data['Customer']['CardDetails']['StartMonth'] = $this->getCard()->getStartDate('m'); + $data['Customer']['CardDetails']['StartYear'] = $this->getCard()->getStartDate('y'); + } + + if ($this->getCard()->getIssueNumber()) { + $data['Customer']['CardDetails']['IssueNumber'] = $this->getCard()->getIssueNumber(); + } + } + + if ($this->getItems()) { + $data['Items'] = $this->getItemData(); + } + + return $data; + } + + public function sendData($data) + { + $httpResponse = $this->httpClient->post($this->getEndpoint(), null, json_encode($data)) + ->setAuth($this->getApiKey(), $this->getPassword()) + ->send(); + + return $this->response = new RapidResponse($this, $httpResponse->json()); + } +} diff --git a/src/Message/RapidDirectAuthorizeRequest.php b/src/Message/RapidDirectAuthorizeRequest.php new file mode 100644 index 0000000..254a727 --- /dev/null +++ b/src/Message/RapidDirectAuthorizeRequest.php @@ -0,0 +1,92 @@ + + * // Create a gateway for the eWAY Direct Gateway + * $gateway = Omnipay::create('Eway_RapidDirect'); + * + * // Initialise the gateway + * $gateway->initialize(array( + * 'apiKey' => 'Rapid API Key', + * 'password' => 'Rapid API Password', + * 'testMode' => true, // Or false when you are ready for live transactions + * )); + * + * // Create a credit card object + * $card = new CreditCard(array( + * 'firstName' => 'Example', + * 'lastName' => 'User', + * 'number' => '4444333322221111', + * 'expiryMonth' => '01', + * 'expiryYear' => '2020', + * 'cvv' => '321', + * 'billingAddress1' => '1 Scrubby Creek Road', + * 'billingCountry' => 'AU', + * 'billingCity' => 'Scrubby Creek', + * 'billingPostcode' => '4999', + * 'billingState' => 'QLD', + * )); + * + * // Do an authorisation transaction on the gateway + * $request = $gateway->authorize(array( + * 'amount' => '10.00', + * 'currency' => 'AUD', + * 'transactionType' => 'Purchase', + * 'card' => $card, + * )); + * + * $response = $request->send(); + * if ($response->isSuccessful()) { + * echo "Authorisation transaction was successful!\n"; + * $txn_id = $response->getTransactionReference(); + * echo "Transaction ID = " . $txn_id . "\n"; + * } + * + * + * @link https://eway.io/api-v3/#direct-connection + * @link https://eway.io/api-v3/#pre-auth + * @see RapidCaptureRequest + */ +class RapidDirectAuthorizeRequest extends RapidDirectAbstractRequest +{ + public function getData() + { + $data = $this->getBaseData(); + + $this->validate('amount'); + + $data['Payment'] = array(); + $data['Payment']['TotalAmount'] = $this->getAmountInteger(); + $data['Payment']['InvoiceNumber'] = $this->getTransactionId(); + $data['Payment']['InvoiceDescription'] = $this->getDescription(); + $data['Payment']['CurrencyCode'] = $this->getCurrency(); + $data['Payment']['InvoiceReference'] = $this->getInvoiceReference(); + + $data['Method'] = 'Authorise'; + + return $data; + } + + protected function getEndpoint() + { + return $this->getEndpointBase().'/DirectPayment.json'; + } +} diff --git a/src/Message/RapidDirectCreateCardRequest.php b/src/Message/RapidDirectCreateCardRequest.php new file mode 100644 index 0000000..b4c6d8b --- /dev/null +++ b/src/Message/RapidDirectCreateCardRequest.php @@ -0,0 +1,76 @@ + + * // Create a gateway for the eWAY Direct Gateway + * $gateway = Omnipay::create('Eway_RapidDirect'); + * + * // Initialise the gateway + * $gateway->initialize(array( + * 'apiKey' => 'Rapid API Key', + * 'password' => 'Rapid API Password', + * 'testMode' => true, // Or false when you are ready for live transactions + * )); + * + * // Create a credit card object + * $card = new CreditCard(array( + * 'firstName' => 'Example', + * 'lastName' => 'User', + * 'number' => '4444333322221111', + * 'expiryMonth' => '01', + * 'expiryYear' => '2020', + * 'billingAddress1' => '1 Scrubby Creek Road', + * 'billingCountry' => 'AU', + * 'billingCity' => 'Scrubby Creek', + * 'billingPostcode' => '4999', + * 'billingState' => 'QLD', + * )); + * + * // Do a create card transaction on the gateway + * $request = $gateway->createCard(array( + * 'card' => $card, + * )); + * + * $response = $request->send(); + * $cardReference = $response->getCardReference(); + * + * + * @link https://eway.io/api-v3/#direct-connection + * @link https://eway.io/api-v3/#token-payments + */ +class RapidDirectCreateCardRequest extends RapidDirectAbstractRequest +{ + public function getData() + { + $data = $this->getBaseData(); + + $data['Payment'] = array(); + $data['Payment']['TotalAmount'] = 0; + + $data['Method'] = 'CreateTokenCustomer'; + + return $data; + } + + protected function getEndpoint() + { + return $this->getEndpointBase().'/DirectPayment.json'; + } +} diff --git a/src/Message/RapidDirectPurchaseRequest.php b/src/Message/RapidDirectPurchaseRequest.php new file mode 100644 index 0000000..9d7dd40 --- /dev/null +++ b/src/Message/RapidDirectPurchaseRequest.php @@ -0,0 +1,103 @@ + + * // Create a gateway for the eWAY Direct Gateway + * $gateway = Omnipay::create('Eway_RapidDirect'); + * + * // Initialise the gateway + * $gateway->initialize(array( + * 'apiKey' => 'Rapid API Key', + * 'password' => 'Rapid API Password', + * 'testMode' => true, // Or false when you are ready for live transactions + * )); + * + * // Create a credit card object + * $card = new CreditCard(array( + * 'firstName' => 'Example', + * 'lastName' => 'User', + * 'number' => '4444333322221111', + * 'expiryMonth' => '01', + * 'expiryYear' => '2020', + * 'cvv' => '321', + * 'billingAddress1' => '1 Scrubby Creek Road', + * 'billingCountry' => 'AU', + * 'billingCity' => 'Scrubby Creek', + * 'billingPostcode' => '4999', + * 'billingState' => 'QLD', + * )); + * + * // Do a purchase transaction on the gateway + * $request = $gateway->purchase(array( + * 'amount' => '10.00', + * 'currency' => 'AUD', + * 'transactionType' => 'Purchase', + * 'card' => $card, + * )); + * + * $response = $request->send(); + * if ($response->isSuccessful()) { + * echo "Purchase transaction was successful!\n"; + * $txn_id = $response->getTransactionReference(); + * echo "Transaction ID = " . $txn_id . "\n"; + * } + * + * + * @link https://eway.io/api-v3/#direct-connection + * @link https://eway.io/api-v3/#client-side-encryption + * @see RapidDirectAbstractRequest + */ +class RapidDirectPurchaseRequest extends RapidDirectAbstractRequest +{ + public function getData() + { + $data = $this->getBaseData(); + + $this->validate('amount', 'transactionType'); + + $data['Payment'] = array(); + $data['Payment']['TotalAmount'] = $this->getAmountInteger(); + $data['Payment']['InvoiceNumber'] = $this->getTransactionId(); + $data['Payment']['InvoiceDescription'] = $this->getDescription(); + $data['Payment']['CurrencyCode'] = $this->getCurrency(); + $data['Payment']['InvoiceReference'] = $this->getInvoiceReference(); + + if ($this->getCardReference()) { + $data['Method'] = 'TokenPayment'; + } else { + $data['Method'] = 'ProcessPayment'; + } + + return $data; + } + + /** + * Get transaction endpoint. + * + * @return string + */ + protected function getEndpoint() + { + return $this->getEndpointBase().'/DirectPayment.json'; + } +} diff --git a/src/Message/RapidDirectUpdateCardRequest.php b/src/Message/RapidDirectUpdateCardRequest.php new file mode 100644 index 0000000..52e9698 --- /dev/null +++ b/src/Message/RapidDirectUpdateCardRequest.php @@ -0,0 +1,83 @@ + + * // Create a gateway for the eWAY Direct Gateway + * $gateway = Omnipay::create('Eway_RapidDirect'); + * + * // Initialise the gateway + * $gateway->initialize(array( + * 'apiKey' => 'Rapid API Key', + * 'password' => 'Rapid API Password', + * 'testMode' => true, // Or false when you are ready for live transactions + * )); + * + * // Create a credit card object + * $card = new CreditCard(array( + * 'firstName' => 'Example', + * 'lastName' => 'User', + * 'number' => '5454545454545454', + * 'expiryMonth' => '01', + * 'expiryYear' => '2022', + * 'billingAddress1' => '2 Scrubby Creek Road', + * 'billingCountry' => 'AU', + * 'billingCity' => 'Scrubby Creek', + * 'billingPostcode' => '4998', + * 'billingState' => 'QLD', + * )); + * + * // Do a create card transaction on the gateway + * $request = $gateway->updateCard(array( + * 'card' => $card, + * 'cardReference' => $cardReference, + * )); + * + * $response = $request->send(); + * $cardReference = $response->getCardReference(); + * + * + * @link https://eway.io/api-v3/#direct-connection + * @link https://eway.io/api-v3/#token-payments + */ +class RapidDirectUpdateCardRequest extends RapidDirectAbstractRequest +{ + public function getData() + { + $data = $this->getBaseData(); + + $this->validate('cardReference'); + + $data['Payment'] = array(); + $data['Payment']['TotalAmount'] = 0; + + $data['Customer']['TokenCustomerID'] = $this->getCardReference(); + + $data['Method'] = 'UpdateTokenCustomer'; + + return $data; + } + + protected function getEndpoint() + { + return $this->getEndpointBase().'/DirectPayment.json'; + } +} diff --git a/src/Message/RapidPurchaseRequest.php b/src/Message/RapidPurchaseRequest.php index 3911ff7..cd34289 100644 --- a/src/Message/RapidPurchaseRequest.php +++ b/src/Message/RapidPurchaseRequest.php @@ -1,4 +1,7 @@ validate('amount', 'returnUrl'); @@ -43,7 +46,7 @@ public function sendData($data) return $this->response = new RapidResponse($this, $httpResponse->json()); } - public function getEndpoint() + protected function getEndpoint() { return $this->getEndpointBase().'/CreateAccessCode.json'; } diff --git a/src/Message/RapidResponse.php b/src/Message/RapidResponse.php index 3e63d48..8412e97 100644 --- a/src/Message/RapidResponse.php +++ b/src/Message/RapidResponse.php @@ -1,11 +1,17 @@ data['Customer']['TokenCustomerID'])) { + return $this->data['Customer']['TokenCustomerID']; + } + + return null; + } } diff --git a/src/Message/RapidSharedPurchaseRequest.php b/src/Message/RapidSharedPurchaseRequest.php index 43e288d..a1e0497 100644 --- a/src/Message/RapidSharedPurchaseRequest.php +++ b/src/Message/RapidSharedPurchaseRequest.php @@ -1,4 +1,7 @@ validate('amount', 'returnUrl'); @@ -53,7 +56,7 @@ public function sendData($data) return $this->response = new RapidSharedResponse($this, $httpResponse->json()); } - public function getEndpoint() + protected function getEndpoint() { return $this->getEndpointBase().'/CreateAccessCodeShared.json'; } diff --git a/src/Message/RapidSharedResponse.php b/src/Message/RapidSharedResponse.php index 3b47cb2..6c04da2 100644 --- a/src/Message/RapidSharedResponse.php +++ b/src/Message/RapidSharedResponse.php @@ -1,4 +1,7 @@ data['Customer']['TokenCustomerID'])) { + return $this->data['Customer']['TokenCustomerID']; + } + } } diff --git a/src/Message/RefundRequest.php b/src/Message/RefundRequest.php index 243a556..72177c6 100644 --- a/src/Message/RefundRequest.php +++ b/src/Message/RefundRequest.php @@ -1,11 +1,38 @@ + * $transaction = $gateway->refund(array( + * 'amount' => '10.00', + * 'currency' => 'AUD', + * )); + * $transaction->setTransactionReference($txn_id); + * $response = $transaction->send(); + * if ($response->isSuccessful()) { + * echo "Refund transaction was successful!\n"; + * $data = $response->getData(); + * echo "Gateway refund response data == " . print_r($data, true) . "\n"; + * } + * + * + * @link https://eway.io/api-v3/#refunds + * @see RapidDirectPurchaseRequest + */ class RefundRequest extends AbstractRequest { public function getData() @@ -36,7 +63,7 @@ public function sendData($data) return $this->response = new RefundResponse($this, $httpResponse->json()); } - public function getEndpoint() + protected function getEndpoint() { return $this->getEndpointBase().'/DirectRefund.json'; } diff --git a/src/RapidDirectGateway.php b/src/RapidDirectGateway.php new file mode 100644 index 0000000..1e04296 --- /dev/null +++ b/src/RapidDirectGateway.php @@ -0,0 +1,202 @@ + + * // Create a gateway for the eWAY Direct Gateway + * $gateway = Omnipay::create('Eway_RapidDirect'); + * + * // Initialise the gateway + * $gateway->initialize(array( + * 'apiKey' => 'Rapid API Key', + * 'password' => 'Rapid API Password', + * 'testMode' => true, // Or false when you are ready for live transactions + * )); + * + * // Create a credit card object + * $card = new CreditCard(array( + * 'firstName' => 'Example', + * 'lastName' => 'User', + * 'number' => '4444333322221111', + * 'expiryMonth' => '01', + * 'expiryYear' => '2020', + * 'cvv' => '321', + * 'billingAddress1' => '1 Scrubby Creek Road', + * 'billingCountry' => 'AU', + * 'billingCity' => 'Scrubby Creek', + * 'billingPostcode' => '4999', + * 'billingState' => 'QLD', + * )); + * + * // Do a purchase transaction on the gateway + * $request = $gateway->purchase(array( + * 'amount' => '10.00', + * 'currency' => 'AUD', + * 'transactionType' => 'Purchase', + * 'card' => $card, + * )); + * + * $response = $request->send(); + * if ($response->isSuccessful()) { + * echo "Purchase transaction was successful!\n"; + * $txn_id = $response->getTransactionReference(); + * echo "Transaction ID = " . $txn_id . "\n"; + * } + * + * + * @link https://eway.io/api-v3/#direct-connection + * @link https://eway.io/api-v3/#authentication + * @link https://go.eway.io/s/article/How-do-I-setup-my-Live-eWAY-API-Key-and-Password + */ +class RapidDirectGateway extends AbstractGateway +{ + public $transparentRedirect = false; + + public function getName() + { + return 'eWAY Rapid Direct'; + } + + public function getDefaultParameters() + { + return array( + 'apiKey' => '', + 'password' => '', + 'testMode' => false, + ); + } + + public function getApiKey() + { + return $this->getParameter('apiKey'); + } + + public function setApiKey($value) + { + return $this->setParameter('apiKey', $value); + } + + public function getPassword() + { + return $this->getParameter('password'); + } + + public function setPassword($value) + { + return $this->setParameter('password', $value); + } + + /** + * Create a purchase request. + * + * Used for initiating a purchase transaction. + * This resource accepts plain card details, an eWAY Token (as a cardReference) + * or encrypted card details from eWAY's client side encryption. + * + * @link https://eway.io/api-v3/#direct-connection + * @param array $parameters + * @return \Omnipay\Eway\Message\RapidDirectPurchaseRequest + */ + public function purchase(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Eway\Message\RapidDirectPurchaseRequest', $parameters); + } + + /** + * Create an authorisation request. + * + * To collect payment at a later time, a pre-auth can be made on a card. + * You can then capture the payment to complete the sale and collect payment. + * + * Only available for Australian eWAY merchants + * + * @link https://eway.io/api-v3/#pre-auth + * @param array $parameters + * @return \Omnipay\Eway\Message\RapidDirectAuthorizeRequest + */ + public function authorize(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Eway\Message\RapidDirectAuthorizeRequest', $parameters); + } + + /** + * Capture an authorisation. + * + * Use this resource to capture and process a previously created authorisation. + * To use this resource requires the transaction reference from the authorisation. + * + * @link https://eway.io/api-v3/#capture-a-payment + * @param array $parameters + * @return \Omnipay\Eway\Message\RapidCaptureRequest + */ + public function capture(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Eway\Message\RapidCaptureRequest', $parameters); + } + + /** + * Refund a Transaction + * + * Use this resource to refund a complete payment. To use this resource requires the transaction + * reference from the purchase or capture. + * + * @link https://eway.io/api-v3/#refunds + * @param array $parameters + * @return \Omnipay\Eway\Message\RefundRequest + */ + public function refund(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Eway\Message\RefundRequest', $parameters); + } + + /** + * Store a credit card as a Token + * + * You can currently securely store card details with eWAY for future + * charging using eWAY's Tokens. + * After storing the card, pass the cardReference instead of the card + * details to complete a payment. + * + * @link https://eway.io/api-v3/#create-token-customer + * @param array $parameters + * @return \Omnipay\Eway\Message\RapidDirectCreateCardRequest + */ + public function createCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Eway\Message\RapidDirectCreateCardRequest', $parameters); + } + + /** + * Update a credit card stored as a Token + * + * You can currently securely store card details with eWAY for future + * charging using eWAY's Tokens. + * This resource requires the cardReference for the card to be updated. + * + * @link https://eway.io/api-v3/#update-token-customer + * @param array $parameters + * @return \Omnipay\Eway\Message\RapidDirectUpdateCardRequest + */ + public function updateCard(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Eway\Message\RapidDirectUpdateCardRequest', $parameters); + } +} diff --git a/src/RapidGateway.php b/src/RapidGateway.php index 0080489..0de8d04 100644 --- a/src/RapidGateway.php +++ b/src/RapidGateway.php @@ -1,11 +1,28 @@ request = new RapidCaptureRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'amount' => '10.00', + 'transactionReference' => '12345678', + )); + } + + public function testGetData() + { + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'amount' => '10.00', + 'currency' => 'AUD', + 'transactionReference' => '12345678', + 'description' => 'new car', + 'transactionId' => '999', + 'invoiceReference' => 'INV-123', + )); + + $data = $this->request->getData(); + + $this->assertSame(1000, $data['Payment']['TotalAmount']); + $this->assertSame('999', $data['Payment']['InvoiceNumber']); + $this->assertSame('new car', $data['Payment']['InvoiceDescription']); + $this->assertSame('INV-123', $data['Payment']['InvoiceReference']); + $this->assertSame('AUD', $data['Payment']['CurrencyCode']); + $this->assertSame('12345678', $data['TransactionId']); + } + + public function testSendSuccess() + { + $this->setMockHttpResponse('RapidCaptureRequestSuccess.txt'); + $response = $this->request->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertSame('11369052', $response->getTransactionReference()); + } + + public function testSendFailure() + { + $this->setMockHttpResponse('RapidCaptureRequestFailure.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertSame('0', $response->getTransactionReference()); + $this->assertSame('Error', $response->getMessage()); + $this->assertSame('D4406', $response->getCode()); + } +} diff --git a/tests/Message/RapidDirectAuthorizeRequestTest.php b/tests/Message/RapidDirectAuthorizeRequestTest.php new file mode 100644 index 0000000..2a008f0 --- /dev/null +++ b/tests/Message/RapidDirectAuthorizeRequestTest.php @@ -0,0 +1,107 @@ +request = new RapidDirectAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'amount' => '10.00', + 'card' => array( + 'firstName' => 'John', + 'lastName' => 'Smith', + 'number' => '4111111111111111', + 'expiryMonth' => '12', + 'expiryYear' => gmdate('Y') + rand(1, 5), + 'cvv' => rand(100, 999), + ), + )); + } + + public function testGetData() + { + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'partnerId' => '1234', + 'transactionType' => 'Purchase', + 'shippingMethod' => 'NextDay', + 'amount' => '10.00', + 'transactionId' => '999', + 'description' => 'new car', + 'currency' => 'AUD', + 'invoiceReference' => 'INV-123', + 'clientIp' => '127.0.0.1', + 'card' => array( + 'firstName' => 'John', + 'lastName' => 'Smith', + 'shippingFirstName' => 'Bob', + 'shippingLastName' => 'Mann', + 'shippingAddress1' => 'Level 1', + 'shippingAddress2' => '123 Test Lane', + 'shippingState' => 'NSW', + 'shippingCountry' => 'AU', + 'number' => '4111111111111111', + 'expiryMonth' => '12', + 'expiryYear' => gmdate('Y') + rand(1, 5), + 'cvv' => rand(100, 999), + 'startMonth' => '01', + 'startYear' => '13', + 'issueNumber' => '1', + ), + )); + + $data = $this->request->getData(); + + $this->assertSame('Authorise', $data['Method']); + $this->assertSame('127.0.0.1', $data['CustomerIP']); + $this->assertSame('1234', $data['PartnerID']); + $this->assertSame('Purchase', $data['TransactionType']); + $this->assertSame('NextDay', $data['ShippingMethod']); + $this->assertSame(1000, $data['Payment']['TotalAmount']); + $this->assertSame('999', $data['Payment']['InvoiceNumber']); + $this->assertSame('new car', $data['Payment']['InvoiceDescription']); + $this->assertSame('INV-123', $data['Payment']['InvoiceReference']); + $this->assertSame('AUD', $data['Payment']['CurrencyCode']); + $this->assertSame('John', $data['Customer']['FirstName']); + $this->assertSame('Smith', $data['Customer']['LastName']); + $this->assertSame('Bob', $data['ShippingAddress']['FirstName']); + $this->assertSame('Mann', $data['ShippingAddress']['LastName']); + $this->assertSame('NSW', $data['ShippingAddress']['State']); + $this->assertSame('au', $data['ShippingAddress']['Country']); + $this->assertSame('4111111111111111', $data['Customer']['CardDetails']['Number']); + $this->assertSame('12', $data['Customer']['CardDetails']['ExpiryMonth']); + $this->assertSame('01', $data['Customer']['CardDetails']['StartMonth']); + $this->assertSame('13', $data['Customer']['CardDetails']['StartYear']); + $this->assertSame('1', $data['Customer']['CardDetails']['IssueNumber']); + } + + public function testSendSuccess() + { + $this->setMockHttpResponse('RapidDirectAuthoriseRequestSuccess.txt'); + $response = $this->request->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertSame('11369246', $response->getTransactionReference()); + $this->assertSame('Transaction Approved', $response->getMessage()); + } + + public function testSendFailure() + { + $this->setMockHttpResponse('RapidDirectAuthoriseRequestFailure.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertNull($response->getTransactionReference()); + $this->assertSame('Invalid TotalAmount', $response->getMessage()); + $this->assertSame('V6011', $response->getCode()); + } +} diff --git a/tests/Message/RapidDirectCreateCardRequestTest.php b/tests/Message/RapidDirectCreateCardRequestTest.php new file mode 100644 index 0000000..6cd8cb5 --- /dev/null +++ b/tests/Message/RapidDirectCreateCardRequestTest.php @@ -0,0 +1,94 @@ +request = new RapidDirectCreateCardRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'card' => array( + 'title' => 'Mr.', + 'firstName' => 'John', + 'lastName' => 'Smith', + 'number' => '4111111111111111', + 'expiryMonth' => '12', + 'expiryYear' => gmdate('Y') + rand(1, 5), + 'cvv' => rand(100, 999), + ), + )); + } + + public function testGetData() + { + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'partnerId' => '1234', + 'shippingMethod' => 'NextDay', + 'transactionId' => '999', + 'description' => 'new car', + 'currency' => 'AUD', + 'invoiceReference' => 'INV-123', + 'clientIp' => '127.0.0.1', + 'card' => array( + 'title' => 'Mr.', + 'firstName' => 'John', + 'lastName' => 'Smith', + 'shippingFirstName' => 'Bob', + 'shippingLastName' => 'Mann', + 'shippingAddress1' => 'Level 1', + 'shippingAddress2' => '123 Test Lane', + 'shippingState' => 'NSW', + 'shippingCountry' => 'AU', + 'number' => '4111111111111111', + 'expiryMonth' => '12', + 'expiryYear' => gmdate('Y') + rand(1, 5), + 'cvv' => rand(100, 999), + ), + )); + + $data = $this->request->getData(); + + $this->assertSame('127.0.0.1', $data['CustomerIP']); + $this->assertSame('1234', $data['PartnerID']); + $this->assertSame('NextDay', $data['ShippingMethod']); + $this->assertSame(0, $data['Payment']['TotalAmount']); + $this->assertSame('Mr.', $data['Customer']['Title']); + $this->assertSame('John', $data['Customer']['FirstName']); + $this->assertSame('Smith', $data['Customer']['LastName']); + $this->assertSame('Bob', $data['ShippingAddress']['FirstName']); + $this->assertSame('Mann', $data['ShippingAddress']['LastName']); + $this->assertSame('NSW', $data['ShippingAddress']['State']); + $this->assertSame('au', $data['ShippingAddress']['Country']); + $this->assertSame('4111111111111111', $data['Customer']['CardDetails']['Number']); + $this->assertSame('12', $data['Customer']['CardDetails']['ExpiryMonth']); + } + + public function testSendSuccess() + { + $this->setMockHttpResponse('RapidDirectCreateCardRequestSuccess.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertSame(916260137222, $response->getCardReference()); + $this->assertSame('Transaction Approved', $response->getMessage()); + } + + public function testSendFailure() + { + $this->setMockHttpResponse('RapidDirectCreateCardRequestFailure.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertNull($response->getCardReference()); + $this->assertSame('Customer First Name Required', $response->getMessage()); + $this->assertSame('V6042', $response->getCode()); + } +} diff --git a/tests/Message/RapidDirectPurchaseRequestTest.php b/tests/Message/RapidDirectPurchaseRequestTest.php new file mode 100644 index 0000000..772f242 --- /dev/null +++ b/tests/Message/RapidDirectPurchaseRequestTest.php @@ -0,0 +1,216 @@ +request = new RapidDirectPurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'amount' => '10.00', + 'transactionType' => 'Purchase', + 'card' => array( + 'firstName' => 'John', + 'lastName' => 'Smith', + 'number' => '4111111111111111', + 'expiryMonth' => '12', + 'expiryYear' => gmdate('Y') + rand(1, 5), + 'cvv' => rand(100, 999), + ), + )); + } + + public function testGetData() + { + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'partnerId' => '1234', + 'transactionType' => 'Purchase', + 'shippingMethod' => 'NextDay', + 'amount' => '10.00', + 'transactionId' => '999', + 'description' => 'new car', + 'currency' => 'AUD', + 'invoiceReference' => 'INV-123', + 'clientIp' => '127.0.0.1', + 'card' => array( + 'firstName' => 'John', + 'lastName' => 'Smith', + 'shippingFirstName' => 'Bob', + 'shippingLastName' => 'Mann', + 'shippingAddress1' => 'Level 1', + 'shippingAddress2' => '123 Test Lane', + 'shippingState' => 'NSW', + 'shippingCountry' => 'AU', + 'number' => '4111111111111111', + 'expiryMonth' => '12', + 'expiryYear' => gmdate('Y') + rand(1, 5), + 'cvv' => rand(100, 999), + 'startMonth' => '01', + 'startYear' => '13', + 'issueNumber' => '1', + ), + )); + + $data = $this->request->getData(); + + $this->assertSame('ProcessPayment', $data['Method']); + $this->assertSame('127.0.0.1', $data['CustomerIP']); + $this->assertSame('1234', $data['PartnerID']); + $this->assertSame('Purchase', $data['TransactionType']); + $this->assertSame('NextDay', $data['ShippingMethod']); + $this->assertSame(1000, $data['Payment']['TotalAmount']); + $this->assertSame('999', $data['Payment']['InvoiceNumber']); + $this->assertSame('new car', $data['Payment']['InvoiceDescription']); + $this->assertSame('INV-123', $data['Payment']['InvoiceReference']); + $this->assertSame('AUD', $data['Payment']['CurrencyCode']); + $this->assertSame('John', $data['Customer']['FirstName']); + $this->assertSame('Smith', $data['Customer']['LastName']); + $this->assertSame('Bob', $data['ShippingAddress']['FirstName']); + $this->assertSame('Mann', $data['ShippingAddress']['LastName']); + $this->assertSame('NSW', $data['ShippingAddress']['State']); + $this->assertSame('au', $data['ShippingAddress']['Country']); + $this->assertSame('4111111111111111', $data['Customer']['CardDetails']['Number']); + $this->assertSame('12', $data['Customer']['CardDetails']['ExpiryMonth']); + $this->assertSame('01', $data['Customer']['CardDetails']['StartMonth']); + $this->assertSame('13', $data['Customer']['CardDetails']['StartYear']); + $this->assertSame('1', $data['Customer']['CardDetails']['IssueNumber']); + } + + public function testGetDataWithToken() + { + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'transactionType' => 'MOTO', + 'amount' => '10.00', + 'transactionId' => '999', + 'description' => 'new car', + 'currency' => 'AUD', + 'invoiceReference' => 'INV-123', + 'cardReference' => '87654321', + )); + + $data = $this->request->getData(); + + $this->assertSame('87654321', $data['Customer']['TokenCustomerID']); + $this->assertSame('TokenPayment', $data['Method']); + $this->assertSame('MOTO', $data['TransactionType']); + } + + public function testGetDataWithEncryption() + { + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'partnerId' => '1234', + 'transactionType' => 'Purchase', + 'shippingMethod' => 'NextDay', + 'amount' => '10.00', + 'transactionId' => '999', + 'description' => 'new car', + 'currency' => 'AUD', + 'invoiceReference' => 'INV-123', + 'clientIp' => '127.0.0.1', + 'encryptedCardNumber' => 'eCrypted:YVe4GMLMSxF5m1nixtBvVlmaLDgjI+ZYM5GHuX1XjlbRTnhe/khA2csWblJDqaQE9S4BV+y4Xnf61GmRDNC9yLBVduGFuigHJ8rk360m580fYOiHy+OaZpgpRvHPw==', + 'encryptedCardCvv' => 'eCrypted:ZvEfRd1DHwJ7dYV59DZqoaCFujvK+26VKS9Tp3uGp5kVki8CHpy67WUaFqqDzjZ8C6e3+TUXtW6/rrXGYYIXMfbph4Uw+XyLja3MJzOGniULWJA5zt90wxRwpZeYGDNQ==', + 'card' => array( + 'firstName' => 'John', + 'lastName' => 'Smith', + 'shippingFirstName' => 'Bob', + 'shippingLastName' => 'Mann', + 'shippingAddress1' => 'Level 1', + 'shippingAddress2' => '123 Test Lane', + 'shippingState' => 'NSW', + 'shippingCountry' => 'AU', + 'expiryMonth' => '12', + 'expiryYear' => gmdate('Y') + rand(1, 5), + 'startMonth' => '01', + 'startYear' => '13', + 'issueNumber' => '1', + ), + )); + + $data = $this->request->getData(); + + $this->assertSame('ProcessPayment', $data['Method']); + $this->assertSame('127.0.0.1', $data['CustomerIP']); + $this->assertSame('1234', $data['PartnerID']); + $this->assertSame('Purchase', $data['TransactionType']); + $this->assertSame('au', $data['ShippingAddress']['Country']); + $this->assertSame('eCrypted:YVe4GMLMSxF5m1nixtBvVlmaLDgjI+ZYM5GHuX1XjlbRTnhe/khA2csWblJDqaQE9S4BV+y4Xnf61GmRDNC9yLBVduGFuigHJ8rk360m580fYOiHy+OaZpgpRvHPw==', $data['Customer']['CardDetails']['Number']); + $this->assertSame('eCrypted:ZvEfRd1DHwJ7dYV59DZqoaCFujvK+26VKS9Tp3uGp5kVki8CHpy67WUaFqqDzjZ8C6e3+TUXtW6/rrXGYYIXMfbph4Uw+XyLja3MJzOGniULWJA5zt90wxRwpZeYGDNQ==', $data['Customer']['CardDetails']['CVN']); + $this->assertSame('01', $data['Customer']['CardDetails']['StartMonth']); + $this->assertSame('13', $data['Customer']['CardDetails']['StartYear']); + $this->assertSame('1', $data['Customer']['CardDetails']['IssueNumber']); + } + + + public function testGetDataWithItems() + { + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'amount' => '10.00', + 'transactionType' => 'Purchase', + 'transactionId' => '999', + 'description' => 'new car', + 'currency' => 'AUD', + 'clientIp' => '127.0.0.1', + 'card' => array( + 'firstName' => 'John', + 'lastName' => 'Smith', + 'number' => '4111111111111111', + 'expiryMonth' => '12', + 'expiryYear' => gmdate('Y') + rand(1, 5), + 'cvv' => rand(100, 999), + ), + )); + + $this->request->setItems(array( + array('name' => 'Floppy Disk', 'description' => 'MS-DOS', 'quantity' => 2, 'price' => 10), + array('name' => 'CD-ROM', 'description' => 'Windows 95', 'quantity' => 1, 'price' => 40), + )); + + $data = $this->request->getData(); + + $this->assertSame('Floppy Disk', $data['Items'][0]['SKU']); + $this->assertSame('MS-DOS', $data['Items'][0]['Description']); + $this->assertSame('2', $data['Items'][0]['Quantity']); + $this->assertSame('1000', $data['Items'][0]['UnitCost']); + + $this->assertSame('CD-ROM', $data['Items'][1]['SKU']); + $this->assertSame('Windows 95', $data['Items'][1]['Description']); + $this->assertSame('1', $data['Items'][1]['Quantity']); + $this->assertSame('4000', $data['Items'][1]['UnitCost']); + } + + public function testSendSuccess() + { + $this->setMockHttpResponse('RapidDirectPurchaseRequestSuccess.txt'); + $response = $this->request->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertSame('11355498', $response->getTransactionReference()); + $this->assertSame('Transaction Approved', $response->getMessage()); + } + + public function testSendFailure() + { + $this->setMockHttpResponse('RapidDirectPurchaseRequestFailure.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertNull($response->getTransactionReference()); + $this->assertSame('Invalid TotalAmount', $response->getMessage()); + $this->assertSame('V6011', $response->getCode()); + } +} diff --git a/tests/Message/RapidDirectUpdateCardRequestTest.php b/tests/Message/RapidDirectUpdateCardRequestTest.php new file mode 100644 index 0000000..ba18bd3 --- /dev/null +++ b/tests/Message/RapidDirectUpdateCardRequestTest.php @@ -0,0 +1,84 @@ +request = new RapidDirectUpdateCardRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'cardReference' => '987654321', + 'card' => array( + 'title' => 'Mr.', + 'firstName' => 'John', + 'lastName' => 'Smith', + 'number' => '4111111111111111', + 'expiryMonth' => '12', + 'expiryYear' => gmdate('Y') + rand(1, 5), + 'cvv' => rand(100, 999), + ), + )); + } + + public function testGetData() + { + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'cardReference' => '987654321', + 'card' => array( + 'title' => 'Mr.', + 'firstName' => 'John', + 'lastName' => 'Smith', + 'billingAddress1' => 'Level 1', + 'billingAddress2' => '123 Test Lane', + 'billingState' => 'NSW', + 'billingCountry' => 'AU', + 'number' => '4111111111111111', + 'expiryMonth' => '12', + 'expiryYear' => gmdate('Y') + rand(1, 5), + 'cvv' => rand(100, 999), + ), + )); + + $data = $this->request->getData(); + + $this->assertSame('UpdateTokenCustomer', $data['Method']); + $this->assertSame('987654321', $data['Customer']['TokenCustomerID']); + $this->assertSame(0, $data['Payment']['TotalAmount']); + $this->assertSame('Mr.', $data['Customer']['Title']); + $this->assertSame('John', $data['Customer']['FirstName']); + $this->assertSame('Smith', $data['Customer']['LastName']); + $this->assertSame('NSW', $data['Customer']['State']); + $this->assertSame('au', $data['Customer']['Country']); + $this->assertSame('4111111111111111', $data['Customer']['CardDetails']['Number']); + $this->assertSame('12', $data['Customer']['CardDetails']['ExpiryMonth']); + } + + public function testSendSuccess() + { + $this->setMockHttpResponse('RapidDirectUpdateCardRequestSuccess.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertSame(917758625852, $response->getCardReference()); + $this->assertSame('Transaction Approved', $response->getMessage()); + } + + public function testSendFailure() + { + $this->setMockHttpResponse('RapidDirectUpdateCardRequestFailure.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertSame(917758625852, $response->getCardReference()); + $this->assertSame('Invalid TotalAmount', $response->getMessage()); + $this->assertSame('V6011', $response->getCode()); + } +} diff --git a/tests/Message/RapidSharedPurchaseRequestTest.php b/tests/Message/RapidSharedPurchaseRequestTest.php index 044c3c0..40fddeb 100644 --- a/tests/Message/RapidSharedPurchaseRequestTest.php +++ b/tests/Message/RapidSharedPurchaseRequestTest.php @@ -110,6 +110,7 @@ public function testSendSuccess() $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->getCardReference()); $this->assertNull($response->getMessage()); $this->assertNull($response->getCode()); } @@ -123,6 +124,7 @@ public function testSendFailure() $this->assertFalse($response->isRedirect()); $this->assertNull($response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); + $this->assertNull($response->getCardReference()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Invalid TotalAmount', $response->getMessage()); $this->assertSame('V6011', $response->getCode()); diff --git a/tests/Mock/RapidCaptureRequestFailure.txt b/tests/Mock/RapidCaptureRequestFailure.txt new file mode 100644 index 0000000..7d9b002 --- /dev/null +++ b/tests/Mock/RapidCaptureRequestFailure.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/CapturePayment +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/CapturePayment +X-ID: AM-143 +X-Powered-By: eWAY +Content-Length: 108 +Connection: keep-alive + +{"ResponseCode":"06","ResponseMessage":"D4406","TransactionID":0,"TransactionStatus":false,"Errors":"D4406"} diff --git a/tests/Mock/RapidCaptureRequestSuccess.txt b/tests/Mock/RapidCaptureRequestSuccess.txt new file mode 100644 index 0000000..112a0ea --- /dev/null +++ b/tests/Mock/RapidCaptureRequestSuccess.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/CapturePayment +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/CapturePayment +X-ID: AM-143 +X-Powered-By: eWAY +Content-Length: 116 +Connection: keep-alive + +{"ResponseCode":"902226","ResponseMessage":"902226","TransactionID":11369052,"TransactionStatus":true,"Errors":null} diff --git a/tests/Mock/RapidDirectAuthoriseRequestFailure.txt b/tests/Mock/RapidDirectAuthoriseRequestFailure.txt new file mode 100644 index 0000000..5362a1c --- /dev/null +++ b/tests/Mock/RapidDirectAuthoriseRequestFailure.txt @@ -0,0 +1,17 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Fri, 06 Mar 2015 04:46:48 GMT +p3p: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT" +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/Transaction +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/Transaction +X-ID: AM-143 +X-Powered-By: eWAY +Content-Length: 782 +Connection: keep-alive + +{"AuthorisationCode":null,"ResponseCode":null,"ResponseMessage":null,"TransactionID":null,"TransactionStatus":null,"TransactionType":"Purchase","BeagleScore":null,"Verification":null,"Customer":{"CardDetails":{"Number":"444433XXXXXX1111","Name":"John Smith","ExpiryMonth":"12","ExpiryYear":"25","StartMonth":null,"StartYear":null,"IssueNumber":null},"TokenCustomerID":null,"Reference":null,"Title":"Mr.","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},"Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},"Errors":"V6011"} \ No newline at end of file diff --git a/tests/Mock/RapidDirectAuthoriseRequestSuccess.txt b/tests/Mock/RapidDirectAuthoriseRequestSuccess.txt new file mode 100644 index 0000000..2efc456 --- /dev/null +++ b/tests/Mock/RapidDirectAuthoriseRequestSuccess.txt @@ -0,0 +1,17 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Fri, 06 Mar 2015 04:20:12 GMT +p3p: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT" +Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D00F53B19AA8D0E66C1AD34691F2170CBA3CC4FEE8666E2FB3C85D3B0E238FA2E93B31AAC1C98DFF4D0639139359FE706;PATH=/;MAX-AGE=86400 +X-EWAY-VIA: api-au.sandbox.ewaypayments.com/ +X-EWAY-VIA-FROM: http://api-au.sandbox.ewaypayments.com/DirectPayment.json +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/DirectPayment.json +X-ID: AM-131 +X-Powered-By: eWAY +Content-Length: 798 +Connection: keep-alive + +{"AuthorisationCode":"595093","ResponseCode":"00","ResponseMessage":"A2000","TransactionID":11369246,"TransactionStatus":true,"TransactionType":"Purchase","BeagleScore":0,"Verification":{"CVN":0,"Address":0,"Email":0,"Mobile":0,"Phone":0},"Customer":{"CardDetails":{"Number":"444433XXXXXX1111","Name":"John Smith","ExpiryMonth":"12","ExpiryYear":"25","StartMonth":null,"StartYear":null,"IssueNumber":null},"TokenCustomerID":null,"Reference":"","Title":"Mr.","FirstName":"","LastName":"","CompanyName":"","JobDescription":"","Street1":"","Street2":"","City":"","State":"","PostalCode":"","Country":"","Email":"","Phone":"","Mobile":"","Comments":"","Fax":"","Url":""},"Payment":{"TotalAmount":1000,"InvoiceNumber":"","InvoiceDescription":"","InvoiceReference":"","CurrencyCode":"AUD"},"Errors":null} diff --git a/tests/Mock/RapidDirectCreateCardRequestFailure.txt b/tests/Mock/RapidDirectCreateCardRequestFailure.txt new file mode 100644 index 0000000..fe623c0 --- /dev/null +++ b/tests/Mock/RapidDirectCreateCardRequestFailure.txt @@ -0,0 +1,17 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Fri, 06 Mar 2015 04:20:12 GMT +p3p: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT" +Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D00F53B19AA8D0E66C1AD34691F2170CBA3CC4FEE8666E2FB3C85D3B0E238FA2E93B31AAC1C98DFF4D0639139359FE706;PATH=/;MAX-AGE=86400 +X-EWAY-VIA: api-au.sandbox.ewaypayments.com/ +X-EWAY-VIA-FROM: http://api-au.sandbox.ewaypayments.com/DirectPayment.json +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/DirectPayment.json +X-ID: AM-131 +X-Powered-By: eWAY +Content-Length: 780 +Connection: keep-alive + +{"AuthorisationCode":null,"ResponseCode":null,"ResponseMessage":null,"TransactionID":null,"TransactionStatus":null,"TransactionType":"Purchase","BeagleScore":null,"Verification":null,"Customer":{"CardDetails":{"Number":"444433XXXXXX1111","Name":"Smith","ExpiryMonth":"12","ExpiryYear":"25","StartMonth":null,"StartYear":null,"IssueNumber":null},"TokenCustomerID":null,"Reference":null,"Title":"Mr.","FirstName":null,"LastName":"Smith","CompanyName":null,"JobDescription":null,"Street1":null,"Street2":null,"City":null,"State":null,"PostalCode":null,"Country":"au","Email":null,"Phone":null,"Mobile":null,"Comments":null,"Fax":null,"Url":null},"Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},"Errors":"V6042"} diff --git a/tests/Mock/RapidDirectCreateCardRequestSuccess.txt b/tests/Mock/RapidDirectCreateCardRequestSuccess.txt new file mode 100644 index 0000000..8aa9367 --- /dev/null +++ b/tests/Mock/RapidDirectCreateCardRequestSuccess.txt @@ -0,0 +1,17 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Fri, 06 Mar 2015 04:20:12 GMT +p3p: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT" +Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D00F53B19AA8D0E66C1AD34691F2170CBA3CC4FEE8666E2FB3C85D3B0E238FA2E93B31AAC1C98DFF4D0639139359FE706;PATH=/;MAX-AGE=86400 +X-EWAY-VIA: api-au.sandbox.ewaypayments.com/ +X-EWAY-VIA-FROM: http://api-au.sandbox.ewaypayments.com/DirectPayment.json +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/DirectPayment.json +X-ID: AM-131 +X-Powered-By: eWAY +Content-Length: 810 +Connection: keep-alive + +{"AuthorisationCode":null,"ResponseCode":"00","ResponseMessage":"A2000","TransactionID":null,"TransactionStatus":false,"TransactionType":"Purchase","BeagleScore":null,"Verification":{"CVN":0,"Address":0,"Email":0,"Mobile":0,"Phone":0},"Customer":{"CardDetails":{"Number":"444433XXXXXX1111","Name":"John Smith","ExpiryMonth":"12","ExpiryYear":"25","StartMonth":null,"StartYear":null,"IssueNumber":null},"TokenCustomerID":916260137222,"Reference":"","Title":"Mr.","FirstName":"John","LastName":"Smith","CompanyName":"","JobDescription":"","Street1":"","Street2":"","City":"","State":"","PostalCode":"","Country":"au","Email":"","Phone":"","Mobile":"","Comments":"","Fax":"","Url":""},"Payment":{"TotalAmount":0,"InvoiceNumber":"","InvoiceDescription":"","InvoiceReference":"","CurrencyCode":"AUD"},"Errors":null} diff --git a/tests/Mock/RapidDirectPurchaseRequestFailure.txt b/tests/Mock/RapidDirectPurchaseRequestFailure.txt new file mode 100644 index 0000000..5362a1c --- /dev/null +++ b/tests/Mock/RapidDirectPurchaseRequestFailure.txt @@ -0,0 +1,17 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Fri, 06 Mar 2015 04:46:48 GMT +p3p: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT" +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/Transaction +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/Transaction +X-ID: AM-143 +X-Powered-By: eWAY +Content-Length: 782 +Connection: keep-alive + +{"AuthorisationCode":null,"ResponseCode":null,"ResponseMessage":null,"TransactionID":null,"TransactionStatus":null,"TransactionType":"Purchase","BeagleScore":null,"Verification":null,"Customer":{"CardDetails":{"Number":"444433XXXXXX1111","Name":"John Smith","ExpiryMonth":"12","ExpiryYear":"25","StartMonth":null,"StartYear":null,"IssueNumber":null},"TokenCustomerID":null,"Reference":null,"Title":"Mr.","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},"Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},"Errors":"V6011"} \ No newline at end of file diff --git a/tests/Mock/RapidDirectPurchaseRequestSuccess.txt b/tests/Mock/RapidDirectPurchaseRequestSuccess.txt new file mode 100644 index 0000000..3318d69 --- /dev/null +++ b/tests/Mock/RapidDirectPurchaseRequestSuccess.txt @@ -0,0 +1,17 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Fri, 06 Mar 2015 04:20:12 GMT +p3p: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT" +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/Transaction +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/Transaction +X-ID: AM-131 +X-Powered-By: eWAY +Content-Length: 798 +Connection: keep-alive + +{"AuthorisationCode":"868678","ResponseCode":"00","ResponseMessage":"A2000","TransactionID":11355498,"TransactionStatus":true,"TransactionType":"Purchase","BeagleScore":0,"Verification":{"CVN":0,"Address":0,"Email":0,"Mobile":0,"Phone":0},"Customer":{"CardDetails":{"Number":"444433XXXXXX1111","Name":"John Smith","ExpiryMonth":"12","ExpiryYear":"25","StartMonth":null,"StartYear":null,"IssueNumber":null},"TokenCustomerID":null,"Reference":"","Title":"Mr.","FirstName":"","LastName":"","CompanyName":"","JobDescription":"","Street1":"","Street2":"","City":"","State":"","PostalCode":"","Country":"","Email":"","Phone":"","Mobile":"","Comments":"","Fax":"","Url":""},"Payment":{"TotalAmount":1000,"InvoiceNumber":"","InvoiceDescription":"","InvoiceReference":"","CurrencyCode":"AUD"},"Errors":null} diff --git a/tests/Mock/RapidDirectUpdateCardRequestFailure.txt b/tests/Mock/RapidDirectUpdateCardRequestFailure.txt new file mode 100644 index 0000000..f98d707 --- /dev/null +++ b/tests/Mock/RapidDirectUpdateCardRequestFailure.txt @@ -0,0 +1,17 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Fri, 06 Mar 2015 04:20:12 GMT +p3p: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT" +Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D00F53B19AA8D0E66C1AD34691F2170CBA3CC4FEE8666E2FB3C85D3B0E238FA2E93B31AAC1C98DFF4D0639139359FE706;PATH=/;MAX-AGE=86400 +X-EWAY-VIA: api-au.sandbox.ewaypayments.com/ +X-EWAY-VIA-FROM: http://api-au.sandbox.ewaypayments.com/DirectPayment.json +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/DirectPayment.json +X-ID: AM-131 +X-Powered-By: eWAY +Content-Length: 810 +Connection: keep-alive + +{"AuthorisationCode":null,"ResponseCode":null,"ResponseMessage":null,"TransactionID":null,"TransactionStatus":null,"TransactionType":"Purchase","BeagleScore":null,"Verification":null,"Customer":{"CardDetails":{"Number":"444433XXXXXX1111","Name":"John Smith","ExpiryMonth":"12","ExpiryYear":"25","StartMonth":null,"StartYear":null,"IssueNumber":null},"TokenCustomerID":917758625852,"Reference":null,"Title":"Mr.","FirstName":"Jane","LastName":"Smith","CompanyName":null,"JobDescription":null,"Street1":null,"Street2":null,"City":null,"State":null,"PostalCode":null,"Country":"au","Email":null,"Phone":null,"Mobile":null,"Comments":null,"Fax":null,"Url":null},"Payment":{"TotalAmount":1000,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},"Errors":"V6011"} diff --git a/tests/Mock/RapidDirectUpdateCardRequestSuccess.txt b/tests/Mock/RapidDirectUpdateCardRequestSuccess.txt new file mode 100644 index 0000000..2fd6112 --- /dev/null +++ b/tests/Mock/RapidDirectUpdateCardRequestSuccess.txt @@ -0,0 +1,17 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Fri, 06 Mar 2015 04:20:12 GMT +p3p: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT" +Set-Cookie: AWSELB=8361C96B088FEBBC7D3ABDFE8BA0FF6501B9705E7D00F53B19AA8D0E66C1AD34691F2170CBA3CC4FEE8666E2FB3C85D3B0E238FA2E93B31AAC1C98DFF4D0639139359FE706;PATH=/;MAX-AGE=86400 +X-EWAY-VIA: api-au.sandbox.ewaypayments.com/ +X-EWAY-VIA-FROM: http://api-au.sandbox.ewaypayments.com/DirectPayment.json +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/DirectPayment.json +X-ID: AM-131 +X-Powered-By: eWAY +Content-Length: 810 +Connection: keep-alive + +{"AuthorisationCode":null,"ResponseCode":"00","ResponseMessage":"A2000","TransactionID":null,"TransactionStatus":false,"TransactionType":"Purchase","BeagleScore":null,"Verification":{"CVN":0,"Address":0,"Email":0,"Mobile":0,"Phone":0},"Customer":{"CardDetails":{"Number":"444433XXXXXX1111","Name":"John Smith","ExpiryMonth":"12","ExpiryYear":"25","StartMonth":null,"StartYear":null,"IssueNumber":null},"TokenCustomerID":917758625852,"Reference":"","Title":"Mr.","FirstName":"Jane","LastName":"Smith","CompanyName":"","JobDescription":"","Street1":"","Street2":"","City":"","State":"","PostalCode":"","Country":"au","Email":"","Phone":"","Mobile":"","Comments":"","Fax":"","Url":""},"Payment":{"TotalAmount":0,"InvoiceNumber":"","InvoiceDescription":"","InvoiceReference":"","CurrencyCode":"AUD"},"Errors":null} diff --git a/tests/RapidDirectGatewayTest.php b/tests/RapidDirectGatewayTest.php new file mode 100644 index 0000000..2363b25 --- /dev/null +++ b/tests/RapidDirectGatewayTest.php @@ -0,0 +1,47 @@ +gateway = new RapidDirectGateway($this->getHttpClient(), $this->getHttpRequest()); + } + + public function testPurchase() + { + $request = $this->gateway->purchase(array('amount' => '10.00')); + + $this->assertInstanceOf('Omnipay\Eway\Message\RapidDirectPurchaseRequest', $request); + $this->assertSame('10.00', $request->getAmount()); + } + + public function testAuthorise() + { + $request = $this->gateway->authorize(array('amount' => '10.00')); + + $this->assertInstanceOf('Omnipay\Eway\Message\RapidDirectAuthorizeRequest', $request); + $this->assertSame('10.00', $request->getAmount()); + } + + public function testCapture() + { + $request = $this->gateway->capture(array('amount' => '10.00', 'transactionId' => '87654321')); + + $this->assertInstanceOf('Omnipay\Eway\Message\RapidCaptureRequest', $request); + $this->assertSame('10.00', $request->getAmount()); + } + + public function testCreateCard() + { + $request = $this->gateway->createCard(array('amount' => '10.00')); + + $this->assertInstanceOf('Omnipay\Eway\Message\RapidDirectCreateCardRequest', $request); + $this->assertSame('10.00', $request->getAmount()); + } +}