├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml.dist ├── src ├── Gateway.php └── Message │ ├── AuthorizeRequest.php │ ├── CaptureRequest.php │ ├── CreditRequest.php │ ├── MoneyPointsRequest.php │ ├── PurchaseRequest.php │ ├── RefundRequest.php │ ├── Response.php │ ├── SettleRequest.php │ └── VoidRequest.php └── tests ├── GatewayTest.php ├── Message ├── ReferencedPurchaseRequestTest.php ├── RefundRequestTest.php └── ResponseTest.php └── Mock ├── PurchaseFailure.txt ├── PurchaseFailureWithoutStatusCode.txt ├── PurchaseRedirect.txt └── PurchaseSuccess.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | /nbproject 3 | composer.lock 4 | composer.phar 5 | .idea/ 6 | src/.DS_Store 7 | -------------------------------------------------------------------------------- /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-2015 Yasin Kuyu 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: NestPay 2 | 3 | **NestPay (EST) (İş Bankası, Akbank, Finansbank, Denizbank, Kuveytturk, Halkbank, Anadolubank, ING Bank, Citibank, Cardplus, Ziraat Bankası sanal pos) gateway for Omnipay payment processing library** 4 | 5 | [![Latest Stable Version](https://poser.pugx.org/yasinkuyu/omnipay-nestpay/v/stable)](https://packagist.org/packages/yasinkuyu/omnipay-nestpay) 6 | [![Total Downloads](https://poser.pugx.org/yasinkuyu/omnipay-nestpay/downloads)](https://packagist.org/packages/yasinkuyu/omnipay-nestpay) 7 | [![Latest Unstable Version](https://poser.pugx.org/yasinkuyu/omnipay-nestpay/v/unstable)](https://packagist.org/packages/yasinkuyu/omnipay-nestpay) 8 | [![License](https://poser.pugx.org/yasinkuyu/omnipay-nestpay/license)](https://packagist.org/packages/yasinkuyu/omnipay-nestpay) 9 | 10 | [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment 11 | processing library for PHP 5.3+. This package implements NestPay (Turkish Payment Gateways) support for Omnipay. 12 | 13 | 14 | NestPay (eski adıyla EST) altyapısını kullanan Türkiye bankaları için Omnipay kütüphanesi. Desteklenmesi hedeflenen bankalar; İş Bankası, Akbank, Finansbank, Denizbank, Kuveytturk, Halkbank, Anadolubank, ING Bank, Citibank, Cardplus, Ziraat Bankası 15 | 16 | 17 | ## Installation 18 | 19 | composer require yasinkuyu/omnipay-nestpay:~2.0 20 | 21 | ## Basic Usage 22 | 23 | The following gateways are provided by this package: 24 | 25 | * NestPay 26 | - İş Bankası 27 | - Akbank 28 | - Finansbank 29 | - Denizbank 30 | - Kuveytturk 31 | - Halkbank 32 | - Anadolubank 33 | - ING Bank 34 | - Citibank 35 | - Cardplus 36 | - Ziraat Bankası 37 | 38 | Gateway Methods 39 | 40 | * authorize($options) - authorize an amount on the customer's card 41 | * capture($options) - capture an amount you have previously authorized 42 | * purchase($options) - authorize and immediately capture an amount on the customer's card 43 | * refund($options) - refund an already processed transaction 44 | * void($options) - generally can only be called up to 24 hours after submitting a transaction 45 | * credit($options) - money points processed transaction 46 | * settle($options) - settlement query processed transaction 47 | 48 | For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) 49 | repository. 50 | 51 | ## Unit Tests 52 | 53 | PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. 54 | 55 | ## Sample App 56 | setBank("isbank"); 65 | $gateway->setUserName("api"); 66 | $gateway->setClientId("700658785"); 67 | $gateway->setPassword("TEST1111"); 68 | $gateway->setTestMode(TRUE); 69 | 70 | $options = [ 71 | 'number' => '5406675406675403', 72 | 'expiryMonth' => '12', 73 | 'expiryYear' => '2022', 74 | 'cvv' => '000', 75 | 'email' => 'yasinkuyu@gmail.com', 76 | 'firstname' => 'Yasin', 77 | 'lastname' => 'Kuyu' 78 | ]; 79 | 80 | try { 81 | 82 | $response = $gateway->purchase( 83 | [ 84 | //'installment' => '', # Taksit 85 | //'moneypoints' => 1.00, // Set money points (Maxi puan gir) 86 | 'amount' => 12.00, 87 | 'type' => 'Auth', 88 | 'orderid' => 'ORDER-3651233', 89 | 'card' => $options 90 | ] 91 | )->send(); 92 | /* 93 | $response = $gateway->authorize( 94 | [ 95 | 'type' => 'PostAuth', 96 | 'orderid' => 'ORDER-365123', 97 | 'card' => $options 98 | ] 99 | )->send(); 100 | 101 | $response = $gateway->capture( 102 | [ 103 | 'orderid' => 'ORDER-365123', 104 | 'amount' => 1.00, 105 | 'currency' => 'TRY', 106 | 'card' => $options 107 | ] 108 | )->send(); 109 | 110 | 111 | $response = $gateway->refund( 112 | [ 113 | 'orderid' => 'ORDER-365123', 114 | 'amount' => 1.00, 115 | 'currency' => 'TRY', 116 | 'card' => $options 117 | ] 118 | )->send(); 119 | 120 | $response = $gateway->credit( 121 | [ 122 | 'orderid' => 'ORDER-365123', 123 | 'amount' => 1.00, 124 | 'currency' => 'TRY', // Optional (default parameter TRY) 125 | 'card' => $options 126 | ] 127 | )->send(); 128 | 129 | $response = $gateway->void( 130 | [ 131 | 'orderid' => 'ORDER-365123', 132 | 'amount' => 1.00, 133 | 'currency' => 'TRY', 134 | 'card' => $options 135 | ] 136 | )->send(); 137 | 138 | $response = $gateway->credit( 139 | [ 140 | 'amount' => 1.00, 141 | 'card' => $options 142 | ] 143 | )->send(); 144 | 145 | $response = $gateway->settle( 146 | [ 147 | 'settlement' => true, 148 | 'card' => $options 149 | ] 150 | )->send(); 151 | 152 | $response = $gateway->money( 153 | [ 154 | 'moneypoints' => "1", 155 | 'card' => $options 156 | ] 157 | )->send(); 158 | */ 159 | 160 | if ($response->isSuccessful()) { 161 | echo "Successful"; 162 | 163 | } elseif ($response->isRedirect()) { 164 | $response->redirect(); 165 | 166 | } else { 167 | exit($response->getMessage()); 168 | } 169 | } catch (\Exception $e) { 170 | exit($e->getMessage()); 171 | } 172 | 173 | // Debug 174 | //var_dump($response); 175 | 176 | 177 | 178 | ## Posnet 179 | Posnet (Yapı Kredi, Vakıfbank, Anadolubank) gateway for Omnipay payment processing library 180 | https://github.com/yasinkuyu/omnipay-posnet 181 | 182 | ## Iyzico 183 | Iyzico gateway for Omnipay payment processing library 184 | https://github.com/yasinkuyu/omnipay-iyzico 185 | 186 | ## GVP (Granti Sanal Pos) 187 | Gvp (Garanti, Denizbank, TEB, ING, Şekerbank, TFKB) gateway for Omnipay payment processing library 188 | https://github.com/yasinkuyu/omnipay-gvp 189 | 190 | ## BKM Express 191 | BKM Express gateway for Omnipay payment processing library 192 | https://github.com/yasinkuyu/omnipay-bkm 193 | 194 | ## Paratika 195 | Paratika (Asseco) (Akbank, TEB, Halkbank, Finansbank, İş Bankası, Şekerbank, Vakıfbank ) gateway for Omnipay payment processing library 196 | https://github.com/yasinkuyu/omnipay-paratika 197 | 198 | 199 | ## Composer Installation 200 | 201 | Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it 202 | to your `composer.json` file: 203 | 204 | ```json 205 | { 206 | "require": { 207 | "yasinkuyu/omnipay-nestpay": "~2.0" 208 | } 209 | } 210 | ``` 211 | 212 | And run composer to update your dependencies: 213 | 214 | $ curl -s http://getcomposer.org/installer | php 215 | $ php composer.phar update 216 | 217 | 218 | ## Support 219 | 220 | If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/yasinkuyu/omnipay-nestpay/issues), 221 | or better yet, fork the library and submit a pull request. 222 | 223 | ## Roadmap 224 | 3D Secure payment 225 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yasinkuyu/omnipay-nestpay", 3 | "type": "library", 4 | "description": "NestPay (EST) (İş Bankası, Akbank, Finansbank, Denizbank, Kuveytturk, Halkbank, Anadolubank, ING Bank, Citibank, Cardplus, Ziraat Bankası sanal pos) gateway for Omnipay payment processing library", 5 | "keywords": [ 6 | "nestpay", 7 | "est", 8 | "Isbank", 9 | "Akbank", 10 | "Finansbank", 11 | "Denizbank", 12 | "Kuveytturk", 13 | "Halkbank", 14 | "Anadolubank", 15 | "ING Bank", 16 | "Citibank", 17 | "Cardplus", 18 | "Ziraat Bankası", 19 | "gateway", 20 | "merchant", 21 | "sanal pos", 22 | "omnipay", 23 | "pay", 24 | "payment" 25 | ], 26 | "homepage": "https://github.com/yasinkuyu/omnipay-nestpay", 27 | "license": "MIT", 28 | "authors": [ 29 | { 30 | "name": "Yasin Kuyu", 31 | "email": "yasinkuyu@gmail.com" 32 | }, 33 | { 34 | "name": "Omnipay Contributors", 35 | "homepage": "https://github.com/yasinkuyu/omnipay-nestpay/contributors" 36 | } 37 | ], 38 | "autoload": { 39 | "psr-4": { 40 | "Omnipay\\NestPay\\": "src/" 41 | } 42 | }, 43 | "require": { 44 | "omnipay/common": "~2.0" 45 | }, 46 | "require-dev": { 47 | "omnipay/tests": "~2.0" 48 | }, 49 | "extra": { 50 | "branch-alias": { 51 | "dev-yasin": "2.0.x-dev" 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests/ 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | ./src 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/Gateway.php: -------------------------------------------------------------------------------- 1 | '', 23 | 'username' => '', 24 | 'clientId' => '', 25 | 'password' => '', 26 | 'installment' => '', 27 | 'type' => 'Auth', 28 | 'currency' => 'TRY', 29 | 'testMode' => false 30 | ); 31 | } 32 | 33 | public function authorize(array $parameters = array()) { 34 | return $this->createRequest('\Omnipay\NestPay\Message\AuthorizeRequest', $parameters); 35 | } 36 | 37 | public function capture(array $parameters = array()) { 38 | return $this->createRequest('\Omnipay\NestPay\Message\CaptureRequest', $parameters); 39 | } 40 | 41 | public function purchase(array $parameters = array()) { 42 | return $this->createRequest('\Omnipay\NestPay\Message\PurchaseRequest', $parameters); 43 | } 44 | 45 | public function refund(array $parameters = array()) { 46 | return $this->createRequest('\Omnipay\NestPay\Message\RefundRequest', $parameters); 47 | } 48 | 49 | public function void(array $parameters = array()) { 50 | return $this->createRequest('\Omnipay\NestPay\Message\VoidRequest', $parameters); 51 | } 52 | 53 | public function credit(array $parameters = array()) { 54 | return $this->createRequest('\Omnipay\NestPay\Message\CreditRequest', $parameters); 55 | } 56 | 57 | public function settle(array $parameters = array()) { 58 | return $this->createRequest('\Omnipay\NestPay\Message\SettleRequest', $parameters); 59 | } 60 | 61 | public function money(array $parameters = array()) { 62 | return $this->createRequest('\Omnipay\NestPay\Message\MoneyPointsRequest', $parameters); 63 | } 64 | 65 | public function getBank() { 66 | return $this->getParameter('bank'); 67 | } 68 | 69 | public function setBank($value) { 70 | return $this->setParameter('bank', $value); 71 | } 72 | 73 | public function getUserName() { 74 | return $this->getParameter('username'); 75 | } 76 | 77 | public function setUserName($value) { 78 | return $this->setParameter('username', $value); 79 | } 80 | 81 | public function getClientId() { 82 | return $this->getParameter('clientId'); 83 | } 84 | 85 | public function setClientId($value) { 86 | return $this->setParameter('clientId', $value); 87 | } 88 | 89 | public function getPassword() { 90 | return $this->getParameter('password'); 91 | } 92 | 93 | public function setPassword($value) { 94 | return $this->setParameter('password', $value); 95 | } 96 | 97 | public function getInstallment() { 98 | return $this->getParameter('installment'); 99 | } 100 | 101 | public function setInstallment($value) { 102 | return $this->setParameter('installment', $value); 103 | } 104 | 105 | public function getType() { 106 | return $this->getParameter('type'); 107 | } 108 | 109 | public function setType($value) { 110 | return $this->setParameter('type', $value); 111 | } 112 | 113 | public function getOrderId() { 114 | return $this->getParameter('orderid'); 115 | } 116 | 117 | public function setOrderId($value) { 118 | return $this->setParameter('orderid', $value); 119 | } 120 | 121 | public function getMoneyPoints() { 122 | return $this->getParameter('moneypoints'); 123 | } 124 | 125 | public function setMoneyPoints($value) { 126 | return $this->setParameter('moneypoints', $value); 127 | } 128 | 129 | public function getSettlement() { 130 | return $this->getParameter('settlement'); 131 | } 132 | 133 | public function setSettlement($value) { 134 | return $this->setParameter('settlement', $value); 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/Message/AuthorizeRequest.php: -------------------------------------------------------------------------------- 1 | validate('orderid'); 17 | 18 | $data['Type'] = $this->getType(); 19 | $data['OrderId'] = $this->getOrderId(); 20 | 21 | return $data; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/Message/CaptureRequest.php: -------------------------------------------------------------------------------- 1 | validate('orderid', 'amount'); 17 | $currency = $this->getCurrency(); 18 | 19 | $data['Type'] = 'PostAuth'; 20 | $data['OrderId'] = $this->getOrderId(); 21 | $data['Currency'] = $this->currencies[$currency]; 22 | $data['Total'] = $this->getAmount(); 23 | 24 | return $data; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/Message/CreditRequest.php: -------------------------------------------------------------------------------- 1 | validate('amount'); 17 | $currency = $this->getCurrency(); 18 | 19 | $data['Type'] = 'Credit'; 20 | $data['OrderId'] = $this->getOrderId(); 21 | $data['Currency'] = $this->currencies[$currency]; 22 | $data['Total'] = $this->getAmount(); 23 | $data['Number'] = $this->getCard()->getNumber(); 24 | $data['Expires'] = $this->getCard()->getExpiryDate('my'); 25 | $data["Cvv2Val"] = $this->getCard()->getCvv(); 26 | 27 | return $data; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/Message/MoneyPointsRequest.php: -------------------------------------------------------------------------------- 1 | 'https://entegrasyon.asseco-see.com.tr/fim/api', 20 | 'asseco' => 'https://entegrasyon.asseco-see.com.tr/fim/api', 21 | 'isbank' => 'spos.isbank.com.tr', 22 | 'akbank' => 'www.sanalakpos.com', 23 | 'finansbank' => 'www.fbwebpos.com', 24 | 'denizbank' => 'denizbank.est.com.tr', 25 | 'kuveytturk' => 'kuveytturk.est.com.tr', 26 | 'halkbank' => 'sanalpos.halkbank.com.tr', 27 | 'anadolubank' => 'anadolusanalpos.est.com.tr', 28 | 'hsbc' => 'vpos.advantage.com.tr', 29 | 'ziraatbank' => 'sanalpos2.ziraatbank.com.tr', 30 | 31 | // Todo 32 | 'ingbank' => 'ingbank.est.com.tr', 33 | 'citibank' => 'citibank.est.com.tr', 34 | 'cardplus' => 'cardplus.est.com.tr' 35 | ]; 36 | protected $url = [ 37 | "3d" => "/servlet/est3Dgate", 38 | "3dhsbc" => "/servlet/hsbc3Dgate", 39 | "list" => "/servlet/listapproved", 40 | "detail" => "/servlet/cc5ApiServer", 41 | "cancel" => "/servlet/cc5ApiServer", 42 | "return" => "/servlet/cc5ApiServer", 43 | "purchase" => "/servlet/cc5ApiServer" 44 | ]; 45 | protected $currencies = [ 46 | 'TRY' => 949, 47 | 'YTL' => 949, 48 | 'TRL' => 949, 49 | 'TL' => 949, 50 | 'USD' => 840, 51 | 'EUR' => 978, 52 | 'GBP' => 826, 53 | 'JPY' => 392 54 | ]; 55 | 56 | public function getData() { 57 | 58 | $this->validate('amount', 'card'); 59 | $this->getCard()->validate(); 60 | $currency = $this->getCurrency(); 61 | 62 | $data['Email'] = $this->getCard()->getEmail(); 63 | $data['OrderId'] = $this->getOrderId(); 64 | $data['GroupId'] = ''; 65 | $data['TransId'] = ''; 66 | $data['UserId'] = ''; 67 | $data['Type'] = $this->getType(); 68 | $data['Currency'] = $this->currencies[$currency]; 69 | $data['Installment'] = $this->getInstallment(); 70 | 71 | $data['Total'] = $this->getAmount(); 72 | $data['Number'] = $this->getCard()->getNumber(); 73 | $data['Expires'] = $this->getCard()->getExpiryDate('my'); 74 | $data["Cvv2Val"] = $this->getCard()->getCvv(); 75 | $data["IPAddress"] = $this->getClientIp(); 76 | 77 | return $data; 78 | } 79 | 80 | public function sendData($data) { 81 | 82 | // API info 83 | $data['Name'] = $this->getUserName(); 84 | $data['ClientId'] = $this->getClientId(); 85 | $data['Password'] = $this->getPassword(); 86 | $data['Mode'] = $this->getTestMode() ? 'T' : 'P'; 87 | 88 | // Get geteway 89 | // ex: isbank 90 | $gateway = $this->getBank(); 91 | 92 | // Todo: http protocol 93 | $protocol = 'https://'; 94 | 95 | if (!array_key_exists($gateway, $this->endpoints)) { 96 | throw new \Exception('Invalid Gateway'); 97 | } else { 98 | $this->endpoint = $this->endpoints[$gateway]; 99 | } 100 | 101 | // Build api post url 102 | $this->endpoint = $this->getTestMode() == TRUE ? $this->endpoints["test"] : $protocol . $this->endpoints[$gateway] . $this->url["purchase"]; 103 | 104 | $document = new DOMDocument('1.0', 'UTF-8'); 105 | $root = $document->createElement('CC5Request'); 106 | 107 | // Each array element 108 | foreach ($data as $id => $value) { 109 | $root->appendChild($document->createElement($id, $value)); 110 | } 111 | 112 | $document->appendChild($root); 113 | 114 | if (!empty($this->getCard()->getFirstName())) { 115 | $dataShip = [ 116 | "Name" => $this->getCard()->getFirstName() . " " . $this->getCard()->getLastName(), 117 | "Street1" => $this->getCard()->getShippingAddress1(), 118 | "Street2" => $this->getCard()->getShippingAddress2(), 119 | "Street3" => "", 120 | "City" => $this->getCard()->getShippingCity(), 121 | "StateProv" => $this->getCard()->getShippingState(), 122 | "PostalCode" => $this->getCard()->getShippingPostcode(), 123 | "Country" => $this->getCard()->getShippingCountry(), 124 | "Company" => $this->getCard()->getCompany(), 125 | "TelVoice" => $this->getCard()->getShippingPhone() 126 | ]; 127 | 128 | $shipTo = $document->createElement('ShipTo'); 129 | foreach ($dataShip as $id => $value) { 130 | $shipTo->appendChild($document->createElement($id, $value)); 131 | } 132 | $root->appendChild($shipTo); 133 | 134 | $dataBill = [ 135 | "Name" => $this->getCard()->getFirstName() . " " . $this->getCard()->getLastName(), 136 | "Street1" => $this->getCard()->getBillingAddress1(), 137 | "Street2" => $this->getCard()->getBillingAddress2(), 138 | "Street3" => "", 139 | "City" => $this->getCard()->getBillingCity(), 140 | "StateProv" => $this->getCard()->getBillingState(), 141 | "PostalCode" => $this->getCard()->getBillingPostcode(), 142 | "Country" => $this->getCard()->getBillingCountry(), 143 | "Company" => $this->getCard()->getCompany(), 144 | "TelVoice" => $this->getCard()->getBillingPhone() 145 | ]; 146 | } 147 | 148 | // Set money points (maxi puan) 149 | $extra = $document->createElement('Extra'); 150 | if (!empty($this->getMoneyPoints())) { 151 | $extra->appendChild($document->createElement('MAXIPUAN', $this->getMoneyPoints())); 152 | $root->appendChild($extra); 153 | } 154 | 155 | // Get money points (maxi puan) 156 | if (!empty($this->getMoneyPoints())) { 157 | $extra->appendChild($document->createElement('MAXIPUANSORGU', 'MAXIPUANSORGU')); 158 | $root->appendChild($extra); 159 | } 160 | 161 | // Settlement 162 | if (!empty($this->getSettlement())) { 163 | $extra->appendChild($document->createElement('SETTLE', 'SETTLE')); 164 | $root->appendChild($extra); 165 | } 166 | 167 | $billTo = $document->createElement('BillTo'); 168 | foreach ($dataBill as $id => $value) { 169 | $billTo->appendChild($document->createElement($id, $value)); 170 | } 171 | $root->appendChild($billTo); 172 | 173 | // Post to NestPay 174 | $headers = array( 175 | 'Content-Type' => 'application/x-www-form-urlencoded' 176 | ); 177 | 178 | // Register the payment 179 | $this->httpClient->setConfig(array( 180 | 'curl.options' => array( 181 | 'CURLOPT_SSL_VERIFYHOST' => 2, 182 | 'CURLOPT_SSLVERSION' => 0, 183 | 'CURLOPT_SSL_VERIFYPEER' => 0, 184 | 'CURLOPT_RETURNTRANSFER' => 1, 185 | 'CURLOPT_POST' => 1 186 | ) 187 | )); 188 | 189 | $httpResponse = $this->httpClient->post($this->endpoint, $headers, $document->saveXML())->send(); 190 | 191 | return $this->response = new Response($this, $httpResponse->getBody()); 192 | } 193 | 194 | public function getBank() { 195 | return $this->getParameter('bank'); 196 | } 197 | 198 | public function setBank($value) { 199 | return $this->setParameter('bank', $value); 200 | } 201 | 202 | public function getUserName() { 203 | return $this->getParameter('username'); 204 | } 205 | 206 | public function setUserName($value) { 207 | return $this->setParameter('username', $value); 208 | } 209 | 210 | public function getClientId() { 211 | return $this->getParameter('clientId'); 212 | } 213 | 214 | public function setClientId($value) { 215 | return $this->setParameter('clientId', $value); 216 | } 217 | 218 | public function getPassword() { 219 | return $this->getParameter('password'); 220 | } 221 | 222 | public function setPassword($value) { 223 | return $this->setParameter('password', $value); 224 | } 225 | 226 | public function getInstallment() { 227 | return $this->getParameter('installment'); 228 | } 229 | 230 | public function setInstallment($value) { 231 | return $this->setParameter('installment', $value); 232 | } 233 | 234 | public function getType() { 235 | return $this->getParameter('type'); 236 | } 237 | 238 | public function setType($value) { 239 | return $this->setParameter('type', $value); 240 | } 241 | 242 | public function getOrderId() { 243 | return $this->getParameter('orderid'); 244 | } 245 | 246 | public function setOrderId($value) { 247 | return $this->setParameter('orderid', $value); 248 | } 249 | 250 | public function getMoneyPoints() { 251 | return $this->getParameter('moneypoints'); 252 | } 253 | 254 | public function setMoneyPoints($value) { 255 | return $this->setParameter('moneypoints', $value); 256 | } 257 | 258 | public function getSettlement() { 259 | return $this->getParameter('settlement'); 260 | } 261 | 262 | public function setSettlement($value) { 263 | return $this->setParameter('settlement', $value); 264 | } 265 | 266 | } 267 | -------------------------------------------------------------------------------- /src/Message/RefundRequest.php: -------------------------------------------------------------------------------- 1 | validate('orderid', 'amount'); 17 | $currency = $this->getCurrency(); 18 | 19 | $data['Type'] = 'Credit'; 20 | $data['OrderId'] = $this->getOrderId(); 21 | $data['Currency'] = $this->currencies[$currency]; 22 | $data['Total'] = $this->getAmount(); 23 | 24 | return $data; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/Message/Response.php: -------------------------------------------------------------------------------- 1 | request = $request; 28 | try { 29 | $this->data = (array) simplexml_load_string($data); 30 | } catch (\Exception $ex) { 31 | throw new InvalidResponseException(); 32 | } 33 | } 34 | 35 | /** 36 | * Whether or not response is successful 37 | * 38 | * @return bool 39 | */ 40 | public function isSuccessful() { 41 | if (isset($this->data["ProcReturnCode"])) { 42 | return (string) $this->data["ProcReturnCode"] === '00' || $this->data["Response"] === 'Approved'; 43 | } else { 44 | return false; 45 | } 46 | } 47 | 48 | /** 49 | * Get is redirect 50 | * 51 | * @return bool 52 | */ 53 | public function isRedirect() { 54 | return false; //todo 55 | } 56 | 57 | /** 58 | * Get a code describing the status of this response. 59 | * 60 | * @return string|null code 61 | */ 62 | public function getCode() { 63 | return $this->isSuccessful() ? $this->data["AuthCode"] : parent::getCode(); 64 | } 65 | 66 | /** 67 | * Get transaction reference 68 | * 69 | * @return string 70 | */ 71 | public function getTransactionReference() { 72 | 73 | return $this->isSuccessful() ? $this->data["TransId"] : ''; 74 | } 75 | 76 | /** 77 | * Get message 78 | * 79 | * @return string 80 | */ 81 | public function getMessage() { 82 | if ($this->isSuccessful()) { 83 | $moneyPoints = $this->data["Extra"]->KULLANILABILIRBONUS; 84 | if (!empty($moneyPoints)) 85 | return (string) $this->data["Response"] . '. Available money points : ' . $moneyPoints; 86 | else 87 | return $this->data["Response"]; 88 | } 89 | return $this->data["ErrMsg"]; 90 | } 91 | 92 | /** 93 | * Get error 94 | * 95 | * @return string 96 | */ 97 | public function getError() { 98 | return $this->data["ErrMsg"]; 99 | } 100 | 101 | /** 102 | * Get Redirect url 103 | * 104 | * @return string 105 | */ 106 | public function getRedirectUrl() { 107 | if ($this->isRedirect()) { 108 | $data = array( 109 | 'TransId' => $this->data["TransId"] 110 | ); 111 | return $this->getRequest()->getEndpoint() . '/test/index?' . http_build_query($data); 112 | } 113 | } 114 | 115 | /** 116 | * Get Redirect method 117 | * 118 | * @return POST 119 | */ 120 | public function getRedirectMethod() { 121 | return 'POST'; 122 | } 123 | 124 | /** 125 | * Get Redirect url 126 | * 127 | * @return null 128 | */ 129 | public function getRedirectData() { 130 | return null; 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/Message/SettleRequest.php: -------------------------------------------------------------------------------- 1 | validate('orderid'); 17 | 18 | $data['Type'] = 'Void'; 19 | $data['OrderId'] = $this->getOrderId(); 20 | 21 | return $data; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /tests/GatewayTest.php: -------------------------------------------------------------------------------- 1 | gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); 20 | 21 | $this->options = array( 22 | 'bank' => 'denizbank', 23 | 'name' => 'DENIZTEST', 24 | 'clientId' => '800100000', 25 | 'password' => 'DENIZTEST123', 26 | 'amount' => 10.00, 27 | 'currency' => 'TRY', 28 | 'returnUrl' => 'http://sanalmagaza.org/return', 29 | 'card' => new CreditCard(array( 30 | 'number' => '5406675406675403', 31 | 'expiryMonth' => '12', 32 | 'expiryYear' => '2015', 33 | 'cvv' => '000', 34 | 'email' => 'yasinkuyu@gmail.com', 35 | 'firstname' => 'Yasin', 36 | 'lastname' => 'Kuyu' 37 | )), 38 | ); 39 | } 40 | 41 | public function testPurchase() 42 | { 43 | $this->setMockHttpResponse('PurchaseSuccess.txt'); 44 | 45 | $response = $this->gateway->purchase($this->options)->send(); 46 | 47 | $this->assertInstanceOf('\Omnipay\NestPay\Message\Response', $response); 48 | $this->assertTrue($response->isSuccessful()); 49 | $this->assertEquals('130215141054377801316798', $response->getTransactionReference()); 50 | } 51 | 52 | public function testPurchaseError() 53 | { 54 | $this->setMockHttpResponse('PurchaseFailure.txt'); 55 | 56 | $response = $this->gateway->purchase($this->options)->send(); 57 | 58 | $this->assertFalse($response->isSuccessful()); 59 | $this->assertSame('Input variable errors', $response->getMessage()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tests/Message/ReferencedPurchaseRequestTest.php: -------------------------------------------------------------------------------- 1 | request = new ReferencedPurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); 19 | $this->request->initialize( 20 | array( 21 | 'transactionReference' => '0987654345678900987654', 22 | 'amount' => '10.00', 23 | 'currency' => 949, 24 | 'testMode' => true, 25 | ) 26 | ); 27 | } 28 | 29 | public function testGetData() 30 | { 31 | $data = $this->request->getData(); 32 | 33 | /* 34 | * See https://bugs.php.net/bug.php?id=29500 for why this is cast to string 35 | */ 36 | $this->assertSame('Auth', (string)$data['Type']); 37 | $this->assertSame('1200', (string)$data['Amount']); 38 | $this->assertSame('949', (string)$data['Currency']); 39 | $this->assertSame('0987654345678900987654', (string)$data['CrossReference']); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /tests/Message/RefundRequestTest.php: -------------------------------------------------------------------------------- 1 | request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest()); 19 | $this->request->initialize( 20 | array( 21 | 'amount' => '11.00', 22 | 'orderId' => 'ORDER-365123', 23 | 'currency' => 'TRY', 24 | 'testMode' => true, 25 | ) 26 | ); 27 | } 28 | 29 | public function testGetData() 30 | { 31 | $data = $this->request->getData(); 32 | 33 | /* 34 | * See https://bugs.php.net/bug.php?id=29500 for why this is cast to string 35 | */ 36 | $this->assertSame('Credit', (string)$data['Type']); 37 | $this->assertSame('1200', (string)$data['Amount']); 38 | $this->assertSame('TRY', (string)$data['Currency']); 39 | $this->assertSame('ORDER-365123', (string)$data['orderId']); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /tests/Message/ResponseTest.php: -------------------------------------------------------------------------------- 1 | getMockHttpResponse('PurchaseFailureWithoutStatusCode.txt'); 21 | new Response($this->getMockRequest(), $httpResponse->getBody()); 22 | } 23 | 24 | public function testPurchaseSuccess() 25 | { 26 | $httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt'); 27 | $response = new Response($this->getMockRequest(), $httpResponse->getBody()); 28 | 29 | $this->assertTrue($response->isSuccessful()); 30 | $this->assertEquals('130215141054377801316798', $response->getTransactionReference()); 31 | $this->assertSame('AuthCode: 672167', $response->getMessage()); 32 | $this->assertEmpty($response->getRedirectUrl()); 33 | } 34 | 35 | public function testPurchaseFailure() 36 | { 37 | $httpResponse = $this->getMockHttpResponse('PurchaseFailure.txt'); 38 | $response = new Response($this->getMockRequest(), $httpResponse->getBody()); 39 | 40 | $this->assertFalse($response->isSuccessful()); 41 | $this->assertSame('', $response->getTransactionReference()); 42 | $this->assertSame('Input variable errors', $response->getMessage()); 43 | } 44 | 45 | public function testRedirect() 46 | { 47 | $httpResponse = $this->getMockHttpResponse('PurchaseRedirect.txt'); 48 | 49 | $request = m::mock('\Omnipay\Common\Message\AbstractRequest'); 50 | $request->shouldReceive('getReturnUrl')->once()->andReturn('http://sanalmagaza.org/'); 51 | 52 | $response = new Response($request, $httpResponse->getBody()); 53 | 54 | $this->assertTrue($response->isRedirect()); 55 | $this->assertSame('POST', $response->getRedirectMethod()); 56 | $this->assertSame('http://sanalmagaza.org/', $response->getRedirectUrl()); 57 | 58 | $expectedData = array( 59 | 'ReturnUrl' => 'http://sanalmagaza.org/', 60 | 'ReferanceId' => '130215141054377801316798' 61 | ); 62 | $this->assertEquals($expectedData, $response->getRedirectData()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /tests/Mock/PurchaseFailure.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasinkuyu/omnipay-nestpay/a8fe1eeb5ac6f4eb61b3073d09fd8a9b204d1c10/tests/Mock/PurchaseFailure.txt -------------------------------------------------------------------------------- /tests/Mock/PurchaseFailureWithoutStatusCode.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasinkuyu/omnipay-nestpay/a8fe1eeb5ac6f4eb61b3073d09fd8a9b204d1c10/tests/Mock/PurchaseFailureWithoutStatusCode.txt -------------------------------------------------------------------------------- /tests/Mock/PurchaseRedirect.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasinkuyu/omnipay-nestpay/a8fe1eeb5ac6f4eb61b3073d09fd8a9b204d1c10/tests/Mock/PurchaseRedirect.txt -------------------------------------------------------------------------------- /tests/Mock/PurchaseSuccess.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasinkuyu/omnipay-nestpay/a8fe1eeb5ac6f4eb61b3073d09fd8a9b204d1c10/tests/Mock/PurchaseSuccess.txt --------------------------------------------------------------------------------