├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml.dist ├── src ├── Gateway.php ├── Message │ ├── AbstractRequest.php │ ├── AbstractResponse.php │ ├── CompletePurchaseRequest.php │ ├── CompletePurchaseResponse.php │ ├── FetchIssuersRequest.php │ ├── FetchIssuersResponse.php │ ├── FetchPaymentMethodsRequest.php │ ├── FetchPaymentMethodsResponse.php │ ├── PurchaseRequest.php │ ├── PurchaseResponse.php │ ├── RestAbstractRequest.php │ ├── RestAbstractResponse.php │ ├── RestCompletePurchaseRequest.php │ ├── RestCompletePurchaseResponse.php │ ├── RestFetchIssuersRequest.php │ ├── RestFetchIssuersResponse.php │ ├── RestFetchPaymentMethodsRequest.php │ ├── RestFetchPaymentMethodsResponse.php │ ├── RestFetchTransactionRequest.php │ ├── RestFetchTransactionResponse.php │ ├── RestPurchaseRequest.php │ ├── RestPurchaseResponse.php │ ├── RestRefundRequest.php │ └── RestRefundResponse.php ├── RestGateway.php └── XmlGateway.php └── tests ├── Message ├── RestFetchIssuersRequestTest.php ├── RestFetchPaymentMethodsRequestTest.php ├── RestPurchaseRequestTest.php ├── XmlAbstractRequestTest.php ├── XmlCompletePurchaseRequestTest.php ├── XmlFetchIssuersRequestTest.php ├── XmlFetchPaymentMethodsRequestTest.php └── XmlPurchaseRequestTest.php ├── Mock ├── RestFetchIssuersFailure.txt ├── RestFetchIssuersSuccess.txt ├── RestFetchPaymentMethodsSuccess.txt ├── RestInvalidApiKeyFailure.txt ├── RestPurchaseInvalidAmount.txt ├── RestPurchaseSuccess.txt ├── XmlCompletePurchaseFailure.txt ├── XmlCompletePurchaseSuccess.txt ├── XmlFetchIssuersFailure.txt ├── XmlFetchIssuersSuccess.txt ├── XmlFetchPaymentMethodsFailure.txt ├── XmlFetchPaymentMethodsSuccess.txt ├── XmlPurchaseFailure.txt └── XmlPurchaseSuccess.txt ├── RestGatewayTest.php └── XmlGatewayTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | composer.phar 4 | phpunit.xml 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.6 5 | - 7.0 6 | - 7.1 7 | - 7.2 8 | 9 | # This triggers builds to run on the new TravisCI infrastructure. 10 | # See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/ 11 | sudo: false 12 | 13 | ## Cache composer 14 | cache: 15 | directories: 16 | - $HOME/.composer/cache 17 | 18 | env: 19 | global: 20 | - setup=basic 21 | 22 | matrix: 23 | include: 24 | - php: 5.6 25 | env: setup=lowest 26 | 27 | install: 28 | - if [[ $setup = 'basic' ]]; then travis_retry composer install --prefer-dist --no-interaction; fi 29 | - if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi 30 | 31 | script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text 32 | -------------------------------------------------------------------------------- /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: MultiSafepay 2 | 3 | **MultiSafepay driver for the Omnipay PHP payment processing library** 4 | 5 | [![Build Status](https://travis-ci.org/thephpleague/omnipay-multisafepay.png?branch=master)](https://travis-ci.org/thephpleague/omnipay-multisafepay) 6 | [![Latest Stable Version](https://poser.pugx.org/omnipay/multisafepay/version.png)](https://packagist.org/packages/omnipay/multisafepay) 7 | [![Total Downloads](https://poser.pugx.org/omnipay/multisafepay/d/total.png)](https://packagist.org/packages/omnipay/multisafepay) 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 MultiSafepay 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/multisafepay": "~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 | * MultiSafepay_Rest 35 | * MultiSafepay_Xml (Deprecated) 36 | 37 | For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) 38 | repository. 39 | 40 | ## Support 41 | 42 | If you are having general issues with Omnipay, we suggest posting on 43 | [Stack Overflow](http://stackoverflow.com/). Be sure to add the 44 | [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found. 45 | 46 | If you want to keep up to date with release anouncements, discuss ideas for the project, 47 | or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which 48 | you can subscribe to. 49 | 50 | If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/thephpleague/omnipay-multisafepay/issues), 51 | or better yet, fork the library and submit a pull request. 52 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "omnipay/multisafepay", 3 | "type": "library", 4 | "description": "MultiSafepay driver for the Omnipay payment processing library", 5 | "keywords": [ 6 | "gateway", 7 | "merchant", 8 | "multi safepay", 9 | "multisafepay", 10 | "omnipay", 11 | "pay", 12 | "payment" 13 | ], 14 | "homepage": "https://github.com/thephpleague/omnipay-multisafepay", 15 | "license": "MIT", 16 | "authors": [ 17 | { 18 | "name": "Adrian Macneil", 19 | "email": "adrian@adrianmacneil.com" 20 | }, 21 | { 22 | "name": "Omnipay Contributors", 23 | "homepage": "https://github.com/thephpleague/omnipay-multisafepay/contributors" 24 | } 25 | ], 26 | "autoload": { 27 | "psr-4": { "Omnipay\\MultiSafepay\\" : "src/" } 28 | }, 29 | "require": { 30 | "omnipay/common": "^3" 31 | }, 32 | "require-dev": { 33 | "omnipay/tests": "^3", 34 | "squizlabs/php_codesniffer": "^3" 35 | }, 36 | "extra": { 37 | "branch-alias": { 38 | "dev-master": "3.0.x-dev" 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests/ 15 | 16 | 17 | 18 | 19 | ./src 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/Gateway.php: -------------------------------------------------------------------------------- 1 | getParameter('accountId'); 53 | } 54 | 55 | /** 56 | * Set the account identifier. 57 | * 58 | * @param $value 59 | * @return BaseAbstractRequest 60 | */ 61 | public function setAccountId($value) 62 | { 63 | return $this->setParameter('accountId', $value); 64 | } 65 | 66 | /** 67 | * Get the site identifier. 68 | * 69 | * @return mixed 70 | */ 71 | public function getSiteId() 72 | { 73 | return $this->getParameter('siteId'); 74 | } 75 | 76 | /** 77 | * Set the site identifier. 78 | * 79 | * @param $value 80 | * @return BaseAbstractRequest 81 | */ 82 | public function setSiteId($value) 83 | { 84 | return $this->setParameter('siteId', $value); 85 | } 86 | 87 | /** 88 | * Get the site code. 89 | * 90 | * @return mixed 91 | */ 92 | public function getSiteCode() 93 | { 94 | return $this->getParameter('siteCode'); 95 | } 96 | 97 | /** 98 | * Set the site code. 99 | * 100 | * @param $value 101 | * @return BaseAbstractRequest 102 | */ 103 | public function setSiteCode($value) 104 | { 105 | return $this->setParameter('siteCode', $value); 106 | } 107 | 108 | /** 109 | * Get the API endpoint. 110 | * 111 | * @return string 112 | */ 113 | public function getEndpoint() 114 | { 115 | if ($this->getTestMode()) { 116 | return $this->testEndpoint; 117 | } 118 | 119 | return $this->liveEndpoint; 120 | } 121 | 122 | /** 123 | * Get headers. 124 | * 125 | * @return array 126 | */ 127 | protected function getHeaders() 128 | { 129 | return array( 130 | 'User-Agent' => $this->userAgent, 131 | ); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/Message/AbstractResponse.php: -------------------------------------------------------------------------------- 1 | data->error)) { 24 | return (string) $this->data->error->description; 25 | } 26 | 27 | return null; 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | public function getCode() 34 | { 35 | if (isset($this->data->error)) { 36 | return (string) $this->data->error->code; 37 | } 38 | 39 | return null; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Message/CompletePurchaseRequest.php: -------------------------------------------------------------------------------- 1 | validate('transactionId'); 24 | 25 | $data = new SimpleXMLElement(''); 26 | $data->addAttribute('ua', $this->userAgent); 27 | 28 | $merchant = $data->addChild('merchant'); 29 | $merchant->addChild('account', $this->getAccountId()); 30 | $merchant->addChild('site_id', $this->getSiteId()); 31 | $merchant->addChild('site_secure_code', $this->getSiteCode()); 32 | 33 | $transaction = $data->addChild('transaction'); 34 | $transaction->addChild('id', $this->getTransactionId()); 35 | 36 | return $data; 37 | } 38 | 39 | /** 40 | * {@inheritdoc} 41 | */ 42 | public function sendData($data) 43 | { 44 | $httpResponse = $this->httpClient->request( 45 | 'POST', 46 | $this->getEndpoint(), 47 | $this->getHeaders(), 48 | $data->asXML() 49 | ); 50 | 51 | $this->response = new CompletePurchaseResponse( 52 | $this, 53 | simplexml_load_string($httpResponse->getBody()->getContents()) 54 | ); 55 | 56 | return $this->response; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Message/CompletePurchaseResponse.php: -------------------------------------------------------------------------------- 1 | getPaymentStatus() === 'completed'; 22 | } 23 | 24 | /** 25 | * {@inheritdoc} 26 | */ 27 | public function getTransactionReference() 28 | { 29 | if (isset($this->data->transaction->id)) { 30 | return (string) $this->data->transaction->id; 31 | } 32 | } 33 | 34 | /** 35 | * Is the payment created, but uncompleted? 36 | * 37 | * @return boolean 38 | */ 39 | public function isInitialized() 40 | { 41 | return $this->getPaymentStatus() === 'initialized'; 42 | } 43 | 44 | /** 45 | * Is the payment created, but not yet exempted (credit cards)? 46 | * 47 | * @return boolean 48 | */ 49 | public function isUncleared() 50 | { 51 | return $this->getPaymentStatus() === 'uncleared'; 52 | } 53 | 54 | /** 55 | * Is the payment canceled? 56 | * 57 | * @return boolean 58 | */ 59 | public function isCanceled() 60 | { 61 | return $this->getPaymentStatus() === 'canceled'; 62 | } 63 | 64 | /** 65 | * Is the payment rejected? 66 | * 67 | * @return boolean 68 | */ 69 | public function isRejected() 70 | { 71 | return $this->getPaymentStatus() === 'declined'; 72 | } 73 | 74 | /** 75 | * Is the payment refunded? 76 | * 77 | * @return boolean 78 | */ 79 | public function isRefunded() 80 | { 81 | return $this->getPaymentStatus() === 'refunded'; 82 | } 83 | 84 | /** 85 | * Is the payment expired? 86 | * 87 | * @return boolean 88 | */ 89 | public function isExpired() 90 | { 91 | return $this->getPaymentStatus() === 'expired'; 92 | } 93 | 94 | /** 95 | * Get raw payment status. 96 | * 97 | * @return null|string 98 | */ 99 | public function getPaymentStatus() 100 | { 101 | if (isset($this->data->ewallet->status)) { 102 | return (string)$this->data->ewallet->status; 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/Message/FetchIssuersRequest.php: -------------------------------------------------------------------------------- 1 | '); 24 | $data->addAttribute('ua', $this->userAgent); 25 | 26 | $merchant = $data->addChild('merchant'); 27 | $merchant->addChild('account', $this->getAccountId()); 28 | $merchant->addChild('site_id', $this->getSiteId()); 29 | $merchant->addChild('site_secure_code', $this->getSiteCode()); 30 | 31 | return $data; 32 | } 33 | 34 | /** 35 | * {@inheritdoc} 36 | */ 37 | public function sendData($data) 38 | { 39 | $httpResponse = $this->httpClient->request( 40 | 'POST', 41 | $this->getEndpoint(), 42 | $this->getHeaders(), 43 | $data->asXML() 44 | ); 45 | 46 | $this->response = new FetchIssuersResponse( 47 | $this, 48 | simplexml_load_string($httpResponse->getBody()->getContents()) 49 | ); 50 | 51 | return $this->response; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Message/FetchIssuersResponse.php: -------------------------------------------------------------------------------- 1 | data->issuers); 22 | } 23 | 24 | /** 25 | * Return available issuers as an associative array. 26 | * 27 | * @return array 28 | */ 29 | public function getIssuers() 30 | { 31 | $result = array(); 32 | 33 | foreach ($this->data->issuers->issuer as $issuer) { 34 | $result[(string) $issuer->code] = (string) $issuer->description; 35 | } 36 | 37 | return $result; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Message/FetchPaymentMethodsRequest.php: -------------------------------------------------------------------------------- 1 | getParameter('country'); 25 | } 26 | 27 | /** 28 | * Set the country. 29 | * 30 | * @param $value 31 | * @return \Omnipay\Common\Message\AbstractRequest 32 | */ 33 | public function setCountry($value) 34 | { 35 | return $this->setParameter('country', $value); 36 | } 37 | 38 | /** 39 | * {@inheritdoc} 40 | */ 41 | public function getData() 42 | { 43 | $data = new SimpleXMLElement(''); 44 | $data->addAttribute('ua', $this->userAgent); 45 | 46 | $merchant = $data->addChild('merchant'); 47 | $merchant->addChild('account', $this->getAccountId()); 48 | $merchant->addChild('site_id', $this->getSiteId()); 49 | $merchant->addChild('site_secure_code', $this->getSiteCode()); 50 | 51 | $customer = $data->addChild('customer'); 52 | $customer->addChild('country', $this->getCountry()); 53 | 54 | return $data; 55 | } 56 | 57 | /** 58 | * {@inheritdoc} 59 | */ 60 | public function sendData($data) 61 | { 62 | $httpResponse = $this->httpClient->request( 63 | 'POST', 64 | $this->getEndpoint(), 65 | $this->getHeaders(), 66 | $data->asXML() 67 | ); 68 | 69 | $this->response = new FetchPaymentMethodsResponse( 70 | $this, 71 | simplexml_load_string($httpResponse->getBody()->getContents()) 72 | ); 73 | 74 | return $this->response; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Message/FetchPaymentMethodsResponse.php: -------------------------------------------------------------------------------- 1 | data->gateways); 22 | } 23 | 24 | /** 25 | * Return available payment methods as an associative array. 26 | * 27 | * @return array 28 | */ 29 | public function getPaymentMethods() 30 | { 31 | $result = array(); 32 | 33 | foreach ($this->data->gateways->gateway as $gateway) { 34 | $result[(string) $gateway->id] = (string) $gateway->description; 35 | } 36 | 37 | return $result; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Message/PurchaseRequest.php: -------------------------------------------------------------------------------- 1 | getParameter('language'); 27 | } 28 | 29 | /** 30 | * Set the language. 31 | * 32 | * @param $value 33 | * @return \Omnipay\Common\Message\AbstractRequest 34 | */ 35 | public function setLanguage($value) 36 | { 37 | return $this->setParameter('language', $value); 38 | } 39 | 40 | /** 41 | * Get the gateway. 42 | * 43 | * @return mixed 44 | */ 45 | public function getGateway() 46 | { 47 | return $this->getParameter('gateway'); 48 | } 49 | 50 | /** 51 | * Set the gateway. 52 | * 53 | * @param $value 54 | * @return \Omnipay\Common\Message\AbstractRequest 55 | */ 56 | public function setGateway($value) 57 | { 58 | return $this->setParameter('gateway', $value); 59 | } 60 | 61 | /** 62 | * Get Issuer. 63 | * 64 | * @return mixed 65 | */ 66 | public function getIssuer() 67 | { 68 | return $this->getParameter('issuer'); 69 | } 70 | 71 | /** 72 | * Set issuer. 73 | * 74 | * @param string $value 75 | * @return \Omnipay\Common\Message\AbstractRequest 76 | */ 77 | public function setIssuer($value) 78 | { 79 | return $this->setParameter('issuer', $value); 80 | } 81 | 82 | /** 83 | * Get the Google analytics code. 84 | * 85 | * @return mixed 86 | */ 87 | public function getGoogleAnalyticsCode() 88 | { 89 | return $this->getParameter('googleAnalyticsCode'); 90 | } 91 | 92 | /** 93 | * Set the Google analytics code. 94 | * 95 | * @param $value 96 | * @return \Omnipay\Common\Message\AbstractRequest 97 | */ 98 | public function setGoogleAnalyticsCode($value) 99 | { 100 | return $this->setParameter('googleAnalyticsCode', $value); 101 | } 102 | 103 | /** 104 | * Get the value of "extradata1" 105 | * 106 | * @return mixed 107 | */ 108 | public function getExtraData1() 109 | { 110 | return $this->getParameter('extraData1'); 111 | } 112 | 113 | /** 114 | * Set the value of "extradata1" 115 | * 116 | * @param $value 117 | * @return \Omnipay\Common\Message\AbstractRequest 118 | */ 119 | public function setExtraData1($value) 120 | { 121 | return $this->setParameter('extraData1', $value); 122 | } 123 | 124 | /** 125 | * Get the value of "extradata2" 126 | * 127 | * @return mixed 128 | */ 129 | public function getExtraData2() 130 | { 131 | return $this->getParameter('extraData2'); 132 | } 133 | 134 | /** 135 | * Set the value of "extraData2 136 | * 137 | * @param $value 138 | * @return \Omnipay\Common\Message\AbstractRequest 139 | */ 140 | public function setExtraData2($value) 141 | { 142 | return $this->setParameter('extraData2', $value); 143 | } 144 | 145 | /** 146 | * Get the value of "extraData3" 147 | * 148 | * @return mixed 149 | */ 150 | public function getExtraData3() 151 | { 152 | return $this->getParameter('extraData3'); 153 | } 154 | 155 | /** 156 | * Set the value of "extraData3" 157 | * 158 | * @param $value 159 | * @return \Omnipay\Common\Message\AbstractRequest 160 | */ 161 | public function setExtraData3($value) 162 | { 163 | return $this->setParameter('extraData3', $value); 164 | } 165 | 166 | /** 167 | * Get the items. 168 | * 169 | * @return mixed 170 | */ 171 | public function getItems() 172 | { 173 | return $this->getParameter('items'); 174 | } 175 | 176 | /** 177 | * Set the items. 178 | * 179 | * @param array|\Omnipay\Common\ItemBag $value 180 | * @return \Omnipay\Common\Message\AbstractRequest 181 | */ 182 | public function setItems($value) 183 | { 184 | return $this->setParameter('items', $value); 185 | } 186 | 187 | /** 188 | * {@inheritdoc} 189 | */ 190 | public function getData() 191 | { 192 | $this->validate('transactionId', 'amount', 'currency', 'description', 'clientIp', 'card'); 193 | 194 | if ('IDEAL' === $this->getGateway() && $this->getIssuer()) { 195 | $data = new SimpleXMLElement(''); 196 | } else { 197 | $data = new SimpleXMLElement(''); 198 | } 199 | 200 | $data->addAttribute('ua', $this->userAgent); 201 | 202 | $merchant = $data->addChild('merchant'); 203 | $merchant->addChild('account', $this->getAccountId()); 204 | $merchant->addChild('site_id', $this->getSiteId()); 205 | $merchant->addChild('site_secure_code', $this->getSiteCode()); 206 | $merchant->addChild('notification_url', htmlspecialchars($this->getNotifyUrl())); 207 | $merchant->addChild('cancel_url', htmlspecialchars($this->getCancelUrl())); 208 | $merchant->addChild('redirect_url', htmlspecialchars($this->getReturnUrl())); 209 | 210 | /** @var CreditCard $card */ 211 | $card = $this->getCard(); 212 | $customer = $data->addChild('customer'); 213 | $customer->addChild('ipaddress', $this->getClientIp()); 214 | $customer->addChild('locale', $this->getLanguage()); 215 | $customer->addChild('email', $card->getEmail()); 216 | $customer->addChild('firstname', $card->getFirstName()); 217 | $customer->addChild('lastname', $card->getLastName()); 218 | $customer->addChild('address1', $card->getAddress1()); 219 | $customer->addChild('address2', $card->getAddress2()); 220 | $customer->addChild('zipcode', $card->getPostcode()); 221 | $customer->addChild('city', $card->getCity()); 222 | $customer->addChild('country', $card->getCountry()); 223 | $customer->addChild('phone', $card->getPhone()); 224 | 225 | $data->addChild('google_analytics', $this->getGoogleAnalyticsCode()); 226 | 227 | $transaction = $data->addChild('transaction'); 228 | $transaction->addChild('id', $this->getTransactionId()); 229 | $transaction->addChild('currency', $this->getCurrency()); 230 | $transaction->addChild('amount', $this->getAmountInteger()); 231 | $transaction->addChild('description', $this->getDescription()); 232 | $transaction->addChild('var1', $this->getExtraData1()); 233 | $transaction->addChild('var2', $this->getExtraData2()); 234 | $transaction->addChild('var3', $this->getExtraData3()); 235 | $transaction->addChild('gateway', $this->getGateway()); 236 | 237 | if ($items = $this->getItems()) { 238 | $itemsHtml = '
    '; 239 | foreach ($items as $item) { 240 | $itemsHtml .= "
  • {$item['quantity']} x {$item['name']}
  • "; 241 | } 242 | $itemsHtml .= '
