From f46bcbb267de5d2c39b5c191b04a37fe351b518f Mon Sep 17 00:00:00 2001 From: John C Date: Sat, 22 Nov 2014 23:28:15 +0000 Subject: [PATCH 1/2] Added eWAY Rapid Responsive Shared Page gateway and eWAY Rapid Refunds (and tests) --- README.md | 1 + src/Message/AbstractRequest.php | 37 +++ src/Message/AbstractResponse.php | 225 ++++++++++++++++++ src/Message/RapidPurchaseRequest.php | 36 +-- src/Message/RapidResponse.php | 174 -------------- src/Message/RapidSharedPurchaseRequest.php | 140 +++++++++++ src/Message/RapidSharedResponse.php | 31 +++ src/Message/RefundRequest.php | 43 ++++ src/Message/RefundResponse.php | 13 + src/RapidGateway.php | 5 + src/RapidSharedGateway.php | 60 +++++ tests/Message/AbstractResponseTest.php | 42 ++++ tests/Message/RapidPurchaseRequestTest.php | 2 +- .../RapidSharedPurchaseRequestTest.php | 179 ++++++++++++++ tests/Message/RefundRequestTest.php | 118 +++++++++ tests/Mock/RapidRefundRequestFailure.txt | 16 ++ tests/Mock/RapidRefundRequestSuccess.txt | 16 ++ .../RapidSharedPurchaseRequestFailure.txt | 17 ++ .../RapidSharedPurchaseRequestSuccess.txt | 16 ++ tests/RapidSharedGatewayTest.php | 31 +++ 20 files changed, 994 insertions(+), 208 deletions(-) create mode 100644 src/Message/AbstractResponse.php create mode 100644 src/Message/RapidSharedPurchaseRequest.php create mode 100644 src/Message/RapidSharedResponse.php create mode 100644 src/Message/RefundRequest.php create mode 100644 src/Message/RefundResponse.php create mode 100644 src/RapidSharedGateway.php create mode 100644 tests/Message/AbstractResponseTest.php create mode 100644 tests/Message/RapidSharedPurchaseRequestTest.php create mode 100644 tests/Message/RefundRequestTest.php create mode 100644 tests/Mock/RapidRefundRequestFailure.txt create mode 100644 tests/Mock/RapidRefundRequestSuccess.txt create mode 100644 tests/Mock/RapidSharedPurchaseRequestFailure.txt create mode 100644 tests/Mock/RapidSharedPurchaseRequestSuccess.txt create mode 100644 tests/RapidSharedGatewayTest.php diff --git a/README.md b/README.md index c8958c7..4d4d90b 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ And run composer to update your dependencies: The following gateways are provided by this package: * Eway_Rapid +* Eway_RapidShared For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) repository. diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index bec3b79..171010b 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -74,6 +74,43 @@ public function setInvoiceReference($value) { return $this->setParameter('invoiceReference', $value); } + + protected function getBaseData() + { + $data = array(); + $data['DeviceID'] = 'https://github.com/adrianmacneil/omnipay'; + $data['CustomerIP'] = $this->getClientIp(); + $data['PartnerID'] = $this->getPartnerId(); + $data['ShippingMethod'] = $this->getShippingMethod(); + + $data['Customer'] = array(); + $card = $this->getCard(); + if ($card) { + $data['Customer']['FirstName'] = $card->getFirstName(); + $data['Customer']['LastName'] = $card->getLastName(); + $data['Customer']['CompanyName'] = $card->getCompany(); + $data['Customer']['Street1'] = $card->getAddress1(); + $data['Customer']['Street2'] = $card->getAddress2(); + $data['Customer']['City'] = $card->getCity(); + $data['Customer']['State'] = $card->getState(); + $data['Customer']['PostalCode'] = $card->getPostCode(); + $data['Customer']['Country'] = strtolower($card->getCountry()); + $data['Customer']['Email'] = $card->getEmail(); + $data['Customer']['Phone'] = $card->getPhone(); + + $data['ShippingAddress']['FirstName'] = $card->getShippingFirstName(); + $data['ShippingAddress']['LastName'] = $card->getShippingLastName(); + $data['ShippingAddress']['Street1'] = $card->getShippingAddress1(); + $data['ShippingAddress']['Street2'] = $card->getShippingAddress2(); + $data['ShippingAddress']['City'] = $card->getShippingCity(); + $data['ShippingAddress']['State'] = $card->getShippingState(); + $data['ShippingAddress']['Country'] = strtolower($card->getShippingCountry()); + $data['ShippingAddress']['PostalCode'] = $card->getShippingPostcode(); + $data['ShippingAddress']['Phone'] = $card->getShippingPhone(); + } + + return $data; + } protected function getItemData() { diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php new file mode 100644 index 0000000..b8094b4 --- /dev/null +++ b/src/Message/AbstractResponse.php @@ -0,0 +1,225 @@ + 'Transaction Approved', + 'A2008' => 'Honour With Identification', + 'A2010' => 'Approved For Partial Amount', + 'A2011' => 'Approved, VIP', + 'A2016' => 'Approved, Update Track 3', + 'D4401' => 'Refer to Issuer', + 'D4402' => 'Refer to Issuer, special', + 'D4403' => 'No Merchant', + 'D4404' => 'Pick Up Card', + 'D4405' => 'Do Not Honour', + 'D4406' => 'Error', + 'D4407' => 'Pick Up Card, Special', + 'D4409' => 'Request In Progress', + 'D4412' => 'Invalid Transaction', + 'D4413' => 'Invalid Amount', + 'D4414' => 'Invalid Card Number', + 'D4415' => 'No Issuer', + 'D4419' => 'Re-enter Last Transaction', + 'D4421' => 'No Action Taken', + 'D4422' => 'Suspected Malfunction', + 'D4423' => 'Unacceptable Transaction Fee', + 'D4425' => 'Unable to Locate Record On File', + 'D4430' => 'Format Error', + 'D4431' => 'Bank Not Supported By Switch', + 'D4433' => 'Expired Card, Capture', + 'D4434' => 'Suspected Fraud, Retain Card', + 'D4435' => 'Card Acceptor, Contact Acquirer, Retain Card', + 'D4436' => 'Restricted Card, Retain Card', + 'D4437' => 'Contact Acquirer Security Department, Retain Card', + 'D4438' => 'PIN Tries Exceeded, Capture', + 'D4439' => 'No Credit Account', + 'D4440' => 'Function Not Supported', + 'D4441' => 'Lost Card', + 'D4442' => 'No Universal Account', + 'D4443' => 'Stolen Card', + 'D4444' => 'No Investment Account', + 'D4451' => 'Insufficient Funds', + 'D4452' => 'No Cheque Account', + 'D4453' => 'No Savings Account', + 'D4454' => 'Expired Card', + 'D4455' => 'Incorrect PIN', + 'D4456' => 'No Card Record', + 'D4457' => 'Function Not Permitted to Cardholder', + 'D4458' => 'Function Not Permitted to Terminal', + 'D4459' => 'Suspected Fraud', + 'D4460' => 'Acceptor Contact Acquirer', + 'D4461' => 'Exceeds Withdrawal Limit', + 'D4462' => 'Restricted Card', + 'D4463' => 'Security Violation', + 'D4464' => 'Original Amount Incorrect', + 'D4466' => 'Acceptor Contact Acquirer, Security', + 'D4467' => 'Capture Card', + 'D4475' => 'PIN Tries Exceeded', + 'D4482' => 'CVV Validation Error', + 'D4490' => 'Cut off In Progress', + 'D4491' => 'Card Issuer Unavailable', + 'D4492' => 'Unable To Route Transaction', + 'D4493' => 'Cannot Complete, Violation Of The Law', + 'D4494' => 'Duplicate Transaction', + 'D4496' => 'System Error', + 'D4497' => 'MasterPass Error', + 'D4498' => 'PayPal Create Transaction Error', + 'D4499' => 'Invalid Transaction for Auth/Void', + 'S5000' => 'System Error', + 'S5011' => 'PayPal Connection Error', + 'S5012' => 'PayPal Settings Error', + 'S5085' => 'Started 3dSecure', + 'S5086' => 'Routed 3dSecure', + 'S5087' => 'Completed 3dSecure', + 'S5099' => 'Incomplete (Access Code in progress/incomplete)', + 'V6000' => 'Validation error', + 'V6001' => 'Invalid CustomerIP', + 'V6002' => 'Invalid DeviceID', + 'V6003' => 'Invalid PartnerID', + 'V6004' => 'Invalid Method', + 'V6010' => 'Invalid TransactionType, account not certified for eCome only MOTO or Recurring available', + 'V6011' => 'Invalid TotalAmount', + 'V6012' => 'Invalid InvoiceDescription', + 'V6013' => 'Invalid InvoiceNumber', + 'V6014' => 'Invalid InvoiceReference', + 'V6015' => 'Invalid CurrencyCode', + 'V6016' => 'Payment Required', + 'V6017' => 'Payment CurrencyCode Required', + 'V6018' => 'Unknown Payment CurrencyCode', + 'V6021' => 'EWAY_CARDNAME Required', + 'V6022' => 'EWAY_CARDNUMBER Required', + 'V6023' => 'EWAY_CARDCVN Required', + 'V6033' => 'Invalid Expiry Date', + 'V6034' => 'Invalid Issue Number', + 'V6035' => 'Invalid Valid From Date', + 'V6040' => 'Invalid TokenCustomerID', + 'V6041' => 'Customer Required', + 'V6042' => 'Customer First Name Required', + 'V6043' => 'Customer Last Name Required', + 'V6044' => 'Customer CountryCode Required', + 'V6045' => 'Customer Title Required', + 'V6046' => 'TokenCustomerID Required', + 'V6047' => 'RedirectURL Required', + 'V6051' => 'Invalid Customer FirstName', + 'V6052' => 'Invalid Customer LastName', + 'V6053' => 'Invalid Customer CountryCode', + 'V6058' => 'Invalid Customer Title', + 'V6059' => 'Invalid RedirectURL', + 'V6060' => 'Invalid TokenCustomerID', + 'V6061' => 'Invalid Customer Reference', + 'V6062' => 'Invalid Customer CompanyName', + 'V6063' => 'Invalid Customer JobDescription', + 'V6064' => 'Invalid Customer Street1', + 'V6065' => 'Invalid Customer Street2', + 'V6066' => 'Invalid Customer City', + 'V6067' => 'Invalid Customer State', + 'V6068' => 'Invalid Customer PostalCode', + 'V6069' => 'Invalid Customer Email', + 'V6070' => 'Invalid Customer Phone', + 'V6071' => 'Invalid Customer Mobile', + 'V6072' => 'Invalid Customer Comments', + 'V6073' => 'Invalid Customer Fax', + 'V6074' => 'Invalid Customer URL', + 'V6075' => 'Invalid ShippingAddress FirstName', + 'V6076' => 'Invalid ShippingAddress LastName', + 'V6077' => 'Invalid ShippingAddress Street1', + 'V6078' => 'Invalid ShippingAddress Street2', + 'V6079' => 'Invalid ShippingAddress City', + 'V6080' => 'Invalid ShippingAddress State', + 'V6081' => 'Invalid ShippingAddress PostalCode', + 'V6082' => 'Invalid ShippingAddress Email', + 'V6083' => 'Invalid ShippingAddress Phone', + 'V6084' => 'Invalid ShippingAddress Country', + 'V6085' => 'Invalid ShippingAddress ShippingMethod', + 'V6086' => 'Invalid ShippingAddress Fax', + 'V6091' => 'Unknown Customer CountryCode', + 'V6092' => 'Unknown ShippingAddress CountryCode', + 'V6100' => 'Invalid EWAY_CARDNAME', + 'V6101' => 'Invalid EWAY_CARDEXPIRYMONTH', + 'V6102' => 'Invalid EWAY_CARDEXPIRYYEAR', + 'V6103' => 'Invalid EWAY_CARDSTARTMONTH', + 'V6104' => 'Invalid EWAY_CARDSTARTYEAR', + 'V6105' => 'Invalid EWAY_CARDISSUENUMBER', + 'V6106' => 'Invalid EWAY_CARDCVN', + 'V6107' => 'Invalid EWAY_ACCESSCODE', + 'V6108' => 'Invalid CustomerHostAddress', + 'V6109' => 'Invalid UserAgent', + 'V6110' => 'Invalid EWAY_CARDNUMBER', + 'V6111' => 'Unauthorised API Access, Account Not PCI Certified', + 'V6112' => 'Redundant card details other than expiry year and month', + 'V6113' => 'Invalid transaction for refund', + 'V6114' => 'Gateway validation error', + 'V6115' => 'Invalid Refund Transaction ID', + 'V6116' => 'Invalid card data on original TransactionID', + 'V6117' => 'Invalid CreateAccessCodeSharedRequest, FooterText', + 'V6118' => 'Invalid CreateAccessCodeSharedRequest, HeaderText', + 'V6119' => 'Invalid CreateAccessCodeSharedRequest, Language', + 'V6120' => 'Invalid CreateAccessCodeSharedRequest, LogoUrl', + 'V6121' => 'Invalid TransactionSearch, Filter Match Type', + 'V6122' => 'Invalid TransactionSearch, Non numeric Transaction ID', + 'V6123' => 'Invalid TransactionSearch,no TransactionID or AccessCode specified', + 'V6124' => 'Invalid Line Items. The line items have been provided however the totals do not match the + TotalAmount field', + 'V6125' => 'Selected Payment Type not enabled', + 'V6126' => 'Invalid encrypted card number, decryption failed', + 'V6127' => 'Invalid encrypted cvn, decryption failed', + 'V6128' => 'Invalid Method for Payment Type', + 'V6129' => 'Transaction has not been authorised for Capture/Cancellation', + 'V6130' => 'Generic customer information error', + 'V6131' => 'Generic shipping information error', + 'V6132' => 'Transaction has already been completed or voided, operation not permitted', + 'V6133' => 'Checkout not available for Payment Type', + 'V6134' => 'Invalid Auth Transaction ID for Capture/Void', + 'V6135' => 'PayPal Error Processing Refund', + 'V6140' => 'Merchant account is suspended', + 'V6141' => 'Invalid PayPal account details or API signature', + 'V6142' => 'Authorise not available for Bank/Branch', + 'V6150' => 'Invalid Refund Amount', + 'V6151' => 'Refund amount greater than original transaction', + 'V6152' => 'Original transaction already refunded for total amount', + 'V6153' => 'Card type not support by merchant', + ); + + public function isSuccessful() + { + return isset($this->data['TransactionStatus']) && $this->data['TransactionStatus']; + } + + public function getTransactionReference() + { + return isset($this->data['TransactionID']) ? (string) $this->data['TransactionID'] : null; + } + + public function getMessage() + { + $codes = explode(',', $this->getCode()); + $messages = array(); + + foreach ($codes as $code) { + $code = trim($code); + if (isset(static::$MESSAGES[$code])) { + $messages[] = static::$MESSAGES[$code]; + } else { + $messages[] = $code; + } + } + + return implode(', ', $messages) ?: null; + } + + public function getCode() + { + if (!empty($this->data['ResponseMessage'])) { + return $this->data['ResponseMessage']; + } elseif (!empty($this->data['Errors'])) { + return $this->data['Errors']; + } + } +} diff --git a/src/Message/RapidPurchaseRequest.php b/src/Message/RapidPurchaseRequest.php index 9bc329a..3911ff7 100644 --- a/src/Message/RapidPurchaseRequest.php +++ b/src/Message/RapidPurchaseRequest.php @@ -3,7 +3,7 @@ namespace Omnipay\Eway\Message; /** - * eWAY Rapid 3.0 Purchase Request + * eWAY Rapid Purchase Request * * Creates a payment URL using eWAY's Transparent Redirect * http://api-portal.anypoint.mulesoft.com/eway/api/eway-rapid-31-api/docs/reference/transparent-redirect @@ -15,14 +15,10 @@ public function getData() { $this->validate('amount', 'returnUrl'); - $data = array(); + $data = $this->getBaseData(); $data['Method'] = 'ProcessPayment'; - $data['DeviceID'] = 'https://github.com/adrianmacneil/omnipay'; - $data['CustomerIP'] = $this->getClientIp(); - $data['RedirectUrl'] = $this->getReturnUrl(); - $data['PartnerID'] = $this->getPartnerId(); $data['TransactionType'] = $this->getTransactionType(); - $data['ShippingMethod'] = $this->getShippingMethod(); + $data['RedirectUrl'] = $this->getReturnUrl(); $data['Payment'] = array(); $data['Payment']['TotalAmount'] = $this->getAmountInteger(); @@ -31,32 +27,6 @@ public function getData() $data['Payment']['CurrencyCode'] = $this->getCurrency(); $data['Payment']['InvoiceReference'] = $this->getInvoiceReference(); - $data['Customer'] = array(); - $card = $this->getCard(); - if ($card) { - $data['Customer']['FirstName'] = $card->getFirstName(); - $data['Customer']['LastName'] = $card->getLastName(); - $data['Customer']['CompanyName'] = $card->getCompany(); - $data['Customer']['Street1'] = $card->getAddress1(); - $data['Customer']['Street2'] = $card->getAddress2(); - $data['Customer']['City'] = $card->getCity(); - $data['Customer']['State'] = $card->getState(); - $data['Customer']['PostalCode'] = $card->getPostCode(); - $data['Customer']['Country'] = strtolower($card->getCountry()); - $data['Customer']['Email'] = $card->getEmail(); - $data['Customer']['Phone'] = $card->getPhone(); - - $data['ShippingAddress']['FirstName'] = $card->getShippingFirstName(); - $data['ShippingAddress']['LastName'] = $card->getShippingLastName(); - $data['ShippingAddress']['Street1'] = $card->getShippingAddress1(); - $data['ShippingAddress']['Street2'] = $card->getShippingAddress2(); - $data['ShippingAddress']['City'] = $card->getShippingCity(); - $data['ShippingAddress']['State'] = $card->getShippingState(); - $data['ShippingAddress']['Country'] = strtolower($card->getShippingCountry()); - $data['ShippingAddress']['PostalCode'] = $card->getShippingPostcode(); - $data['ShippingAddress']['Phone'] = $card->getShippingPhone(); - } - if ($this->getItems()) { $data['Items'] = $this->getItemData(); } diff --git a/src/Message/RapidResponse.php b/src/Message/RapidResponse.php index 8288340..3e63d48 100644 --- a/src/Message/RapidResponse.php +++ b/src/Message/RapidResponse.php @@ -2,7 +2,6 @@ namespace Omnipay\Eway\Message; -use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RedirectResponseInterface; /** @@ -10,149 +9,6 @@ */ class RapidResponse extends AbstractResponse implements RedirectResponseInterface { - public static $MESSAGES = array( - 'A2000' => 'Transaction Approved', - 'A2008' => 'Honour With Identification', - 'A2010' => 'Approved For Partial Amount', - 'A2011' => 'Approved, VIP', - 'A2016' => 'Approved, Update Track 3', - 'D4401' => 'Refer to Issuer', - 'D4402' => 'Refer to Issuer, special', - 'D4403' => 'No Merchant', - 'D4404' => 'Pick Up Card', - 'D4405' => 'Do Not Honour', - 'D4406' => 'Error', - 'D4407' => 'Pick Up Card, Special', - 'D4409' => 'Request In Progress', - 'D4412' => 'Invalid Transaction', - 'D4413' => 'Invalid Amount', - 'D4414' => 'Invalid Card Number', - 'D4415' => 'No Issuer', - 'D4419' => 'Re-enter Last Transaction', - 'D4421' => 'No Action Taken', - 'D4422' => 'Suspected Malfunction', - 'D4423' => 'Unacceptable Transaction Fee', - 'D4425' => 'Unable to Locate Record On File', - 'D4430' => 'Format Error', - 'D4431' => 'Bank Not Supported By Switch', - 'D4433' => 'Expired Card, Capture', - 'D4434' => 'Suspected Fraud, Retain Card', - 'D4435' => 'Card Acceptor, Contact Acquirer, Retain Card', - 'D4436' => 'Restricted Card, Retain Card', - 'D4437' => 'Contact Acquirer Security Department, Retain Card', - 'D4438' => 'PIN Tries Exceeded, Capture', - 'D4439' => 'No Credit Account', - 'D4440' => 'Function Not Supported', - 'D4441' => 'Lost Card', - 'D4442' => 'No Universal Account', - 'D4443' => 'Stolen Card', - 'D4444' => 'No Investment Account', - 'D4451' => 'Insufficient Funds', - 'D4452' => 'No Cheque Account', - 'D4453' => 'No Savings Account', - 'D4454' => 'Expired Card', - 'D4455' => 'Incorrect PIN', - 'D4456' => 'No Card Record', - 'D4457' => 'Function Not Permitted to Cardholder', - 'D4458' => 'Function Not Permitted to Terminal', - 'D4459' => 'Suspected Fraud', - 'D4460' => 'Acceptor Contact Acquirer', - 'D4461' => 'Exceeds Withdrawal Limit', - 'D4462' => 'Restricted Card', - 'D4463' => 'Security Violation', - 'D4464' => 'Original Amount Incorrect', - 'D4466' => 'Acceptor Contact Acquirer, Security', - 'D4467' => 'Capture Card', - 'D4475' => 'PIN Tries Exceeded', - 'D4482' => 'CVV Validation Error', - 'D4490' => 'Cut off In Progress', - 'D4491' => 'Card Issuer Unavailable', - 'D4492' => 'Unable To Route Transaction', - 'D4493' => 'Cannot Complete, Violation Of The Law', - 'D4494' => 'Duplicate Transaction', - 'D4496' => 'System Error', - 'S5000' => 'System Error', - 'S5085' => 'Started 3dSecure', - 'S5086' => 'Routed 3dSecure', - 'S5087' => 'Completed 3dSecure', - 'S5099' => 'Incomplete (Access Code in progress/incomplete)', - 'V6000' => 'Validation error', - 'V6001' => 'Invalid CustomerIP', - 'V6002' => 'Invalid DeviceID', - 'V6011' => 'Invalid Payment TotalAmount', - 'V6012' => 'Invalid Payment InvoiceDescription', - 'V6013' => 'Invalid Payment InvoiceNumber', - 'V6014' => 'Invalid Payment InvoiceReference', - 'V6015' => 'Invalid Payment CurrencyCode', - 'V6016' => 'Payment Required', - 'V6017' => 'Payment CurrencyCode Required', - 'V6018' => 'Unknown Payment CurrencyCode', - 'V6021' => 'EWAY_CARDNAME Required', - 'V6022' => 'EWAY_CARDNUMBER Required', - 'V6023' => 'EWAY_CARDCVN Required', - 'V6033' => 'Invalid Expiry Date', - 'V6034' => 'Invalid Issue Number', - 'V6035' => 'Invalid Valid From Date', - 'V6040' => 'Invalid TokenCustomerID', - 'V6041' => 'Customer Required', - 'V6042' => 'Customer FirstName Required', - 'V6043' => 'Customer LastName Required', - 'V6044' => 'Customer CountryCode Required', - 'V6045' => 'Customer Title Required', - 'V6046' => 'TokenCustomerID Required', - 'V6047' => 'RedirectURL Required', - 'V6051' => 'Invalid Customer FirstName', - 'V6052' => 'Invalid Customer LastName', - 'V6053' => 'Invalid Customer CountryCode', - 'V6058' => 'Invalid Customer Title', - 'V6059' => 'Invalid RedirectURL', - 'V6060' => 'Invalid TokenCustomerID', - 'V6061' => 'Invalid Customer Reference', - 'V6062' => 'Invalid Customer CompanyName', - 'V6063' => 'Invalid Customer JobDescription', - 'V6064' => 'Invalid Customer Street1', - 'V6065' => 'Invalid Customer Street2', - 'V6066' => 'Invalid Customer City', - 'V6067' => 'Invalid Customer State', - 'V6068' => 'Invalid Customer PostalCode', - 'V6069' => 'Invalid Customer Email', - 'V6070' => 'Invalid Customer Phone', - 'V6071' => 'Invalid Customer Mobile', - 'V6072' => 'Invalid Customer Comments', - 'V6073' => 'Invalid Customer Fax', - 'V6074' => 'Invalid Customer URL', - 'V6075' => 'Invalid ShippingAddress FirstName', - 'V6076' => 'Invalid ShippingAddress LastName', - 'V6077' => 'Invalid ShippingAddress Street1', - 'V6078' => 'Invalid ShippingAddress Street2', - 'V6079' => 'Invalid ShippingAddress City', - 'V6080' => 'Invalid ShippingAddress State', - 'V6081' => 'Invalid ShippingAddress PostalCode', - 'V6082' => 'Invalid ShippingAddress Email', - 'V6083' => 'Invalid ShippingAddress Phone', - 'V6084' => 'Invalid ShippingAddress Country', - 'V6085' => 'Invalid ShippingAddress ShippingMethod', - 'V6086' => 'Invalid ShippingAddress Fax', - 'V6091' => 'Unknown Customer CountryCode', - 'V6092' => 'Unknown ShippingAddress CountryCode', - 'V6100' => 'Invalid EWAY_CARDNAME', - 'V6101' => 'Invalid EWAY_CARDEXPIRYMONTH', - 'V6102' => 'Invalid EWAY_CARDEXPIRYYEAR', - 'V6103' => 'Invalid EWAY_CARDSTARTMONTH', - 'V6104' => 'Invalid EWAY_CARDSTARTYEAR', - 'V6105' => 'Invalid EWAY_CARDISSUENUMBER', - 'V6106' => 'Invalid EWAY_CARDCVN', - 'V6107' => 'Invalid EWAY_ACCESSCODE', - 'V6108' => 'Invalid CustomerHostAddress', - 'V6109' => 'Invalid UserAgent', - 'V6110' => 'Invalid EWAY_CARDNUMBER', - ); - - public function isSuccessful() - { - return isset($this->data['TransactionStatus']) && $this->data['TransactionStatus']; - } - public function isRedirect() { return isset($this->data['FormActionURL']); @@ -176,34 +32,4 @@ public function getRedirectData() ); } } - - public function getTransactionReference() - { - return isset($this->data['TransactionID']) ? (string) $this->data['TransactionID'] : null; - } - - public function getMessage() - { - $codes = explode(',', $this->getCode()); - $messages = array(); - - foreach ($codes as $code) { - if (isset(static::$MESSAGES[$code])) { - $messages[] = static::$MESSAGES[$code]; - } else { - $messages[] = $code; - } - } - - return implode(', ', $messages) ?: null; - } - - public function getCode() - { - if (!empty($this->data['ResponseMessage'])) { - return $this->data['ResponseMessage']; - } elseif (!empty($this->data['Errors'])) { - return $this->data['Errors']; - } - } } diff --git a/src/Message/RapidSharedPurchaseRequest.php b/src/Message/RapidSharedPurchaseRequest.php new file mode 100644 index 0000000..43e288d --- /dev/null +++ b/src/Message/RapidSharedPurchaseRequest.php @@ -0,0 +1,140 @@ +validate('amount', 'returnUrl'); + + $data = $this->getBaseData(); + $data['Method'] = 'ProcessPayment'; + $data['RedirectUrl'] = $this->getReturnUrl(); + $data['TransactionType'] = $this->getTransactionType(); + + // 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['VerifyCustomerPhone'] = $this->getVerifyCustomerPhone(); + $data['VerifyCustomerEmail'] = $this->getVerifyCustomerEmail(); + + $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->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 RapidSharedResponse($this, $httpResponse->json()); + } + + public function getEndpoint() + { + return $this->getEndpointBase().'/CreateAccessCodeShared.json'; + } + + public function getCancelUrl() + { + return $this->getParameter('cancelUrl'); + } + + public function setCancelUrl($value) + { + return $this->setParameter('cancelUrl', $value); + } + + public function getLogoUrl() + { + return $this->getParameter('logoUrl'); + } + + public function setLogoUrl($value) + { + return $this->setParameter('logoUrl', $value); + } + + public function getHeaderText() + { + return $this->getParameter('headerText'); + } + + public function setHeaderText($value) + { + return $this->setParameter('headerText', $value); + } + + public function getLanguage() + { + return $this->getParameter('language'); + } + + public function setLanguage($value) + { + return $this->setParameter('language', $value); + } + + public function getCustomerReadOnly() + { + return $this->getParameter('customerReadOnly'); + } + + public function setCustomerReadOnly($value) + { + return $this->setParameter('customerReadOnly', $value); + } + + public function getCustomView() + { + return $this->getParameter('customView'); + } + + public function setCustomView($value) + { + return $this->setParameter('customView', $value); + } + + public function getVerifyCustomerPhone() + { + return $this->getParameter('verifyCustomerPhone'); + } + + public function setVerifyCustomerPhone($value) + { + return $this->setParameter('verifyCustomerPhone', $value); + } + + public function getVerifyCustomerEmail() + { + return $this->getParameter('verifyCustomerEmail'); + } + + public function setVerifyCustomerEmail($value) + { + return $this->setParameter('verifyCustomerEmail', $value); + } +} diff --git a/src/Message/RapidSharedResponse.php b/src/Message/RapidSharedResponse.php new file mode 100644 index 0000000..3b47cb2 --- /dev/null +++ b/src/Message/RapidSharedResponse.php @@ -0,0 +1,31 @@ +data['SharedPaymentUrl']); + } + + public function getRedirectUrl() + { + return isset($this->data['SharedPaymentUrl']) ? $this->data['SharedPaymentUrl'] : null; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } +} diff --git a/src/Message/RefundRequest.php b/src/Message/RefundRequest.php new file mode 100644 index 0000000..243a556 --- /dev/null +++ b/src/Message/RefundRequest.php @@ -0,0 +1,43 @@ +validate('transactionReference', 'amount'); + + $data = $this->getBaseData(); + $data['Refund']['TotalAmount'] = $this->getAmountInteger(); + $data['Refund']['TransactionID'] = $this->getTransactionReference(); + $data['Refund']['InvoiceNumber'] = $this->getTransactionId(); + $data['Refund']['InvoiceDescription'] = $this->getDescription(); + $data['Refund']['CurrencyCode'] = $this->getCurrency(); + $data['Refund']['InvoiceReference'] = $this->getInvoiceReference(); + + 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 RefundResponse($this, $httpResponse->json()); + } + + public function getEndpoint() + { + return $this->getEndpointBase().'/DirectRefund.json'; + } +} diff --git a/src/Message/RefundResponse.php b/src/Message/RefundResponse.php new file mode 100644 index 0000000..2e8ef2b --- /dev/null +++ b/src/Message/RefundResponse.php @@ -0,0 +1,13 @@ +createRequest('\Omnipay\Eway\Message\RapidCompletePurchaseRequest', $parameters); } + + public function refund(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Eway\Message\RefundRequest', $parameters); + } } diff --git a/src/RapidSharedGateway.php b/src/RapidSharedGateway.php new file mode 100644 index 0000000..a12016f --- /dev/null +++ b/src/RapidSharedGateway.php @@ -0,0 +1,60 @@ + '', + '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); + } + + public function purchase(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Eway\Message\RapidSharedPurchaseRequest', $parameters); + } + + public function completePurchase(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Eway\Message\RapidCompletePurchaseRequest', $parameters); + } + + public function refund(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Eway\Message\RefundRequest', $parameters); + } +} diff --git a/tests/Message/AbstractResponseTest.php b/tests/Message/AbstractResponseTest.php new file mode 100644 index 0000000..90a26f7 --- /dev/null +++ b/tests/Message/AbstractResponseTest.php @@ -0,0 +1,42 @@ +response = m::mock('\Omnipay\Eway\Message\AbstractResponse')->makePartial(); + } + + public function testIsSuccessful() + { + $data = array('TransactionStatus' => true); + $request = $this->getMockRequest(); + $this->response = m::mock('\Omnipay\Eway\Message\AbstractResponse', array($request, $data))->makePartial(); + + $this->assertTrue($this->response->isSuccessful()); + } + + public function testGetMessage() + { + $data = array('ResponseMessage' => 'A2000'); + $request = $this->getMockRequest(); + $this->response = m::mock('\Omnipay\Eway\Message\AbstractResponse', array($request, $data))->makePartial(); + + $this->assertSame('Transaction Approved', $this->response->getMessage()); + } + + public function testGetMessageMultiple() + { + $data = array('ResponseMessage' => 'V6101,V6102'); + $request = $this->getMockRequest(); + $this->response = m::mock('\Omnipay\Eway\Message\AbstractResponse', array($request, $data))->makePartial(); + + $this->assertSame('Invalid EWAY_CARDEXPIRYMONTH, Invalid EWAY_CARDEXPIRYYEAR', $this->response->getMessage()); + } +} diff --git a/tests/Message/RapidPurchaseRequestTest.php b/tests/Message/RapidPurchaseRequestTest.php index debf8d4..fd5624d 100644 --- a/tests/Message/RapidPurchaseRequestTest.php +++ b/tests/Message/RapidPurchaseRequestTest.php @@ -124,7 +124,7 @@ public function testSendFailure() $this->assertNull($response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); $this->assertNull($response->getTransactionReference()); - $this->assertSame('Invalid Payment TotalAmount', $response->getMessage()); + $this->assertSame('Invalid TotalAmount', $response->getMessage()); $this->assertSame('V6011', $response->getCode()); } } diff --git a/tests/Message/RapidSharedPurchaseRequestTest.php b/tests/Message/RapidSharedPurchaseRequestTest.php new file mode 100644 index 0000000..044c3c0 --- /dev/null +++ b/tests/Message/RapidSharedPurchaseRequestTest.php @@ -0,0 +1,179 @@ +request = new RapidSharedPurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'amount' => '10.00', + 'returnUrl' => 'https://www.example.com/return', + )); + } + + 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', + 'returnUrl' => 'https://www.example.com/return', + 'card' => array( + 'firstName' => 'Patrick', + 'lastName' => 'Collison', + 'shippingFirstName' => 'John', + 'shippingLastName' => 'Smith', + 'shippingAddress1' => 'Level 1', + 'shippingAddress2' => '123 Test Lane', + 'shippingState' => 'NSW', + 'shippingCountry' => 'AU', + ), + )); + + $data = $this->request->getData(); + + $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('https://www.example.com/return', $data['RedirectUrl']); + $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('Patrick', $data['Customer']['FirstName']); + $this->assertSame('Collison', $data['Customer']['LastName']); + $this->assertSame('John', $data['ShippingAddress']['FirstName']); + $this->assertSame('Smith', $data['ShippingAddress']['LastName']); + $this->assertSame('NSW', $data['ShippingAddress']['State']); + $this->assertSame('au', $data['ShippingAddress']['Country']); + } + + public function testGetDataWithItems() + { + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'amount' => '10.00', + 'transactionId' => '999', + 'description' => 'new car', + 'currency' => 'AUD', + 'clientIp' => '127.0.0.1', + 'returnUrl' => 'https://www.example.com/return', + 'card' => array( + 'firstName' => 'Patrick', + 'lastName' => 'Collison', + ), + )); + + $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('RapidSharedPurchaseRequestSuccess.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()); + } + + public function testSendFailure() + { + $this->setMockHttpResponse('RapidSharedPurchaseRequestFailure.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertNull($response->getRedirectUrl()); + $this->assertNull($response->getRedirectData()); + $this->assertNull($response->getTransactionReference()); + $this->assertSame('Invalid TotalAmount', $response->getMessage()); + $this->assertSame('V6011', $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/RefundRequestTest.php b/tests/Message/RefundRequestTest.php new file mode 100644 index 0000000..62ef01b --- /dev/null +++ b/tests/Message/RefundRequestTest.php @@ -0,0 +1,118 @@ +request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'amount' => '10.00', + 'transactionReference' => '87654321', + )); + } + + public function testGetData() + { + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'partnerId' => '1234', + 'amount' => '10.00', + 'transactionReference' => '87654321', + 'transactionId' => '999', + 'description' => 'new car', + 'currency' => 'AUD', + 'invoiceReference' => 'INV-123', + 'clientIp' => '127.0.0.1', + 'card' => array( + 'firstName' => 'Patrick', + 'lastName' => 'Collison', + 'shippingFirstName' => 'John', + 'shippingLastName' => 'Smith', + 'shippingAddress1' => 'Level 1', + 'shippingAddress2' => '123 Test Lane', + 'shippingState' => 'NSW', + 'shippingCountry' => 'AU', + ), + )); + + $data = $this->request->getData(); + + $this->assertSame('127.0.0.1', $data['CustomerIP']); + $this->assertSame('1234', $data['PartnerID']); + $this->assertSame(1000, $data['Refund']['TotalAmount']); + $this->assertSame('87654321', $data['Refund']['TransactionID']); + $this->assertSame('999', $data['Refund']['InvoiceNumber']); + $this->assertSame('new car', $data['Refund']['InvoiceDescription']); + $this->assertSame('INV-123', $data['Refund']['InvoiceReference']); + $this->assertSame('AUD', $data['Refund']['CurrencyCode']); + $this->assertSame('Patrick', $data['Customer']['FirstName']); + $this->assertSame('Collison', $data['Customer']['LastName']); + $this->assertSame('John', $data['ShippingAddress']['FirstName']); + $this->assertSame('Smith', $data['ShippingAddress']['LastName']); + $this->assertSame('NSW', $data['ShippingAddress']['State']); + $this->assertSame('au', $data['ShippingAddress']['Country']); + } + + public function testGetDataWithItems() + { + $this->request->initialize(array( + 'apiKey' => 'my api key', + 'password' => 'secret', + 'amount' => '10.00', + 'transactionReference' => '87654321', + 'transactionId' => '999', + 'description' => 'new car', + 'currency' => 'AUD', + 'clientIp' => '127.0.0.1', + 'card' => array( + 'firstName' => 'Patrick', + 'lastName' => 'Collison', + ), + )); + + $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('RapidRefundRequestSuccess.txt'); + $response = $this->request->send(); + + $this->assertTrue($response->isSuccessful()); + $this->assertSame('11092404', $response->getTransactionReference()); + $this->assertSame('A2000', $response->getCode()); + } + + public function testSendFailure() + { + $this->setMockHttpResponse('RapidRefundRequestFailure.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertNull($response->getTransactionReference()); + $this->assertSame('Unauthorised API Access, Account Not PCI Certified, Invalid Refund Transaction ID', $response->getMessage()); + $this->assertSame('V6111,V6115', $response->getCode()); + } +} \ No newline at end of file diff --git a/tests/Mock/RapidRefundRequestFailure.txt b/tests/Mock/RapidRefundRequestFailure.txt new file mode 100644 index 0000000..5f61a41 --- /dev/null +++ b/tests/Mock/RapidRefundRequestFailure.txt @@ -0,0 +1,16 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Thu, 27 Jun 2014 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/DirectRefund.json +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/DirectRefund.json +X-ID: AM-131 +X-Powered-By: eWAY +Content-Length: 787 +Connection: keep-alive + +{"AuthorisationCode": null,"ResponseCode": null,"ResponseMessage": null,"TransactionID": null,"TransactionStatus": null,"Verification": null,"Customer": {"CardDetails": {"Number": null,"Name": null,"ExpiryMonth": null,"ExpiryYear": null,"StartMonth": null,"StartYear": null,"IssueNumber": null},"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},"Refund": {"TransactionID": "123456789","TotalAmount": 100,"InvoiceNumber": null,"InvoiceDescription": null,"InvoiceReference": null,"CurrencyCode": null},"Errors": "V6111,V6115"} diff --git a/tests/Mock/RapidRefundRequestSuccess.txt b/tests/Mock/RapidRefundRequestSuccess.txt new file mode 100644 index 0000000..0dc449a --- /dev/null +++ b/tests/Mock/RapidRefundRequestSuccess.txt @@ -0,0 +1,16 @@ +HTTP/1.1 200 OK +Cache-control: no-cache="set-cookie" +Content-Type: application/json; charset=utf-8 +Date: Thu, 27 Jun 2014 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/DirectRefund.json +X-EWAY-VIA-HTTP-METHOD: POST +X-EWAY-VIA-HTTP-STATUS: 200 +X-EWAY-VIA-TO: http://api-au.sandbox.ewaypayments.com/DirectRefund.json +X-ID: AM-131 +X-Powered-By: eWAY +Content-Length: 766 +Connection: keep-alive + +{"AuthorisationCode": "748299","ResponseCode": null,"ResponseMessage": "A2000","TransactionID": 11092404,"TransactionStatus": true,"Verification": null,"Customer": {"CardDetails": {"Number": null,"Name": null,"ExpiryMonth": null,"ExpiryYear": null,"StartMonth": null,"StartYear": null,"IssueNumber": null},"TokenCustomerID": null,"Reference": null,"Title": null,"FirstName": "","LastName": "","CompanyName": null,"JobDescription": null,"Street1": "","Street2": null,"City": "","State": "","PostalCode": "","Country": "","Email": "","Phone": "","Mobile": null,"Comments": null,"Fax": null,"Url": null},"Refund": {"TransactionID": "11092403","TotalAmount": 100,"InvoiceNumber": null,"InvoiceDescription": "","InvoiceReference": "","CurrencyCode": null},"Errors": null} diff --git a/tests/Mock/RapidSharedPurchaseRequestFailure.txt b/tests/Mock/RapidSharedPurchaseRequestFailure.txt new file mode 100644 index 0000000..c517a35 --- /dev/null +++ b/tests/Mock/RapidSharedPurchaseRequestFailure.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":-1000,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},"FormActionURL":null,"Errors":"V6011"} diff --git a/tests/Mock/RapidSharedPurchaseRequestSuccess.txt b/tests/Mock/RapidSharedPurchaseRequestSuccess.txt new file mode 100644 index 0000000..fc81a83 --- /dev/null +++ b/tests/Mock/RapidSharedPurchaseRequestSuccess.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":null,"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":1000,"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} diff --git a/tests/RapidSharedGatewayTest.php b/tests/RapidSharedGatewayTest.php new file mode 100644 index 0000000..78802c0 --- /dev/null +++ b/tests/RapidSharedGatewayTest.php @@ -0,0 +1,31 @@ +gateway = new RapidSharedGateway($this->getHttpClient(), $this->getHttpRequest()); + } + + public function testPurchase() + { + $request = $this->gateway->purchase(array('amount' => '10.00')); + + $this->assertInstanceOf('Omnipay\Eway\Message\RapidSharedPurchaseRequest', $request); + $this->assertSame('10.00', $request->getAmount()); + } + + public function testPurchaseReturn() + { + $request = $this->gateway->completePurchase(array('amount' => '10.00')); + + $this->assertInstanceOf('Omnipay\Eway\Message\RapidCompletePurchaseRequest', $request); + $this->assertSame('10.00', $request->getAmount()); + } +} From 96fb1eafaabaec75cf10422555841566ae8b9832 Mon Sep 17 00:00:00 2001 From: John C Date: Wed, 18 Mar 2015 03:36:40 +0000 Subject: [PATCH 2/2] Added eWAY Direct Connection support: includes purchase, authorise, capture and token (saved card) Comes complete with tests and documentation. Some doco improvements for other eWAY Rapid methods and noted legacy status of eWAY Direct --- README.md | 9 +- src/DirectGateway.php | 13 +- src/Message/AbstractRequest.php | 20 +- src/Message/AbstractResponse.php | 18 +- src/Message/RapidCaptureRequest.php | 68 ++++++ src/Message/RapidCompletePurchaseRequest.php | 11 +- src/Message/RapidDirectAbstractRequest.php | 107 +++++++++ src/Message/RapidDirectAuthorizeRequest.php | 92 ++++++++ src/Message/RapidDirectCreateCardRequest.php | 76 ++++++ src/Message/RapidDirectPurchaseRequest.php | 103 +++++++++ src/Message/RapidDirectUpdateCardRequest.php | 83 +++++++ src/Message/RapidPurchaseRequest.php | 9 +- src/Message/RapidResponse.php | 24 +- src/Message/RapidSharedPurchaseRequest.php | 9 +- src/Message/RapidSharedResponse.php | 17 ++ src/Message/RefundRequest.php | 35 ++- src/RapidDirectGateway.php | 202 ++++++++++++++++ src/RapidGateway.php | 19 +- src/RapidSharedGateway.php | 20 +- tests/Message/RapidCaptureRequestTest.php | 64 ++++++ .../RapidDirectAuthorizeRequestTest.php | 107 +++++++++ .../RapidDirectCreateCardRequestTest.php | 94 ++++++++ .../RapidDirectPurchaseRequestTest.php | 216 ++++++++++++++++++ .../RapidDirectUpdateCardRequestTest.php | 84 +++++++ .../RapidSharedPurchaseRequestTest.php | 2 + tests/Mock/RapidCaptureRequestFailure.txt | 16 ++ tests/Mock/RapidCaptureRequestSuccess.txt | 16 ++ .../RapidDirectAuthoriseRequestFailure.txt | 17 ++ .../RapidDirectAuthoriseRequestSuccess.txt | 17 ++ .../RapidDirectCreateCardRequestFailure.txt | 17 ++ .../RapidDirectCreateCardRequestSuccess.txt | 17 ++ .../RapidDirectPurchaseRequestFailure.txt | 17 ++ .../RapidDirectPurchaseRequestSuccess.txt | 17 ++ .../RapidDirectUpdateCardRequestFailure.txt | 17 ++ .../RapidDirectUpdateCardRequestSuccess.txt | 17 ++ tests/RapidDirectGatewayTest.php | 47 ++++ 36 files changed, 1684 insertions(+), 33 deletions(-) create mode 100644 src/Message/RapidCaptureRequest.php create mode 100644 src/Message/RapidDirectAbstractRequest.php create mode 100644 src/Message/RapidDirectAuthorizeRequest.php create mode 100644 src/Message/RapidDirectCreateCardRequest.php create mode 100644 src/Message/RapidDirectPurchaseRequest.php create mode 100644 src/Message/RapidDirectUpdateCardRequest.php create mode 100644 src/RapidDirectGateway.php create mode 100644 tests/Message/RapidCaptureRequestTest.php create mode 100644 tests/Message/RapidDirectAuthorizeRequestTest.php create mode 100644 tests/Message/RapidDirectCreateCardRequestTest.php create mode 100644 tests/Message/RapidDirectPurchaseRequestTest.php create mode 100644 tests/Message/RapidDirectUpdateCardRequestTest.php create mode 100644 tests/Mock/RapidCaptureRequestFailure.txt create mode 100644 tests/Mock/RapidCaptureRequestSuccess.txt create mode 100644 tests/Mock/RapidDirectAuthoriseRequestFailure.txt create mode 100644 tests/Mock/RapidDirectAuthoriseRequestSuccess.txt create mode 100644 tests/Mock/RapidDirectCreateCardRequestFailure.txt create mode 100644 tests/Mock/RapidDirectCreateCardRequestSuccess.txt create mode 100644 tests/Mock/RapidDirectPurchaseRequestFailure.txt create mode 100644 tests/Mock/RapidDirectPurchaseRequestSuccess.txt create mode 100644 tests/Mock/RapidDirectUpdateCardRequestFailure.txt create mode 100644 tests/Mock/RapidDirectUpdateCardRequestSuccess.txt create mode 100644 tests/RapidDirectGatewayTest.php 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()); + } +}