├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml.dist ├── src ├── Message │ ├── PxFusionCompletePurchaseRequest.php │ ├── PxFusionCompletePurchaseResponse.php │ ├── PxFusionCreateCardRequest.php │ ├── PxFusionPurchaseRequest.php │ ├── PxFusionPurchaseResponse.php │ ├── PxPayAuthorizeRequest.php │ ├── PxPayAuthorizeResponse.php │ ├── PxPayCompleteAuthorizeRequest.php │ ├── PxPayCreateCardRequest.php │ ├── PxPayPurchaseRequest.php │ ├── PxPostAuthorizeRequest.php │ ├── PxPostCaptureRequest.php │ ├── PxPostCreateCardRequest.php │ ├── PxPostPurchaseRequest.php │ ├── PxPostRefundRequest.php │ └── Response.php ├── PxFusionGateway.php ├── PxPayGateway.php └── PxPostGateway.php └── tests ├── Message ├── PxPayAuthorizeResponseTest.php ├── PxPayCreateCardRequestTest.php └── ResponseTest.php ├── Mock ├── PxFusionCompletePurchaseFailure.txt ├── PxFusionCompletePurchaseSuccess.txt ├── PxFusionPurchaseFailure.txt ├── PxFusionPurchaseSuccess.txt ├── PxPayCompleteCreateCardFailure.txt ├── PxPayCompleteCreateCardSuccess.txt ├── PxPayCompletePurchaseFailure.txt ├── PxPayCompletePurchaseSuccess.txt ├── PxPayCreateCardFailure.txt ├── PxPayCreateCardSuccess.txt ├── PxPayPurchaseFailure.txt ├── PxPayPurchaseSuccess.txt ├── PxPostCreateCardFailure.txt ├── PxPostCreateCardSuccess.txt ├── PxPostPurchaseFailure.txt └── PxPostPurchaseSuccess.txt ├── PxFusionGatewayTest.php ├── PxPayGatewayTest.php └── PxPostGatewayTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | composer.phar 4 | phpunit.xml 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | sudo: false 4 | 5 | cache: 6 | directories: 7 | - $HOME/.composer/cache 8 | 9 | php: 10 | - 5.6 11 | - 7.0 12 | - 7.1 13 | - 7.2 14 | 15 | before_script: 16 | - composer install -n --dev --prefer-dist 17 | 18 | script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text 19 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | * Fork the project. 4 | * Make your feature addition or bug fix. 5 | * Add tests for it. This is important so I don't break it in a future version unintentionally. 6 | * Commit just the modifications, do not mess with the composer.json or CHANGELOG.md files. 7 | * Ensure your code is nicely formatted in the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) 8 | style and that all tests pass. 9 | * Send the pull request. 10 | * Check that the Travis CI build passed. If not, rinse and repeat. 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2013 Adrian Macneil 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Omnipay: Payment Express 2 | 3 | **DPS Payment Express driver for the Omnipay PHP payment processing library** 4 | 5 | [![Build Status](https://travis-ci.org/thephpleague/omnipay-paymentexpress.png?branch=master)](https://travis-ci.org/thephpleague/omnipay-paymentexpress) 6 | [![Latest Stable Version](https://poser.pugx.org/omnipay/paymentexpress/version.png)](https://packagist.org/packages/omnipay/paymentexpress) 7 | [![Total Downloads](https://poser.pugx.org/omnipay/paymentexpress/d/total.png)](https://packagist.org/packages/omnipay/paymentexpress) 8 | 9 | [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment 10 | processing library for PHP 5.3+. This package implements Payment Express support for Omnipay. 11 | 12 | ## Installation 13 | 14 | Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it 15 | to your `composer.json` file: 16 | 17 | ```json 18 | { 19 | "require": { 20 | "omnipay/paymentexpress": "~2.0" 21 | } 22 | } 23 | ``` 24 | 25 | And run composer to update your dependencies: 26 | 27 | $ curl -s http://getcomposer.org/installer | php 28 | $ php composer.phar update 29 | 30 | ## Basic Usage 31 | 32 | The following gateways are provided by this package: 33 | 34 | * PaymentExpress_PxPay. The PxPay version 2.0 endpoint is supported. If you are still using the version 1.0 endpoint then please contact PxPay and they will change you to the 2.0 endpoint. The API is backwards compatible. 35 | * PaymentExpress_PxPost 36 | * PaymentExpress_PxFusion 37 | 38 | For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) 39 | repository. 40 | 41 | ## Support 42 | 43 | If you are having general issues with Omnipay, we suggest posting on 44 | [Stack Overflow](http://stackoverflow.com/). Be sure to add the 45 | [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found. 46 | 47 | If you want to keep up to date with release anouncements, discuss ideas for the project, 48 | or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which 49 | you can subscribe to. 50 | 51 | If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/thephpleague/omnipay-paymentexpress/issues), 52 | or better yet, fork the library and submit a pull request. 53 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "omnipay/paymentexpress", 3 | "type": "library", 4 | "description": "Payment Express (DPS) driver for the Omnipay payment processing library", 5 | "keywords": [ 6 | "direct payment solutions", 7 | "dps", 8 | "gateway", 9 | "merchant", 10 | "omnipay", 11 | "pay", 12 | "payment express", 13 | "payment", 14 | "paymentexpress", 15 | "pxaccess", 16 | "pxpay", 17 | "pxpost" 18 | ], 19 | "homepage": "https://github.com/thephpleague/omnipay-paymentexpress", 20 | "license": "MIT", 21 | "minimum-stability" : "beta", 22 | "authors": [ 23 | { 24 | "name": "Adrian Macneil", 25 | "email": "adrian@adrianmacneil.com" 26 | }, 27 | { 28 | "name": "Omnipay Contributors", 29 | "homepage": "https://github.com/thephpleague/omnipay-paymentexpress/contributors" 30 | } 31 | ], 32 | "autoload": { 33 | "psr-4": { "Omnipay\\PaymentExpress\\" : "src/" } 34 | }, 35 | "require": { 36 | "omnipay/common": "~3.0" 37 | }, 38 | "require-dev": { 39 | "omnipay/tests": "~3.0", 40 | "squizlabs/php_codesniffer": "^3" 41 | }, 42 | "extra": { 43 | "branch-alias": { 44 | "dev-master": "3.0.x-dev" 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests/ 15 | 16 | 17 | 18 | 19 | ./src 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/Message/PxFusionCompletePurchaseRequest.php: -------------------------------------------------------------------------------- 1 | getParameter('sessionId'); 16 | } 17 | 18 | public function setSessionId($value) 19 | { 20 | return $this->setParameter('sessionId', $value); 21 | } 22 | 23 | public function getData() 24 | { 25 | $this->validate('sessionId'); 26 | 27 | $data = new SimpleXMLElement(''); 28 | $data->addAttribute('xmlns', $this->namespace); 29 | $data->username = $this->getUsername(); 30 | $data->password = $this->getPassword(); 31 | $data->transactionId = $this->getSessionId(); 32 | 33 | return $data; 34 | } 35 | 36 | protected function createResponse($data) 37 | { 38 | return $this->response = new PxFusionCompletePurchaseResponse($this, $data); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Message/PxFusionCompletePurchaseResponse.php: -------------------------------------------------------------------------------- 1 | request = $request; 17 | 18 | $responseDom = new DOMDocument; 19 | $responseDom->loadXML($data); 20 | 21 | $this->data = simplexml_import_dom($responseDom->documentElement->firstChild->firstChild->firstChild); 22 | } 23 | 24 | public function isSuccessful() 25 | { 26 | return $this->getCode() === 0; 27 | } 28 | 29 | public function getMessage() 30 | { 31 | return (string) $this->data->responseText; 32 | } 33 | 34 | public function getCode() 35 | { 36 | return (int) $this->data->status; 37 | } 38 | 39 | public function getTransactionReference() 40 | { 41 | return (string) $this->data->dpsTxnRef; 42 | } 43 | 44 | public function getTransactionId() 45 | { 46 | return (string) $this->data->merchantReference; 47 | } 48 | 49 | public function getCardReference() 50 | { 51 | return (string) $this->data->dpsBillingId; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Message/PxFusionCreateCardRequest.php: -------------------------------------------------------------------------------- 1 | getParameter('action'); 23 | } 24 | 25 | public function setAction($value) 26 | { 27 | return $this->setParameter('action', $value); 28 | } 29 | 30 | public function getData() 31 | { 32 | $this->setAmount($this->getAmount() ? $this->getAmount() : '1.00'); 33 | 34 | 35 | if ($this->getAction()) { 36 | $this->action = $this->getAction(); 37 | } 38 | 39 | $data = parent::getData(); 40 | 41 | return $data; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Message/PxFusionPurchaseRequest.php: -------------------------------------------------------------------------------- 1 | getParameter('username'); 26 | } 27 | 28 | public function setUsername($value) 29 | { 30 | return $this->setParameter('username', $value); 31 | } 32 | 33 | public function getPassword() 34 | { 35 | return $this->getParameter('password'); 36 | } 37 | 38 | public function setPassword($value) 39 | { 40 | return $this->setParameter('password', $value); 41 | } 42 | 43 | public function getPxPostUsername() 44 | { 45 | return $this->getParameter('pxPostUsername'); 46 | } 47 | 48 | public function setPxPostUsername($value) 49 | { 50 | return $this->setParameter('pxPostUsername', $value); 51 | } 52 | 53 | public function getPxPostPassword() 54 | { 55 | return $this->getParameter('pxPostPassword'); 56 | } 57 | 58 | public function setPxPostPassword($value) 59 | { 60 | return $this->setParameter('pxPostPassword', $value); 61 | } 62 | 63 | public function getTxnRef() 64 | { 65 | return $this->getParameter('txnRef'); 66 | } 67 | 68 | public function setTxnRef($value) 69 | { 70 | return $this->setParameter('txnRef', $value); 71 | } 72 | 73 | public function getData() 74 | { 75 | 76 | $this->validate('amount', 'currency', 'transactionId', 'returnUrl'); 77 | 78 | $data = new SimpleXMLElement(''); 79 | $data->addAttribute('xmlns', $this->namespace); 80 | $data->username = $this->getUsername(); 81 | $data->password = $this->getPassword(); 82 | 83 | $tranDetail = $data->addChild('tranDetail'); 84 | $tranDetail->amount = $this->getAmount(); 85 | $tranDetail->currency = $this->getCurrency(); 86 | $tranDetail->enableAddBillCard = $this->getAddBillCard(); 87 | $tranDetail->merchantReference = $this->getTransactionId(); 88 | $tranDetail->returnUrl = $this->getReturnUrl(); 89 | $tranDetail->txnType = $this->action; 90 | $tranDetail->txnRef = $this->getTransactionId(); 91 | return $data; 92 | } 93 | 94 | public function sendData($data) 95 | { 96 | 97 | $document = new DOMDocument('1.0', 'utf-8'); 98 | 99 | $envelope = $document->appendChild( 100 | $document->createElementNS('http://schemas.xmlsoap.org/soap/envelope/', 'soap:Envelope') 101 | ); 102 | 103 | $body = $envelope->appendChild($document->createElement('soap:Body')); 104 | 105 | $body->appendChild($document->importNode(dom_import_simplexml($data), true)); 106 | 107 | $headers = array( 108 | 'Content-Type' => 'text/xml; charset=utf-8', 109 | 'SOAPAction' => $this->namespace.'/IPxFusion/'.$data->getName(), 110 | ); 111 | 112 | $httpResponse = $this->httpClient->request('POST', $this->endpoint, $headers, $document->saveXML()); 113 | 114 | return $this->createResponse($httpResponse->getBody()); 115 | } 116 | 117 | protected function createResponse($data) 118 | { 119 | return $this->response = new PxFusionPurchaseResponse($this, $data); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/Message/PxFusionPurchaseResponse.php: -------------------------------------------------------------------------------- 1 | request = $request; 26 | 27 | $responseDom = new DOMDocument; 28 | $responseDom->loadXML($data); 29 | 30 | $result = simplexml_import_dom($responseDom->documentElement->firstChild->firstChild->firstChild); 31 | 32 | $this->data = $result->children($this->namespace); 33 | } 34 | 35 | public function isSuccessful() 36 | { 37 | return false; 38 | } 39 | 40 | public function isRedirect() 41 | { 42 | return ((string) $this->data->success === 'true'); 43 | } 44 | 45 | public function isTransparentRedirect() 46 | { 47 | return true; 48 | } 49 | 50 | public function getSessionId() 51 | { 52 | if ($this->isRedirect()) { 53 | return (string) $this->data->sessionId; 54 | } 55 | } 56 | 57 | public function getRedirectUrl() 58 | { 59 | if ($this->isRedirect()) { 60 | return 'https://sec.windcave.com/pxmi3/pxfusionauth'; 61 | } 62 | } 63 | 64 | public function getRedirectMethod() 65 | { 66 | return 'POST'; 67 | } 68 | 69 | public function getRedirectData() 70 | { 71 | if ($this->isRedirect()) { 72 | return array( 73 | 'SessionId' => $this->getSessionId(), 74 | ); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Message/PxPayAuthorizeRequest.php: -------------------------------------------------------------------------------- 1 | getParameter('username'); 46 | } 47 | 48 | /** 49 | * Set the PxPay PxPayUserId 50 | * 51 | * @param string $value 52 | * @return $this 53 | */ 54 | public function setUsername($value) 55 | { 56 | return $this->setParameter('username', $value); 57 | } 58 | 59 | /** 60 | * Get the PxPay PxPayKey 61 | * 62 | * @return mixed 63 | */ 64 | public function getPassword() 65 | { 66 | return $this->getParameter('password'); 67 | } 68 | 69 | /** 70 | * Set the PxPay PxPayKey 71 | * 72 | * @param string $value 73 | * @return $this 74 | */ 75 | public function setPassword($value) 76 | { 77 | return $this->setParameter('password', $value); 78 | } 79 | 80 | public function getPxPostUsername() 81 | { 82 | return $this->getParameter('pxPostUsername'); 83 | } 84 | 85 | public function setPxPostUsername($value) 86 | { 87 | return $this->setParameter('pxPostUsername', $value); 88 | } 89 | 90 | public function getPxPostPassword() 91 | { 92 | return $this->getParameter('pxPostPassword'); 93 | } 94 | 95 | public function setPxPostPassword($value) 96 | { 97 | return $this->setParameter('pxPostPassword', $value); 98 | } 99 | 100 | public function getEndpoint() 101 | { 102 | return $this->getTestMode() === true ? $this->testEndpoint : $this->liveEndpoint; 103 | } 104 | 105 | /** 106 | * Get the PxPay TxnData1 107 | * 108 | * Optional free text field that can be used to store information against a 109 | * transaction. Returned in the response and can be retrieved from DPS 110 | * reports. 111 | * 112 | * @return mixed 113 | */ 114 | public function getTransactionData1() 115 | { 116 | return $this->getParameter('transactionData1'); 117 | } 118 | 119 | /** 120 | * Set the PxPay TxnData1 121 | * 122 | * @param string $value Max 255 bytes 123 | * @return $this 124 | */ 125 | public function setTransactionData1($value) 126 | { 127 | return $this->setParameter('transactionData1', $value); 128 | } 129 | 130 | /** 131 | * Get the PxPay TxnData2 132 | * 133 | * Optional free text field that can be used to store information against a 134 | * transaction. Returned in the response and can be retrieved from DPS 135 | * reports. 136 | * 137 | * @return mixed 138 | */ 139 | public function getTransactionData2() 140 | { 141 | return $this->getParameter('transactionData2'); 142 | } 143 | 144 | /** 145 | * Set the PxPay TxnData2 146 | * 147 | * @param string $value Max 255 bytes 148 | * @return $this 149 | */ 150 | public function setTransactionData2($value) 151 | { 152 | return $this->setParameter('transactionData2', $value); 153 | } 154 | 155 | /** 156 | * Get the PxPay TxnData3 157 | * 158 | * Optional free text field that can be used to store information against a 159 | * transaction. Returned in the response and can be retrieved from DPS 160 | * reports. 161 | * 162 | * @return mixed 163 | */ 164 | public function getTransactionData3() 165 | { 166 | return $this->getParameter('transactionData3'); 167 | } 168 | 169 | /** 170 | * Set the TxnData3 field on the request 171 | * 172 | * @param string $value Max 255 bytes 173 | * @return $this 174 | */ 175 | public function setTransactionData3($value) 176 | { 177 | return $this->setParameter('transactionData3', $value); 178 | } 179 | 180 | /** 181 | * Get the PxPay Opt 182 | * 183 | * Optional parameter can be used to set a timeout value for the hosted payments page 184 | * or block/allow specified card BIN ranges. 185 | * 186 | * @return mixed 187 | */ 188 | public function getOpt() 189 | { 190 | return $this->getParameter('opt'); 191 | } 192 | 193 | /** 194 | * Set the Opt field on the request 195 | * 196 | * @param string $value Max 64 bytes 197 | * @return $this 198 | */ 199 | public function setOpt($value) 200 | { 201 | return $this->setParameter('opt', $value); 202 | } 203 | 204 | /** 205 | * Get the ForcePaymentMethod Opt 206 | * 207 | * Optional parameter can be used to set force a payment method for the hosted payments page 208 | * and ignore any other payment methods enabled on the account. 209 | * 210 | * @return mixed 211 | */ 212 | public function getForcePaymentMethod() 213 | { 214 | return $this->getParameter('forcePaymentMethod'); 215 | } 216 | 217 | /** 218 | * Set the ForcePaymentMethod field on the request 219 | * 220 | * @param string $value The payment method to force e.g. 'Card', 'Account2Account', etc. 221 | * 222 | * @return mixed 223 | */ 224 | public function setForcePaymentMethod($value) 225 | { 226 | return $this->setParameter('forcePaymentMethod', $value); 227 | } 228 | 229 | 230 | /** 231 | * Get the transaction data 232 | * 233 | * @return SimpleXMLElement 234 | */ 235 | public function getData() 236 | { 237 | $this->validate('amount', 'returnUrl'); 238 | 239 | $data = new SimpleXMLElement(''); 240 | $data->PxPayUserId = $this->getUsername(); 241 | $data->PxPayKey = $this->getPassword(); 242 | $data->TxnType = $this->action; 243 | $data->AmountInput = $this->getAmount(); 244 | $data->CurrencyInput = $this->getCurrency(); 245 | $data->UrlSuccess = $this->getReturnUrl(); 246 | $data->UrlFail = $this->getCancelUrl() ?: $this->getReturnUrl(); 247 | 248 | if ($this->getDescription()) { 249 | $data->MerchantReference = $this->getDescription(); 250 | } 251 | 252 | if ($this->getTransactionId()) { 253 | $data->TxnId = $this->getTransactionId(); 254 | } 255 | 256 | if ($this->getTransactionData1()) { 257 | $data->TxnData1 = $this->getTransactionData1(); 258 | } 259 | 260 | if ($this->getTransactionData2()) { 261 | $data->TxnData2 = $this->getTransactionData2(); 262 | } 263 | 264 | if ($this->getTransactionData3()) { 265 | $data->TxnData3 = $this->getTransactionData3(); 266 | } 267 | 268 | if ($this->getCardReference()) { 269 | $data->DpsBillingId = $this->getCardReference(); 270 | } 271 | 272 | if ($this->getOpt()) { 273 | $data->Opt = $this->getOpt(); 274 | } 275 | 276 | if ($this->getForcePaymentMethod()) { 277 | $data->ForcePaymentMethod = $this->getForcePaymentMethod(); 278 | } 279 | 280 | return $data; 281 | } 282 | 283 | /** 284 | * Send request 285 | * 286 | * @param SimpleXMLElement $data 287 | * @return Omnipay\PaymentExpress\Message\PxPayAuthorizeResponse 288 | */ 289 | public function sendData($data) 290 | { 291 | $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [], $data->asXML()); 292 | 293 | return $this->createResponse($httpResponse->getBody()->getContents()); 294 | } 295 | 296 | /** 297 | * Create an authorize response 298 | * 299 | * @param SimpleXMLElement $data 300 | * @return Omnipay\PaymentExpress\Message\PxPayAuthorizeResponse 301 | */ 302 | protected function createResponse($data) 303 | { 304 | return $this->response = new PxPayAuthorizeResponse($this, simplexml_load_string($data)); 305 | } 306 | 307 | /** 308 | * Get the request return URL. 309 | * 310 | * @return string 311 | */ 312 | public function getReturnUrl() 313 | { 314 | return htmlentities($this->getParameter('returnUrl')); 315 | } 316 | } 317 | -------------------------------------------------------------------------------- /src/Message/PxPayAuthorizeResponse.php: -------------------------------------------------------------------------------- 1 | data['valid']) && !empty($this->data->URI)); 21 | } 22 | 23 | public function getTransactionReference() 24 | { 25 | return null; 26 | } 27 | 28 | public function getMessage() 29 | { 30 | if (!$this->isRedirect()) { 31 | return $this->data->URI ? (string) $this->data->URI : (string) $this->data->ResponseText; 32 | } 33 | } 34 | 35 | public function getRedirectUrl() 36 | { 37 | if ($this->isRedirect()) { 38 | return (string) $this->data->URI; 39 | } 40 | } 41 | 42 | public function getRedirectMethod() 43 | { 44 | return 'GET'; 45 | } 46 | 47 | public function getRedirectData() 48 | { 49 | return null; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Message/PxPayCompleteAuthorizeRequest.php: -------------------------------------------------------------------------------- 1 | httpRequest->query->get('result'); 16 | if (empty($result)) { 17 | $result = $this->httpRequest->request->get('result'); 18 | if (empty($result)) { 19 | throw new InvalidResponseException; 20 | } 21 | } 22 | 23 | // validate dps response 24 | $data = new SimpleXMLElement(''); 25 | $data->PxPayUserId = $this->getUsername(); 26 | $data->PxPayKey = $this->getPassword(); 27 | $data->Response = $result; 28 | 29 | return $data; 30 | } 31 | 32 | protected function createResponse($data) 33 | { 34 | return $this->response = new Response($this, simplexml_load_string($data)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Message/PxPayCreateCardRequest.php: -------------------------------------------------------------------------------- 1 | getParameter('action'); 13 | } 14 | 15 | public function setAction($value) 16 | { 17 | return $this->setParameter('action', $value); 18 | } 19 | 20 | public function getData() 21 | { 22 | $this->setAmount($this->getAmount() ? $this->getAmount() : '1.00'); 23 | 24 | 25 | if ($this->getAction()) { 26 | $this->action = $this->getAction(); 27 | } 28 | 29 | $data = parent::getData(); 30 | $data->EnableAddBillCard = 1; 31 | 32 | return $data; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Message/PxPayPurchaseRequest.php: -------------------------------------------------------------------------------- 1 | getParameter('username'); 19 | } 20 | 21 | public function setUsername($value) 22 | { 23 | return $this->setParameter('username', $value); 24 | } 25 | 26 | public function getPassword() 27 | { 28 | return $this->getParameter('password'); 29 | } 30 | 31 | public function setPassword($value) 32 | { 33 | return $this->setParameter('password', $value); 34 | } 35 | 36 | public function getEndpoint() 37 | { 38 | return $this->getTestMode() === true ? $this->testEndpoint : $this->liveEndpoint; 39 | } 40 | 41 | /** 42 | * @return mixed 43 | */ 44 | public function getReceiptEmail() 45 | { 46 | return $this->getParameter('ReceiptEmail'); 47 | } 48 | 49 | /** 50 | * @param mixed $email 51 | * @return $this 52 | */ 53 | public function setReceiptEmail($email) 54 | { 55 | $this->setParameter('ReceiptEmail', $email); 56 | 57 | return $this; 58 | } 59 | 60 | /** 61 | * Get the PxPost TxnData1 62 | * 63 | * Optional free text field that can be used to store information against a 64 | * transaction. Returned in the response and can be retrieved from DPS 65 | * reports. 66 | * 67 | * @return mixed 68 | */ 69 | public function getTransactionData1() 70 | { 71 | return $this->getParameter('transactionData1'); 72 | } 73 | 74 | /** 75 | * Set the PxPost TxnData1 76 | * 77 | * @param string $value Max 255 bytes 78 | * @return $this 79 | */ 80 | public function setTransactionData1($value) 81 | { 82 | return $this->setParameter('transactionData1', $value); 83 | } 84 | 85 | /** 86 | * Get the PxPost TxnData2 87 | * 88 | * Optional free text field that can be used to store information against a 89 | * transaction. Returned in the response and can be retrieved from DPS 90 | * reports. 91 | * 92 | * @return mixed 93 | */ 94 | public function getTransactionData2() 95 | { 96 | return $this->getParameter('transactionData2'); 97 | } 98 | 99 | /** 100 | * Set the PxPost TxnData2 101 | * 102 | * @param string $value Max 255 bytes 103 | * @return $this 104 | */ 105 | public function setTransactionData2($value) 106 | { 107 | return $this->setParameter('transactionData2', $value); 108 | } 109 | 110 | /** 111 | * Get the PxPost TxnData3 112 | * 113 | * Optional free text field that can be used to store information against a 114 | * transaction. Returned in the response and can be retrieved from DPS 115 | * reports. 116 | * 117 | * @return mixed 118 | */ 119 | public function getTransactionData3() 120 | { 121 | return $this->getParameter('transactionData3'); 122 | } 123 | 124 | /** 125 | * Set the PxPost TxnData3 126 | * 127 | * @param string $value Max 255 bytes 128 | * @return $this 129 | */ 130 | public function setTransactionData3($value) 131 | { 132 | return $this->setParameter('transactionData3', $value); 133 | } 134 | 135 | protected function getBaseData() 136 | { 137 | $data = new \SimpleXMLElement(''); 138 | $data->PostUsername = $this->getUsername(); 139 | $data->PostPassword = $this->getPassword(); 140 | $data->TxnType = $this->action; 141 | 142 | return $data; 143 | } 144 | 145 | public function getData() 146 | { 147 | $this->validate('amount'); 148 | 149 | $data = $this->getBaseData(); 150 | $data->InputCurrency = $this->getCurrency(); 151 | $data->Amount = $this->getAmount(); 152 | 153 | if ($this->getDescription()) { 154 | $data->MerchantReference = $this->getDescription(); 155 | } 156 | 157 | if ($this->getTransactionId()) { 158 | $data->TxnId = $this->getTransactionId(); 159 | } 160 | 161 | if ($this->getTransactionData1()) { 162 | $data->TxnData1 = $this->getTransactionData1(); 163 | } 164 | 165 | if ($this->getTransactionData2()) { 166 | $data->TxnData2 = $this->getTransactionData2(); 167 | } 168 | 169 | if ($this->getTransactionData3()) { 170 | $data->TxnData3 = $this->getTransactionData3(); 171 | } 172 | 173 | if ($this->getCardReference()) { 174 | $data->DpsBillingId = $this->getCardReference(); 175 | } elseif ($this->getCard()) { 176 | $this->getCard()->validate(); 177 | $data->CardNumber = $this->getCard()->getNumber(); 178 | $data->CardHolderName = $this->getCard()->getName(); 179 | $data->DateExpiry = $this->getCard()->getExpiryDate('my'); 180 | $data->Cvc2 = $this->getCard()->getCvv(); 181 | } else { 182 | // either cardReference or card is required 183 | $this->validate('card'); 184 | } 185 | 186 | if ($this->getReceiptEmail()) { 187 | $data->ReceiptEmail = $this->getReceiptEmail(); 188 | } 189 | 190 | return $data; 191 | } 192 | 193 | public function sendData($data) 194 | { 195 | $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [], $data->asXML()); 196 | 197 | $xml = simplexml_load_string($httpResponse->getBody()->getContents()); 198 | 199 | return $this->response = new Response($this, $xml); 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /src/Message/PxPostCaptureRequest.php: -------------------------------------------------------------------------------- 1 | validate('transactionReference', 'amount'); 15 | 16 | $data = $this->getBaseData(); 17 | $data->DpsTxnRef = $this->getTransactionReference(); 18 | $data->Amount = $this->getAmount(); 19 | 20 | return $data; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Message/PxPostCreateCardRequest.php: -------------------------------------------------------------------------------- 1 | validate('card'); 13 | $this->getCard()->validate(); 14 | 15 | $data = $this->getBaseData(); 16 | $data->InputCurrency = $this->getCurrency(); 17 | $data->Amount = '1.00'; 18 | $data->EnableAddBillCard = 1; 19 | $data->CardNumber = $this->getCard()->getNumber(); 20 | $data->CardHolderName = $this->getCard()->getName(); 21 | $data->DateExpiry = $this->getCard()->getExpiryDate('my'); 22 | $data->Cvc2 = $this->getCard()->getCvv(); 23 | 24 | return $data; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Message/PxPostPurchaseRequest.php: -------------------------------------------------------------------------------- 1 | data->Success; 15 | } 16 | 17 | public function getTransactionReference() 18 | { 19 | return empty($this->data->DpsTxnRef) ? null : (string) $this->data->DpsTxnRef; 20 | } 21 | 22 | public function getTransactionId() 23 | { 24 | return empty($this->data->TxnId) ? null : (string) $this->data->TxnId; 25 | } 26 | 27 | public function getCardReference() 28 | { 29 | if (! empty($this->data->Transaction->DpsBillingId)) { 30 | return (string) $this->data->Transaction->DpsBillingId; 31 | } elseif (! empty($this->data->DpsBillingId)) { 32 | return (string) $this->data->DpsBillingId; 33 | } 34 | 35 | return null; 36 | } 37 | 38 | public function getMessage() 39 | { 40 | if (isset($this->data->HelpText)) { 41 | return (string) $this->data->HelpText; 42 | } else { 43 | return (string) $this->data->ResponseText; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/PxFusionGateway.php: -------------------------------------------------------------------------------- 1 | '', 23 | 'password' => '', 24 | ); 25 | } 26 | 27 | public function getUsername() 28 | { 29 | return $this->getParameter('username'); 30 | } 31 | 32 | public function setUsername($value) 33 | { 34 | return $this->setParameter('username', $value); 35 | } 36 | 37 | public function getPassword() 38 | { 39 | return $this->getParameter('password'); 40 | } 41 | 42 | public function setPassword($value) 43 | { 44 | return $this->setParameter('password', $value); 45 | } 46 | 47 | 48 | public function getPxPostUsername() 49 | { 50 | return $this->getParameter('pxPostUsername'); 51 | } 52 | 53 | public function setPxPostUsername($value) 54 | { 55 | return $this->setParameter('pxPostUsername', $value); 56 | } 57 | 58 | public function getPxPostPassword() 59 | { 60 | return $this->getParameter('pxPostPassword'); 61 | } 62 | 63 | public function setPxPostPassword($value) 64 | { 65 | return $this->setParameter('pxPostPassword', $value); 66 | } 67 | 68 | public function purchase(array $parameters = array()) 69 | { 70 | if (!empty($parameters['cardReference']) && $this->getPxPostPassword() && $this->getPxPostUsername()) { 71 | $gateway = Omnipay::create('PaymentExpress_PxPost'); 72 | $gateway->setPassword($this->getPxPostPassword()); 73 | $gateway->setUserName($this->getPxPostUsername()); 74 | return $gateway->purchase($parameters); 75 | } 76 | return $this->createRequest('\Omnipay\PaymentExpress\Message\PxFusionPurchaseRequest', $parameters); 77 | } 78 | 79 | public function completePurchase(array $parameters = array()) 80 | { 81 | return $this->createRequest('\Omnipay\PaymentExpress\Message\PxFusionCompletePurchaseRequest', $parameters); 82 | } 83 | 84 | public function createCard(array $parameters = array()) 85 | { 86 | return $this->createRequest('\Omnipay\PaymentExpress\Message\PxFusionCreateCardRequest', $parameters); 87 | } 88 | 89 | public function completeCreateCard(array $parameters = array()) 90 | { 91 | return $this->completeAuthorize($parameters); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/PxPayGateway.php: -------------------------------------------------------------------------------- 1 | '', 25 | 'password' => '', 26 | 'pxPostUsername' => '', 27 | 'pxPostPassword' => '', 28 | 'testMode' => false, 29 | ); 30 | } 31 | 32 | public function getUsername() 33 | { 34 | return $this->getParameter('username'); 35 | } 36 | 37 | public function setUsername($value) 38 | { 39 | return $this->setParameter('username', $value); 40 | } 41 | 42 | public function getPassword() 43 | { 44 | return $this->getParameter('password'); 45 | } 46 | 47 | public function setPassword($value) 48 | { 49 | return $this->setParameter('password', $value); 50 | } 51 | 52 | public function getPxPostUsername() 53 | { 54 | return $this->getParameter('pxPostUsername'); 55 | } 56 | 57 | public function setPxPostUsername($value) 58 | { 59 | return $this->setParameter('pxPostUsername', $value); 60 | } 61 | 62 | 63 | public function getPxPostPassword() 64 | { 65 | return $this->getParameter('pxPostPassword'); 66 | } 67 | 68 | public function setPxPostPassword($value) 69 | { 70 | return $this->setParameter('pxPostPassword', $value); 71 | } 72 | 73 | public function authorize(array $parameters = array()) 74 | { 75 | return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPayAuthorizeRequest', $parameters); 76 | } 77 | 78 | public function completeAuthorize(array $parameters = array()) 79 | { 80 | return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPayCompleteAuthorizeRequest', $parameters); 81 | } 82 | 83 | public function purchase(array $parameters = array()) 84 | { 85 | if (!empty($parameters['cardReference']) && $this->getPxPostPassword() && $this->getPxPostUsername()) { 86 | $gateway = Omnipay::create('PaymentExpress_PxPost'); 87 | $gateway->setPassword($this->getPxPostPassword()); 88 | $gateway->setUserName($this->getPxPostUsername()); 89 | return $gateway->purchase($parameters); 90 | } 91 | return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPayPurchaseRequest', $parameters); 92 | } 93 | 94 | public function completePurchase(array $parameters = array()) 95 | { 96 | return $this->completeAuthorize($parameters); 97 | } 98 | 99 | public function createCard(array $parameters = array()) 100 | { 101 | return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPayCreateCardRequest', $parameters); 102 | } 103 | 104 | public function completeCreateCard(array $parameters = array()) 105 | { 106 | return $this->completeAuthorize($parameters); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/PxPostGateway.php: -------------------------------------------------------------------------------- 1 | '', 25 | 'password' => '', 26 | 'testMode' => false, 27 | ); 28 | } 29 | 30 | public function getUsername() 31 | { 32 | return $this->getParameter('username'); 33 | } 34 | 35 | public function setUsername($value) 36 | { 37 | return $this->setParameter('username', $value); 38 | } 39 | 40 | public function getPassword() 41 | { 42 | return $this->getParameter('password'); 43 | } 44 | 45 | public function setPassword($value) 46 | { 47 | return $this->setParameter('password', $value); 48 | } 49 | 50 | public function authorize(array $parameters = array()) 51 | { 52 | return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPostAuthorizeRequest', $parameters); 53 | } 54 | 55 | public function capture(array $parameters = array()) 56 | { 57 | return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPostCaptureRequest', $parameters); 58 | } 59 | 60 | public function purchase(array $parameters = array()) 61 | { 62 | return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPostPurchaseRequest', $parameters); 63 | } 64 | 65 | public function refund(array $parameters = array()) 66 | { 67 | return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPostRefundRequest', $parameters); 68 | } 69 | 70 | public function createCard(array $parameters = array()) 71 | { 72 | return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPostCreateCardRequest', $parameters); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/Message/PxPayAuthorizeResponseTest.php: -------------------------------------------------------------------------------- 1 | getMockHttpResponse('PxPayPurchaseSuccess.txt'); 12 | $xml = simplexml_load_string($httpResponse->getBody()->getContents()); 13 | $response = new PxPayAuthorizeResponse($this->getMockRequest(), $xml); 14 | 15 | $this->assertFalse($response->isSuccessful()); 16 | $this->assertTrue($response->isRedirect()); 17 | $this->assertNull($response->getTransactionReference()); 18 | $this->assertNull($response->getMessage()); 19 | $this->assertSame('https://sec.windcave.com/pxpay/pxpay.aspx?userid=Developer&request=v5H7JrBTzH-4Whs__1iQnz4RGSb9qxRKNR4kIuDP8kIkQzIDiIob9GTIjw_9q_AdRiR47ViWGVx40uRMu52yz2mijT39YtGeO7cZWrL5rfnx0Mc4DltIHRnIUxy1EO1srkNpxaU8fT8_1xMMRmLa-8Fd9bT8Oq0BaWMxMquYa1hDNwvoGs1SJQOAJvyyKACvvwsbMCC2qJVyN0rlvwUoMtx6gGhvmk7ucEsPc_Cyr5kNl3qURnrLKxINnS0trdpU4kXPKOlmT6VacjzT1zuj_DnrsWAPFSFq-hGsow6GpKKciQ0V0aFbAqECN8rl_c-aZWFFy0gkfjnUM4qp6foS0KMopJlPzGAgMjV6qZ0WfleOT64c3E-FRLMP5V_-mILs8a', $response->getRedirectUrl()); 20 | $this->assertSame('GET', $response->getRedirectMethod()); 21 | } 22 | 23 | public function testPurchaseFailure() 24 | { 25 | $httpResponse = $this->getMockHttpResponse('PxPayPurchaseFailure.txt'); 26 | $xml = simplexml_load_string($httpResponse->getBody()->getContents()); 27 | $response = new PxPayAuthorizeResponse($this->getMockRequest(), $xml); 28 | 29 | $this->assertFalse($response->isSuccessful()); 30 | $this->assertFalse($response->isRedirect()); 31 | $this->assertNull($response->getTransactionReference()); 32 | $this->assertSame('Invalid Key', $response->getMessage()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/Message/PxPayCreateCardRequestTest.php: -------------------------------------------------------------------------------- 1 | getHttpClient(), $this->getHttpRequest()); 26 | $request->initialize( 27 | array( 28 | 'returnUrl' => 'abc123', 29 | 'action' => 'Purchase', 30 | ) 31 | ); 32 | $request->getData(); 33 | $this->assertEquals('Purchase', $request->getAction()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/Message/ResponseTest.php: -------------------------------------------------------------------------------- 1 | getMockHttpResponse('PxPostPurchaseSuccess.txt'); 12 | $xml = simplexml_load_string($httpResponse->getBody()->getContents()); 13 | $response = new Response($this->getMockRequest(), $xml); 14 | 15 | $this->assertTrue($response->isSuccessful()); 16 | $this->assertFalse($response->isRedirect()); 17 | $this->assertSame('000000030884cdc6', $response->getTransactionReference()); 18 | $this->assertNull($response->getCardReference()); 19 | $this->assertSame('Transaction Approved', $response->getMessage()); 20 | } 21 | 22 | public function testPurchaseFailure() 23 | { 24 | $httpResponse = $this->getMockHttpResponse('PxPostPurchaseFailure.txt'); 25 | $xml = simplexml_load_string($httpResponse->getBody()->getContents()); 26 | $response = new Response($this->getMockRequest(), $xml); 27 | 28 | $this->assertFalse($response->isSuccessful()); 29 | $this->assertFalse($response->isRedirect()); 30 | $this->assertNull($response->getTransactionReference()); 31 | $this->assertNull($response->getCardReference()); 32 | $this->assertSame('The transaction was Declined (U5)', $response->getMessage()); 33 | } 34 | 35 | public function testCompletePurchaseSuccess() 36 | { 37 | $httpResponse = $this->getMockHttpResponse('PxPayCompletePurchaseSuccess.txt'); 38 | $xml = simplexml_load_string($httpResponse->getBody()->getContents()); 39 | $response = new Response($this->getMockRequest(), $xml); 40 | 41 | $this->assertTrue($response->isSuccessful()); 42 | $this->assertFalse($response->isRedirect()); 43 | $this->assertSame('0000000103f5dc65', $response->getTransactionReference()); 44 | $this->assertNull($response->getCardReference()); 45 | $this->assertSame('APPROVED', $response->getMessage()); 46 | } 47 | 48 | public function testCompletePurchaseFailure() 49 | { 50 | $httpResponse = $this->getMockHttpResponse('PxPayCompletePurchaseFailure.txt'); 51 | $xml = simplexml_load_string($httpResponse->getBody()->getContents()); 52 | $response = new Response($this->getMockRequest(), $xml); 53 | 54 | $this->assertFalse($response->isSuccessful()); 55 | $this->assertFalse($response->isRedirect()); 56 | $this->assertNull($response->getTransactionReference()); 57 | $this->assertNull($response->getCardReference()); 58 | $this->assertSame('Length of the data to decrypt is invalid.', $response->getMessage()); 59 | } 60 | 61 | public function testCreateCardSuccess() 62 | { 63 | $httpResponse = $this->getMockHttpResponse('PxPostCreateCardSuccess.txt'); 64 | $xml = simplexml_load_string($httpResponse->getBody()->getContents()); 65 | $response = new Response($this->getMockRequest(), $xml); 66 | 67 | $this->assertTrue($response->isSuccessful()); 68 | $this->assertFalse($response->isRedirect()); 69 | $this->assertSame('00000001040c73ea', $response->getTransactionReference()); 70 | $this->assertSame('0000010009328404', $response->getCardReference()); 71 | $this->assertSame('Transaction Approved', $response->getMessage()); 72 | } 73 | 74 | public function testCreateCardFailure() 75 | { 76 | $httpResponse = $this->getMockHttpResponse('PxPostCreateCardFailure.txt'); 77 | $xml = simplexml_load_string($httpResponse->getBody()->getContents()); 78 | $response = new Response($this->getMockRequest(), $xml); 79 | 80 | $this->assertFalse($response->isSuccessful()); 81 | $this->assertFalse($response->isRedirect()); 82 | $this->assertNull($response->getTransactionReference()); 83 | $this->assertNull($response->getCardReference()); 84 | $this->assertSame('An Invalid Card Number was entered. Check the card number', $response->getMessage()); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /tests/Mock/PxFusionCompletePurchaseFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | 3 | 5.00JOHN SMITHVisa411111........15554NZDNotUsed01162014-11-19T00:00:00000000011a0ae59776DECLINED00000100497868209a55fb72393d8d011false00000100497868209a55fb72393d8d01F2833952Purchase 4 | -------------------------------------------------------------------------------- /tests/Mock/PxFusionCompletePurchaseSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | 3 | 15.00123024spree:user_id:87ALICE 5 | JONESVisa411111........11554NZDNotUsed03152013-09-23T00:00:000000010024838715000000010a838c1c00APPROVED000001001974701382c9911e025dc3010false000001001974701382c9911e025dc301spree:order_id:842spree:user_id:871spree:user_email:alice@example.com2BC20210spree:Purchase 9 | -------------------------------------------------------------------------------- /tests/Mock/PxFusionPurchaseFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | 3 | false 6 | -------------------------------------------------------------------------------- /tests/Mock/PxFusionPurchaseSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | 3 | 000001001974701382c9911e025dc301true000001001974701382c9911e025dc301 6 | -------------------------------------------------------------------------------- /tests/Mock/PxPayCompleteCreateCardFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Server: DPS_PX_SERVER 3 | Cache-Control: private 4 | Content-Length: 744 5 | Content-Type: application/xhtml+xml; charset=utf-8 6 | Expires: Sat, 23 Feb 2013 15:14:26 GMT 7 | Date: Sat, 23 Feb 2013 15:15:26 GMT 8 | 9 | Length of the data to decrypt is invalid. 10 | -------------------------------------------------------------------------------- /tests/Mock/PxPayCompleteCreateCardSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Server: DPS_PX_SERVER 3 | Cache-Control: private 4 | Content-Length: 866 5 | Content-Type: application/xhtml+xml; charset=utf-8 6 | Expires: Sat, 23 Feb 2013 15:11:45 GMT 7 | Date: Sat, 23 Feb 2013 15:12:45 GMT 8 | 9 | 1.00115141Visa411111........111234000000030a1806f01APPROVED0000030007487668ABCDNZDAuthNZD122.62.25.442BC20210201504010NotUsed00 10 | -------------------------------------------------------------------------------- /tests/Mock/PxPayCompletePurchaseFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Server: DPS_PX_SERVER 3 | Cache-Control: private 4 | Content-Length: 744 5 | Content-Type: application/xhtml+xml; charset=utf-8 6 | Expires: Sat, 23 Feb 2013 15:14:26 GMT 7 | Date: Sat, 23 Feb 2013 15:15:26 GMT 8 | 9 | Length of the data to decrypt is invalid. 10 | -------------------------------------------------------------------------------- /tests/Mock/PxPayCompletePurchaseSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Server: DPS_PX_SERVER 3 | Cache-Control: private 4 | Content-Length: 866 5 | Content-Type: application/xhtml+xml; charset=utf-8 6 | Expires: Sat, 23 Feb 2013 15:11:45 GMT 7 | Date: Sat, 23 Feb 2013 15:12:45 GMT 8 | 9 | 1AuthNZDTestReferenceBusiness NameBusiness PhoneBusiness ID041211VisaJDFKL FDJKSL411111........110819115.67.229.192P075985DA31094D80000000103f5dc6510.00NZD20130224APPROVED0NotUsed00 10 | -------------------------------------------------------------------------------- /tests/Mock/PxPayCreateCardFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Server: DPS_PX_SERVER 3 | Cache-Control: private 4 | Content-Length: 51 5 | Content-Type: application/xhtml+xml; charset=utf-8 6 | Expires: Sat, 23 Feb 2013 14:54:40 GMT 7 | Date: Sat, 23 Feb 2013 14:55:40 GMT 8 | 9 | userpass too short 10 | -------------------------------------------------------------------------------- /tests/Mock/PxPayCreateCardSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Server: DPS_PX_SERVER 3 | Cache-Control: private 4 | Content-Length: 507 5 | Content-Type: application/xhtml+xml; charset=utf-8 6 | Expires: Sat, 23 Feb 2013 14:56:42 GMT 7 | Date: Sat, 23 Feb 2013 14:57:41 GMT 8 | 9 | https://sec.windcave.com/pxmi3/EF4054F622D6C4C1B0FA3975F5B37D5883A7AA411DF778AEBA9C4E3CBE1B394B50478552233E3FBD7 10 | -------------------------------------------------------------------------------- /tests/Mock/PxPayPurchaseFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Server: DPS_PX_SERVER 3 | Cache-Control: private 4 | Content-Length: 51 5 | Content-Type: application/xhtml+xml; charset=utf-8 6 | Expires: Sat, 23 Feb 2013 14:54:40 GMT 7 | Date: Sat, 23 Feb 2013 14:55:40 GMT 8 | 9 | Invalid Key 10 | -------------------------------------------------------------------------------- /tests/Mock/PxPayPurchaseSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Server: DPS_PX_SERVER 3 | Cache-Control: private 4 | Content-Length: 507 5 | Content-Type: application/xhtml+xml; charset=utf-8 6 | Expires: Sat, 23 Feb 2013 14:56:42 GMT 7 | Date: Sat, 23 Feb 2013 14:57:41 GMT 8 | 9 | https://sec.windcave.com/pxpay/pxpay.aspx?userid=Developer&request=v5H7JrBTzH-4Whs__1iQnz4RGSb9qxRKNR4kIuDP8kIkQzIDiIob9GTIjw_9q_AdRiR47ViWGVx40uRMu52yz2mijT39YtGeO7cZWrL5rfnx0Mc4DltIHRnIUxy1EO1srkNpxaU8fT8_1xMMRmLa-8Fd9bT8Oq0BaWMxMquYa1hDNwvoGs1SJQOAJvyyKACvvwsbMCC2qJVyN0rlvwUoMtx6gGhvmk7ucEsPc_Cyr5kNl3qURnrLKxINnS0trdpU4kXPKOlmT6VacjzT1zuj_DnrsWAPFSFq-hGsow6GpKKciQ0V0aFbAqECN8rl_c-aZWFFy0gkfjnUM4qp6foS0KMopJlPzGAgMjV6qZ0WfleOT64c3E-FRLMP5V_-mILs8a 10 | -------------------------------------------------------------------------------- /tests/Mock/PxPostCreateCardFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Server: DPS_PX_SERVER 3 | Cache-Control: private 4 | Content-Length: 2618 5 | Content-Type: application/xhtml+xml; charset=utf-8 6 | Expires: Tue, 26 Feb 2013 16:55:13 GMT 7 | Date: Tue, 26 Feb 2013 16:56:12 GMT 8 | 9 | 0QK2013022616561820130226165618UTC000.001.00554554NZD1.00NZDFJKSDL FJDKSL19800101Auth000000........0004199000QKInvalid Card Number00INVALID CARD NUMBERAn Invalid Card Number was entered. Check the card numberAn Invalid Card Number was entered. Check the card numberINVALID CARD NUMBERAn Invalid Card Number was entered. Check the card numberAn Invalid Card Number was entered. Check the card number0-099970040c754e000000010000000000000000-1QKINVALID CARD NUMBERAn Invalid Card Number was entered. Check the card number00000000000000000-1 10 | -------------------------------------------------------------------------------- /tests/Mock/PxPostCreateCardSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Server: DPS_PX_SERVER 3 | Cache-Control: private 4 | Content-Length: 2542 5 | Content-Type: application/xhtml+xml; charset=utf-8 6 | Expires: Tue, 26 Feb 2013 16:50:08 GMT 7 | Date: Tue, 26 Feb 2013 16:51:09 GMT 8 | 9 | 1002013022616511420130226165114UTCVisa00055111040c73ea000000010.001.00554554NZD1.00NZDFJKSDL FJDKSL20130227Auth411111........112BC202100419201302270551119001Undefined00APPROVED02APPROVEDThe Transaction was approvedThe Transaction was approvedAPPROVEDThe Transaction was approvedThe Transaction was approved0NotUsed10000000-1000402160744999700000001040c73ea10000010009328404040c73ea000000010000000000000000-100APPROVEDTransaction Approved100000001040c73ea0000000000000000-1 10 | -------------------------------------------------------------------------------- /tests/Mock/PxPostPurchaseFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Server: DPS_PX_SERVER 3 | Cache-Control: private 4 | Content-Length: 2435 5 | Content-Type: application/xhtml+xml; charset=utf-8 6 | Expires: Sat, 23 Feb 2013 14:09:13 GMT 7 | Date: Sat, 23 Feb 2013 14:10:12 GMT 8 | 9 | 0U52013022314103020130223141030UTC000.0010.00554554NZD1.00NZDFJKSDL FJDKSL19800101Purchase411111........1104190D500DECLINEDThe transaction was Declined (U5)The transaction was Declined (U5)DECLINEDThe transaction was Declined (U5)The transaction was Declined (U5)0-0-1000000000000000010000000000000000-1U5DECLINEDThe transaction was Declined (U5)00000000000000000-1 10 | -------------------------------------------------------------------------------- /tests/Mock/PxPostPurchaseSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | 3 | 00APPROVEDTransaction Approved1000000030884cdc6inv1278TestReferenceBusiness NameBusiness PhoneBusiness ID 4 | -------------------------------------------------------------------------------- /tests/PxFusionGatewayTest.php: -------------------------------------------------------------------------------- 1 | gateway = new PxFusionGateway($this->getHttpClient(), $this->getHttpRequest()); 14 | 15 | $this->purchaseOptions = array( 16 | 'amount' => '10.00', 17 | 'currency' => 'NZD', 18 | 'txnRef' => 'test', 19 | 'returnUrl' => 'https://www.example.com/return', 20 | 'transactionId' => 123, 21 | ); 22 | 23 | $this->completePurchaseOptions = array( 24 | 'sessionId' => '000001001974701382c9911e025dc301', 25 | ); 26 | } 27 | 28 | public function testPurchaseSuccess() 29 | { 30 | $this->setMockHttpResponse('PxFusionPurchaseSuccess.txt'); 31 | 32 | $response = $this->gateway->purchase($this->purchaseOptions)->send(); 33 | 34 | $this->assertFalse($response->isSuccessful()); 35 | $this->assertTrue($response->isRedirect()); 36 | $this->assertNull($response->getMessage()); 37 | $this->assertSame('https://sec.windcave.com/pxmi3/pxfusionauth', $response->getRedirectUrl()); 38 | $this->assertSame('POST', $response->getRedirectMethod()); 39 | $this->assertSame(array('SessionId' => '000001001974701382c9911e025dc301'), $response->getRedirectData()); 40 | } 41 | 42 | public function testPurchaseFailure() 43 | { 44 | $this->setMockHttpResponse('PxFusionPurchaseFailure.txt'); 45 | 46 | $response = $this->gateway->purchase($this->purchaseOptions)->send(); 47 | 48 | $this->assertFalse($response->isSuccessful()); 49 | $this->assertFalse($response->isRedirect()); 50 | $this->assertNull($response->getTransactionReference()); 51 | $this->assertNull($response->getMessage()); 52 | } 53 | 54 | public function testCompletePurchaseSuccess() 55 | { 56 | $this->setMockHttpResponse('PxFusionCompletePurchaseSuccess.txt'); 57 | 58 | $response = $this->gateway->completePurchase($this->completePurchaseOptions)->send(); 59 | 60 | $this->assertTrue($response->isSuccessful()); 61 | $this->assertFalse($response->isRedirect()); 62 | $this->assertSame('000000010a838c1c', $response->getTransactionReference()); 63 | $this->assertSame('APPROVED', $response->getMessage()); 64 | } 65 | 66 | public function testCompletePurchaseFailure() 67 | { 68 | $this->setMockHttpResponse('PxFusionCompletePurchaseFailure.txt'); 69 | 70 | $response = $this->gateway->completePurchase($this->completePurchaseOptions)->send(); 71 | 72 | $this->assertFalse($response->isSuccessful()); 73 | $this->assertFalse($response->isRedirect()); 74 | $this->assertSame('000000011a0ae597', $response->getTransactionReference()); 75 | $this->assertSame('DECLINED', $response->getMessage()); 76 | $this->assertSame(1, $response->getCode()); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /tests/PxPayGatewayTest.php: -------------------------------------------------------------------------------- 1 | gateway = new PxPayGateway($this->getHttpClient(), $this->getHttpRequest()); 14 | 15 | $this->options = array( 16 | 'amount' => '10.00', 17 | 'returnUrl' => 'https://www.example.com/return', 18 | ); 19 | } 20 | 21 | public function testAuthorizeSuccess() 22 | { 23 | $this->setMockHttpResponse('PxPayPurchaseSuccess.txt'); 24 | 25 | $response = $this->gateway->authorize($this->options)->send(); 26 | 27 | $this->_testSuccessfulPurchase($response); 28 | } 29 | 30 | public function testAuthorizeFailure() 31 | { 32 | $this->setMockHttpResponse('PxPayPurchaseFailure.txt'); 33 | 34 | $response = $this->gateway->authorize($this->options)->send(); 35 | 36 | $this->assertFalse($response->isSuccessful()); 37 | $this->assertFalse($response->isRedirect()); 38 | $this->assertNull($response->getTransactionReference()); 39 | $this->assertNull($response->getRedirectData()); 40 | $this->assertNull($response->getRedirectUrl()); 41 | $this->assertSame('Invalid Key', $response->getMessage()); 42 | } 43 | 44 | public function testAuthorizeWithTransactionDataSuccess() 45 | { 46 | $this->setMockHttpResponse('PxPayPurchaseSuccess.txt'); 47 | 48 | $options = array_merge($this->options, array( 49 | 'description' => 'TestReference', 50 | 'transactionId' => 'P075985DA31094D8', 51 | 'transactionData1' => 'Business Name', 52 | 'transactionData2' => 'Business Phone', 53 | 'transactionData3' => 'Business ID', 54 | 'cardReference' => '000000030884cdc6' 55 | )); 56 | 57 | $request = $this->gateway->authorize($options); 58 | 59 | $this->assertSame($options['description'], $request->getDescription()); 60 | $this->assertSame($options['transactionId'], $request->getTransactionId()); 61 | $this->assertSame($options['transactionData1'], $request->getTransactionData1()); 62 | $this->assertSame($options['transactionData2'], $request->getTransactionData2()); 63 | $this->assertSame($options['transactionData3'], $request->getTransactionData3()); 64 | $this->assertSame($options['cardReference'], $request->getCardReference()); 65 | 66 | $response = $request->send(); 67 | 68 | $this->_testSuccessfulPurchase($response); 69 | } 70 | 71 | public function testPurchaseSuccess() 72 | { 73 | $this->setMockHttpResponse('PxPayPurchaseSuccess.txt'); 74 | 75 | $response = $this->gateway->purchase($this->options)->send(); 76 | 77 | $this->_testSuccessfulPurchase($response); 78 | } 79 | 80 | public function testPurchaseWithCardReferenceSuccess() 81 | { 82 | $this->setMockHttpResponse('PxPayPurchaseSuccess.txt'); 83 | 84 | $options = array_merge($this->options, array( 85 | 'cardReference' => 'Card reference', 86 | 'EnableAddBillCard' => 1 87 | )); 88 | 89 | $response = $this->gateway->purchase($options)->send(); 90 | 91 | $this->_testSuccessfulPurchase($response); 92 | } 93 | 94 | public function testPurchaseFailure() 95 | { 96 | $this->setMockHttpResponse('PxPayPurchaseFailure.txt'); 97 | 98 | $response = $this->gateway->purchase($this->options)->send(); 99 | 100 | $this->assertFalse($response->isSuccessful()); 101 | $this->assertFalse($response->isRedirect()); 102 | $this->assertNull($response->getTransactionReference()); 103 | $this->assertSame('Invalid Key', $response->getMessage()); 104 | } 105 | 106 | public function testCreateCardSuccess() 107 | { 108 | $this->setMockHttpResponse('PxPayCreateCardSuccess.txt'); 109 | 110 | $response = $this->gateway->authorize($this->options)->send(); 111 | 112 | $this->assertFalse($response->isSuccessful()); 113 | $this->assertTrue($response->isRedirect()); 114 | $this->assertNull($response->getTransactionReference()); 115 | $this->assertNull($response->getMessage()); 116 | $this->assertSame('https://sec.windcave.com/pxmi3/EF4054F622D6C4C1B0FA3975F5B37D5883A7AA411DF778AEBA9C4E3CBE1B394B50478552233E3FBD7', $response->getRedirectUrl()); 117 | $this->assertSame('GET', $response->getRedirectMethod()); 118 | } 119 | 120 | public function testCreateCardFailure() 121 | { 122 | $this->setMockHttpResponse('PxPayCreateCardFailure.txt'); 123 | 124 | $response = $this->gateway->authorize($this->options)->send(); 125 | 126 | $this->assertFalse($response->isSuccessful()); 127 | $this->assertFalse($response->isRedirect()); 128 | $this->assertNull($response->getTransactionReference()); 129 | $this->assertSame('userpass too short', $response->getMessage()); 130 | } 131 | 132 | public function testCompleteAuthorizeSuccess() 133 | { 134 | $this->getHttpRequest()->query->replace(array('result' => 'abc123')); 135 | 136 | $this->setMockHttpResponse('PxPayCompletePurchaseSuccess.txt'); 137 | 138 | $response = $this->gateway->completeAuthorize($this->options)->send(); 139 | 140 | $this->assertTrue($response->isSuccessful()); 141 | $this->assertFalse($response->isRedirect()); 142 | $this->assertSame('0000000103f5dc65', $response->getTransactionReference()); 143 | $this->assertSame('APPROVED', $response->getMessage()); 144 | } 145 | 146 | public function testCompleteAuthorizeSuccessWithPostResult() 147 | { 148 | $this->getHttpRequest()->query->replace(array()); 149 | $this->getHttpRequest()->request->replace(array('result' => 'abc123')); 150 | 151 | $this->setMockHttpResponse('PxPayCompletePurchaseSuccess.txt'); 152 | 153 | $response = $this->gateway->completeAuthorize($this->options)->send(); 154 | 155 | $this->assertTrue($response->isSuccessful()); 156 | $this->assertFalse($response->isRedirect()); 157 | $this->assertSame('0000000103f5dc65', $response->getTransactionReference()); 158 | $this->assertSame('APPROVED', $response->getMessage()); 159 | } 160 | 161 | public function testCompleteAuthorizeFailure() 162 | { 163 | $this->getHttpRequest()->query->replace(array('result' => 'abc123')); 164 | 165 | $this->setMockHttpResponse('PxPayCompletePurchaseFailure.txt'); 166 | 167 | $response = $this->gateway->completeAuthorize($this->options)->send(); 168 | 169 | $this->assertFalse($response->isSuccessful()); 170 | $this->assertFalse($response->isRedirect()); 171 | $this->assertNull($response->getTransactionReference()); 172 | $this->assertSame('Length of the data to decrypt is invalid.', $response->getMessage()); 173 | } 174 | 175 | public function testCompleteCreateCardSuccess() 176 | { 177 | $this->getHttpRequest()->query->replace(array('result' => 'abc123')); 178 | 179 | $this->setMockHttpResponse('PxPayCompleteCreateCardSuccess.txt'); 180 | 181 | $response = $this->gateway->completeCreateCard($this->options)->send(); 182 | 183 | $this->assertTrue($response->isSuccessful()); 184 | $this->assertFalse($response->isRedirect()); 185 | $this->assertSame('000000030a1806f0', $response->getTransactionReference()); 186 | $this->assertSame('0000030007487668', $response->getCardReference()); 187 | $this->assertSame('APPROVED', $response->getMessage()); 188 | } 189 | 190 | public function testCompleteCreateCardFailure() 191 | { 192 | $this->getHttpRequest()->query->replace(array('result' => 'abc123')); 193 | 194 | $this->setMockHttpResponse('PxPayCompleteCreateCardFailure.txt'); 195 | 196 | $response = $this->gateway->completeCreateCard($this->options)->send(); 197 | 198 | $this->assertFalse($response->isSuccessful()); 199 | $this->assertFalse($response->isRedirect()); 200 | $this->assertNull($response->getTransactionReference()); 201 | $this->assertSame('Length of the data to decrypt is invalid.', $response->getMessage()); 202 | } 203 | 204 | /** 205 | * @expectedException Omnipay\Common\Exception\InvalidResponseException 206 | */ 207 | public function testCompleteAuthorizeInvalid() 208 | { 209 | $this->getHttpRequest()->query->replace(array()); 210 | 211 | $response = $this->gateway->completeAuthorize($this->options)->send(); 212 | } 213 | 214 | public function testCompletePurchaseSuccess() 215 | { 216 | $this->getHttpRequest()->query->replace(array('result' => 'abc123')); 217 | 218 | $this->setMockHttpResponse('PxPayCompletePurchaseSuccess.txt'); 219 | 220 | $response = $this->gateway->completePurchase($this->options)->send(); 221 | 222 | $this->assertTrue($response->isSuccessful()); 223 | $this->assertFalse($response->isRedirect()); 224 | $this->assertSame('0000000103f5dc65', $response->getTransactionReference()); 225 | $this->assertSame('APPROVED', $response->getMessage()); 226 | } 227 | 228 | public function testCompletePurchaseWithTransactionDataSuccess() 229 | { 230 | $this->getHttpRequest()->query->replace(array('result' => 'abc123')); 231 | 232 | $this->setMockHttpResponse('PxPayCompletePurchaseSuccess.txt'); 233 | 234 | $options = array_merge($this->options, array( 235 | 'MerchantReference' => 'TestReference', 236 | 'TxnId' => 'P075985DA31094D8', 237 | 'TxnData1' => 'Business Name', 238 | 'TxnData2' => 'Business Phone', 239 | 'TxnData3' => 'Business ID', 240 | )); 241 | 242 | $response = $this->gateway->completePurchase($options)->send(); 243 | 244 | $this->assertTrue($response->isSuccessful()); 245 | $this->assertFalse($response->isRedirect()); 246 | $this->assertSame('0000000103f5dc65', $response->getTransactionReference()); 247 | $this->assertSame('TestReference', $response->getData()->MerchantReference->__toString()); 248 | $this->assertSame('P075985DA31094D8', $response->getTransactionId()); 249 | $this->assertSame('Business Name', $response->getData()->TxnData1->__toString()); 250 | $this->assertSame('Business Phone', $response->getData()->TxnData2->__toString()); 251 | $this->assertSame('Business ID', $response->getData()->TxnData3->__toString()); 252 | $this->assertSame('APPROVED', $response->getMessage()); 253 | } 254 | 255 | public function testCompletePurchaseFailure() 256 | { 257 | $this->getHttpRequest()->query->replace(array('result' => 'abc123')); 258 | 259 | $this->setMockHttpResponse('PxPayCompletePurchaseFailure.txt'); 260 | 261 | $response = $this->gateway->completePurchase($this->options)->send(); 262 | 263 | $this->assertFalse($response->isSuccessful()); 264 | $this->assertFalse($response->isRedirect()); 265 | $this->assertNull($response->getTransactionReference()); 266 | $this->assertSame('Length of the data to decrypt is invalid.', $response->getMessage()); 267 | } 268 | 269 | /** 270 | * @expectedException Omnipay\Common\Exception\InvalidResponseException 271 | */ 272 | public function testCompletePurchaseInvalid() 273 | { 274 | $this->getHttpRequest()->query->replace(array()); 275 | 276 | $response = $this->gateway->completePurchase($this->options)->send(); 277 | } 278 | 279 | public function testTestModeDisabled() 280 | { 281 | $options = array( 282 | 'testMode' => false 283 | ); 284 | 285 | $request = $this->gateway->authorize($options); 286 | 287 | $this->assertFalse($request->getTestMode()); 288 | $this->assertContains('sec.windcave.com', $request->getEndpoint()); 289 | } 290 | 291 | public function testTestModeEnabled() 292 | { 293 | $options = array( 294 | 'testMode' => true 295 | ); 296 | 297 | $request = $this->gateway->authorize($options); 298 | 299 | $this->assertTrue($request->getTestMode()); 300 | $this->assertContains('uat.windcave.com', $request->getEndpoint()); 301 | } 302 | 303 | private function _testSuccessfulPurchase($response) 304 | { 305 | $this->assertFalse($response->isSuccessful()); 306 | $this->assertTrue($response->isRedirect()); 307 | $this->assertNull($response->getTransactionReference()); 308 | $this->assertNull($response->getMessage()); 309 | $this->assertSame('https://sec.windcave.com/pxpay/pxpay.aspx?userid=Developer&request=v5H7JrBTzH-4Whs__1iQnz4RGSb9qxRKNR4kIuDP8kIkQzIDiIob9GTIjw_9q_AdRiR47ViWGVx40uRMu52yz2mijT39YtGeO7cZWrL5rfnx0Mc4DltIHRnIUxy1EO1srkNpxaU8fT8_1xMMRmLa-8Fd9bT8Oq0BaWMxMquYa1hDNwvoGs1SJQOAJvyyKACvvwsbMCC2qJVyN0rlvwUoMtx6gGhvmk7ucEsPc_Cyr5kNl3qURnrLKxINnS0trdpU4kXPKOlmT6VacjzT1zuj_DnrsWAPFSFq-hGsow6GpKKciQ0V0aFbAqECN8rl_c-aZWFFy0gkfjnUM4qp6foS0KMopJlPzGAgMjV6qZ0WfleOT64c3E-FRLMP5V_-mILs8a', 310 | $response->getRedirectUrl()); 311 | $this->assertSame('GET', $response->getRedirectMethod()); 312 | } 313 | 314 | } 315 | -------------------------------------------------------------------------------- /tests/PxPostGatewayTest.php: -------------------------------------------------------------------------------- 1 | gateway = new PxPostGateway($this->getHttpClient(), $this->getHttpRequest()); 14 | 15 | $this->options = array( 16 | 'amount' => '10.00', 17 | 'card' => $this->getValidCard(), 18 | ); 19 | } 20 | 21 | public function testAuthorizeSuccess() 22 | { 23 | $this->setMockHttpResponse('PxPostPurchaseSuccess.txt'); 24 | 25 | $response = $this->gateway->authorize($this->options)->send(); 26 | 27 | $this->assertTrue($response->isSuccessful()); 28 | $this->assertFalse($response->isRedirect()); 29 | $this->assertSame('000000030884cdc6', $response->getTransactionReference()); 30 | $this->assertSame('Transaction Approved', $response->getMessage()); 31 | } 32 | 33 | public function testAuthorizeFailure() 34 | { 35 | $this->setMockHttpResponse('PxPostPurchaseFailure.txt'); 36 | 37 | $response = $this->gateway->authorize($this->options)->send(); 38 | 39 | $this->assertFalse($response->isSuccessful()); 40 | $this->assertFalse($response->isRedirect()); 41 | $this->assertNull($response->getTransactionReference()); 42 | $this->assertSame('The transaction was Declined (U5)', $response->getMessage()); 43 | } 44 | 45 | public function testAuthorizeWithTransactionDataSuccess() 46 | { 47 | $this->setMockHttpResponse('PxPostPurchaseSuccess.txt'); 48 | 49 | $options = array_merge($this->options, array( 50 | 'description' => 'TestReference', 51 | 'transactionId' => 'inv1278', 52 | 'transactionData1' => 'Business Name', 53 | 'transactionData2' => 'Business Phone', 54 | 'transactionData3' => 'Business ID', 55 | 'cardReference' => '000000030884cdc6' 56 | )); 57 | 58 | $request = $this->gateway->authorize($options); 59 | 60 | $this->assertSame($options['description'], $request->getDescription()); 61 | $this->assertSame($options['transactionId'], $request->getTransactionId()); 62 | $this->assertSame($options['transactionData1'], $request->getTransactionData1()); 63 | $this->assertSame($options['transactionData2'], $request->getTransactionData2()); 64 | $this->assertSame($options['transactionData3'], $request->getTransactionData3()); 65 | 66 | $response = $request->send(); 67 | 68 | $this->assertTrue($response->isSuccessful()); 69 | $this->assertFalse($response->isRedirect()); 70 | $this->assertSame('000000030884cdc6', $response->getTransactionReference()); 71 | $this->assertSame('TestReference', $response->getData()->MerchantReference->__toString()); 72 | $this->assertSame('inv1278', $response->getData()->TxnRef->__toString()); 73 | $this->assertSame('Business Name', $response->getData()->TxnData1->__toString()); 74 | $this->assertSame('Business Phone', $response->getData()->TxnData2->__toString()); 75 | $this->assertSame('Business ID', $response->getData()->TxnData3->__toString()); 76 | $this->assertSame('Transaction Approved', $response->getMessage()); 77 | } 78 | 79 | public function testCaptureSuccess() 80 | { 81 | $this->setMockHttpResponse('PxPostPurchaseSuccess.txt'); 82 | 83 | $options = array( 84 | 'amount' => '10.00', 85 | 'transactionReference' => '000000030884cdc6', 86 | ); 87 | 88 | $response = $this->gateway->capture($options)->send(); 89 | 90 | $this->assertTrue($response->isSuccessful()); 91 | $this->assertEquals('000000030884cdc6', $response->getTransactionReference()); 92 | } 93 | 94 | public function testPurchaseSuccess() 95 | { 96 | $this->setMockHttpResponse('PxPostPurchaseSuccess.txt'); 97 | 98 | $response = $this->gateway->purchase($this->options)->send(); 99 | 100 | $this->assertTrue($response->isSuccessful()); 101 | $this->assertFalse($response->isRedirect()); 102 | $this->assertSame('000000030884cdc6', $response->getTransactionReference()); 103 | $this->assertSame('Transaction Approved', $response->getMessage()); 104 | } 105 | 106 | public function testPurchaseWithTransactionDataSuccess() 107 | { 108 | $this->setMockHttpResponse('PxPostPurchaseSuccess.txt'); 109 | 110 | $options = array_merge($this->options, array( 111 | 'description' => 'TestReference', 112 | 'transactionId' => 'inv1278', 113 | 'transactionData1' => 'Business Name', 114 | 'transactionData2' => 'Business Phone', 115 | 'transactionData3' => 'Business ID', 116 | )); 117 | 118 | $response = $this->gateway->purchase($options)->send(); 119 | 120 | $this->assertTrue($response->isSuccessful()); 121 | $this->assertFalse($response->isRedirect()); 122 | $this->assertSame('000000030884cdc6', $response->getTransactionReference()); 123 | $this->assertSame('TestReference', $response->getData()->MerchantReference->__toString()); 124 | $this->assertSame('inv1278', $response->getData()->TxnRef->__toString()); 125 | $this->assertSame('Business Name', $response->getData()->TxnData1->__toString()); 126 | $this->assertSame('Business Phone', $response->getData()->TxnData2->__toString()); 127 | $this->assertSame('Business ID', $response->getData()->TxnData3->__toString()); 128 | $this->assertSame('Transaction Approved', $response->getMessage()); 129 | } 130 | 131 | public function testPurchaseFailure() 132 | { 133 | $this->setMockHttpResponse('PxPostPurchaseFailure.txt'); 134 | 135 | $response = $this->gateway->purchase($this->options)->send(); 136 | 137 | $this->assertFalse($response->isSuccessful()); 138 | $this->assertFalse($response->isRedirect()); 139 | $this->assertNull($response->getTransactionReference()); 140 | $this->assertSame('The transaction was Declined (U5)', $response->getMessage()); 141 | } 142 | 143 | public function testRefundSuccess() 144 | { 145 | $this->setMockHttpResponse('PxPostPurchaseSuccess.txt'); 146 | 147 | $options = array( 148 | 'amount' => '10.00', 149 | 'transactionReference' => '000000030884cdc6', 150 | ); 151 | 152 | $response = $this->gateway->refund($options)->send(); 153 | 154 | $this->assertTrue($response->isSuccessful()); 155 | $this->assertEquals('000000030884cdc6', $response->getTransactionReference()); 156 | } 157 | 158 | public function testCreateCardSuccess() 159 | { 160 | $this->setMockHttpResponse('PxPostCreateCardSuccess.txt'); 161 | $response = $this->gateway->createCard($this->options)->send(); 162 | 163 | $this->assertTrue($response->isSuccessful()); 164 | $this->assertFalse($response->isRedirect()); 165 | $this->assertSame('00000001040c73ea', $response->getTransactionReference()); 166 | $this->assertSame('0000010009328404', $response->getCardReference()); 167 | $this->assertSame('Transaction Approved', $response->getMessage()); 168 | } 169 | 170 | public function testCreateCardFailure() 171 | { 172 | $this->setMockHttpResponse('PxPostCreateCardFailure.txt'); 173 | $response = $this->gateway->createCard($this->options)->send(); 174 | 175 | $this->assertFalse($response->isSuccessful()); 176 | $this->assertFalse($response->isRedirect()); 177 | $this->assertNull($response->getTransactionReference()); 178 | $this->assertNull($response->getCardReference()); 179 | $this->assertSame('An Invalid Card Number was entered. Check the card number', $response->getMessage()); 180 | } 181 | 182 | public function testTestModeDisabled() 183 | { 184 | $options = array( 185 | 'testMode' => false 186 | ); 187 | 188 | $request = $this->gateway->authorize($options); 189 | 190 | $this->assertFalse($request->getTestMode()); 191 | $this->assertContains('sec.windcave.com', $request->getEndpoint()); 192 | } 193 | 194 | public function testTestModeEnabled() 195 | { 196 | $options = array( 197 | 'testMode' => true 198 | ); 199 | 200 | $request = $this->gateway->authorize($options); 201 | 202 | $this->assertTrue($request->getTestMode()); 203 | $this->assertContains('uat.windcave.com', $request->getEndpoint()); 204 | } 205 | } 206 | --------------------------------------------------------------------------------