'; 243 | $transaction->addChild('items', htmlspecialchars($itemsHtml)); 244 | } 245 | 246 | if ('IDEAL' === $this->getGateway() && $this->getIssuer()) { 247 | $gatewayInfo = $data->addChild('gatewayinfo'); 248 | $gatewayInfo->addChild('issuerid', $this->getIssuer()); 249 | } 250 | 251 | $data->addChild('signature', $this->generateSignature()); 252 | 253 | return $data; 254 | } 255 | 256 | /** 257 | * {@inheritdoc} 258 | */ 259 | public function sendData($data) 260 | { 261 | $httpResponse = $this->httpClient->request( 262 | 'POST', 263 | $this->getEndpoint(), 264 | $this->getHeaders(), 265 | $data->asXML() 266 | ); 267 | 268 | $this->response = new PurchaseResponse( 269 | $this, 270 | simplexml_load_string($httpResponse->getBody()->getContents()) 271 | ); 272 | 273 | return $this->response; 274 | } 275 | 276 | /** 277 | * Generate signature. 278 | * 279 | * @return string 280 | */ 281 | protected function generateSignature() 282 | { 283 | return md5( 284 | $this->getAmountInteger(). 285 | $this->getCurrency(). 286 | $this->getAccountId(). 287 | $this->getSiteId(). 288 | $this->getTransactionId() 289 | ); 290 | } 291 | } 292 | -------------------------------------------------------------------------------- /src/Message/PurchaseResponse.php: -------------------------------------------------------------------------------- 1 | data->transaction->id)) { 24 | return (string)$this->data->transaction->id; 25 | } 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function isSuccessful() 32 | { 33 | return false; 34 | } 35 | 36 | /** 37 | * {@inheritdoc} 38 | */ 39 | public function isRedirect() 40 | { 41 | if (isset($this->data->transaction->payment_url) || 42 | isset($this->data->gatewayinfo->redirecturl) 43 | ) { 44 | return true; 45 | } 46 | 47 | return false; 48 | } 49 | 50 | /** 51 | * {@inheritdoc} 52 | */ 53 | public function getRedirectUrl() 54 | { 55 | if (isset($this->data->gatewayinfo->redirecturl)) { 56 | return (string)$this->data->gatewayinfo->redirecturl; 57 | } 58 | 59 | if (isset($this->data->transaction->payment_url)) { 60 | return (string) $this->data->transaction->payment_url; 61 | } 62 | 63 | return null; 64 | } 65 | 66 | /** 67 | * {@inheritdoc} 68 | */ 69 | public function getRedirectMethod() 70 | { 71 | return 'GET'; 72 | } 73 | 74 | /** 75 | * {@inheritdoc} 76 | */ 77 | public function getRedirectData() 78 | { 79 | return null; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Message/RestAbstractRequest.php: -------------------------------------------------------------------------------- 1 | getParameter('locale'); 60 | } 61 | 62 | /** 63 | * Set the locale. 64 | * 65 | * Optional ISO 639-1 language code which is used to specify a 66 | * a language used to display gateway information and other 67 | * messages in the responses. 68 | * 69 | * The default language is English. 70 | * 71 | * @param $value 72 | * @return \Omnipay\Common\Message\AbstractRequest 73 | */ 74 | public function setLocale($value) 75 | { 76 | return $this->setParameter('locale', $value); 77 | } 78 | 79 | /** 80 | * Get the gateway API Key 81 | * 82 | * Authentication is by means of a single secret API key set as 83 | * the apiKey parameter when creating the gateway object. 84 | * 85 | * @return string 86 | */ 87 | public function getApiKey() 88 | { 89 | return $this->getParameter('apiKey'); 90 | } 91 | 92 | /** 93 | * Set the gateway API Key 94 | * 95 | * Authentication is by means of a single secret API key set as 96 | * the apiKey parameter when creating the gateway object. 97 | * 98 | * @param $value 99 | * @return \Omnipay\Common\Message\AbstractRequest 100 | */ 101 | public function setApiKey($value) 102 | { 103 | return $this->setParameter('apiKey', $value); 104 | } 105 | 106 | /** 107 | * Get endpoint 108 | * 109 | * @return string 110 | */ 111 | public function getEndpoint() 112 | { 113 | if ($this->getTestMode()) { 114 | return $this->testEndpoint; 115 | } 116 | 117 | return $this->liveEndpoint; 118 | } 119 | 120 | /** 121 | * Get the raw data array for this message. The format of this varies from gateway to 122 | * gateway, but will usually be either an associative array, or a SimpleXMLElement. 123 | * 124 | * @return mixed 125 | * @throws \Omnipay\Common\Exception\InvalidRequestException 126 | */ 127 | public function getData() 128 | { 129 | $this->validate('apiKey'); 130 | } 131 | 132 | /** 133 | * Get headers. 134 | * 135 | * @return array 136 | */ 137 | protected function getHeaders() 138 | { 139 | return array( 140 | 'api_key' => $this->getApiKey(), 141 | 'User-Agent' => $this->userAgent, 142 | ); 143 | } 144 | 145 | /** 146 | * Execute the Guzzle request. 147 | * 148 | * @param $method 149 | * @param $endpoint 150 | * @param null $data 151 | * @return ResponseInterface 152 | */ 153 | protected function sendRequest($method, $endpoint, $data = null) 154 | { 155 | return $this->httpClient->request( 156 | strtoupper($method), 157 | $this->getEndpoint() . $endpoint, 158 | $this->getHeaders(), 159 | $data 160 | ); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /src/Message/RestAbstractResponse.php: -------------------------------------------------------------------------------- 1 | data['success'])) { 26 | return false; 27 | } 28 | 29 | return $this->data['success']; 30 | } 31 | 32 | /** 33 | * Response Message. 34 | * 35 | * @return null|string A response message from the payment gateway 36 | */ 37 | public function getMessage() 38 | { 39 | if (!$this->isSuccessful() && isset($this->data['error_info'])) { 40 | return $this->data['error_info']; 41 | } 42 | } 43 | 44 | /** 45 | * Response code. 46 | * 47 | * @return null|string A response code from the payment gateway 48 | */ 49 | public function getCode() 50 | { 51 | if (! $this->isSuccessful() && isset($this->data['error_code'])) { 52 | return $this->data['error_code']; 53 | } 54 | } 55 | 56 | /** 57 | * Gateway Reference. 58 | * 59 | * @return null|string A reference provided by the gateway to represent this transaction 60 | */ 61 | public function getTransactionReference() 62 | { 63 | if (isset($this->data['data']['transaction_id'])) { 64 | return $this->data['data']['transaction_id']; 65 | } 66 | } 67 | 68 | /** 69 | * Get the transaction ID as generated by the merchant website. 70 | * 71 | * @return string 72 | */ 73 | public function getTransactionId() 74 | { 75 | if (isset($this->data['data']['order_id'])) { 76 | return $this->data['data']['order_id']; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Message/RestCompletePurchaseRequest.php: -------------------------------------------------------------------------------- 1 | 14 | * $transaction = $gateway->completePurchase(); 15 | * $transaction->setTransactionId($transactionId); 16 | * $response = $transaction->send(); 17 | * print_r($response->getData()); 18 | * 19 | * 20 | */ 21 | class RestCompletePurchaseRequest extends RestFetchTransactionRequest 22 | { 23 | /** 24 | * Get the required data from the API request. 25 | * 26 | * @return array 27 | * @throws \Omnipay\Common\Exception\InvalidRequestException 28 | */ 29 | public function getData() 30 | { 31 | $this->validate('transactionId'); 32 | 33 | $transactionId = $this->getTransactionId(); 34 | 35 | return compact('transactionId'); 36 | } 37 | 38 | /** 39 | * Send the API request. 40 | * 41 | * @param mixed $data 42 | * @return RestCompletePurchaseResponse 43 | */ 44 | public function sendData($data) 45 | { 46 | $httpResponse = $this->sendRequest( 47 | 'get', 48 | '/orders/' . $data['transactionId'] 49 | ); 50 | 51 | $this->response = new RestCompletePurchaseResponse( 52 | $this, 53 | json_decode($httpResponse->getBody()->getContents(), true) 54 | ); 55 | 56 | return $this->response; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Message/RestCompletePurchaseResponse.php: -------------------------------------------------------------------------------- 1 | 14 | * $transaction = $gateway->completePurchase(); 15 | * $transaction->setTransactionId($transactionId); 16 | * $response = $transaction->send(); 17 | * print_r($response->getData()); 18 | * 19 | * 20 | */ 21 | class RestCompletePurchaseResponse extends RestFetchTransactionResponse 22 | { 23 | /** 24 | * {@inheritdoc} 25 | */ 26 | public function isSuccessful() 27 | { 28 | return $this->getPaymentStatus() == 'completed'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Message/RestFetchIssuersRequest.php: -------------------------------------------------------------------------------- 1 | 18 | * $request = $gateway->fetchIssuers(); 19 | * $request->setPaymentMethod('IDEAL'); 20 | * $response = $request->send(); 21 | * $issuers = $response->getIssuers(); 22 | * print_r($issuers); 23 | * 24 | * 25 | * @link https://www.multisafepay.com/documentation/doc/API-Reference 26 | */ 27 | class RestFetchIssuersRequest extends RestAbstractRequest 28 | { 29 | /** 30 | * Get the required data for the API request. 31 | * 32 | * @return array 33 | * @throws \Omnipay\Common\Exception\InvalidRequestException 34 | */ 35 | public function getData() 36 | { 37 | parent::getData(); 38 | 39 | $this->validate('paymentMethod'); 40 | 41 | $paymentMethod = $this->getPaymentMethod(); 42 | 43 | return compact('paymentMethod'); 44 | } 45 | 46 | /** 47 | * Execute the API request. 48 | * 49 | * @param mixed $data 50 | * @return FetchIssuersResponse 51 | */ 52 | public function sendData($data) 53 | { 54 | $httpResponse = $this->sendRequest( 55 | 'GET', 56 | '/issuers/' . $data['paymentMethod'] 57 | ); 58 | 59 | $this->response = new RestFetchIssuersResponse( 60 | $this, 61 | json_decode($httpResponse->getBody()->getContents(), true) 62 | ); 63 | 64 | return $this->response; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Message/RestFetchIssuersResponse.php: -------------------------------------------------------------------------------- 1 | 21 | * $request = $gateway->fetchIssuers(); 22 | * $request->setPaymentMethod('IDEAL'); 23 | * $response = $request->send(); 24 | * $issuers = $response->getIssuers(); 25 | * print_r($issuers); 26 | * 27 | */ 28 | class RestFetchIssuersResponse extends RestAbstractResponse implements FetchIssuersResponseInterface 29 | { 30 | /** 31 | * Return available issuers as an associative array. 32 | * 33 | * @return \Omnipay\Common\Issuer[] 34 | */ 35 | public function getIssuers() 36 | { 37 | $issuers = array(); 38 | 39 | foreach ($this->data['data'] as $issuer) { 40 | $issuers[] = new Issuer( 41 | $issuer['code'], 42 | $issuer['description'] 43 | ); 44 | } 45 | 46 | return $issuers; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Message/RestFetchPaymentMethodsRequest.php: -------------------------------------------------------------------------------- 1 | 18 | * $request = $gateway->fetchPaymentMethods(); 19 | * $response = $request->send(); 20 | * $paymentMethods = $response->getPaymentMethods(); 21 | * print_r($paymentMethods); 22 | * 23 | * 24 | * @link https://www.multisafepay.com/documentation/doc/API-Reference 25 | */ 26 | class RestFetchPaymentMethodsRequest extends RestAbstractRequest 27 | { 28 | /** 29 | * Get the country. 30 | * 31 | * @return string|null 32 | */ 33 | public function getCountry() 34 | { 35 | return $this->getParameter('country'); 36 | } 37 | 38 | /** 39 | * Set the country. 40 | * 41 | * @param $value 42 | * @return \Omnipay\Common\Message\AbstractRequest 43 | */ 44 | public function setCountry($value) 45 | { 46 | return $this->setParameter('country', $value); 47 | } 48 | 49 | /** 50 | * Get the required data for the API request. 51 | * 52 | * @return array 53 | */ 54 | public function getData() 55 | { 56 | parent::getData(); 57 | 58 | $data = array( 59 | 'amount' => $this->getAmountInteger(), 60 | 'country' => $this->getCountry(), 61 | 'currency' => $this->getCurrency(), 62 | ); 63 | 64 | return array_filter($data); 65 | } 66 | 67 | /** 68 | * Execute the API request. 69 | * 70 | * @param mixed $data 71 | * @return RestFetchPaymentMethodsResponse 72 | */ 73 | public function sendData($data) 74 | { 75 | $httpResponse = $this->sendRequest('GET', '/gateways', json_encode($data)); 76 | 77 | $this->response = new RestFetchPaymentMethodsResponse( 78 | $this, 79 | json_decode($httpResponse->getBody()->getContents(), true) 80 | ); 81 | 82 | return $this->response; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Message/RestFetchPaymentMethodsResponse.php: -------------------------------------------------------------------------------- 1 | 24 | * $request = $gateway->fetchPaymentMethods(); 25 | * $response = $request->send(); 26 | * $paymentMethods = $response->getPaymentMethods(); 27 | * print_r($paymentMethods); 28 | * 29 | */ 30 | class RestFetchPaymentMethodsResponse extends RestAbstractResponse implements FetchPaymentMethodsResponseInterface 31 | { 32 | /** 33 | * Get the returned list of payment methods. 34 | * 35 | * These represent separate payment methods which the user must choose between. 36 | * 37 | * @return \Omnipay\Common\PaymentMethod[] 38 | */ 39 | public function getPaymentMethods() 40 | { 41 | $paymentMethods = array(); 42 | 43 | foreach ($this->data['data'] as $method) { 44 | $paymentMethods[] = new PaymentMethod( 45 | $method['id'], 46 | $method['description'] 47 | ); 48 | } 49 | 50 | return $paymentMethods; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Message/RestFetchTransactionRequest.php: -------------------------------------------------------------------------------- 1 | 16 | * // Fetch the transaction. 17 | * $transaction = $gateway->fetchTransaction(); 18 | * $transaction->setTransactionId($transactionId); 19 | * $response = $transaction->send(); 20 | * print_r($response->getData()); 21 | * 22 | * 23 | * @link https://www.multisafepay.com/documentation/doc/API-Reference 24 | */ 25 | class RestFetchTransactionRequest extends RestAbstractRequest 26 | { 27 | /** 28 | * Get the required data which is needed 29 | * to execute the API request. 30 | * 31 | * @return array 32 | * @throws \Omnipay\Common\Exception\InvalidRequestException 33 | */ 34 | public function getData() 35 | { 36 | parent::getData(); 37 | 38 | $this->validate('transactionId'); 39 | 40 | $transactionId = $this->getTransactionId(); 41 | 42 | return compact('transactionId'); 43 | } 44 | 45 | /** 46 | * Execute the API request. 47 | * 48 | * @param mixed $data 49 | * @return RestFetchTransactionResponse 50 | */ 51 | public function sendData($data) 52 | { 53 | $httpResponse = $this->sendRequest( 54 | 'get', 55 | '/orders/' . $data['transactionId'] 56 | ); 57 | 58 | $this->response = new RestFetchTransactionResponse( 59 | $this, 60 | json_decode($httpResponse->getBody()->getContents(), true) 61 | ); 62 | 63 | return $this->response; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Message/RestFetchTransactionResponse.php: -------------------------------------------------------------------------------- 1 | 15 | * // Fetch the transaction. 16 | * $transaction = $gateway->fetchTransaction(); 17 | * $transaction->setTransactionId($transactionId); 18 | * $response = $transaction->send(); 19 | * print_r($response->getData()); 20 | * 21 | * 22 | * @link https://www.multisafepay.com/documentation/doc/API-Reference 23 | */ 24 | class RestFetchTransactionResponse extends RestAbstractResponse 25 | { 26 | /** 27 | * Is the payment created, but uncompleted? 28 | * 29 | * @return boolean 30 | */ 31 | public function isInitialized() 32 | { 33 | return $this->getPaymentStatus() == 'initialized'; 34 | } 35 | 36 | /** 37 | * Is the payment created, but not yet exempted (credit cards)? 38 | * 39 | * @return boolean 40 | */ 41 | public function isUncleared() 42 | { 43 | return $this->getPaymentStatus() == 'uncleared'; 44 | } 45 | 46 | /** 47 | * Is the payment cancelled? 48 | * 49 | * @return boolean 50 | */ 51 | public function isCancelled() 52 | { 53 | return $this->getPaymentStatus() == 'canceled'; 54 | } 55 | 56 | /** 57 | * Is the payment rejected? 58 | * 59 | * @return boolean 60 | */ 61 | public function isDeclined() 62 | { 63 | return $this->getPaymentStatus() == 'declined'; 64 | } 65 | 66 | /** 67 | * Is the payment refunded? 68 | * 69 | * @return boolean 70 | */ 71 | public function isRefunded() 72 | { 73 | if ($this->getPaymentStatus() == 'refunded' || 74 | $this->getPaymentStatus() == 'chargedback' 75 | ) { 76 | return true; 77 | } 78 | 79 | return false; 80 | } 81 | 82 | /** 83 | * Is the payment expired? 84 | * 85 | * @return boolean 86 | */ 87 | public function isExpired() 88 | { 89 | return $this->getPaymentStatus() == 'expired'; 90 | } 91 | 92 | /** 93 | * Get raw payment status. 94 | * 95 | * @return null|string 96 | */ 97 | public function getPaymentStatus() 98 | { 99 | if (isset($this->data['data']['status'])) { 100 | return $this->data['data']['status']; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/Message/RestPurchaseRequest.php: -------------------------------------------------------------------------------- 1 | 29 | * // Create a credit card object 30 | * $card = new CreditCard(array( 31 | * 'firstName' => 'Example', 32 | * 'lastName' => 'Customer', 33 | * 'number' => '4222222222222222', 34 | * 'expiryMonth' => '01', 35 | * 'expiryYear' => '2020', 36 | * 'cvv' => '123', 37 | * 'email' => 'customer@example.com', 38 | * 'address1' => '1 Scrubby Creek Road', 39 | * 'country' => 'AU', 40 | * 'city' => 'Scrubby Creek', 41 | * 'postalcode' => '4999', 42 | * 'state' => 'QLD', 43 | * )); 44 | * 45 | * 46 | * ### Initialize a "redirect" payment. 47 | * 48 | * The customer will be redirected to the MultiSafepay website 49 | * where they need to enter their payment details. 50 | * 51 | * 52 | * $request = $gateway->purchase(); 53 | * 54 | * $request->setAmount('20.00'); 55 | * $request->setTransactionId('TEST-TRANSACTION'); 56 | * $request->setDescription('Test transaction'); 57 | * 58 | * $request->setCurrency('EUR'); 59 | * $request->setType('redirect'); 60 | * 61 | * $response = $request->send(); 62 | * var_dump($response->getData()); 63 | * 64 | * 65 | * ### Initialize a "direct" payment. 66 | * 67 | * The merchant website need to collect the payment details, so 68 | * the user can stay at the merchant website. 69 | * 70 | * 71 | * $request = $gateway->purchase(); 72 | * 73 | * $request->setAmount('20.00'); 74 | * $request->setTransactionId('TEST-TRANSACTION'); 75 | * $request->setDescription('Test transaction'); 76 | * 77 | * $request->setCurrency('EUR'); 78 | * $request->setType('direct'); 79 | * $request->setCard($card); 80 | * 81 | * $request->setGateway('IDEAL'); 82 | * $request->setIssuer('ISSUER-ID'); // This ID can be found, with the RestFetchIssuersRequest. 83 | * 84 | * $response = $request->send(); 85 | * var_dump($response->getData()); 86 | * 87 | */ 88 | class RestPurchaseRequest extends RestAbstractRequest 89 | { 90 | /** 91 | * Get payment type. 92 | * 93 | * Specifies the payment flow for the checkout process. 94 | * 95 | * @return string 96 | */ 97 | public function getType() 98 | { 99 | return $this->getParameter('type'); 100 | } 101 | 102 | /** 103 | * Set payment type. 104 | * 105 | * Specifies the payment flow for the checkout process. 106 | * Possible values are 'redirect', 'direct' 107 | * 108 | * @param $value 109 | * @return \Omnipay\Common\Message\AbstractRequest 110 | */ 111 | public function setType($value) 112 | { 113 | return $this->setParameter('type', $value); 114 | } 115 | 116 | /** 117 | * Get recurring Payment Id 118 | * 119 | * A previously stored identifier referring to a 120 | * payment method to be charged again. 121 | * 122 | * @return int|null 123 | */ 124 | public function getRecurringId() 125 | { 126 | return $this->getParameter('recurring_id'); 127 | } 128 | 129 | /** 130 | * Set recurring Payment Id 131 | * 132 | * A previously stored identifier referring to a 133 | * payment method to be charged again. 134 | * 135 | * @param $value 136 | * @return \Omnipay\Common\Message\AbstractRequest 137 | */ 138 | public function setRecurringId($value) 139 | { 140 | return $this->setParameter('recurring_id', $value); 141 | } 142 | 143 | /** 144 | * Get the gateway. 145 | * 146 | * The unique gateway id to immediately direct the customer to the payment method. 147 | * You retrieve these gateways using a gateway request. 148 | * 149 | * @return mixed 150 | */ 151 | public function getGateway() 152 | { 153 | return $this->getParameter('gateway'); 154 | } 155 | 156 | /** 157 | * Set the gateway. 158 | * 159 | * The unique gateway id to immediately direct the customer to the payment method. 160 | * You retrieve these gateways using a gateway request. 161 | * 162 | * @param $value 163 | * @return \Omnipay\Common\Message\AbstractRequest 164 | */ 165 | public function setGateway($value) 166 | { 167 | return $this->setParameter('gateway', $value); 168 | } 169 | 170 | /** 171 | * Get value of var1. 172 | * 173 | * A free variable for custom data to be stored and persisted. 174 | * 175 | * @return string|null 176 | */ 177 | public function getVar1() 178 | { 179 | return $this->getParameter('var1'); 180 | } 181 | 182 | /** 183 | * Set var1. 184 | * 185 | * A free optional variable for custom data to be stored and persisted. 186 | * 187 | * @param $value 188 | * @return \Omnipay\Common\Message\AbstractRequest 189 | */ 190 | public function setVar1($value) 191 | { 192 | return $this->setParameter('var1', $value); 193 | } 194 | 195 | /** 196 | * Get var2. 197 | * 198 | * A free variable for custom data to be stored and persisted. 199 | * 200 | * @return string|null 201 | */ 202 | public function getVar2() 203 | { 204 | return $this->getParameter('var2'); 205 | } 206 | 207 | /** 208 | * Set var2. 209 | * 210 | * A free variable for custom data to be stored and persisted. 211 | * 212 | * @param $value 213 | * @return \Omnipay\Common\Message\AbstractRequest 214 | */ 215 | public function setVar2($value) 216 | { 217 | return $this->setParameter('var2', $value); 218 | } 219 | 220 | /** 221 | * Get var3. 222 | * 223 | * A free variable for custom data to be stored and persisted. 224 | * 225 | * @return string|null 226 | */ 227 | public function getVar3() 228 | { 229 | return $this->getParameter('var3'); 230 | } 231 | 232 | /** 233 | * Set var3. 234 | * 235 | * A free variable for custom data to be stored and persisted. 236 | * 237 | * @param $value 238 | * @return \Omnipay\Common\Message\AbstractRequest 239 | */ 240 | public function setVar3($value) 241 | { 242 | return $this->setParameter('var3', $value); 243 | } 244 | 245 | /** 246 | * Get manual. 247 | * 248 | * If true this forces a credit card transaction to require manual 249 | * acceptance regardless of the outcome from fraud checks. 250 | * It is possible that a high risk transaction is still declined. 251 | * 252 | * @return boolean|null 253 | */ 254 | public function getManual() 255 | { 256 | return $this->getParameter('manual'); 257 | } 258 | 259 | /** 260 | * Set manual. 261 | * 262 | * If true this forces a credit card transaction to require manual 263 | * acceptance regardless of the outcome from fraud checks. 264 | * It is possible that a high risk transaction is still declined. 265 | * 266 | * @param $value 267 | * @return \Omnipay\Common\Message\AbstractRequest 268 | */ 269 | public function setManual($value) 270 | { 271 | return $this->setParameter('manual', $value); 272 | } 273 | 274 | /** 275 | * Get days active. 276 | * 277 | * The number of days the payment link will be active for. 278 | * When not specified the default will be 30 days. 279 | * 280 | * @return int|null 281 | */ 282 | public function getDaysActive() 283 | { 284 | return $this->getParameter('days_active'); 285 | } 286 | 287 | /** 288 | * Set days active. 289 | * 290 | * The number of days the payment link will be active for. 291 | * When not specified the default will be 30 days. 292 | * 293 | * @param $value 294 | * @return \Omnipay\Common\Message\AbstractRequest 295 | */ 296 | public function setDaysActive($value) 297 | { 298 | return $this->setParameter('days_active', $value); 299 | } 300 | 301 | /** 302 | * Get close window. 303 | * 304 | * Set to true if you will display the MultiSafepay payment 305 | * page in a new window and want it to close automatically 306 | * after the payment process has been completed. 307 | * 308 | * @return boolean|null 309 | */ 310 | public function getCloseWindow() 311 | { 312 | return $this->getParameter('close_window'); 313 | } 314 | 315 | /** 316 | * Set close window. 317 | * 318 | * Set to true if you will display the MultiSafepay payment 319 | * page in a new window and want it to close automatically 320 | * after the payment process has been completed. 321 | * 322 | * @param $value 323 | * @return \Omnipay\Common\Message\AbstractRequest 324 | */ 325 | public function setCloseWindow($value) 326 | { 327 | return $this->setParameter('close_window', $value); 328 | } 329 | 330 | /** 331 | * Send mail. 332 | * 333 | * True if you will send your own bank transfer payment instructions to 334 | * consumers and do not want MultiSafepay to do this. 335 | * 336 | * @return boolean 337 | */ 338 | public function getSendMail() 339 | { 340 | return $this->getParameter('disable_send_mail'); 341 | } 342 | 343 | /** 344 | * Send mail. 345 | * 346 | * True if you will send your own bank transfer payment instructions to 347 | * consumers and do not want MultiSafepay to do this. 348 | * 349 | * @param $value 350 | * @return \Omnipay\Common\Message\AbstractRequest 351 | */ 352 | public function setSendMail($value) 353 | { 354 | return $this->setParameter('disable_send_mail', $value); 355 | } 356 | 357 | /** 358 | * Google analytics code. 359 | * 360 | * Your Google Analytics Site Id. 361 | * This will be injected into the payment pages 362 | * so you can trigger custom events and track payment metrics. 363 | * 364 | * @return string|null 365 | */ 366 | public function getGoogleAnalyticsCode() 367 | { 368 | return $this->getParameter('google_analytics'); 369 | } 370 | 371 | /** 372 | * Google analytics code. 373 | * 374 | * Your Google Analytics Site Id. 375 | * This will be injected into the payment pages 376 | * so you can trigger custom events and track payment metrics. 377 | * 378 | * @param $value 379 | * @return \Omnipay\Common\Message\AbstractRequest 380 | */ 381 | public function setGoogleAnalyticsCode($value) 382 | { 383 | return $this->setParameter('google_analytics', $value); 384 | } 385 | 386 | /** 387 | * Get items HTML 388 | * 389 | * @return string 390 | */ 391 | public function setItemsHtml($itemsHtml) 392 | { 393 | $this->setParameter('itemsHtml', $itemsHtml); 394 | } 395 | 396 | /** 397 | * Get items HTML 398 | * 399 | * @return string 400 | */ 401 | public function getItemsHtml() 402 | { 403 | return $this->getParameter('itemsHtml'); 404 | } 405 | 406 | /** 407 | * Get the payment options. 408 | * 409 | * @return array 410 | */ 411 | protected function getPaymentData() 412 | { 413 | $data = array( 414 | 'cancel_url' => $this->getCancelUrl(), 415 | 'close_window' => $this->getCloseWindow(), 416 | 'notification_url' => $this->getNotifyUrl(), 417 | 'redirect_url' => $this->getReturnUrl(), 418 | ); 419 | 420 | return array_filter($data); 421 | } 422 | 423 | /** 424 | * Customer information. 425 | * 426 | * This function returns all the provided 427 | * client related parameters. 428 | * 429 | * @return array 430 | */ 431 | public function getCustomerData() 432 | { 433 | $data = array( 434 | 'disable_send_mail' => $this->getSendMail(), 435 | 'locale' => $this->getLocale(), 436 | ); 437 | 438 | if (is_null($this->getCard())) { 439 | return array_filter($data); 440 | } 441 | 442 | $cardData = array( 443 | 'address1' => $this->getCard()->getAddress1(), 444 | 'address2' => $this->getCard()->getAddress2(), 445 | 'city' => $this->getCard()->getCity(), 446 | 'country' => $this->getCard()->getCountry(), 447 | 'email' => $this->getCard()->getEmail(), 448 | 'first_name' => $this->getCard()->getFirstName(), 449 | 'house_number' => $this->getVar1(), 450 | 'last_name' => $this->getCard()->getLastName(), 451 | 'phone' => $this->getCard()->getPhone(), 452 | 'state' => $this->getCard()->getState(), 453 | 'zip_code' => $this->getCard()->getPostcode(), 454 | ); 455 | 456 | return array_filter( 457 | array_merge($data, $cardData) 458 | ); 459 | } 460 | 461 | /** 462 | * Get gateway data. 463 | * 464 | * @return array 465 | */ 466 | protected function getGatewayData() 467 | { 468 | $data = array( 469 | 'issuer_id' => $this->getIssuer(), 470 | ); 471 | 472 | return array_filter($data); 473 | } 474 | 475 | /** 476 | * Get itembag data. 477 | * 478 | * @return array 479 | */ 480 | protected function getItemBagData() 481 | { 482 | $items = array(); 483 | $itemBag = $this->getItems(); 484 | if (! empty($itemBag)) { 485 | foreach ($itemBag->all() as $item) { 486 | $items[] = array( 487 | 'name' => $item->getName(), 488 | 'description' => $item->getDescription(), 489 | 'quantity' => $item->getQuantity(), 490 | 'unit_price' => $item->getPrice(), 491 | ); 492 | } 493 | } 494 | 495 | return $items; 496 | } 497 | 498 | /** 499 | * Get the raw data array for this message. The format of this varies from gateway to 500 | * gateway, but will usually be either an associative array, or a SimpleXMLElement. 501 | * 502 | * @return array 503 | * @throws \Omnipay\Common\Exception\InvalidRequestException 504 | */ 505 | public function getData() 506 | { 507 | parent::getData(); 508 | 509 | $this->validate( 510 | 'amount', 511 | 'currency', 512 | 'description', 513 | 'transactionId', 514 | 'type' 515 | ); 516 | 517 | // Direct order. 518 | if ($this->getType() === 'direct') { 519 | $this->validate('gateway'); 520 | } 521 | 522 | // When the gateway is set to IDEAL, 523 | // the issuer parameter is required. 524 | if ($this->getType() == 'direct' && $this->getGateway() == 'IDEAL') { 525 | $this->validate('issuer'); 526 | } 527 | 528 | $data = array( 529 | 'amount' => $this->getAmountInteger(), 530 | 'currency' => $this->getCurrency(), 531 | 'days_active' => $this->getDaysActive(), 532 | 'description' => $this->getDescription(), 533 | 'gateway' => $this->getGateway(), 534 | 'google_analytics' => $this->getGoogleAnalyticsCode(), 535 | 'items' => $this->getItemsHtml(), 536 | 'manual' => $this->getManual(), 537 | 'order_id' => $this->getTransactionId(), 538 | 'recurring_id' => $this->getRecurringId(), 539 | 'type' => $this->getType(), 540 | 'var1' => $this->getVar1(), 541 | 'var2' => $this->getVar2(), 542 | 'var3' => $this->getVar3(), 543 | ); 544 | 545 | $paymentData = $this->getPaymentData(); 546 | 547 | if (! empty($paymentData)) { 548 | $data['payment_options'] = $paymentData; 549 | } 550 | 551 | $customerData = $this->getCustomerData(); 552 | 553 | if (! empty($customerData)) { 554 | $data['customer'] = $customerData; 555 | } 556 | 557 | $gatewayData = $this->getGatewayData(); 558 | 559 | if (! empty($gatewayData)) { 560 | $data['gateway_info'] = $gatewayData; 561 | } 562 | 563 | $getItemBagData = $this->getItemBagData(); 564 | 565 | if (! empty($getItemBagData)) { 566 | $data['shopping_cart']['items'] = $getItemBagData; 567 | } 568 | 569 | return array_filter($data); 570 | } 571 | 572 | /** 573 | * Send the request with specified data 574 | * 575 | * @param mixed $data 576 | * @return RestPurchaseResponse 577 | */ 578 | public function sendData($data) 579 | { 580 | $httpResponse = $this->sendRequest('POST', '/orders', json_encode($data)); 581 | 582 | $this->response = new RestPurchaseResponse( 583 | $this, 584 | json_decode($httpResponse->getBody()->getContents(), true) 585 | ); 586 | 587 | return $this->response; 588 | } 589 | } 590 | -------------------------------------------------------------------------------- /src/Message/RestPurchaseResponse.php: -------------------------------------------------------------------------------- 1 | 31 | * // Create a credit card object 32 | * $card = new CreditCard(array( 33 | * 'firstName' => 'Example', 34 | * 'lastName' => 'Customer', 35 | * 'number' => '4222222222222222', 36 | * 'expiryMonth' => '01', 37 | * 'expiryYear' => '2020', 38 | * 'cvv' => '123', 39 | * 'email' => 'customer@example.com', 40 | * 'address1' => '1 Scrubby Creek Road', 41 | * 'country' => 'AU', 42 | * 'city' => 'Scrubby Creek', 43 | * 'postalcode' => '4999', 44 | * 'state' => 'QLD', 45 | * )); 46 | * 47 | * 48 | * ### Initialize a "redirect" payment. 49 | * 50 | * The customer will be redirected to the MultiSafepay website 51 | * where they need to enter their payment details. 52 | * 53 | * 54 | * $request = $gateway->purchase(); 55 | * 56 | * $request->setAmount('20.00'); 57 | * $request->setTransactionId('TEST-TRANSACTION'); 58 | * $request->setDescription('Test transaction'); 59 | * 60 | * $request->setCurrency('EUR'); 61 | * $request->setType('redirect'); 62 | * 63 | * $response = $request->send(); 64 | * var_dump($response->getData()); 65 | * 66 | * 67 | * ### Initialize a "direct" payment. 68 | * 69 | * The merchant website need to collect the payment details, so 70 | * the user can stay at the merchant website. 71 | * 72 | * 73 | * $request = $gateway->purchase(); 74 | * 75 | * $request->setAmount('20.00'); 76 | * $request->setTransactionId('TEST-TRANSACTION'); 77 | * $request->setDescription('Test transaction'); 78 | * 79 | * $request->setCurrency('EUR'); 80 | * $request->setType('direct'); 81 | * $request->setCard($card); 82 | * 83 | * $request->setGateway('IDEAL'); 84 | * $request->setIssuer('ISSUER-ID'); // This ID can be found, with the RestFetchIssuersRequest. 85 | * 86 | * $response = $request->send(); 87 | * var_dump($response->getData()); 88 | * 89 | */ 90 | class RestPurchaseResponse extends RestAbstractResponse implements RedirectResponseInterface 91 | { 92 | /** 93 | * Is the response successful? 94 | * 95 | * @return bool 96 | */ 97 | public function isSuccessful() 98 | { 99 | if ($this->isRedirect()) { 100 | return false; 101 | } 102 | 103 | return parent::isSuccessful(); 104 | } 105 | 106 | /** 107 | * {@inheritdoc} 108 | */ 109 | public function isRedirect() 110 | { 111 | return isset($this->data['data']['payment_url']); 112 | } 113 | 114 | /** 115 | * {@inheritdoc} 116 | */ 117 | public function getRedirectUrl() 118 | { 119 | if (!$this->isRedirect()) { 120 | return; 121 | } 122 | 123 | return $this->data['data']['payment_url']; 124 | } 125 | 126 | /** 127 | * {@inheritdoc} 128 | */ 129 | public function getRedirectMethod() 130 | { 131 | return 'GET'; 132 | } 133 | 134 | /** 135 | * {@inheritdoc} 136 | */ 137 | public function getRedirectData() 138 | { 139 | return; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/Message/RestRefundRequest.php: -------------------------------------------------------------------------------- 1 | 25 | * $request = $this->gateway->refund(); 26 | * 27 | * $request->setTransactionId('test-transaction'); 28 | * $request->setAmount('10.00'); 29 | * $request->setCurrency('eur'); 30 | * $request->setDescription('Test Refund'); 31 | * 32 | * $response = $request->send(); 33 | * var_dump($response->isSuccessful()); 34 | * 35 | */ 36 | class RestRefundRequest extends RestAbstractRequest 37 | { 38 | /** 39 | * Get the required data for the API request. 40 | * 41 | * @return array 42 | * @throws \Omnipay\Common\Exception\InvalidRequestException 43 | */ 44 | public function getData() 45 | { 46 | parent::getData(); 47 | 48 | $this->validate('amount', 'currency', 'description', 'transactionId'); 49 | 50 | return array( 51 | 'amount' => $this->getAmountInteger(), 52 | 'currency' => $this->getCurrency(), 53 | 'description' => $this->getDescription(), 54 | 'id' => $this->getTransactionId(), 55 | 'type' => 'refund', 56 | ); 57 | } 58 | 59 | /** 60 | * Send the request with specified data 61 | * 62 | * @param mixed $data 63 | * @return RestRefundResponse 64 | */ 65 | public function sendData($data) 66 | { 67 | $httpResponse = $this->sendRequest( 68 | 'POST', 69 | '/orders/' . $data['id'] . '/refunds', 70 | json_encode($data) 71 | ); 72 | 73 | $this->response = new RestRefundResponse( 74 | $this, 75 | json_decode($httpResponse->getBody()->getContents(), true) 76 | ); 77 | 78 | return $this->response; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Message/RestRefundResponse.php: -------------------------------------------------------------------------------- 1 | 24 | * $request = $this->gateway->refund(); 25 | * 26 | * $request->setTransactionId('test-transaction'); 27 | * $request->setAmount('10.00'); 28 | * $request->setCurrency('eur'); 29 | * $request->setDescription('Test Refund'); 30 | * 31 | * $response = $request->send(); 32 | * var_dump($response->isSuccessful()); 33 | * 34 | */ 35 | class RestRefundResponse extends RestAbstractResponse 36 | { 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/RestGateway.php: -------------------------------------------------------------------------------- 1 | 58 | * // Create the gateway 59 | * $gateway = Omnipay::create('MultiSafepay_Rest'); 60 | * 61 | * // Initialise the gateway 62 | * $gateway->initialize(array( 63 | * 'apiKey' => 'API-KEY', 64 | * 'locale' => 'en', 65 | * 'testMode' => true, // Or false, when you want to use the production environment 66 | * )); 67 | * 68 | * 69 | * ### Retrieve Payment Methods 70 | * 71 | * 72 | * $request = $gateway->fetchPaymentMethods(); 73 | * $response = $request->send(); 74 | * $paymentMethods = $response->getPaymentMethods(); 75 | * 76 | * 77 | * @link https://github.com/MultiSafepay/PHP 78 | * @link https://www.multisafepay.com/docs/getting-started/ 79 | * @link https://www.multisafepay.com/documentation/doc/API-Reference/ 80 | * @link https://www.multisafepay.com/documentation/doc/Step-by-Step/ 81 | * @link https://www.multisafepay.com/signup/ 82 | */ 83 | class RestGateway extends AbstractGateway 84 | { 85 | /** 86 | * @{inheritdoc} 87 | */ 88 | public function getName() 89 | { 90 | return 'MultiSafepay REST'; 91 | } 92 | 93 | /** 94 | * Get the gateway parameters 95 | * 96 | * @return array 97 | */ 98 | public function getDefaultParameters() 99 | { 100 | return array( 101 | 'apiKey' => '', 102 | 'locale' => 'en', 103 | 'testMode' => false, 104 | ); 105 | } 106 | 107 | /** 108 | * Get the locale. 109 | * 110 | * Optional ISO 639-1 language code which is used to specify a 111 | * a language used to display gateway information and other 112 | * messages in the responses. 113 | * 114 | * The default language is English. 115 | * 116 | * @return string 117 | */ 118 | public function getLocale() 119 | { 120 | return $this->getParameter('locale'); 121 | } 122 | 123 | /** 124 | * Set the locale. 125 | * 126 | * Optional ISO 639-1 language code which is used to specify a 127 | * a language used to display gateway information and other 128 | * messages in the responses. 129 | * 130 | * The default language is English. 131 | * 132 | * @param $value 133 | * @return \Omnipay\Common\Message\AbstractRequest 134 | */ 135 | public function setLocale($value) 136 | { 137 | return $this->setParameter('locale', $value); 138 | } 139 | 140 | /** 141 | * Get the gateway API Key 142 | * 143 | * Authentication is by means of a single secret API key set as 144 | * the apiKey parameter when creating the gateway object. 145 | * 146 | * @return string 147 | */ 148 | public function getApiKey() 149 | { 150 | return $this->getParameter('apiKey'); 151 | } 152 | 153 | /** 154 | * Set the gateway API Key 155 | * 156 | * Authentication is by means of a single secret API key set as 157 | * the apiKey parameter when creating the gateway object. 158 | * 159 | * @param string $value 160 | * @return RestGateway provides a fluent interface. 161 | */ 162 | public function setApiKey($value) 163 | { 164 | return $this->setParameter('apiKey', $value); 165 | } 166 | 167 | /** 168 | * Retrieve payment methods active on the given MultiSafepay 169 | * account. 170 | * 171 | * @param array $parameters 172 | * 173 | * @return \Omnipay\MultiSafepay\Message\RestFetchPaymentMethodsRequest 174 | */ 175 | public function fetchPaymentMethods(array $parameters = array()) 176 | { 177 | return $this->createRequest( 178 | 'Omnipay\MultiSafepay\Message\RestFetchPaymentMethodsRequest', 179 | $parameters 180 | ); 181 | } 182 | 183 | /** 184 | * Retrieve issuers for gateway. 185 | * 186 | * @param array $parameters 187 | * 188 | * @return \Omnipay\MultiSafepay\Message\RestFetchIssuersRequest 189 | */ 190 | public function fetchIssuers(array $parameters = array()) 191 | { 192 | return $this->createRequest( 193 | 'Omnipay\MultiSafepay\Message\RestFetchIssuersRequest', 194 | $parameters 195 | ); 196 | } 197 | 198 | /** 199 | * Retrieve transaction by the given identifier. 200 | * 201 | * @param array $parameters 202 | * @return \Omnipay\MultiSafepay\Message\RestFetchTransactionRequest 203 | */ 204 | public function fetchTransaction(array $parameters = array()) 205 | { 206 | return $this->createRequest( 207 | 'Omnipay\MultiSafepay\Message\RestFetchTransactionRequest', 208 | $parameters 209 | ); 210 | } 211 | 212 | /** 213 | * Create a refund. 214 | * 215 | * @param array $parameters 216 | * @return \Omnipay\MultiSafepay\Message\RestRefundRequest 217 | */ 218 | public function refund(array $parameters = array()) 219 | { 220 | return $this->createRequest( 221 | 'Omnipay\MultiSafepay\Message\RestRefundRequest', 222 | $parameters 223 | ); 224 | } 225 | 226 | /** 227 | * Create a purchase request. 228 | * 229 | * MultisafePay support different types of transactions, 230 | * such as iDEAL, Paypal and CreditCard payments. 231 | * 232 | * @param array $parameters 233 | * 234 | * @return \Omnipay\MultiSafepay\Message\RestPurchaseRequest 235 | */ 236 | public function purchase(array $parameters = array()) 237 | { 238 | return $this->createRequest( 239 | 'Omnipay\MultiSafepay\Message\RestPurchaseRequest', 240 | $parameters 241 | ); 242 | } 243 | 244 | /** 245 | * Complete a payment request. 246 | * 247 | * @param array $parameters 248 | * 249 | * @return \Omnipay\MultiSafepay\Message\RestCompletePurchaseRequest 250 | */ 251 | public function completePurchase(array $parameters = array()) 252 | { 253 | return $this->createRequest( 254 | 'Omnipay\MultiSafepay\Message\RestCompletePurchaseRequest', 255 | $parameters 256 | ); 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /src/XmlGateway.php: -------------------------------------------------------------------------------- 1 | 19 | * // Create the gateway 20 | * $gateway = Omnipay::create('MultiSafepay_Xml'); 21 | * 22 | * // Initialise the gateway 23 | * $gateway->initialize(array( 24 | * 'apiKey' => 'API-KEY', 25 | * 'locale' => 'en', 26 | * 'testMode' => true, // Or false, when you want to use the production environment 27 | * )); 28 | * 29 | * 30 | * @link https://www.multisafepay.com/downloads/handleidingen/Handleiding_connect(ENG).pdf 31 | */ 32 | class XmlGateway extends AbstractGateway 33 | { 34 | /** 35 | * {@inheritdoc} 36 | */ 37 | public function getName() 38 | { 39 | return 'MultiSafepay XML'; 40 | } 41 | 42 | /** 43 | * {@inheritdoc} 44 | */ 45 | public function getDefaultParameters() 46 | { 47 | return array( 48 | 'accountId' => '', 49 | 'siteId' => '', 50 | 'siteCode' => '', 51 | 'testMode' => false, 52 | ); 53 | } 54 | 55 | /** 56 | * Get the account identifier. 57 | * 58 | * @return mixed 59 | */ 60 | public function getAccountId() 61 | { 62 | return $this->getParameter('accountId'); 63 | } 64 | 65 | /** 66 | * Set the account identifier. 67 | * 68 | * @param $value 69 | * @return $this 70 | */ 71 | public function setAccountId($value) 72 | { 73 | return $this->setParameter('accountId', $value); 74 | } 75 | 76 | /** 77 | * Get the site identifier. 78 | * 79 | * @return mixed 80 | */ 81 | public function getSiteId() 82 | { 83 | return $this->getParameter('siteId'); 84 | } 85 | 86 | /** 87 | * Set the site identifier. 88 | * 89 | * @param $value 90 | * @return $this 91 | */ 92 | public function setSiteId($value) 93 | { 94 | return $this->setParameter('siteId', $value); 95 | } 96 | 97 | /** 98 | * Get the site code. 99 | * 100 | * @return mixed 101 | */ 102 | public function getSiteCode() 103 | { 104 | return $this->getParameter('siteCode'); 105 | } 106 | 107 | /** 108 | * Set the site code. 109 | * 110 | * @param $value 111 | * @return $this 112 | */ 113 | public function setSiteCode($value) 114 | { 115 | return $this->setParameter('siteCode', $value); 116 | } 117 | 118 | /** 119 | * Retrieve payment methods active on the given MultiSafepay 120 | * account. 121 | * 122 | * @param array $parameters 123 | * 124 | * @return \Omnipay\MultiSafepay\Message\FetchPaymentMethodsRequest 125 | */ 126 | public function fetchPaymentMethods(array $parameters = array()) 127 | { 128 | return $this->createRequest( 129 | '\Omnipay\MultiSafepay\Message\FetchPaymentMethodsRequest', 130 | $parameters 131 | ); 132 | } 133 | 134 | /** 135 | * Retrieve iDEAL issuers. 136 | * 137 | * @param array $parameters 138 | * 139 | * @return \Omnipay\MultiSafepay\Message\FetchIssuersRequest 140 | */ 141 | public function fetchIssuers(array $parameters = array()) 142 | { 143 | return $this->createRequest( 144 | '\Omnipay\MultiSafepay\Message\FetchIssuersRequest', 145 | $parameters 146 | ); 147 | } 148 | 149 | /** 150 | * Create Purchase request. 151 | * 152 | * @param array $parameters 153 | * 154 | * @return \Omnipay\MultiSafepay\Message\PurchaseRequest 155 | */ 156 | public function purchase(array $parameters = array()) 157 | { 158 | return $this->createRequest( 159 | '\Omnipay\MultiSafepay\Message\PurchaseRequest', 160 | $parameters 161 | ); 162 | } 163 | 164 | /** 165 | * Complete purchase request. 166 | * 167 | * @param array $parameters 168 | * 169 | * @return \Omnipay\MultiSafepay\Message\CompletePurchaseRequest 170 | */ 171 | public function completePurchase(array $parameters = array()) 172 | { 173 | return $this->createRequest( 174 | '\Omnipay\MultiSafepay\Message\CompletePurchaseRequest', 175 | $parameters 176 | ); 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /tests/Message/RestFetchIssuersRequestTest.php: -------------------------------------------------------------------------------- 1 | request = new RestFetchIssuersRequest( 15 | $this->getHttpClient(), 16 | $this->getHttpRequest() 17 | ); 18 | 19 | $this->request->initialize( 20 | array( 21 | 'api_key' => '123456789', 22 | 'paymentMethod' => 'IDEAL' 23 | ) 24 | ); 25 | } 26 | 27 | public function testSendSuccess() 28 | { 29 | $this->setMockHttpResponse('RestFetchIssuersSuccess.txt'); 30 | 31 | $response = $this->request->send(); 32 | 33 | $issuers = $response->getIssuers(); 34 | 35 | $this->assertContainsOnlyInstancesOf('Omnipay\Common\Issuer', $issuers); 36 | $this->assertFalse($response->isRedirect()); 37 | $this->assertInstanceOf('Omnipay\MultiSafepay\Message\RestFetchIssuersResponse', $response); 38 | $this->assertInternalType('array', $issuers); 39 | 40 | $this->assertNull($response->getTransactionReference()); 41 | $this->assertTrue($response->isSuccessful()); 42 | } 43 | 44 | public function testIssuerNotFound() 45 | { 46 | $this->setMockHttpResponse('RestFetchIssuersFailure.txt'); 47 | 48 | $response = $this->request->send(); 49 | 50 | $this->assertEquals('Not found', $response->getMessage()); 51 | $this->assertEquals(404, $response->getCode()); 52 | $this->assertFalse($response->isRedirect()); 53 | 54 | $this->assertFalse($response->isSuccessful()); 55 | $this->assertInstanceOf('Omnipay\MultiSafepay\Message\RestFetchIssuersResponse', $response); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/Message/RestFetchPaymentMethodsRequestTest.php: -------------------------------------------------------------------------------- 1 | request = new RestFetchPaymentMethodsRequest( 15 | $this->getHttpClient(), 16 | $this->getHttpRequest() 17 | ); 18 | 19 | $this->request->initialize( 20 | array( 21 | 'api_key' => '123456789', 22 | 'country' => 'NL' 23 | ) 24 | ); 25 | } 26 | 27 | public function testSendSuccess() 28 | { 29 | $this->setMockHttpResponse('RestFetchPaymentMethodsSuccess.txt'); 30 | 31 | $response = $this->request->send(); 32 | 33 | $paymentMethods = $response->getPaymentMethods(); 34 | 35 | $this->assertTrue($response->isSuccessful()); 36 | $this->assertFalse($response->isRedirect()); 37 | $this->assertNull($response->getTransactionReference()); 38 | 39 | $this->assertInternalType('array', $paymentMethods); 40 | $this->assertContainsOnlyInstancesOf('Omnipay\Common\PaymentMethod', $paymentMethods); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/Message/RestPurchaseRequestTest.php: -------------------------------------------------------------------------------- 1 | request = new RestPurchaseRequest( 15 | $this->getHttpClient(), 16 | $this->getHttpRequest() 17 | ); 18 | 19 | $this->request->initialize( 20 | array( 21 | 'apiKey' => '123456789', 22 | 'amount' => 10.00, 23 | 'currency' => 'eur', 24 | 'description' => 'Test transaction', 25 | 'cancel_url' => 'http://localhost/cancel', 26 | 'notify_url' => 'http://localhost/notify', 27 | 'return_url' => 'http://localhost/return', 28 | 'close_window' => false, 29 | 'days_active' => 3, 30 | 'send_mail' => true, 31 | 'gateway' => 'IDEAL', 32 | 'google_analytics_code' => '123456789', 33 | 'manual' => false, 34 | 'transactionId' => 'TEST-TRANS-1', 35 | 'type' => 'redirect', 36 | 'var1' => 'extra data 1', 37 | 'var2' => 'extra data 2', 38 | 'var3' => 'extra data 3', 39 | ) 40 | ); 41 | } 42 | 43 | public function testSendSuccess() 44 | { 45 | $this->setMockHttpResponse('RestPurchaseSuccess.txt'); 46 | 47 | $response = $this->request->send(); 48 | 49 | $this->assertFalse($response->isSuccessful()); 50 | $this->assertTrue($response->isRedirect()); 51 | 52 | $this->assertEquals( 53 | 'https://testpay.multisafepay.com/pay/?order_id=TEST-TRANS-1', 54 | $response->getRedirectUrl() 55 | ); 56 | 57 | $this->assertEquals('TEST-TRANS-1', $response->getTransactionId()); 58 | } 59 | 60 | public function testInvalidAmount() 61 | { 62 | $this->setMockHttpResponse('RestPurchaseInvalidAmount.txt'); 63 | 64 | $response = $this->request->send(); 65 | 66 | $this->assertFalse($response->isSuccessful()); 67 | $this->assertEquals('Invalid amount', $response->getMessage()); 68 | $this->assertEquals(1001, $response->getCode()); 69 | } 70 | 71 | public function testDataIntegrity() 72 | { 73 | $this->assertEquals('123456789', $this->request->getGoogleAnalyticsCode()); 74 | $this->assertEquals('EUR', $this->request->getCurrency()); 75 | $this->assertEquals('extra data 1', $this->request->getVar1()); 76 | $this->assertEquals('extra data 2', $this->request->getVar2()); 77 | $this->assertEquals('extra data 3', $this->request->getVar3()); 78 | $this->assertEquals('http://localhost/cancel', $this->request->getCancelUrl()); 79 | $this->assertEquals('http://localhost/notify', $this->request->getNotifyUrl()); 80 | $this->assertEquals('http://localhost/return', $this->request->getReturnUrl()); 81 | $this->assertEquals('IDEAL', $this->request->getGateway()); 82 | $this->assertEquals('redirect', $this->request->getType()); 83 | $this->assertEquals('Test transaction', $this->request->getDescription()); 84 | $this->assertEquals('TEST-TRANS-1', $this->request->getTransactionId()); 85 | $this->assertEquals(10.00, $this->request->getAmount()); 86 | $this->assertEquals(3, $this->request->getDaysActive()); 87 | $this->assertFalse($this->request->getCloseWindow()); 88 | $this->assertFalse($this->request->getManual()); 89 | $this->assertTrue($this->request->getSendMail()); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /tests/Message/XmlAbstractRequestTest.php: -------------------------------------------------------------------------------- 1 | request = m::mock('\Omnipay\MultiSafepay\Message\AbstractRequest')->makePartial(); 19 | } 20 | 21 | /** 22 | * @covers \Omnipay\MultiSafepay\Message\AbstractRequest::getHeaders() 23 | */ 24 | public function testUserAgentHeaderMustNotBeSet() 25 | { 26 | $method = new ReflectionMethod('\Omnipay\MultiSafepay\Message\AbstractRequest', 'getHeaders'); 27 | $method->setAccessible(true); 28 | 29 | $headers = $method->invoke($this->request); 30 | $this->assertArrayHasKey( 31 | 'User-Agent', 32 | $headers, 33 | 'Omitting User-Agent header not allowed because then Guzzle will set it and cause 403 Forbidden on the gateway' 34 | ); 35 | $this->assertEquals('Omnipay', $headers['User-Agent'], 'User-Agent header set'); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/Message/XmlCompletePurchaseRequestTest.php: -------------------------------------------------------------------------------- 1 | request = new CompletePurchaseRequest( 17 | $this->getHttpClient(), 18 | $this->getHttpRequest() 19 | ); 20 | 21 | $this->request->initialize(array( 22 | 'accountId' => '111111', 23 | 'siteId' => '222222', 24 | 'siteCode' => '333333', 25 | 'notifyUrl' => 'http://localhost/notify', 26 | 'cancelUrl' => 'http://localhost/cancel', 27 | 'returnUrl' => 'http://localhost/return', 28 | 'gateway' => 'IDEAL', 29 | 'issuer' => 'issuer', 30 | 'transactionId' => '123456', 31 | 'currency' => 'EUR', 32 | 'amount' => '100.00', 33 | 'description' => 'desc', 34 | 'extraData1' => 'extra 1', 35 | 'extraData2' => 'extra 2', 36 | 'extraData3' => 'extra 3', 37 | 'language' => 'a language', 38 | 'clientIp' => '127.0.0.1', 39 | 'googleAnalyticsCode' => 'analytics code', 40 | 'card' => array( 41 | 'email' => 'something@example.com', 42 | 'firstName' => 'first name', 43 | 'lastName' => 'last name', 44 | 'address1' => 'address 1', 45 | 'address2' => 'address 2', 46 | 'postcode' => '1000', 47 | 'city' => 'a city', 48 | 'country' => 'a country', 49 | 'phone' => 'phone number', 50 | ) 51 | )); 52 | } 53 | 54 | public function testSendSuccess() 55 | { 56 | $this->setMockHttpResponse('XmlCompletePurchaseSuccess.txt'); 57 | 58 | $response = $this->request->send(); 59 | 60 | $this->assertTrue($response->isSuccessful()); 61 | $this->assertEquals('123456', $response->getTransactionReference()); 62 | } 63 | 64 | public function testSendFailure() 65 | { 66 | $this->setMockHttpResponse('XmlCompletePurchaseFailure.txt'); 67 | 68 | $response = $this->request->send(); 69 | 70 | $this->assertFalse($response->isSuccessful()); 71 | $this->assertEquals('Back-end: missing data', $response->getMessage()); 72 | $this->assertEquals(1016, $response->getCode()); 73 | } 74 | 75 | /** 76 | * @dataProvider dataProvider 77 | */ 78 | public function testGetData($xml) 79 | { 80 | $data = $this->request->getData(); 81 | $this->assertInstanceOf('SimpleXMLElement', $data); 82 | 83 | // Just so the provider remains readable... 84 | $dom = dom_import_simplexml($data)->ownerDocument; 85 | $dom->formatOutput = true; 86 | $this->assertEquals($xml, $dom->saveXML()); 87 | } 88 | 89 | public function dataProvider() 90 | { 91 | $xml = << 93 | 94 | 95 | 111111 96 | 222222 97 | 333333 98 | 99 | 100 | 123456 101 | 102 | 103 | 104 | EOF; 105 | 106 | return array( 107 | array($xml), 108 | ); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /tests/Message/XmlFetchIssuersRequestTest.php: -------------------------------------------------------------------------------- 1 | request = new FetchIssuersRequest( 17 | $this->getHttpClient(), 18 | $this->getHttpRequest() 19 | ); 20 | 21 | $this->request->initialize(array( 22 | 'accountId' => '111111', 23 | 'siteId' => '222222', 24 | 'siteCode' => '333333', 25 | )); 26 | } 27 | 28 | /** 29 | * @dataProvider issuersProvider 30 | */ 31 | public function testSendSuccess($expected) 32 | { 33 | $this->setMockHttpResponse('XmlFetchIssuersSuccess.txt'); 34 | 35 | $response = $this->request->send(); 36 | 37 | $this->assertTrue($response->isSuccessful()); 38 | $this->assertEquals($expected, $response->getIssuers()); 39 | } 40 | 41 | public function testSendFailure() 42 | { 43 | $this->setMockHttpResponse('XmlFetchIssuersFailure.txt'); 44 | 45 | $response = $this->request->send(); 46 | 47 | $this->assertFalse($response->isSuccessful()); 48 | $this->assertEquals('Invalid merchant security code', $response->getMessage()); 49 | $this->assertEquals(1005, $response->getCode()); 50 | } 51 | 52 | /** 53 | * @dataProvider dataProvider 54 | */ 55 | public function testGetData($xml) 56 | { 57 | $data = $this->request->getData(); 58 | $this->assertInstanceOf('SimpleXMLElement', $data); 59 | 60 | // Just so the provider remains readable... 61 | $dom = dom_import_simplexml($data)->ownerDocument; 62 | $dom->formatOutput = true; 63 | $this->assertEquals($xml, $dom->saveXML()); 64 | } 65 | 66 | public function issuersProvider() 67 | { 68 | return array( 69 | array( 70 | array( 71 | '0031' => 'ABN AMRO', 72 | '0751' => 'SNS Bank', 73 | '0721' => 'ING', 74 | '0021' => 'Rabobank', 75 | '0091' => 'Friesland Bank', 76 | '0761' => 'ASN Bank', 77 | '0771' => 'SNS Regio Bank', 78 | '0511' => 'Triodos Bank', 79 | '0161' => 'Van Lanschot Bankiers', 80 | '0801' => 'Knab', 81 | ), 82 | ), 83 | ); 84 | } 85 | 86 | public function dataProvider() 87 | { 88 | $xml = << 90 | 91 | 92 | 111111 93 | 222222 94 | 333333 95 | 96 | 97 | 98 | EOF; 99 | 100 | return array( 101 | array($xml), 102 | ); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /tests/Message/XmlFetchPaymentMethodsRequestTest.php: -------------------------------------------------------------------------------- 1 | request = new FetchPaymentMethodsRequest( 17 | $this->getHttpClient(), 18 | $this->getHttpRequest() 19 | ); 20 | 21 | $this->request->initialize(array( 22 | 'accountId' => '111111', 23 | 'siteId' => '222222', 24 | 'siteCode' => '333333', 25 | 'country' => 'NL', 26 | )); 27 | } 28 | 29 | /** 30 | * @dataProvider paymentMethodsProvider 31 | */ 32 | public function testSendSuccess($expected) 33 | { 34 | $this->setMockHttpResponse('XmlFetchPaymentMethodsSuccess.txt'); 35 | 36 | $response = $this->request->send(); 37 | 38 | $this->assertTrue($response->isSuccessful()); 39 | $this->assertEquals($expected, $response->getPaymentMethods()); 40 | } 41 | 42 | public function testSendFailure() 43 | { 44 | $this->setMockHttpResponse('XmlFetchPaymentMethodsFailure.txt'); 45 | 46 | $response = $this->request->send(); 47 | 48 | $this->assertFalse($response->isSuccessful()); 49 | $this->assertEquals('Invalid merchant security code', $response->getMessage()); 50 | $this->assertEquals(1005, $response->getCode()); 51 | } 52 | 53 | /** 54 | * @dataProvider dataProvider 55 | */ 56 | public function testGetData($xml) 57 | { 58 | $data = $this->request->getData(); 59 | $this->assertInstanceOf('SimpleXMLElement', $data); 60 | 61 | // Just so the provider remains readable... 62 | $dom = dom_import_simplexml($data)->ownerDocument; 63 | $dom->formatOutput = true; 64 | $this->assertEquals($xml, $dom->saveXML()); 65 | } 66 | 67 | public function paymentMethodsProvider() 68 | { 69 | return array( 70 | array( 71 | array( 72 | 'VISA' => 'Visa CreditCards', 73 | 'WALLET' => 'MultiSafepay', 74 | 'IDEAL' => 'iDEAL', 75 | 'BANKTRANS' => 'Bank Transfer', 76 | 'MASTERCARD' => 'MasterCard', 77 | ), 78 | ), 79 | ); 80 | } 81 | 82 | public function dataProvider() 83 | { 84 | $xml = << 86 | 87 | 88 | 111111 89 | 222222 90 | 333333 91 | 92 | 93 | NL 94 | 95 | 96 | 97 | EOF; 98 | 99 | return array( 100 | array($xml), 101 | ); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /tests/Message/XmlPurchaseRequestTest.php: -------------------------------------------------------------------------------- 1 | request = new PurchaseRequest( 18 | $this->getHttpClient(), 19 | $this->getHttpRequest() 20 | ); 21 | 22 | $this->request->initialize(array( 23 | 'accountId' => '111111', 24 | 'siteId' => '222222', 25 | 'siteCode' => '333333', 26 | 'notifyUrl' => 'http://localhost/notify', 27 | 'cancelUrl' => 'http://localhost/cancel', 28 | 'returnUrl' => 'http://localhost/return', 29 | 'gateway' => 'IDEAL', 30 | 'issuer' => 'issuer', 31 | 'transactionId' => '123456', 32 | 'currency' => 'EUR', 33 | 'amount' => '100.00', 34 | 'description' => 'desc', 35 | 'extraData1' => 'extra 1', 36 | 'extraData2' => 'extra 2', 37 | 'extraData3' => 'extra 3', 38 | 'language' => 'a language', 39 | 'items' => array( 40 | array('name' => 'item 1', 'quantity' => 1), 41 | array('name' => 'item 2', 'quantity' => 2) 42 | ), 43 | 'clientIp' => '127.0.0.1', 44 | 'googleAnalyticsCode' => 'analytics code', 45 | 'card' => array( 46 | 'email' => 'something@example.com', 47 | 'firstName' => 'first name', 48 | 'lastName' => 'last name', 49 | 'address1' => 'address 1', 50 | 'address2' => 'address 2', 51 | 'postcode' => '1000', 52 | 'city' => 'a city', 53 | 'country' => 'a country', 54 | 'phone' => 'phone number', 55 | ) 56 | )); 57 | } 58 | 59 | public function testSendSuccess() 60 | { 61 | $this->setMockHttpResponse('XmlPurchaseSuccess.txt'); 62 | 63 | $response = $this->request->send(); 64 | 65 | $this->assertFalse($response->isSuccessful()); 66 | $this->assertTrue($response->isRedirect()); 67 | $this->assertEquals( 68 | 'https://testpay.multisafepay.com/pay/?transaction=1373536347Hz4sFtg7WgMulO5q123456&lang=', 69 | $response->getRedirectUrl() 70 | ); 71 | 72 | $this->assertEquals('123456', $response->getTransactionReference()); 73 | } 74 | 75 | public function testSendFailure() 76 | { 77 | $this->setMockHttpResponse('XmlPurchaseFailure.txt'); 78 | 79 | $response = $this->request->send(); 80 | 81 | $this->assertFalse($response->isSuccessful()); 82 | $this->assertEquals('Invalid amount', $response->getMessage()); 83 | $this->assertEquals(1001, $response->getCode()); 84 | } 85 | 86 | /** 87 | * @dataProvider allDataProvider 88 | */ 89 | public function testGetData($xml) 90 | { 91 | $data = $this->request->getData(); 92 | $this->assertInstanceOf('SimpleXMLElement', $data); 93 | 94 | // Just so the provider remains readable... 95 | $dom = dom_import_simplexml($data)->ownerDocument; 96 | $dom->formatOutput = true; 97 | $this->assertEquals($xml, $dom->saveXML()); 98 | } 99 | 100 | /** 101 | * @dataProvider noIssuerDataProvider 102 | */ 103 | public function testGetDataWithNonIDEALGatewayDoesNotSetIssuer($xml) 104 | { 105 | $this->request->setGateway('another'); 106 | $data = $this->request->getData(); 107 | $this->assertInstanceOf('SimpleXMLElement', $data); 108 | 109 | // Just so the provider remains readable... 110 | $dom = dom_import_simplexml($data)->ownerDocument; 111 | $dom->formatOutput = true; 112 | $this->assertEquals($xml, $dom->saveXML()); 113 | } 114 | 115 | /** 116 | * @dataProvider specialCharsDataProvider 117 | */ 118 | public function testGetDataWithUrlsWithSpecialChars($xml) 119 | { 120 | $this->request->setReturnUrl('http://localhost/?one=1&two=2'); 121 | $this->request->setCancelUrl('http://localhost/?one=1&two=2'); 122 | $this->request->setNotifyUrl('http://localhost/?one=1&two=2'); 123 | $data = $this->request->getData(); 124 | $this->assertInstanceOf('SimpleXMLElement', $data); 125 | 126 | // Just so the provider remains readable... 127 | $dom = dom_import_simplexml($data)->ownerDocument; 128 | $dom->formatOutput = true; 129 | $this->assertEquals($xml, $dom->saveXML()); 130 | } 131 | 132 | /** 133 | * @covers \Omnipay\MultiSafepay\Message\PurchaseRequest::generateSignature() 134 | */ 135 | public function testGenerateSignature() 136 | { 137 | $method = new ReflectionMethod('\Omnipay\MultiSafepay\Message\PurchaseRequest', 'generateSignature'); 138 | $method->setAccessible(true); 139 | 140 | $signature = $method->invoke($this->request); 141 | $this->assertEquals('ad447bab87b8597853432c891e341db1', $signature); 142 | } 143 | 144 | public function allDataProvider() 145 | { 146 | $xml = << 148 | 149 | 150 | 111111 151 | 222222 152 | 333333 153 | http://localhost/notify 154 | http://localhost/cancel 155 | http://localhost/return 156 | 157 | 158 | 127.0.0.1 159 | a language 160 | something@example.com 161 | first name 162 | last name 163 | address 1 164 | address 2 165 | 1000 166 | a city 167 | a country 168 | phone number 169 | 170 | analytics code 171 | 172 | 123456 173 | EUR 174 | 10000 175 | desc 176 | extra 1 177 | extra 2 178 | extra 3 179 | IDEAL 180 | <ul><li>1 x item 1</li><li>2 x item 2</li></ul> 181 | 182 | 183 | issuer 184 | 185 | ad447bab87b8597853432c891e341db1 186 | 187 | 188 | EOF; 189 | 190 | return array( 191 | array($xml), 192 | ); 193 | } 194 | 195 | public function noIssuerDataProvider() 196 | { 197 | $xml = << 199 | 200 | 201 | 111111 202 | 222222 203 | 333333 204 | http://localhost/notify 205 | http://localhost/cancel 206 | http://localhost/return 207 | 208 | 209 | 127.0.0.1 210 | a language 211 | something@example.com 212 | first name 213 | last name 214 | address 1 215 | address 2 216 | 1000 217 | a city 218 | a country 219 | phone number 220 | 221 | analytics code 222 | 223 | 123456 224 | EUR 225 | 10000 226 | desc 227 | extra 1 228 | extra 2 229 | extra 3 230 | another 231 | <ul><li>1 x item 1</li><li>2 x item 2</li></ul> 232 | 233 | ad447bab87b8597853432c891e341db1 234 | 235 | 236 | EOF; 237 | 238 | return array( 239 | array($xml), 240 | ); 241 | } 242 | 243 | public function specialCharsDataProvider() 244 | { 245 | $xml = << 247 | 248 | 249 | 111111 250 | 222222 251 | 333333 252 | http://localhost/?one=1&two=2 253 | http://localhost/?one=1&two=2 254 | http://localhost/?one=1&two=2 255 | 256 | 257 | 127.0.0.1 258 | a language 259 | something@example.com 260 | first name 261 | last name 262 | address 1 263 | address 2 264 | 1000 265 | a city 266 | a country 267 | phone number 268 | 269 | analytics code 270 | 271 | 123456 272 | EUR 273 | 10000 274 | desc 275 | extra 1 276 | extra 2 277 | extra 3 278 | IDEAL 279 | <ul><li>1 x item 1</li><li>2 x item 2</li></ul> 280 | 281 | 282 | issuer 283 | 284 | ad447bab87b8597853432c891e341db1 285 | 286 | 287 | EOF; 288 | 289 | return array( 290 | array($xml), 291 | ); 292 | } 293 | } 294 | -------------------------------------------------------------------------------- /tests/Mock/RestFetchIssuersFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Fri, 05 Feb 2016 10:11:02 GMT 3 | Server: Apache 4 | Vary: Accept-Encoding 5 | Content-Length: 88 6 | Content-Type: application/json; charset=UTF-8; 7 | 8 | {"success":false,"data":{},"error_code":404,"error_info":"Not found"} -------------------------------------------------------------------------------- /tests/Mock/RestFetchIssuersSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Fri, 05 Feb 2016 09:18:54 GMT 3 | Server: Apache 4 | Vary: Accept-Encoding 5 | Content-Length: 214 6 | Content-Type: application/json; charset=UTF-8; 7 | 8 | {"success":true,"data":[{"code":"0031","description":"ABN AMRO"},{"code":"0751","description":"SNS Bank"},{"code":"0721","description":"ING"},{"code":"0021","description":"Rabobank"},{"code":"0761","description":"ASN Bank"},{"code":"0771","description":"Regio Bank"},{"code":"0511","description":"Triodos Bank"},{"code":"0161","description":"Van Lanschot Bankiers"},{"code":"0801","description":"Knab"},{"code":4371,"description":"Bunq"}]} -------------------------------------------------------------------------------- /tests/Mock/RestFetchPaymentMethodsSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Fri, 05 Feb 2016 10:25:42 GMT 3 | Server: Apache 4 | Vary: Accept-Encoding 5 | Content-Length: 52 6 | Content-Type: application/json; charset=UTF-8; 7 | 8 | {"success":true,"data":[{"id":"BANKTRANS","description":"Wire Transfer"},{"id":"MAESTRO","description":"Maestro"},{"id":"VISA","description":"Visa"},{"id":"WALLET","description":"MultiSafepay"},{"id":"IDEAL","description":"iDEAL"},{"id":"MASTERCARD","description":"MasterCard"}]} -------------------------------------------------------------------------------- /tests/Mock/RestInvalidApiKeyFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Fri, 05 Feb 2016 10:11:02 GMT 3 | Server: Apache 4 | Vary: Accept-Encoding 5 | Content-Length: 95 6 | Content-Type: application/json; charset=UTF-8; 7 | 8 | {"success":false,"data":{},"error_code":1032,"error_info":"Invalid API key"} -------------------------------------------------------------------------------- /tests/Mock/RestPurchaseInvalidAmount.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Fri, 05 Feb 2016 10:11:02 GMT 3 | Server: Apache 4 | Vary: Accept-Encoding 5 | Content-Length: 75 6 | Content-Type: application/json; charset=UTF-8; 7 | 8 | {"success":false,"data":{},"error_code":1001,"error_info":"Invalid amount"} -------------------------------------------------------------------------------- /tests/Mock/RestPurchaseSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Fri, 05 Feb 2016 09:18:54 GMT 3 | Server: Apache 4 | Vary: Accept-Encoding 5 | Content-Length: 131 6 | Content-Type: application/json; charset=UTF-8; 7 | 8 | {"success":true,"data":{"order_id":"TEST-TRANS-1","payment_url":"https:\/\/testpay.multisafepay.com\/pay\/?order_id=TEST-TRANS-1"}} -------------------------------------------------------------------------------- /tests/Mock/XmlCompletePurchaseFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Thu, 11 Jul 2013 10:36:27 GMT 3 | Server: Apache/2.2.22 (FreeBSD) mod_ssl/2.2.22 OpenSSL/0.9.8q DAV/2 4 | Content-Length: 153 5 | Content-Type: text/xml 6 | 7 | 8 | 1016Back-end: missing data 9 | -------------------------------------------------------------------------------- /tests/Mock/XmlCompletePurchaseSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Thu, 11 Jul 2013 10:34:48 GMT 3 | Server: Apache/2.2.22 (FreeBSD) mod_ssl/2.2.22 OpenSSL/0.9.8q DAV/2 4 | Content-Length: 931 5 | Content-Type: text/xml 6 | 7 | 8 | 2087325completedNO201307111233082013071112331710000EURen_UStester@example.com123456EUR10000descIDEAL213698412Hr E G H Küppers en/of Mw M J Küppers an nog een lange consumername0050000075107095 9 | -------------------------------------------------------------------------------- /tests/Mock/XmlFetchIssuersFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Thu, 11 Jul 2013 13:22:17 GMT 3 | Server: Apache/2.2.16 (Debian) 4 | X-Powered-By: PHP/5.3.3-7+squeeze14 5 | Vary: Accept-Encoding 6 | Content-Length: 173 7 | Content-Type: text/xml 8 | 9 | 10 | 1005Invalid merchant security code 11 | -------------------------------------------------------------------------------- /tests/Mock/XmlFetchIssuersSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Thu, 11 Jul 2013 13:21:39 GMT 3 | Server: Apache/2.2.16 (Debian) 4 | X-Powered-By: PHP/5.3.3-7+squeeze14 5 | Vary: Accept-Encoding 6 | Content-Length: 810 7 | Content-Type: text/xml 8 | 9 | 10 | 0031ABN AMRO0751SNS Bank0721ING0021Rabobank0091Friesland Bank0761ASN Bank0771SNS Regio Bank0511Triodos Bank0161Van Lanschot Bankiers0801Knab 11 | -------------------------------------------------------------------------------- /tests/Mock/XmlFetchPaymentMethodsFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Thu, 11 Jul 2013 12:32:27 GMT 3 | Server: Apache/2.2.16 (Debian) 4 | X-Powered-By: PHP/5.3.3-7+squeeze14 5 | Vary: Accept-Encoding 6 | Content-Length: 165 7 | Content-Type: text/xml 8 | 9 | 10 | 1005Invalid merchant security code 11 | -------------------------------------------------------------------------------- /tests/Mock/XmlFetchPaymentMethodsSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Thu, 11 Jul 2013 12:31:26 GMT 3 | Server: Apache/2.2.16 (Debian) 4 | X-Powered-By: PHP/5.3.3-7+squeeze14 5 | Vary: Accept-Encoding 6 | Content-Length: 459 7 | Content-Type: text/xml 8 | 9 | 10 | VISAVisa CreditCardsWALLETMultiSafepayIDEALiDEALBANKTRANSBank TransferMASTERCARDMasterCard 11 | -------------------------------------------------------------------------------- /tests/Mock/XmlPurchaseFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Thu, 11 Jul 2013 10:06:38 GMT 3 | Server: Apache/2.2.22 (FreeBSD) mod_ssl/2.2.22 OpenSSL/0.9.8q DAV/2 4 | Content-Length: 213 5 | Content-Type: text/xml 6 | 7 | 8 | 1001Invalid amount123456 9 | -------------------------------------------------------------------------------- /tests/Mock/XmlPurchaseSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Thu, 11 Jul 2013 09:52:27 GMT 3 | Server: Apache/2.2.22 (FreeBSD) mod_ssl/2.2.22 OpenSSL/0.9.8q DAV/2 4 | Content-Length: 256 5 | Content-Type: text/xml 6 | 7 | 8 | 123456https://testpay.multisafepay.com/pay/?transaction=1373536347Hz4sFtg7WgMulO5q123456&lang= 9 | -------------------------------------------------------------------------------- /tests/RestGatewayTest.php: -------------------------------------------------------------------------------- 1 | gateway = new RestGateway( 20 | $this->getHttpClient(), 21 | $this->getHttpRequest() 22 | ); 23 | 24 | $this->gateway->setApiKey('123456789'); 25 | } 26 | 27 | public function testFetchPaymentMethodsRequest() 28 | { 29 | $request = $this->gateway->fetchPaymentMethods( 30 | array('country' => 'NL') 31 | ); 32 | 33 | $this->assertInstanceOf('Omnipay\MultiSafepay\Message\RestFetchPaymentMethodsRequest', $request); 34 | $this->assertEquals('NL', $request->getCountry()); 35 | } 36 | 37 | public function testFetchIssuersRequest() 38 | { 39 | $request = $this->gateway->fetchIssuers(); 40 | 41 | $this->assertInstanceOf('Omnipay\MultiSafepay\Message\RestFetchIssuersRequest', $request); 42 | } 43 | 44 | public function testPurchaseRequest() 45 | { 46 | $request = $this->gateway->purchase(array('amount' => 10.00)); 47 | 48 | $this->assertInstanceOf('Omnipay\MultiSafepay\Message\RestPurchaseRequest', $request); 49 | $this->assertEquals($request->getAmount(), 10.00); 50 | } 51 | 52 | public function testCompletePurchaseRequest() 53 | { 54 | $request = $this->gateway->completePurchase(array('amount' => 10.00)); 55 | 56 | $this->assertInstanceOf('Omnipay\MultiSafepay\Message\RestCompletePurchaseRequest', $request); 57 | $this->assertEquals($request->getAmount(), 10.00); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tests/XmlGatewayTest.php: -------------------------------------------------------------------------------- 1 | gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); 34 | $this->gateway->setAccountId('111111'); 35 | $this->gateway->setSiteId('222222'); 36 | $this->gateway->setSiteCode('333333'); 37 | 38 | $this->options = array( 39 | 'notifyUrl' => 'http://localhost/notify', 40 | 'cancelUrl' => 'http://localhost/cancel', 41 | 'returnUrl' => 'http://localhost/return', 42 | 'gateway' => 'IDEAL', 43 | 'issuer' => 'issuer', 44 | 'transactionId' => '123456', 45 | 'currency' => 'EUR', 46 | 'amount' => '100.00', 47 | 'description' => 'desc', 48 | 'extraData1' => 'extra 1', 49 | 'extraData2' => 'extra 2', 50 | 'extraData3' => 'extra 3', 51 | 'language' => 'a language', 52 | 'clientIp' => '127.0.0.1', 53 | 'googleAnalyticsCode' => 'analytics code', 54 | 'card' => array( 55 | 'email' => 'something@example.com', 56 | 'firstName' => 'first name', 57 | 'lastName' => 'last name', 58 | 'address1' => 'address 1', 59 | 'address2' => 'address 2', 60 | 'postcode' => '1000', 61 | 'city' => 'a city', 62 | 'country' => 'a country', 63 | 'phone' => 'phone number', 64 | ) 65 | ); 66 | } 67 | 68 | public function testFetchPaymentMethods() 69 | { 70 | /** @var \Omnipay\MultiSafepay\Message\FetchPaymentMethodsRequest $request */ 71 | $request = $this->gateway->fetchPaymentMethods(array('country' => 'NL')); 72 | 73 | $this->assertInstanceOf('Omnipay\MultiSafepay\Message\FetchPaymentMethodsRequest', $request); 74 | $this->assertEquals('NL', $request->getCountry()); 75 | } 76 | 77 | public function testFetchIssuers() 78 | { 79 | /** @var \Omnipay\MultiSafepay\Message\FetchIssuersRequest $request */ 80 | $request = $this->gateway->fetchIssuers(); 81 | 82 | $this->assertInstanceOf('Omnipay\MultiSafepay\Message\FetchIssuersRequest', $request); 83 | } 84 | 85 | public function testPurchase() 86 | { 87 | /** @var \Omnipay\MultiSafepay\Message\PurchaseRequest $request */ 88 | $request = $this->gateway->purchase($this->options); 89 | 90 | /** @var CreditCard $card */ 91 | $card = $request->getCard(); 92 | 93 | $this->assertInstanceOf('Omnipay\MultiSafepay\Message\PurchaseRequest', $request); 94 | $this->assertSame('http://localhost/notify', $request->getNotifyUrl()); 95 | $this->assertSame('http://localhost/cancel', $request->getCancelUrl()); 96 | $this->assertSame('http://localhost/return', $request->getReturnUrl()); 97 | $this->assertSame('IDEAL', $request->getGateway()); 98 | $this->assertSame('issuer', $request->getIssuer()); 99 | $this->assertSame('123456', $request->getTransactionId()); 100 | $this->assertSame('EUR', $request->getCurrency()); 101 | $this->assertSame('100.00', $request->getAmount()); 102 | $this->assertSame('desc', $request->getDescription()); 103 | $this->assertSame('extra 1', $request->getExtraData1()); 104 | $this->assertSame('extra 2', $request->getExtraData2()); 105 | $this->assertSame('extra 3', $request->getExtraData3()); 106 | $this->assertSame('a language', $request->getLanguage()); 107 | $this->assertSame('analytics code', $request->getGoogleAnalyticsCode()); 108 | $this->assertSame('127.0.0.1', $request->getClientIp()); 109 | $this->assertSame('something@example.com', $card->getEmail()); 110 | $this->assertSame('first name', $card->getFirstName()); 111 | $this->assertSame('last name', $card->getLastName()); 112 | $this->assertSame('address 1', $card->getAddress1()); 113 | $this->assertSame('address 2', $card->getAddress2()); 114 | $this->assertSame('1000', $card->getPostcode()); 115 | $this->assertSame('a city', $card->getCity()); 116 | $this->assertSame('a country', $card->getCountry()); 117 | $this->assertSame('phone number', $card->getPhone()); 118 | } 119 | 120 | public function testCompletePurchase() 121 | { 122 | /** @var \Omnipay\MultiSafepay\Message\CompletePurchaseRequest $request */ 123 | $request = $this->gateway->completePurchase($this->options); 124 | 125 | /** @var CreditCard $card */ 126 | $card = $request->getCard(); 127 | 128 | $this->assertInstanceOf('Omnipay\MultiSafepay\Message\CompletePurchaseRequest', $request); 129 | $this->assertSame('http://localhost/notify', $request->getNotifyUrl()); 130 | $this->assertSame('http://localhost/cancel', $request->getCancelUrl()); 131 | $this->assertSame('http://localhost/return', $request->getReturnUrl()); 132 | $this->assertSame('IDEAL', $request->getGateway()); 133 | $this->assertSame('issuer', $request->getIssuer()); 134 | $this->assertSame('123456', $request->getTransactionId()); 135 | $this->assertSame('EUR', $request->getCurrency()); 136 | $this->assertSame('100.00', $request->getAmount()); 137 | $this->assertSame('desc', $request->getDescription()); 138 | $this->assertSame('extra 1', $request->getExtraData1()); 139 | $this->assertSame('extra 2', $request->getExtraData2()); 140 | $this->assertSame('extra 3', $request->getExtraData3()); 141 | $this->assertSame('a language', $request->getLanguage()); 142 | $this->assertSame('analytics code', $request->getGoogleAnalyticsCode()); 143 | $this->assertSame('127.0.0.1', $request->getClientIp()); 144 | $this->assertSame('something@example.com', $card->getEmail()); 145 | $this->assertSame('first name', $card->getFirstName()); 146 | $this->assertSame('last name', $card->getLastName()); 147 | $this->assertSame('address 1', $card->getAddress1()); 148 | $this->assertSame('address 2', $card->getAddress2()); 149 | $this->assertSame('1000', $card->getPostcode()); 150 | $this->assertSame('a city', $card->getCity()); 151 | $this->assertSame('a country', $card->getCountry()); 152 | $this->assertSame('phone number', $card->getPhone()); 153 | } 154 | } 155 | --------------------------------------------------------------------------------