├── .gitignore ├── composer.json ├── LICENSE ├── README.md └── src └── est.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | composer.phar 3 | phpunit.xml 4 | composer.lock 5 | .DS_Store -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ozgur/est", 3 | "version": "1.0", 4 | "description": "Virtual POS interface to the EST Payment Gateway (Turkey)", 5 | "keywords": ["est", "payment", "turkey"], 6 | "homepage": "http://ozgur.github.com/php-est/", 7 | "type": "library", 8 | "license": "MIT", 9 | "authors": [ 10 | { 11 | "name": "Ozgur Vatansever", 12 | "email": "ozgurvt@gmail.com", 13 | "homepage": "https://github.com/ozgur" 14 | } 15 | ], 16 | "require": { 17 | "php": ">=5.2.1" 18 | }, 19 | "repositories": [ 20 | { 21 | "type": "vcs", 22 | "url": "https://github.com/ozgur/php-est" 23 | } 24 | ], 25 | "autoload": { 26 | "psr-0": {"est": "src/"} 27 | } 28 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright © 2013 Ozgur Vatansever (ozgurvt@gmail.com) 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without restriction, 6 | including without limitation the rights to use, copy, modify, merge, 7 | publish, distribute, sublicense, and/or sell copies of the Software, 8 | and to permit persons to whom the Software is furnished to do so, 9 | subject to 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 16 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP EST 2 | 3 | PHP tabanlı EST Sanal POS Sistemleri Arabirimi 4 | 5 | [![EST](http://www.asseco-see.com.tr/images/est_logo.jpg)](http://www.asseco-see.com.tr/index.asp) 6 | 7 | Bu arabirim EST tabanlı sanal pos arabirimlerine bağlanıp, kredi kartı ile sipariş verme işleri için geliştirilmiştir. 8 | 9 | Bu arabirim sadece **İş Bankası**, **Akbank**, **Anadolubank**, **Halkbank**, **Finansbank** Sanal POS arabirimleri ile uyumludur. Diğer EST tabanlı arabirimler için kullanılamamaktadır. 10 | 11 | EST Türkiye'nin e-Ticaret güvenli ödeme sistem ve hizmetleri sağlayıcısıdır. Türkiye'de e-Ticaret ödemeleri alanında faaliyet gösteren bankaların tamamına yakını bunu EST Ürün, Çözüm, Hizmetlerinden bir veya daha fazlasını kullanarak gerçekleştirmektedir. 12 | 13 | 14 | ## Kurulum 15 | 16 | Bu arabirim PHP 5.3.2 ya da daha yüksek sürümlerinde kullanılabilmektedir. Kurulum için [composer](http://getcomposer.org/download/) paket yöneticisi kurmanız gerekmektedir. 17 | 18 | $ php composer.phar install 19 | 20 | 21 | ## Kullanımı 22 | 23 | Bu arabirimi kullanabilmeniz için **İşyeri No**, **Kullanıcı adı** ve **Parola** bilgileri gereklidir. Her bir bankanın kendi sanal POS arabirimlerini kullanabilmek için ayrı ayrı bu bilgileri edinmeniz gerekmektedir. Bu bilgileri edinmek istiyorsanız **destek@est.com.tr** adresine e-posta yollayınız. 24 | 25 | Bu arabirim ile aşağıdaki pos işlemleri yapılabilir; 26 | 27 | * Sipariş vermek, 28 | * Siparişi iptal etme, 29 | * Siparişten belli bir miktarı iade etme, 30 | * Yapılmış bir siparişin detaylarını görebilme, 31 | 32 | Sanal POS sistemine yapılan bütün istekler EST sınıfı tarafından düzenlenmektedir. EST sınıfının yukarıdaki işlemleri yapabilmesi için aşağıdaki metodlar tanımlanmıştır. 33 | 34 | * purchase() ~ Sipariş vermek için bu metod çağrılır. 35 | * postAuth() ~ Bloke edilen miktarı karttan çekmek için bu metod çağrılır. 36 | * cancel() ~ Siparişi iptal etmek için bu metod çağrılır. 37 | * refund() ~ Siparişten belli bir miktar para iade etmek için bu metod çağrılır. 38 | * getDetail() ~ Bir siparişin detaylarını görmek için bu metod çağrılır. 39 | 40 | ```php 41 | require 'est.php'; 42 | $api = new EST("akbank", "100100000", "AKTEST", "AKTEST123", $debug=TRUE); 43 | ``` 44 | 45 | Eğer test sunucusu değil de gerçek ortamda çalışmak istiyorsanız **debug** parametresini FALSE olarak set ediniz. 46 | 47 | Sipariş verme isteği göndermemiz için **.pay()** metodunu çağırmanız gerekmektedir. Bu metodu çağırmak için sırasıyla aşağıdaki parametreler gerekmektedir. 48 | 49 | ```php 50 | $cc_num = "5456165456165454"; // kart numarası 51 | $cc_cvv = "000"; 52 | $month = "12"; 53 | $year = "12"; 54 | $amount = 10.00; 55 | $taksit = 0; // peşin 56 | $order_num = "qwaszx"; // sipariş numarası 57 | $result = $api->pay($cc_num, $cc_cvv, $month, $year, $amount, $taksit, $order_num); 58 | print_r($result); 59 | Array 60 | ( 61 | [orderid] => qwaszx 62 | [transid] => 10177-TeYF-1-1543 63 | [groupid] => qwaszx 64 | [response] => Approved 65 | [return_code] => 00 66 | [error_msg] => 67 | [host_msg] => Onay 68 | [auth_code] => 116745 69 | [result] => 1 70 | [transaction_time] => Array 71 | ( 72 | [tm_sec] => 24 73 | [tm_min] => 30 74 | [tm_hour] => 19 75 | [tm_mday] => 26 76 | [tm_mon] => 5 77 | [tm_year] => 110 78 | [tm_wday] => 6 79 | [tm_yday] => 176 80 | [unparsed] => 81 | ) 82 | 83 | ) 84 | ``` 85 | 86 | Aynı sipariş numarasıyla tekrar istek yaparsak hata alırız. 87 | 88 | ```php 89 | $result = $api->pay($cc_num, $cc_cvv, $month, $year, $amount, $taksit, $order_num); 90 | print_r($result); 91 | Array 92 | ( 93 | [orderid] => qwaszx 94 | [transid] => 10177-TfgE-1-1544 95 | [groupid] => qwaszx 96 | [response] => Error 97 | [return_code] => 99 98 | [error_msg] => Bu siparis numarasi ile zaten basarili bir siparis var. 99 | [host_msg] => 100 | [auth_code] => 101 | [result] => 102 | [transaction_time] => Array 103 | ( 104 | [tm_sec] => 32 105 | [tm_min] => 31 106 | [tm_hour] => 19 107 | [tm_mday] => 26 108 | [tm_mon] => 5 109 | [tm_year] => 110 110 | [tm_wday] => 6 111 | [tm_yday] => 176 112 | [unparsed] => 113 | ) 114 | 115 | ) 116 | ``` 117 | 118 | Ekstra parametrelerde **fatura adresi** ve **teslimat adresi** ile ilgili detayları set edebilirsiniz. 119 | 120 | ```php 121 | $extra = array("shipping_address_name" => "Ev Adresim", "billing_address_name" => "Fatura Adresim"); 122 | $api->pay($cc_num, $cc_cvv, $month, $year, $amount, $taksit, $order_num, $typ="Auth", $extra=$extra); 123 | ``` 124 | 125 | Kullanıcının kredi kartındaki belli bir miktara bloke koymak için *typ* parametresini **PreAuth** olarak göndermeniz gerekmektedir. 126 | 127 | ```php 128 | $api->pay($cc_num, $cc_cvv, $month, $year, $amount, $taksit, $order_num, $typ="PreAuth"); 129 | ``` 130 | 131 | Bloke koyduğumuz miktarı kullanıcının kartından çekmek için **.postAuth()** metodunu çekmek istediğiniz miktar ile çağırmanız gerekmektedir. 132 | 133 | ```php 134 | $result = $api->postAuth($amount, $order_num); 135 | print_r($result); 136 | Array 137 | ( 138 | [orderid] => qwaszx 139 | [transid] => 10177-TpIF-1-1549 140 | [groupid] => qwaszx 141 | [response] => Approved 142 | [return_code] => 00 143 | [error_msg] => 144 | [host_msg] => 145 | [auth_code] => 691348 146 | [host_ref_num] => 017719080777 147 | [result] => 1 148 | [transaction_time] => Array 149 | ( 150 | [tm_sec] => 8 151 | [tm_min] => 41 152 | [tm_hour] => 19 153 | [tm_mday] => 26 154 | [tm_mon] => 5 155 | [tm_year] => 110 156 | [tm_wday] => 6 157 | [tm_yday] => 176 158 | [unparsed] => 159 | ) 160 | 161 | ) 162 | ``` 163 | 164 | Siparişi yada yaptığınız postAuth isteğini iptal etmek için **.cancel()** metodu çağrılmalıdır. Sipariş numarası parametre olarak verilmelidir. 165 | 166 | ```php 167 | $result = $api->cancel($order_num); 168 | print_r($result); 169 | Array 170 | ( 171 | [orderid] => qwaszx 172 | [transid] => 10177-TpIF-1-1549 173 | [groupid] => qwaszx 174 | [response] => Approved 175 | [return_code] => 00 176 | [error_msg] => 177 | [host_msg] => 178 | [auth_code] => 691348 179 | [host_ref_num] => 017719080777 180 | [result] => 1 181 | [transaction_time] => Array 182 | ( 183 | [tm_sec] => 8 184 | [tm_min] => 41 185 | [tm_hour] => 19 186 | [tm_mday] => 26 187 | [tm_mon] => 5 188 | [tm_year] => 110 189 | [tm_wday] => 6 190 | [tm_yday] => 176 191 | [unparsed] => 192 | ) 193 | 194 | ) 195 | ``` 196 | 197 | Var olmayan ya da daha önceden iptal edilmiş bir siparişi tekrar iptal etmeye çalışılırsa sunucudan aşağıdaki gibi bir cevap alınır. 198 | 199 | ```php 200 | $result = $api->cancel("123456abcdef"); 201 | print_r($result); 202 | Array 203 | ( 204 | [orderid] => 123456abcdef 205 | [transid] => 10177-TtuB-1-1556 206 | [groupid] => 123456abcdef 207 | [response] => Error 208 | [return_code] => 99 209 | [error_msg] => İptal edilmeye uygun satış işlemi bulunamadı. 210 | [host_msg] => 211 | [auth_code] => 212 | [host_ref_num] => 213 | [result] => 214 | [transaction_time] => Array 215 | ( 216 | [tm_sec] => 46 217 | [tm_min] => 45 218 | [tm_hour] => 19 219 | [tm_mday] => 26 220 | [tm_mon] => 5 221 | [tm_year] => 110 222 | [tm_wday] => 6 223 | [tm_yday] => 176 224 | [unparsed] => 225 | ) 226 | 227 | ) 228 | ``` 229 | 230 | Siparişten belli bir miktarın tutarının müşterinin kartına geri yüklenmesi işlem için **.refund()** metodu çağrılmalıdır. 231 | 232 | ```php 233 | $result = $api->refund($amount = 5.00, $orderid = $order_num); 234 | print_r($result); 235 | Array 236 | ( 237 | [orderid] => qwaszx 238 | [transid] => 10177-TxYA-1-1558 239 | [groupid] => qwaszx 240 | [response] => Approved 241 | [return_code] => 00 242 | [error_msg] => 243 | [host_msg] => Onay 244 | [auth_code] => 154681 245 | [host_ref_num] => 017719080780 246 | [result] => 1 247 | [transaction_time] => Array 248 | ( 249 | [tm_sec] => 24 250 | [tm_min] => 49 251 | [tm_hour] => 19 252 | [tm_mday] => 26 253 | [tm_mon] => 5 254 | [tm_year] => 110 255 | [tm_wday] => 6 256 | [tm_yday] => 176 257 | [unparsed] => 258 | ) 259 | 260 | ) 261 | ``` 262 | 263 | Eğer sipariş tutarından daha büyük bir tutar iptal edilmeye çalışırsa aşağıdaki cevap alınır. 264 | 265 | ```php 266 | $result = $api->refund($amount = 9999.0, $orderid = $order_num); 267 | print_r($result); 268 | Array 269 | ( 270 | [orderid] => qwaszx 271 | [transid] => 10177-TybA-1-1559 272 | [groupid] => qwaszx 273 | [response] => Error 274 | [return_code] => 99 275 | [error_msg] => Net miktardan fazlasi iade edilemez. 276 | [host_msg] => 277 | [auth_code] => 278 | [host_ref_num] => 279 | [result] => 280 | [transaction_time] => Array 281 | ( 282 | [tm_sec] => 27 283 | [tm_min] => 50 284 | [tm_hour] => 19 285 | [tm_mday] => 26 286 | [tm_mon] => 5 287 | [tm_year] => 110 288 | [tm_wday] => 6 289 | [tm_yday] => 176 290 | [unparsed] => 291 | ) 292 | 293 | ) 294 | ``` 295 | 296 | Eğer **.refund()** metodu ile yaptığınız iade isteğini iptal etmek istiyorsanız iade işleminden size cevap olarak gönderilen **transid** ve **orderid** değerlerini **.cancel()** metoduna göndermeniz gerekmektedir. 297 | 298 | ```php 299 | $result = $api->cancel($orderid = $order_num, $transid = '10177-TxYA-1-1558'); 300 | print_r($result); 301 | Array 302 | ( 303 | [orderid] => qwaszx 304 | [transid] => 10177-TxYA-1-1558 305 | [groupid] => qwaszx 306 | [response] => Approved 307 | [return_code] => 00 308 | [error_msg] => 309 | [host_msg] => 310 | [auth_code] => 154681 311 | [host_ref_num] => 017719080780 312 | [result] => 1 313 | [transaction_time] => Array 314 | ( 315 | [tm_sec] => 24 316 | [tm_min] => 49 317 | [tm_hour] => 19 318 | [tm_mday] => 26 319 | [tm_mon] => 5 320 | [tm_year] => 110 321 | [tm_wday] => 6 322 | [tm_yday] => 176 323 | [unparsed] => 324 | ) 325 | 326 | ) 327 | ``` 328 | 329 | Daha önceden verilmiş bir siparişin detayı öğrenilmek isteniyorsa **.getDetail()** metodu kullanılmalıdır. Bu metoda sipariş numarası parametre olarak verilir. 330 | 331 | ```php 332 | $result = $api->getDetail($order_num); 333 | print_r($result); 334 | Array 335 | ( 336 | [transid] => 10177-TK3E-1-1540 337 | [orderid] => testorderid01234 338 | [return_code] => 00 339 | [host_ref_num] => 017719080774 340 | [error_msg] => Record(s) found for testorderid01234 341 | [charge_type] => S 342 | [auth_code] => 931005 343 | [amount] => 10 344 | [transaction_time] => Array 345 | ( 346 | [tm_sec] => 53 347 | [tm_min] => 10 348 | [tm_hour] => 19 349 | [tm_mday] => 26 350 | [tm_mon] => 5 351 | [tm_year] => 110 352 | [tm_wday] => 6 353 | [tm_yday] => 176 354 | [unparsed] => 355 | ) 356 | 357 | ) 358 | ``` 359 | 360 | ## İptal ve İade Arasındaki Farklar 361 | 362 | Bilindiği gibi sanal POS'larda da gerçek POS hesapları gibi gün sonu kavramı vardır. Gün sonu kavramı; gün içinde POS ile ilgili yapılan işlemlerin (para çekimi ve para iadesi gibi) gün sonunda POS sahibinin banka hesabına aktarılması demektir. 363 | 364 | Siparişin iptal işlemi gün sonu gelmeden **sadece** aynı gün içinde yapılabilir. Önceki güne ait siparişler iptal edilemezler. Önceki güne ait siparişler ancak **.refund()** metodu ile siparişin tutarı girilerek iade edilirler. 365 | 366 | Eğer sipariş iptal edilirse; siparişin yapıldığı ve iptal edildiği gibi detaylar kart sahibinin ektresinde görünmez. Eğer iade yapılırsa iade işlemi kart sahibinin ekstresine yansır. Bankaların çoğunda gün sonu akşam saat **22:00**'dir. Fakat bu saati bankalar durumlarına göre değiştirebilirler. 367 | -------------------------------------------------------------------------------- /src/est.php: -------------------------------------------------------------------------------- 1 | array("host" => "ccpos.garanti.com.tr", 15 | "testhost" => "ccpostest.garanti.com.tr", 16 | "listOrdersURL" => "/servlet/ozelrapor", 17 | "detailOrderURL" => "/servlet/cc5ApiServer", 18 | "cancelOrderURL" => "/servlet/cc5ApiServer", 19 | "returnOrderURL" => "/servlet/cc5ApiServer", 20 | "purchaseOrderURL" => "/servlet/cc5ApiServer"), 21 | 22 | "akbank" => array("host" => "www.sanalakpos.com", 23 | "testhost" => "testsanalpos.est.com.tr", 24 | "listOrdersURL" => "/servlet/listapproved", 25 | "detailOrderURL" => "/servlet/cc5ApiServer", 26 | "cancelOrderURL" => "/servlet/cc5ApiServer", 27 | "returnOrderURL" => "/servlet/cc5ApiServer", 28 | "purchaseOrderURL" => "/servlet/cc5ApiServer"), 29 | 30 | "finansbank" => array("host" => "www.fbwebpos.com", 31 | "testhost" => "testsanalpos.est.com.tr", 32 | "listOrdersURL" => "/servlet/listapproved", 33 | "detailOrderURL" => "/servlet/cc5ApiServer", 34 | "cancelOrderURL" => "/servlet/cc5ApiServer", 35 | "returnOrderURL" => "/servlet/cc5ApiServer", 36 | "purchaseOrderURL" => "/servlet/cc5ApiServer"), 37 | 38 | "halkbank" => array("host" => "sanalpos.halkbank.com.tr", 39 | "testhost" => "testsanalpos.est.com.tr", 40 | "listOrdersURL" => "/servlet/listapproved", 41 | "detailOrderURL" => "/servlet/cc5ApiServer", 42 | "cancelOrderURL" => "/servlet/cc5ApiServer", 43 | "returnOrderURL" => "/servlet/cc5ApiServer", 44 | "purchaseOrderURL" => "/servlet/cc5ApiServer"), 45 | 46 | "isbank" => array("host" => "spos.isbank.com.tr", 47 | "testhost" => "testsanalpos.est.com.tr", 48 | "listOrdersURL" => "/servlet/listapproved", 49 | "detailOrderURL" => "/servlet/cc5ApiServer", 50 | "cancelOrderURL" => "/servlet/cc5ApiServer", 51 | "returnOrderURL" => "/servlet/cc5ApiServer", 52 | "purchaseOrderURL" => "/servlet/cc5ApiServer"), 53 | 54 | "anadolubank" => array("host" => "anadolusanalpos.est.com.tr", 55 | "testhost" => "testsanalpos.est.com.tr", 56 | "listOrdersURL" => "/servlet/listapproved", 57 | "detailOrderURL" => "/servlet/cc5ApiServer", 58 | "cancelOrderURL" => "/servlet/cc5ApiServer", 59 | "returnOrderURL" => "/servlet/cc5ApiServer", 60 | "purchaseOrderURL" => "/servlet/cc5ApiServer")); 61 | 62 | public function __construct($slug, $company, $name, $password, $debug = TRUE) { 63 | $possibleSlugs = array("akbank", "garanti", "finansbank", "isbank", "anadolubank", "halkbank"); 64 | // If the slug is not among the possible slugs, then immediately throw an exception.. 65 | if(!in_array($slug, $possibleSlugs)) { 66 | throw new Exception("Geçersiz bir slug seçtiniz."); 67 | } 68 | 69 | $this->slug = $slug; 70 | $this->company = $company; 71 | $this->name = $name; 72 | $this->password = $password; 73 | $this->debug = $debug; 74 | $this->credentials = self::$banksDetails[$this->slug]; 75 | } 76 | 77 | private function __get_credentials() { 78 | if($this->credentials) return $this->credentials; 79 | if($this->slug) { 80 | if(array_key_exists($this->slug, self::$banksDetails)) { 81 | return self::$banksDetails[$this->slug]; 82 | } 83 | return null; 84 | } 85 | return null; 86 | } 87 | 88 | private function __connect() { 89 | if($this->debug) 90 | return "https://" . $this->credentials["testhost"]; 91 | else return "https://" . $this->credentials["host"]; 92 | } 93 | 94 | public function pay($credit_card_number, $cvv, $month, $year, $amount, $installment, $orderid, $typ = "Auth", $extra = array()) { 95 | $builder = new XMLBuilder(); 96 | $month = str_pad($month, 2, "0", STR_PAD_LEFT); 97 | $year = str_pad($year, 2, "0", STR_PAD_LEFT); 98 | $expires = $month . $year; 99 | 100 | $amount = number_format($amount, 2, '.', ''); 101 | 102 | $credentials = $this->__get_credentials(); 103 | $username = $this->name; 104 | $password = $this->password; 105 | $clientid = $this->company; 106 | 107 | $email = $this->__get_value($extra, "email"); 108 | $ipaddress = $this->__get_value($extra, "ipaddress"); 109 | $userid = $this->__get_value($extra, "userid"); 110 | 111 | $document = new XMLBuilder(); 112 | $elements = array("Name" => $username, "Password" => $password, "ClientId" => $clientid, 113 | "Mode" => "P", "OrderId" => $orderid, "Type" => $typ, "Currency" => "949", 114 | "GroupId" => "", "TransId" => "", "UserId" => $userid, "Extra" => "", 115 | "Taksit" => $installment, "Number" => $credit_card_number, "Expires" => $expires, 116 | "Cvv2Val" => $cvv, "Total" => $amount, "Email" => $email, "IPAddress" => $ipaddress 117 | ); 118 | $domElements = $document->createElementsWithTextNodes($elements); 119 | $document->appendListOfElementsToElement($document->root(), $domElements); 120 | 121 | $billto = $document->createElement("BillTo"); 122 | $billing_address_name = $this->__get_value($extra, "billing_address_name"); 123 | $billing_address_street1 = $this->__get_value($extra, "billing_address_street1"); 124 | $billing_address_street2 = $this->__get_value($extra, "billing_address_street2"); 125 | $billing_address_street3 = $this->__get_value($extra, "billing_address_street3"); 126 | $billing_address_city = $this->__get_value($extra, "billing_address_city"); 127 | $billing_address_company = $this->__get_value($extra, "billing_address_company"); 128 | $billing_address_postalcode = $this->__get_value($extra, "billing_address_postalcode"); 129 | $billing_address_telvoice = $this->__get_value($extra, "billing_address_telvoice"); 130 | $billing_address_state = $this->__get_value($extra, "billing_address_state"); 131 | 132 | $elements = array("Name" => $billing_address_name, "Street1" => $billing_address_street1, 133 | "Street2" => $billing_address_street2, "Street3" => $billing_address_street3, 134 | "City" => $billing_address_city, "StateProv" => $billing_address_state, 135 | "PostalCode" => $billing_address_postalcode, "Country" => "Türkiye", 136 | "Company" => $billing_address_company, "TelVoice" => $billing_address_telvoice 137 | ); 138 | $domElements = $document->createElementsWithTextNodes($elements); 139 | $document->appendListOfElementsToElement($billto, $domElements); 140 | $document->root()->appendChild($billto); 141 | 142 | 143 | $shipto = $document->createElement("ShipTo"); 144 | $shipping_address_name = $this->__get_value($extra, "shipping_address_name"); 145 | $shipping_address_street1 = $this->__get_value($extra, "shipping_address_street1"); 146 | $shipping_address_street2 = $this->__get_value($extra, "shipping_address_street2"); 147 | $shipping_address_street3 = $this->__get_value($extra, "shipping_address_street3"); 148 | $shipping_address_city = $this->__get_value($extra, "shipping_address_city"); 149 | $shipping_address_company = $this->__get_value($extra, "shipping_address_company"); 150 | $shipping_address_postalcode = $this->__get_value($extra, "shipping_address_postalcode"); 151 | $shipping_address_telvoice = $this->__get_value($extra, "shipping_address_telvoice"); 152 | $shipping_address_state = $this->__get_value($extra, "shipping_address_state"); 153 | 154 | $elements = array("Name" => $shipping_address_name, "Street1" => $shipping_address_street1, 155 | "Street2" => $shipping_address_street2, "Street3" => $shipping_address_street3, 156 | "City" => $shipping_address_city, "StateProv" => $shipping_address_state, 157 | "PostalCode" => $shipping_address_postalcode, "Country" => "Türkiye", 158 | "Company" => $shipping_address_company, "TelVoice" => $shipping_address_telvoice 159 | ); 160 | 161 | $domElements = $document->createElementsWithTextNodes($elements); 162 | $document->appendListOfElementsToElement($shipto, $domElements); 163 | $document->root()->appendChild($shipto); 164 | $documentString = $document->saveXML(); 165 | $this->raw_request = $documentString; 166 | 167 | /* After the XML request has been created, we should now set the HTTP request using curl library.. */ 168 | $url = $this->__connect() . $this->credentials["purchaseOrderURL"]; 169 | $curl = curl_init(); 170 | $postData = urlencode("DATA") . "=" . urlencode($documentString); 171 | // Set the url.. 172 | curl_setopt($curl, CURLOPT_URL, $url); 173 | // Set the HTTP method to POST.. 174 | curl_setopt($curl, CURLOPT_POST, 1); 175 | // Set the HTTP response header to False not to get the response header.. 176 | curl_setopt ($curl, CURLOPT_HEADER, FALSE); 177 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 178 | // Add the HTTP POST body.. 179 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); 180 | // Set the HTTP request header.. 181 | curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type" => "application/x-www-form-urlencoded")); 182 | // Execute the request and save the response inside a variable called 'raw_response'.. 183 | $this->raw_response = curl_exec($curl); 184 | // Close the connection.. 185 | curl_close($curl); 186 | 187 | // After we got the response, we should now parse it using xml library.. 188 | $responseDomObject = new DOMDocument(); 189 | $responseDomObject->loadXML($this->raw_response); 190 | // The result to be returned will be an array containing the response details.. 191 | $result = array(); 192 | try { 193 | $orderid = XMLBuilder::get_data($responseDomObject, "OrderId"); 194 | $groupid = XMLBuilder::get_data($responseDomObject, "GroupId"); 195 | $transid = XMLBuilder::get_data($responseDomObject, "TransId"); 196 | $response = XMLBuilder::get_data($responseDomObject, "Response"); 197 | $return_code = XMLBuilder::get_data($responseDomObject, "ProcReturnCode"); 198 | $error_msg = XMLBuilder::get_data($responseDomObject, "ErrMsg"); 199 | $host_msg = XMLBuilder::get_data($responseDomObject, "HOSTMSG"); 200 | $trx_date = XMLBuilder::get_data($responseDomObject, "TRXDATE"); 201 | $auth_code = XMLBuilder::get_data($responseDomObject, "AuthCode"); 202 | $is_successful = FALSE; 203 | if(intval($return_code) == 0) { 204 | $is_successful = TRUE; 205 | } 206 | $result["orderid"] = $orderid; 207 | $result["transid"] = $transid; 208 | $result["groupid"] = $groupid; 209 | $result["response"] = $response; 210 | $result["return_code"] = $return_code; 211 | $result["error_msg"] = $error_msg; 212 | $result["host_msg"] = $host_msg; 213 | $result["auth_code"] = $auth_code; 214 | $result["result"] = $is_successful; 215 | } 216 | catch(Exception $e){ 217 | $result["result"] = FALSE; 218 | $result["exception"] = $e->getMessage(); 219 | } 220 | 221 | if(isset($trx_date)) { 222 | try { 223 | $trx_date = explode(".", $trx_date); 224 | $trx_date = $trx_date[0]; 225 | $trx_date = strptime($trx_date, "%Y%m%d %H:%M:%S"); 226 | $result["transaction_time"] = $trx_date; 227 | } 228 | catch(Exception $e) { 229 | // pass 230 | } 231 | } 232 | return $result; 233 | } 234 | 235 | public function cancel($orderid, $transid = null) { 236 | $credentials = $this->__get_credentials(); 237 | $username = $this->name; 238 | $password = $this->password; 239 | $clientid = $this->company; 240 | 241 | $document = new XMLBuilder(); 242 | $elements = array("Name" => $username, "Password" => $password, "ClientId" => $clientid, 243 | "Mode" => "P", "OrderId" => $orderid, "Type" => "Void", "Currency" => "949" 244 | ); 245 | 246 | // Include the transaction id if the actual parameter for 'transid' is not null.. 247 | if($transid) { 248 | $elements["TransId"] = $transid; 249 | } 250 | $domElements = $document->createElementsWithTextNodes($elements); 251 | $document->appendListOfElementsToElement($document->root(), $domElements); 252 | $documentString = $document->saveXML(); 253 | $this->raw_request = $documentString; 254 | 255 | /* After the XML request has been created, we should now set the HTTP request using curl library.. */ 256 | $url = $this->__connect() . $this->credentials["cancelOrderURL"]; 257 | $curl = curl_init(); 258 | $postData = urlencode("DATA") . urlencode("=") . urlencode($documentString); 259 | // Set the url.. 260 | curl_setopt($curl, CURLOPT_URL, $url); 261 | // Set the HTTP method to POST.. 262 | curl_setopt($curl, CURLOPT_POST, 1); 263 | // Set the HTTP response header to False not to get the response header.. 264 | curl_setopt ($curl, CURLOPT_HEADER, FALSE); 265 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 266 | // Add the HTTP POST body.. 267 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); 268 | // Set the HTTP request header.. 269 | curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type" => "application/x-www-form-urlencoded")); 270 | // Execute the request and save the response inside a variable called 'raw_response'.. 271 | $this->raw_response = curl_exec($curl); 272 | // Close the connection.. 273 | curl_close($curl); 274 | 275 | // After we got the response, we should now parse it using xml library.. 276 | $responseDomObject = new DOMDocument(); 277 | $responseDomObject->loadXML($this->raw_response); 278 | // The result to be returned will be an array containing the response details.. 279 | $result = array(); 280 | try { 281 | $orderid = XMLBuilder::get_data($responseDomObject, "OrderId"); 282 | $groupid = XMLBuilder::get_data($responseDomObject, "GroupId"); 283 | $transid = XMLBuilder::get_data($responseDomObject, "TransId"); 284 | $response = XMLBuilder::get_data($responseDomObject, "Response"); 285 | $return_code = XMLBuilder::get_data($responseDomObject, "ProcReturnCode"); 286 | $error_msg = XMLBuilder::get_data($responseDomObject, "ErrMsg"); 287 | $host_msg = XMLBuilder::get_data($responseDomObject, "HOSTMSG"); 288 | $trx_date = XMLBuilder::get_data($responseDomObject, "TRXDATE"); 289 | $host_ref_num = XMLBuilder::get_data($responseDomObject, "HostRefNum"); 290 | $auth_code = XMLBuilder::get_data($responseDomObject, "AuthCode"); 291 | $is_successful = FALSE; 292 | if(intval($return_code) == 0) { 293 | $is_successful = TRUE; 294 | } 295 | $result["orderid"] = $orderid; 296 | $result["transid"] = $transid; 297 | $result["groupid"] = $groupid; 298 | $result["response"] = $response; 299 | $result["return_code"] = $return_code; 300 | $result["error_msg"] = $error_msg; 301 | $result["host_msg"] = $host_msg; 302 | $result["auth_code"] = $auth_code; 303 | $result["host_ref_num"] = $host_ref_num; 304 | $result["result"] = $is_successful; 305 | } 306 | catch(Exception $e){ 307 | $result["result"] = FALSE; 308 | $result["exception"] = $e->getMessage(); 309 | } 310 | 311 | if(isset($trx_date)) { 312 | try { 313 | $trx_date = explode(".", $trx_date); 314 | $trx_date = $trx_date[0]; 315 | $trx_date = strptime($trx_date, "%Y%m%d %H:%M:%S"); 316 | $result["transaction_time"] = $trx_date; 317 | } 318 | catch(Exception $e) { 319 | // pass 320 | } 321 | } 322 | return $result; 323 | } 324 | 325 | public function refund($amount, $orderid) { 326 | $credentials = $this->__get_credentials(); 327 | $username = $this->name; 328 | $password = $this->password; 329 | $clientid = $this->company; 330 | 331 | $amount = number_format($amount, 2); 332 | $document = new XMLBuilder(); 333 | $elements = array("Name" => $username, "Password" => $password, "ClientId" => $clientid, 334 | "Mode" => "P", "OrderId" => $orderid, "Type" => "Credit", "Currency" => "949", 335 | "Total" => $amount 336 | ); 337 | $domElements = $document->createElementsWithTextNodes($elements); 338 | $document->appendListOfElementsToElement($document->root(), $domElements); 339 | $documentString = $document->saveXML(); 340 | $this->raw_request = $documentString; 341 | 342 | /* After the XML request has been created, we should now set the HTTP request using curl library.. */ 343 | $url = $this->__connect() . $this->credentials["returnOrderURL"]; 344 | $curl = curl_init(); 345 | $postData = urlencode("DATA") . urlencode("=") . urlencode($documentString); 346 | // Set the url.. 347 | curl_setopt($curl, CURLOPT_URL, $url); 348 | // Set the HTTP method to POST.. 349 | curl_setopt($curl, CURLOPT_POST, 1); 350 | // Set the HTTP response header to False not to get the response header.. 351 | curl_setopt ($curl, CURLOPT_HEADER, FALSE); 352 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 353 | // Add the HTTP POST body.. 354 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); 355 | // Set the HTTP request header.. 356 | curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type" => "application/x-www-form-urlencoded")); 357 | // Execute the request and save the response inside a variable called 'raw_response'.. 358 | $this->raw_response = curl_exec($curl); 359 | // Close the connection.. 360 | curl_close($curl); 361 | // After we got the response, we should now parse it using xml library.. 362 | $responseDomObject = new DOMDocument(); 363 | $responseDomObject->loadXML($this->raw_response); 364 | // The result to be returned will be an array containing the response details.. 365 | $result = array(); 366 | try { 367 | $orderid = XMLBuilder::get_data($responseDomObject, "OrderId"); 368 | $groupid = XMLBuilder::get_data($responseDomObject, "GroupId"); 369 | $transid = XMLBuilder::get_data($responseDomObject, "TransId"); 370 | $response = XMLBuilder::get_data($responseDomObject, "Response"); 371 | $return_code = XMLBuilder::get_data($responseDomObject, "ProcReturnCode"); 372 | $error_msg = XMLBuilder::get_data($responseDomObject, "ErrMsg"); 373 | $host_msg = XMLBuilder::get_data($responseDomObject, "HOSTMSG"); 374 | $trx_date = XMLBuilder::get_data($responseDomObject, "TRXDATE"); 375 | $host_ref_num = XMLBuilder::get_data($responseDomObject, "HostRefNum"); 376 | $auth_code = XMLBuilder::get_data($responseDomObject, "AuthCode"); 377 | $is_successful = FALSE; 378 | if(intval($return_code) == 0) { 379 | $is_successful = TRUE; 380 | } 381 | $result["orderid"] = $orderid; 382 | $result["transid"] = $transid; 383 | $result["groupid"] = $groupid; 384 | $result["response"] = $response; 385 | $result["return_code"] = $return_code; 386 | $result["error_msg"] = $error_msg; 387 | $result["host_msg"] = $host_msg; 388 | $result["auth_code"] = $auth_code; 389 | $result["host_ref_num"] = $host_ref_num; 390 | $result["result"] = $is_successful; 391 | } 392 | catch(Exception $e){ 393 | $result["result"] = FALSE; 394 | $result["exception"] = $e->getMessage(); 395 | } 396 | 397 | if(isset($trx_date)) { 398 | try { 399 | $trx_date = explode(".", $trx_date); 400 | $trx_date = $trx_date[0]; 401 | $trx_date = strptime($trx_date, "%Y%m%d %H:%M:%S"); 402 | $result["transaction_time"] = $trx_date; 403 | } 404 | catch(Exception $e) { 405 | // pass 406 | } 407 | } 408 | return $result; 409 | 410 | } 411 | 412 | public function postAuth($amount, $orderid, $transid = null) { 413 | $credentials = $this->__get_credentials(); 414 | $username = $this->name; 415 | $password = $this->password; 416 | $clientid = $this->company; 417 | 418 | $amount = number_format($amount, 2); 419 | $document = new XMLBuilder(); 420 | $elements = array("Name" => $username, "Password" => $password, "ClientId" => $clientid, 421 | "Mode" => "P", "OrderId" => $orderid, "Type" => "PostAuth", 422 | "Total" => $amount, "Extra" => null, "TransId" => $transid 423 | ); 424 | $domElements = $document->createElementsWithTextNodes($elements); 425 | $document->appendListOfElementsToElement($document->root(), $domElements); 426 | $documentString = $document->saveXML(); 427 | $this->raw_request = $documentString; 428 | 429 | /* After the XML request has been created, we should now set the HTTP request using curl library.. */ 430 | $url = $this->__connect() . $this->credentials["purchaseOrderURL"]; 431 | $curl = curl_init(); 432 | $postData = urlencode("DATA") . urlencode("=") . urlencode($documentString); 433 | // Set the url.. 434 | curl_setopt($curl, CURLOPT_URL, $url); 435 | // Set the HTTP method to POST.. 436 | curl_setopt($curl, CURLOPT_POST, 1); 437 | // Set the HTTP response header to False not to get the response header.. 438 | curl_setopt ($curl, CURLOPT_HEADER, FALSE); 439 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 440 | // Add the HTTP POST body.. 441 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); 442 | // Set the HTTP request header.. 443 | curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type" => "application/x-www-form-urlencoded")); 444 | // Execute the request and save the response inside a variable called 'raw_response'.. 445 | $this->raw_response = curl_exec($curl); 446 | // Close the connection.. 447 | curl_close($curl); 448 | // After we got the response, we should now parse it using xml library.. 449 | $responseDomObject = new DOMDocument(); 450 | $responseDomObject->loadXML($this->raw_response); 451 | // The result to be returned will be an array containing the response details.. 452 | $result = array(); 453 | try { 454 | $orderid = XMLBuilder::get_data($responseDomObject, "OrderId"); 455 | $groupid = XMLBuilder::get_data($responseDomObject, "GroupId"); 456 | $transid = XMLBuilder::get_data($responseDomObject, "TransId"); 457 | $response = XMLBuilder::get_data($responseDomObject, "Response"); 458 | $return_code = XMLBuilder::get_data($responseDomObject, "ProcReturnCode"); 459 | $error_msg = XMLBuilder::get_data($responseDomObject, "ErrMsg"); 460 | $host_msg = XMLBuilder::get_data($responseDomObject, "HOSTMSG"); 461 | $trx_date = XMLBuilder::get_data($responseDomObject, "TRXDATE"); 462 | $host_ref_num = XMLBuilder::get_data($responseDomObject, "HostRefNum"); 463 | $auth_code = XMLBuilder::get_data($responseDomObject, "AuthCode"); 464 | $is_successful = FALSE; 465 | if(intval($return_code) == 0) { 466 | $is_successful = TRUE; 467 | } 468 | $result["orderid"] = $orderid; 469 | $result["transid"] = $transid; 470 | $result["groupid"] = $groupid; 471 | $result["response"] = $response; 472 | $result["return_code"] = $return_code; 473 | $result["error_msg"] = $error_msg; 474 | $result["host_msg"] = $host_msg; 475 | $result["auth_code"] = $auth_code; 476 | $result["host_ref_num"] = $host_ref_num; 477 | $result["result"] = $is_successful; 478 | } 479 | catch(Exception $e){ 480 | $result["result"] = FALSE; 481 | $result["exception"] = $e->getMessage(); 482 | } 483 | 484 | if(isset($trx_date)) { 485 | try { 486 | $trx_date = explode(".", $trx_date); 487 | $trx_date = $trx_date[0]; 488 | $trx_date = strptime($trx_date, "%Y%m%d %H:%M:%S"); 489 | $result["transaction_time"] = $trx_date; 490 | } 491 | catch(Exception $e) { 492 | // pass 493 | } 494 | } 495 | return $result; 496 | } 497 | 498 | public function getDetail($orderid) { 499 | $credentials = $this->__get_credentials(); 500 | $username = $this->name; 501 | $password = $this->password; 502 | $clientid = $this->company; 503 | 504 | $document = new XMLBuilder(); 505 | $elements = array("Name" => $username, "Password" => $password, "ClientId" => $clientid, 506 | "Mode" => "P", "OrderId" => $orderid 507 | ); 508 | $domElements = $document->createElementsWithTextNodes($elements); 509 | $document->appendListOfElementsToElement($document->root(), $domElements); 510 | $element = $document->createElement("Extra"); 511 | $statusElement = $document->createElementWithTextNode("ORDERSTATUS", "SOR"); 512 | $element->appendChild($statusElement); 513 | $document->root()->appendChild($element); 514 | $documentString = $document->saveXML(); 515 | $this->raw_request = $documentString; 516 | 517 | /* After the XML request has been created, we should now set the HTTP request using curl library.. */ 518 | $url = $this->__connect() . $this->credentials["detailOrderURL"]; 519 | $curl = curl_init(); 520 | $postData = urlencode("DATA") . urlencode("=") . urlencode($documentString); 521 | // Set the url.. 522 | curl_setopt($curl, CURLOPT_URL, $url); 523 | // Set the HTTP method to POST.. 524 | curl_setopt($curl, CURLOPT_POST, 1); 525 | // Set the HTTP response header to False not to get the response header.. 526 | curl_setopt ($curl, CURLOPT_HEADER, FALSE); 527 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 528 | // Add the HTTP POST body.. 529 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); 530 | // Set the HTTP request header.. 531 | curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type" => "application/x-www-form-urlencoded")); 532 | // Execute the request and save the response inside a variable called 'raw_response'.. 533 | $this->raw_response = curl_exec($curl); 534 | // Close the connection.. 535 | curl_close($curl); 536 | // After we got the response, we should now parse it using xml library.. 537 | $responseDomObject = new DOMDocument(); 538 | $responseDomObject->loadXML($this->raw_response); 539 | // The result to be returned will be an array containing the response details.. 540 | $result = array(); 541 | 542 | $transid = XMLBuilder::get_data($responseDomObject, "TransId"); 543 | $return_code = XMLBuilder::get_data($responseDomObject, "ProcReturnCode"); 544 | $err_msg = XMLBuilder::get_data($responseDomObject, "ErrMsg"); 545 | $host_ref_num = XMLBuilder::get_data($responseDomObject, "HOST_REF_NUM"); 546 | $auth_code = XMLBuilder::get_data($responseDomObject, "AUTH_CODE"); 547 | $charge_type = XMLBuilder::get_data($responseDomObject, "CHARGE_TYPE_CD"); 548 | $details = XMLBuilder::get_data($responseDomObject, "ORDERSTATUS"); 549 | $capture_amount = XMLBuilder::get_data($responseDomObject, "CAPTURE_AMT"); 550 | $trx_date = XMLBuilder::get_data($responseDomObject, "CAPTURE_DTTM"); 551 | 552 | $result["transid"] = $transid; 553 | $result["orderid"] = $orderid; 554 | $result["return_code"] = $return_code; 555 | $result["host_ref_num"] = $host_ref_num; 556 | $result["error_msg"] = $err_msg; 557 | $result["charge_type"] = $charge_type; 558 | $result["auth_code"] = $auth_code; 559 | $result["amount"] = ""; 560 | $result["transaction_time"] = ""; 561 | 562 | if($trx_date) { 563 | try { 564 | $trx_date = explode(".", $trx_date); 565 | $trx_date = $trx_date[0]; 566 | $trx_date = strptime($trx_date, "%Y-%m-%d %H:%M:%S"); 567 | $result["transaction_time"] = $trx_date; 568 | } 569 | catch(Exception $e) { } 570 | } 571 | 572 | if ($capture_amount) { 573 | try { 574 | $capture_amount = intval($capture_amount) / 100.0; 575 | $result["amount"] = $capture_amount; 576 | } 577 | catch(Exception $e) { } 578 | } 579 | return $result; 580 | 581 | } 582 | 583 | private function __get_value($array, $key) { 584 | if(array_key_exists($key, $array)) { 585 | return $array[$key]; 586 | } 587 | return null; 588 | } 589 | 590 | public function __toString() { 591 | return $this->slug . " sanalpos"; 592 | } 593 | 594 | } 595 | 596 | class XMLBuilder extends DOMDocument { 597 | public $rootElement; 598 | 599 | public function __construct($tag = "CC5Request") { 600 | parent::__construct("1.0"); 601 | $element = $this->createElement($tag); 602 | $this->rootElement = $element; 603 | $this->appendChild($this->rootElement); 604 | } 605 | 606 | public function root() { 607 | return $this->rootElement; 608 | } 609 | 610 | public function createElementWithTextNode($tagName, $nodeValue) { 611 | if($nodeValue == null) { 612 | $nodeValue = ""; 613 | } 614 | $element = $this->createElement(strval($tagName)); 615 | $node = $this->createTextNode(strval($nodeValue)); 616 | $element->appendChild($node); 617 | return $element; 618 | } 619 | 620 | public function createElementsWithTextNodes($arguments) { 621 | $resultArray = array(); 622 | foreach($arguments as $k => $v) { 623 | array_push($resultArray, $this->createElementWithTextNode($k, $v)); 624 | } 625 | return $resultArray; 626 | } 627 | 628 | public function appendListOfElementsToElement($element, $elements) { 629 | /* Appends list of DOM elements to the given DOM element. */ 630 | foreach($elements as $ele) { 631 | $element->appendChild($ele); 632 | } 633 | } 634 | 635 | public function __toString() { 636 | return $this->saveXML(); 637 | } 638 | 639 | public static function get_data($xmlObj, $tag) { 640 | $elements = $xmlObj->getElementsByTagName($tag); 641 | if($elements->length > 0) { 642 | $item = $elements->item(0); 643 | $childiren = $item->childNodes; 644 | if($childiren->length > 0) { 645 | return $childiren->item(0)->nodeValue; 646 | } 647 | return ""; 648 | } 649 | return ""; 650 | } 651 | 652 | } 653 | 654 | ?> --------------------------------------------------------------------------------