├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml.dist ├── src ├── Gateway.php └── Message │ ├── AuthorizeRequest.php │ ├── CaptureRequest.php │ ├── PurchaseRequest.php │ ├── RefundRequest.php │ ├── Response.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 -------------------------------------------------------------------------------- /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: Gvp 2 | 3 | **Gvp (Garanti, Denizbank, TEB, ING, Şekerbank, TFKB sanal pos) gateway for Omnipay payment processing library** 4 | 5 | 6 | [![Latest Stable Version](https://poser.pugx.org/yasinkuyu/omnipay-gvp/v/stable)](https://packagist.org/packages/yasinkuyu/omnipay-gvp) 7 | [![Total Downloads](https://poser.pugx.org/yasinkuyu/omnipay-gvp/downloads)](https://packagist.org/packages/yasinkuyu/omnipay-gvp) 8 | [![Latest Unstable Version](https://poser.pugx.org/yasinkuyu/omnipay-gvp/v/unstable)](https://packagist.org/packages/yasinkuyu/omnipay-gvp) 9 | [![License](https://poser.pugx.org/yasinkuyu/omnipay-gvp/license)](https://packagist.org/packages/yasinkuyu/omnipay-gvp) 10 | 11 | [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment 12 | processing library for PHP 5.3+. This package implements Gvp (Turkish Payment Gateways) support for Omnipay. 13 | 14 | 15 | Gvp (Garanti, Denizbank, TEB, ING, Şekerbank, TFKB) sanal pos hizmeti için omnipay kütüphanesi. 16 | 17 | ## Installation 18 | 19 | Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it 20 | to your `composer.json` file: 21 | 22 | ```json 23 | { 24 | "require": { 25 | "yasinkuyu/omnipay-gvp": "~2.0" 26 | } 27 | } 28 | ``` 29 | 30 | And run composer to update your dependencies: 31 | 32 | $ curl -s http://getcomposer.org/installer | php 33 | $ php composer.phar update 34 | 35 | ## Basic Usage 36 | 37 | The following gateways are provided by this package: 38 | 39 | * Gvp 40 | - Garanti 41 | - Denizbank 42 | - TEB 43 | - ING 44 | - Şekerbank 45 | - TFKB 46 | 47 | Gateway Methods 48 | 49 | * authorize($options) - authorize an amount on the customer's card 50 | * capture($options) - capture an amount you have previously authorized 51 | * purchase($options) - authorize and immediately capture an amount on the customer's card 52 | * refund($options) - refund an already processed transaction 53 | * void($options) - generally can only be called up to 24 hours after submitting a transaction 54 | 55 | For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) 56 | repository. 57 | 58 | ## Unit Tests 59 | 60 | PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. 61 | 62 | ## Sample App 63 | 64 | setMerchantId("7000679"); 74 | $gateway->setTerminalId("30691297"); 75 | 76 | $gateway->setUserName("PROVAUT"); 77 | $gateway->setPassword("123qweASD"); 78 | 79 | $gateway->setRefundUserName("PROVRFN"); 80 | $gateway->setRefundPassword("123qweASD"); 81 | 82 | $gateway->setTestMode(TRUE); 83 | 84 | $options = [ 85 | 'number' => '4824894728063019', 86 | 'expiryMonth' => '06', 87 | 'expiryYear' => '2017', 88 | 'cvv' => '959', 89 | 'fistname' => 'Yasin', 90 | 'lastname' => 'Kuyu' 91 | ]; 92 | 93 | $response = $gateway->purchase( 94 | [ 95 | //'installment' => '2', # Taksit 96 | //'multiplepoint' => 1, // Set money points (Maxi puan gir) 97 | //'extrapoint' => 150, // Set money points (Maxi puan gir) 98 | 'amount' => 100.00, 99 | 'orderid' => '', 100 | 'card' => $options 101 | ] 102 | )->send(); 103 | 104 | $response = $gateway->authorize( 105 | [ 106 | 'orderid' => 'asd2', 107 | 'transactionId' => '111111111111', 108 | 'amount' => 10.00, 109 | 'card' => $options 110 | ] 111 | )->send(); 112 | // 113 | $response = $gateway->capture( 114 | [ 115 | 'transactionId' => '111111111111', 116 | 'amount' => 1.00, 117 | 'currency' => 'TRY', 118 | 'card' => $options 119 | ] 120 | )->send(); 121 | 122 | $response = $gateway->refund( 123 | [ 124 | 'transactionId' => '111111111111', 125 | 'amount' => 1.00, 126 | 'currency' => 'TRY', 127 | 'card' => $options 128 | ] 129 | )->send(); 130 | 131 | $response = $gateway->void( 132 | [ 133 | 'transactionId' => '111111111111', 134 | 'authcode' => '123123', 135 | 'amount' => 1.00, 136 | 'currency' => 'TRY', 137 | 'card' => $options 138 | ] 139 | )->send(); 140 | 141 | if ($response->isSuccessful()) { 142 | //echo $response->getTransactionReference(); 143 | echo $response->getMessage(); 144 | } else { 145 | echo $response->getError(); 146 | } 147 | 148 | // Debug 149 | //var_dump($response); 150 | 151 | } 152 | 153 | } 154 | 155 | ## Postnet 156 | Posnet (Yapı Kredi, Vakıfbank, Anadolubank) gateway for Omnipay payment processing library 157 | https://github.com/yasinkuyu/omnipay-posnet 158 | 159 | ## NestPay (EST) 160 | (İş Bankası, Akbank, Finansbank, Denizbank, Kuveytturk, Halkbank, Anadolubank, ING Bank, Citibank, Cardplus) gateway for Omnipay payment processing library 161 | https://github.com/yasinkuyu/omnipay-nestpay 162 | 163 | ## Iyzico 164 | Iyzico gateway for Omnipay payment processing library 165 | https://github.com/yasinkuyu/omnipay-iyzico 166 | 167 | ## BKM Express 168 | BKM Express gateway for Omnipay payment processing library 169 | https://github.com/yasinkuyu/omnipay-bkm 170 | 171 | ## Paratika 172 | Paratika (Asseco) (Akbank, TEB, Halkbank, Finansbank, İş Bankası, Şekerbank, Vakıfbank ) gateway for Omnipay payment processing library 173 | https://github.com/yasinkuyu/omnipay-paratika 174 | 175 | ## Support 176 | 177 | If you are having general issues with Omnipay, we suggest posting on 178 | [Stack Overflow](http://stackoverflow.com/). Be sure to add the 179 | [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found. 180 | 181 | If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which 182 | you can subscribe to. 183 | 184 | If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/yasinkuyu/omnipay-gvp/issues), 185 | or better yet, fork the library and submit a pull request. 186 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yasinkuyu/omnipay-gvp", 3 | "type": "library", 4 | "description": "Gvp (Garanti, Denizbank, TEB, ING, Şekerbank, TFKB sanal pos) gateway for Omnipay payment processing library", 5 | "keywords": [ 6 | "gvp", 7 | "yapıkredi bankası", 8 | "sanal pos", 9 | "gateway", 10 | "merchant", 11 | "omnipay", 12 | "pay", 13 | "payment" 14 | ], 15 | "homepage": "https://github.com/yasinkuyu/omnipay-gvp", 16 | "license": "MIT", 17 | "authors": [ 18 | { 19 | "name": "Yasin Kuyu", 20 | "email": "yasinkuyu@gmail.com" 21 | }, 22 | { 23 | "name": "Omnipay Contributors", 24 | "homepage": "https://github.com/yasinkuyu/omnipay-gvp/contributors" 25 | } 26 | ], 27 | "autoload": { 28 | "psr-4": { 29 | "Omnipay\\Gvp\\": "src/" 30 | } 31 | }, 32 | "require": { 33 | "omnipay/common": "~2.0" 34 | }, 35 | "require-dev": { 36 | "omnipay/tests": "~2.0" 37 | }, 38 | "extra": { 39 | "branch-alias": { 40 | "dev-master": "2.0.x-dev" 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /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 | 'merchandId' => '', 24 | 'username' => 'PROVAUT', 25 | 'password' => '123qweASD', 26 | 'refundusername' => 'PROVRFN', 27 | 'refundpassword' => '123qweASD', 28 | 'installment' => '', 29 | 'type' => 'preauth', 30 | 'currency' => 'TRY', 31 | 'testMode' => false 32 | ); 33 | } 34 | 35 | public function authorize(array $parameters = array()) { 36 | return $this->createRequest('\Omnipay\Gvp\Message\AuthorizeRequest', $parameters); 37 | } 38 | 39 | public function capture(array $parameters = array()) { 40 | return $this->createRequest('\Omnipay\Gvp\Message\CaptureRequest', $parameters); 41 | } 42 | 43 | public function purchase(array $parameters = array()) { 44 | return $this->createRequest('\Omnipay\Gvp\Message\PurchaseRequest', $parameters); 45 | } 46 | 47 | public function refund(array $parameters = array()) { 48 | return $this->createRequest('\Omnipay\Gvp\Message\RefundRequest', $parameters); 49 | } 50 | 51 | public function void(array $parameters = array()) { 52 | return $this->createRequest('\Omnipay\Gvp\Message\VoidRequest', $parameters); 53 | } 54 | 55 | public function getMerchantId() { 56 | return $this->getParameter('merchantId'); 57 | } 58 | 59 | public function setMerchantId($value) { 60 | return $this->setParameter('merchantId', $value); 61 | } 62 | 63 | public function getTerminalId() { 64 | return $this->getParameter('terminalId'); 65 | } 66 | 67 | public function setTerminalId($value) { 68 | return $this->setParameter('terminalId', $value); 69 | } 70 | 71 | public function getUserName() { 72 | return $this->getParameter('username'); 73 | } 74 | 75 | public function setUserName($value) { 76 | return $this->setParameter('username', $value); 77 | } 78 | 79 | public function getPassword() { 80 | return $this->getParameter('password'); 81 | } 82 | 83 | public function setPassword($value) { 84 | return $this->setParameter('password', $value); 85 | } 86 | 87 | public function getRefundUserName() { 88 | return $this->getParameter('refundusername'); 89 | } 90 | 91 | public function setRefundUserName($value) { 92 | return $this->setParameter('refundusername', $value); 93 | } 94 | 95 | public function getRefundPassword() { 96 | return $this->getParameter('refundpassword'); 97 | } 98 | 99 | public function setRefundPassword($value) { 100 | return $this->setParameter('refundpassword', $value); 101 | } 102 | 103 | public function getSecurekey() { 104 | return $this->getParameter('securekey'); 105 | } 106 | 107 | public function setSecurekey($value) { 108 | return $this->setParameter('securekey', $value); 109 | } 110 | 111 | public function getInstallment() { 112 | return $this->getParameter('installment'); 113 | } 114 | 115 | public function setInstallment($value) { 116 | return $this->setParameter('installment', $value); 117 | } 118 | 119 | public function getType() { 120 | return $this->getParameter('type'); 121 | } 122 | 123 | public function setType($value) { 124 | return $this->setParameter('type', $value); 125 | } 126 | 127 | public function getOrderId() { 128 | return $this->getParameter('orderid'); 129 | } 130 | 131 | public function setOrderId($value) { 132 | return $this->setParameter('orderid', $value); 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /src/Message/AuthorizeRequest.php: -------------------------------------------------------------------------------- 1 | 'https://sanalposprovtest.garanti.com.tr/VPServlet', 21 | 'purchase' => 'https://sanalposprov.garanti.com.tr/VPServlet' 22 | ]; 23 | protected $currencies = [ 24 | 'TRY' => 949, 25 | 'YTL' => 949, 26 | 'TRL' => 949, 27 | 'TL' => 949, 28 | 'USD' => 840, 29 | 'EUR' => 978, 30 | 'GBP' => 826, 31 | 'JPY' => 392 32 | ]; 33 | 34 | public function getData() { 35 | 36 | $this->validate('amount', 'card'); 37 | $this->getCard()->validate(); 38 | $currency = $this->getCurrency(); 39 | 40 | $data['Transaction'] = array( 41 | 'Type' => $this->actionType, 42 | 'InstallmentCnt' => $this->getInstallment(), 43 | 'Amount' => $this->getAmountInteger(), 44 | 'CurrencyCode' => $this->currencies[$currency], 45 | 'CardholderPresentCode' => "0", 46 | 'MotoInd' => "N", 47 | 'Description' => "", 48 | 'OriginalRetrefNum' => $this->getTransactionId(), 49 | 'CepBank' => array( 50 | 'GSMNumber' => $this->getCard()->getBillingPhone(), 51 | 'CepBank' => "" 52 | ), 53 | 'PaymentType' => "K" // K->Kredi Kartı, D->Debit Kart, V->Vadesiz Hesap 54 | ); 55 | 56 | return $data; 57 | } 58 | 59 | public function sendData($data) { 60 | 61 | // API info 62 | $data['Version'] = "v0.01"; 63 | $data['Mode'] = $this->getTestMode() ? 'TEST' : 'PROD'; 64 | 65 | $data['Terminal'] = array( 66 | 'ProvUserID' => $this->getUserName(), 67 | 'HashData' => $this->getTransactionHash($this->getPassword()), 68 | 'UserID' => $this->getUserName(), 69 | 'ID' => $this->getTerminalId(), 70 | 'MerchantID' => $this->getMerchantId(), 71 | ); 72 | 73 | $data['Card'] = array( 74 | 'Number' => $this->getCard()->getNumber(), 75 | 'ExpireDate' => $this->getCard()->getExpiryDate('my'), 76 | 'CVV2' => $this->getCard()->getCvv() 77 | ); 78 | 79 | $data['Order'] = array( 80 | 'OrderID' => $this->getOrderId(), 81 | 'GroupID' => "" 82 | ); 83 | 84 | $data['Customer'] = array( 85 | 'IPAddress' => '127.0.0.1', //$this->getClientIp(), 86 | 'EmailAddress' => $this->getCard()->getEmail() 87 | ); 88 | 89 | // Build api post url 90 | $this->endpoint = $this->getTestMode() == TRUE ? $this->endpoints["test"] : $this->endpoints["purchase"]; 91 | 92 | $document = new DOMDocument('1.0', 'UTF-8'); 93 | $root = $document->createElement('GVPSRequest'); 94 | 95 | // recursive array to xml 96 | $xml = function ($root, $data) use ($document, &$xml) { 97 | foreach ($data as $key => $value) { 98 | if (is_array($value)) { 99 | $subs = $document->createElement($key); 100 | $root->appendChild($subs); 101 | $xml($subs, $value); 102 | } else { 103 | $root->appendChild($document->createElement($key, $value)); 104 | } 105 | } 106 | }; 107 | 108 | $xml($root, $data); 109 | 110 | $document->appendChild($root); 111 | 112 | // Post to Gvp 113 | $headers = array( 114 | 'Content-Type' => 'application/x-www-form-urlencoded' 115 | ); 116 | 117 | // Register the payment 118 | $this->httpClient->setConfig(array( 119 | 'curl.options' => array( 120 | 'CURLOPT_SSL_VERIFYHOST' => 2, 121 | 'CURLOPT_SSLVERSION' => 0, 122 | 'CURLOPT_SSL_VERIFYPEER' => 0, 123 | 'CURLOPT_RETURNTRANSFER' => 1, 124 | 'CURLOPT_POST' => 1 125 | ) 126 | )); 127 | 128 | $httpResponse = $this->httpClient->post($this->endpoint, $headers, $document->saveXML())->send(); 129 | 130 | return $this->response = new Response($this, $httpResponse->getBody()); 131 | } 132 | 133 | private function getSecurityHash($password) { 134 | $tidPrefix = str_repeat('0', 9 - strlen($this->getTerminalId())); 135 | $terminalId = sprintf('%s%s', $tidPrefix, $this->getTerminalId()); 136 | return strtoupper(SHA1(sprintf('%s%s', $password, $terminalId))); 137 | } 138 | 139 | /** 140 | * 141 | * @param string $password 142 | * @return string 143 | */ 144 | private function getTransactionHash($password) { 145 | return strtoupper( 146 | sha1( 147 | $this->getOrderId(), 148 | $this->getTerminalId(), 149 | $this->getCard()->getNumber(), 150 | $this->getAmountInteger(), 151 | $this->getSecurityHash($password) 152 | ) 153 | ); 154 | } 155 | 156 | public function getMerchantId() { 157 | return $this->getParameter('merchantId'); 158 | } 159 | 160 | public function setMerchantId($value) { 161 | return $this->setParameter('merchantId', $value); 162 | } 163 | 164 | public function getTerminalId() { 165 | return $this->getParameter('terminalId'); 166 | } 167 | 168 | public function setTerminalId($value) { 169 | return $this->setParameter('terminalId', $value); 170 | } 171 | 172 | public function getUserName() { 173 | return $this->getParameter('username'); 174 | } 175 | 176 | public function setUserName($value) { 177 | return $this->setParameter('username', $value); 178 | } 179 | 180 | public function getPassword() { 181 | return $this->getParameter('password'); 182 | } 183 | 184 | public function setPassword($value) { 185 | return $this->setParameter('password', $value); 186 | } 187 | 188 | public function getRefundUserName() { 189 | return $this->getParameter('refundusername'); 190 | } 191 | 192 | public function setRefundUserName($value) { 193 | return $this->setParameter('refundusername', $value); 194 | } 195 | 196 | public function getRefundPassword() { 197 | return $this->getParameter('refundpassword'); 198 | } 199 | 200 | public function setRefundPassword($value) { 201 | return $this->setParameter('refundpassword', $value); 202 | } 203 | 204 | public function getSecurekey() { 205 | return $this->getParameter('securekey'); 206 | } 207 | 208 | public function setSecurekey($value) { 209 | return $this->setParameter('securekey', $value); 210 | } 211 | 212 | public function getInstallment() { 213 | return $this->getParameter('installment'); 214 | } 215 | 216 | public function setInstallment($value) { 217 | return $this->setParameter('installment', $value); 218 | } 219 | 220 | public function getType() { 221 | return $this->getParameter('type'); 222 | } 223 | 224 | public function setType($value) { 225 | return $this->setParameter('type', $value); 226 | } 227 | 228 | public function getOrderId() { 229 | return $this->getParameter('orderid'); 230 | } 231 | 232 | public function setOrderId($value) { 233 | return $this->setParameter('orderid', $value); 234 | } 235 | 236 | } 237 | -------------------------------------------------------------------------------- /src/Message/RefundRequest.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 boolean 39 | */ 40 | public function isSuccessful() { 41 | return (string) $this->data["Transaction"]->Response->Code === '00'; 42 | } 43 | 44 | /** 45 | * Get is redirect 46 | * 47 | * @return boolean 48 | */ 49 | public function isRedirect() { 50 | return false; //todo 51 | } 52 | 53 | /** 54 | * Get a code describing the status of this response 55 | * 56 | * @return string 57 | */ 58 | public function getCode() { 59 | return $this->isSuccessful() ? $this->data["Transaction"]->Response->ReasonCode : parent::getCode(); //$this->data["Transaction"]->AuthCode 60 | } 61 | 62 | /** 63 | * Get transaction reference 64 | * 65 | * @return string 66 | */ 67 | public function getTransactionReference() { 68 | 69 | return $this->isSuccessful() ? $this->data["Transaction"]->Response->RetrefNum : ''; 70 | } 71 | 72 | /** 73 | * Get message 74 | * 75 | * @return string 76 | */ 77 | public function getMessage() { 78 | if ($this->isSuccessful()) { 79 | return $this->data["Transaction"]->Response->Message; 80 | } 81 | } 82 | 83 | /** 84 | * Get error 85 | * 86 | * @return string 87 | */ 88 | public function getError() { 89 | return $this->data["Transaction"]->Response->ErrorMsg . " / " . $this->data["Transaction"]->Response->SysErrMsg; 90 | } 91 | 92 | /** 93 | * Get Redirect url 94 | * 95 | * @return string 96 | */ 97 | public function getRedirectUrl() { 98 | if ($this->isRedirect()) { 99 | $data = array( 100 | 'TransId' => $this->data["Transaction"]->RetrefNum 101 | ); 102 | return $this->getRequest()->getEndpoint() . '/test/index?' . http_build_query($data); 103 | } 104 | } 105 | 106 | /** 107 | * Get Redirect method 108 | * 109 | * @return POST 110 | */ 111 | public function getRedirectMethod() { 112 | return 'POST'; 113 | } 114 | 115 | /** 116 | * Get Redirect url 117 | * 118 | * @return null 119 | */ 120 | public function getRedirectData() { 121 | return null; 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /src/Message/VoidRequest.php: -------------------------------------------------------------------------------- 1 | gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); 20 | 21 | $this->options = array( 22 | 'merchantId' => 'XXXXXXXXX', 23 | 'terminalId' => '0XXXXXXXX', 24 | 'provUserId' => '123', 25 | 'provPass' => '123', 26 | 'userId' => 'XXXXXX', 27 | 'amount' => 10.00, 28 | 'currency' => 'TRY', 29 | 'returnUrl' => 'http://sanalmagaza.org/return', 30 | 'card' => new CreditCard(array( 31 | 'number' => '5406675406675403', 32 | 'expiryMonth' => '12', 33 | 'expiryYear' => '2015', 34 | 'cvv' => '000', 35 | 'email' => 'yasinkuyu@gmail.com', 36 | 'firstname' => 'Yasin', 37 | 'lastname' => 'Kuyu' 38 | )), 39 | ); 40 | } 41 | 42 | public function testPurchase() 43 | { 44 | $this->setMockHttpResponse('PurchaseSuccess.txt'); 45 | 46 | $response = $this->gateway->purchase($this->options)->send(); 47 | 48 | $this->assertInstanceOf('\Omnipay\Gvp\Message\Response', $response); 49 | $this->assertTrue($response->isSuccessful()); 50 | $this->assertEquals('130215141054377801316798', $response->getTransactionReference()); 51 | } 52 | 53 | public function testPurchaseError() 54 | { 55 | $this->setMockHttpResponse('PurchaseFailure.txt'); 56 | 57 | $response = $this->gateway->purchase($this->options)->send(); 58 | 59 | $this->assertFalse($response->isSuccessful()); 60 | $this->assertSame('Input variable errors', $response->getMessage()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /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-gvp/6516a5d3192d8593950c0ffe137422a12d87dac8/tests/Mock/PurchaseFailure.txt -------------------------------------------------------------------------------- /tests/Mock/PurchaseFailureWithoutStatusCode.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasinkuyu/omnipay-gvp/6516a5d3192d8593950c0ffe137422a12d87dac8/tests/Mock/PurchaseFailureWithoutStatusCode.txt -------------------------------------------------------------------------------- /tests/Mock/PurchaseRedirect.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasinkuyu/omnipay-gvp/6516a5d3192d8593950c0ffe137422a12d87dac8/tests/Mock/PurchaseRedirect.txt -------------------------------------------------------------------------------- /tests/Mock/PurchaseSuccess.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasinkuyu/omnipay-gvp/6516a5d3192d8593950c0ffe137422a12d87dac8/tests/Mock/PurchaseSuccess.txt --------------------------------------------------------------------------------