From 7dc20fd3d9807321abd5234269730adcb76f9618 Mon Sep 17 00:00:00 2001 From: feyzullah Demir <101548542+feyzullahdemir@users.noreply.github.com> Date: Wed, 1 Mar 2023 10:52:10 +0300 Subject: [PATCH] +BaseUrl --- .DS_Store | Bin 0 -> 6148 bytes iyzicocheckoutform/.DS_Store | Bin 0 -> 6148 bytes iyzicocheckoutform/cancel.php | 16 +- .../classes/IyzipayCheckoutFormObject.php | 248 ++++++++++++++++++ iyzicocheckoutform/classes/IyzipayHelper.php | 79 ++++++ iyzicocheckoutform/classes/IyzipayModel.php | 144 ++++++++++ .../classes/IyzipayOverlayScript.php | 44 ++++ .../classes/IyzipayPkiStringBuilder.php | 120 +++++++++ iyzicocheckoutform/classes/IyzipayRequest.php | 123 +++++++++ iyzicocheckoutform/classes/index.php | 35 +++ iyzicocheckoutform/config.xml | 4 +- iyzicocheckoutform/config_tr.xml | 4 +- .../controllers/front/result.php | 2 +- iyzicocheckoutform/iyzicocheckoutform.php | 163 ++++-------- iyzicocheckoutform/refund.php | 34 +-- 15 files changed, 873 insertions(+), 143 deletions(-) create mode 100644 .DS_Store create mode 100644 iyzicocheckoutform/.DS_Store create mode 100644 iyzicocheckoutform/classes/IyzipayCheckoutFormObject.php create mode 100644 iyzicocheckoutform/classes/IyzipayHelper.php create mode 100644 iyzicocheckoutform/classes/IyzipayModel.php create mode 100644 iyzicocheckoutform/classes/IyzipayOverlayScript.php create mode 100644 iyzicocheckoutform/classes/IyzipayPkiStringBuilder.php create mode 100644 iyzicocheckoutform/classes/IyzipayRequest.php create mode 100644 iyzicocheckoutform/classes/index.php diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5d15cae5c83a7189e6b10a01bef342dc96d39338 GIT binary patch literal 6148 zcmeHKQA+|r5S~@b6A2^=d|c>NNG*)$c1LIcIxk_vp0Q4+oKYHiQfO7PV|xoWlz? zepKs&H;h6R-C_KEuK65{%m6dM46FhJ_H1+Vt56Krzzi@0zsdle4-%EowU`*xM+X}E zeWdXWAqlqWEkP(Px)u|IID#TfDxygh_K6`(I{KxJb1fzYO*#m@GR|XH7WRcA^y=uB zIvj*+kS#O73@kE`Hr)c<|0mzS{}+?E#|$t7E5(4wG`vO~OR{(CQgL+GO4J)v5{gR< mexzVSU&RyKs#L51 literal 0 HcmV?d00001 diff --git a/iyzicocheckoutform/.DS_Store b/iyzicocheckoutform/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..aec784f6c6853078d47dec53e7e988817755bd04 GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8-BN@e6nb3nTClYu7B3;z7cim+m73U~!I&*gY7eE5v%Zi|;`2DO zyAi56coMNQW%rw%pWVy{-5XJpDf~XaUj^WK3np=tX5H>PuT*Orn{^>XQ`~qDYVKuzHcMT9dWEBN zrQ)E_{oo=B=cCs4iApj*O2Vm5h{hp=Twg}XSj}BEOU9|r^^8L_8jVq_y;$@Iy^ic1 z^_CsE80>dD@}PgXTsFkc?%wg)=rMju)Qh2#1M6D0EEezz%9pC1y=fAw7?-000{Y4&00y{^w6)Xt bCF&68Sj-LLENIv1fOHYigiuEe`~m|XB1uf6 literal 0 HcmV?d00001 diff --git a/iyzicocheckoutform/cancel.php b/iyzicocheckoutform/cancel.php index 71eb53b..1cd0e95 100644 --- a/iyzicocheckoutform/cancel.php +++ b/iyzicocheckoutform/cancel.php @@ -21,9 +21,9 @@ if(Tools::getValue('token')) { - if(Tools::getValue('token')!==$token ) { - - + if(Tools::getValue('token')!==$token ) { + + echo json_encode($message); exit; } @@ -31,7 +31,7 @@ $cookie = new Cookie('psAdmin'); if(!$cookie->id_employee){ - + $message['response'] = 'Admin girişiniz zaman aşımına uğramış olabilir.'; echo json_encode($message); exit; @@ -48,12 +48,12 @@ try { IyzipayBootstrap::init(); $error_msg = ''; - + //Set api,secret and base url option to call iyzico API $options = new \Iyzipay\Options(); $options->setApiKey(Configuration::get('IYZICO_FORM_LIVE_API_ID')); $options->setSecretKey(Configuration::get('IYZICO_FORM_LIVE_SECRET')); - $options->setBaseUrl("https://api.iyzipay.com"); + $options->setBaseUrl(Configuration::get('IYZICO_FORM_BASEURL')); //cancel order $transaction_id = pSQL(Tools::getValue('transaction_id')); @@ -66,7 +66,7 @@ $order_detail = Db::getInstance()->ExecuteS($query); $order_array = json_decode($order_detail[0]['response_data']); $payment_id = $order_array->paymentId; - + if (!empty(Tools::getValue('language')) && Tools::getValue('language') == 'tr') { $lang = 'tr'; } else { @@ -80,7 +80,7 @@ $request->setConversationId(uniqid() . '_ps'); $request->setIp((string) Tools::getRemoteAddr()); $request->setPaymentId($payment_id); - + //request form api log $insert_api_log = Db::getInstance()->insert("iyzico_api_log", array( 'id' => Tools::getValue('id'), diff --git a/iyzicocheckoutform/classes/IyzipayCheckoutFormObject.php b/iyzicocheckoutform/classes/IyzipayCheckoutFormObject.php new file mode 100644 index 0000000..ee7dedf --- /dev/null +++ b/iyzicocheckoutform/classes/IyzipayCheckoutFormObject.php @@ -0,0 +1,248 @@ + + * @copyright 2018 iyzico + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + * International Registered Trademark & Property of iyzico + */ + +include_once 'IyzipayHelper.php'; +include_once 'IyzipayModel.php'; + +class IyzipayCheckoutFormObject +{ + + /** + * @param $params + * @param $currency + * @param $context + * @param $apiKey + * @return stdClass + */ + public static function option($params, $currency, $context, $apiKey, $version) + { + + $currency = new Currency((int) $params['cookie']->id_currency); + $thisUserCurrency = $currency->iso_code; + $language=Configuration::get('iyzipay_language'); + + $shipping = $params['cart']->getOrderTotal(true, Cart::ONLY_SHIPPING); + $basketItems = $params['cart']->getProducts(); + $httpProtocol = !Configuration::get('PS_SSL_ENABLED') ? 'http://' : 'https://'; + + $iyzico = new stdClass(); + + if(empty($language)) + { + $iyzico->locale = $context->language->iso_code; + + }else { + + $iyzico->locale = Configuration::get('iyzipay_language'); + + } + $iyzico->conversationId = $params['cookie']->id_cart; + $iyzico->price = IyzipayHelper::orderProductCalc($basketItems, $shipping); + $iyzico->paidPrice = IyzipayHelper::priceParser($params['cart']->getOrderTotal()); + $iyzico->currency = $thisUserCurrency; + $iyzico->basketId = $params['cookie']->id_cart; + $iyzico->paymentGroup = 'PRODUCT'; + $iyzico->forceThreeDS = '0'; + $iyzico->callbackUrl = $httpProtocol.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'index.php?module_action=init&fc=module&module=iyzipay&controller=callback'; + $iyzico->cardUserKey = IyzipayModel::findUserCardKey($params['cookie']->id_customer, $apiKey); + $iyzico->paymentSource = _PS_VERSION_.'|PRESTASHOP|PIE|'.$version; + + return $iyzico; + } + + /** + * @param $buyerAddress + * @return stdClass + */ + public static function buyer($buyerAddress) + { + + $buyer = new stdClass(); + + $buyer->id = $buyerAddress->id; + $buyer->name = $buyerAddress->firstname; + $buyer->surname = $buyerAddress->lastname; + $buyer->identityNumber = '11111111111'; + $buyer->email = $buyerAddress->email; + $buyer->gsmNumber = $buyerAddress->phone; + $buyer->registrationDate = $buyerAddress->date_add; + $buyer->lastLoginDate = $buyerAddress->date_add; + $buyer->registrationAddress = $buyerAddress->address1.$buyerAddress->address2; + $buyer->city = $buyerAddress->city; + $buyer->country = $buyerAddress->country; + $buyer->zipCode = $buyerAddress->postcode; + $buyer->ip = Tools::getRemoteAddr(); + + return $buyer; + } + + /** + * @param $shippingAddressInfo + * @return stdClass + */ + public static function shippingAddress($shippingAddressInfo) + { + + $shippingAddress = new stdClass(); + + $shippingAddress->address = $shippingAddressInfo->address1.$shippingAddressInfo->address2; + $shippingAddress->zipCode = $shippingAddressInfo->postcode; + $shippingAddress->contactName = $shippingAddressInfo->firstname; + $shippingAddress->city = $shippingAddressInfo->city; + $shippingAddress->country = $shippingAddressInfo->country; + + return $shippingAddress; + } + + /** + * @param $billingAddressInfo + * @return stdClass + */ + public static function billingAddress($billingAddressInfo) + { + + $billingAddress = new stdClass(); + + $billingAddress->address = $billingAddressInfo->address1.$billingAddressInfo->address2; + $billingAddress->zipCode = $billingAddressInfo->postcode; + $billingAddress->contactName = $billingAddressInfo->firstname; + $billingAddress->city = $billingAddressInfo->city; + $billingAddress->country = $billingAddressInfo->country; + + return $billingAddress; + } + + /** + * @param $items + * @param $shipping + * @return bool + */ + public static function basketItems($items, $shipping) + { + + $keyNumber = 0; + $basketItems = false; + + foreach ($items as $item) { + $basketItems[$keyNumber] = new stdClass(); + + $basketItems[$keyNumber]->id = $item['id_product_attribute']; + $basketItems[$keyNumber]->price = IyzipayHelper::priceParser($item['total_wt']); + $basketItems[$keyNumber]->name = $item['name']; + $basketItems[$keyNumber]->category1 = $item['category']; + $basketItems[$keyNumber]->itemType = 'PHYSICAL'; + $keyNumber++; + } + + if (!empty($shipping)) { + $basketItems[$keyNumber] = new stdClass(); + $basketItems[$keyNumber]->id = uniqid(); + $basketItems[$keyNumber]->price = IyzipayHelper::priceParser($shipping); + $basketItems[$keyNumber]->name = 'Cargo'; + $basketItems[$keyNumber]->category1 = 'Cargo'; + $basketItems[$keyNumber]->itemType = 'PHYSICAL'; + } + + return $basketItems; + } + + + /** + * @param $objectData + * @return stdClass + */ + public static function checkoutFormObjectSort($objectData) + { + + $form_object = new stdClass(); + + $form_object->locale = $objectData->locale; + $form_object->conversationId = $objectData->conversationId; + $form_object->price = $objectData->price; + $form_object->basketId = $objectData->basketId; + $form_object->paymentGroup = $objectData->paymentGroup; + + $form_object->buyer = new stdClass(); + $form_object->buyer = $objectData->buyer; + + $form_object->shippingAddress = new stdClass(); + $form_object->shippingAddress = $objectData->shippingAddress; + + $form_object->billingAddress = new stdClass(); + $form_object->billingAddress = $objectData->billingAddress; + + foreach ($objectData->basketItems as $key => $item) { + $form_object->basketItems[$key] = new stdClass(); + $form_object->basketItems[$key] = $item; + } + + $form_object->callbackUrl = $objectData->callbackUrl; + $form_object->paymentSource = $objectData->paymentSource; + $form_object->currency = $objectData->currency; + $form_object->paidPrice = $objectData->paidPrice; + $form_object->forceThreeDS = $objectData->forceThreeDS; + $form_object->cardUserKey = $objectData->cardUserKey; + + return $form_object; + } + + /** + * @param $conversationId + * @param $token + * @param $locale + * @return stdClass + */ + public static function responseObject($conversationId, $token, $locale) + { + + $responseObject = new stdClass(); + + $responseObject->locale = $locale; + $responseObject->conversationId = $conversationId; + $responseObject->token = $token; + + return $responseObject; + } + + + /** + * @param $locale + * @param $paymentId + * @param $ip + * @return stdClass + */ + public static function cancelObject($locale, $paymentId, $ip) + { + + $responseObject = new stdClass(); + + $responseObject->locale = $locale; + $responseObject->paymentId = $paymentId; + $responseObject->ip = $ip; + + return $responseObject; + } +} diff --git a/iyzicocheckoutform/classes/IyzipayHelper.php b/iyzicocheckoutform/classes/IyzipayHelper.php new file mode 100644 index 0000000..7bb4c0e --- /dev/null +++ b/iyzicocheckoutform/classes/IyzipayHelper.php @@ -0,0 +1,79 @@ + + * @copyright 2018 iyzico + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + * International Registered Trademark & Property of iyzico + */ + +class IyzipayHelper +{ + + /** + * @param $basketItems + * @param $shipping + * @return int|string + */ + public static function orderProductCalc($basketItems, $shipping) + { + + $price = 0; + foreach ($basketItems as $item) { + $price += $item['total_wt']; + } + + if (!empty($shipping)) { + $price += $shipping; + } + + + $price = IyzipayHelper::priceParser($price); + + return $price; + } + + /** + * @param $price + * @return string + */ + public static function priceParser($price) + { + + if (strpos($price, ".") === false) { + return $price . ".0"; + } + + $subStrIndex = 0; + $priceReversed = strrev($price); + for ($i = 0; $i < strlen($priceReversed); $i++) { + if (strcmp($priceReversed[$i], "0") == 0) { + $subStrIndex = $i + 1; + } else if (strcmp($priceReversed[$i], ".") == 0) { + $priceReversed = "0" . $priceReversed; + break; + } else { + break; + } + } + + return strrev(substr($priceReversed, $subStrIndex)); + } +} \ No newline at end of file diff --git a/iyzicocheckoutform/classes/IyzipayModel.php b/iyzicocheckoutform/classes/IyzipayModel.php new file mode 100644 index 0000000..91ccd88 --- /dev/null +++ b/iyzicocheckoutform/classes/IyzipayModel.php @@ -0,0 +1,144 @@ + + * @copyright 2018 iyzico + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + * International Registered Trademark & Property of iyzico + */ + +class IyzipayModel extends ObjectModel +{ + /** + * @param $customerId + * @param $apiKey + * @return string + */ + public static function findUserCardKey($customerId, $apiKey) + { + $tableName = 'iyzipay_card'; + + $sql = 'SELECT * FROM '._DB_PREFIX_.bqSQL($tableName).' WHERE `api_key` = \''.$apiKey.'\' AND `customer_id` = \''.$customerId.'\''; + + $results = Db::getInstance()->ExecuteS($sql); + + if (isset($results[0]['card_user_key'])) { + return $results[0]['card_user_key']; + } else { + return ''; + } + } + + /** + * @param $customerId + * @param $cardUserKey + * @param $apiKey + * @return mixed + */ + public static function insertCardUserKey($customerId, $cardUserKey, $apiKey) + { + + $tableName = 'iyzipay_card'; + + $sql = 'INSERT INTO '._DB_PREFIX_.bqSQL($tableName).'(`customer_id`,`card_user_key`,`api_key`) + VALUES + (\''.$customerId.'\', + \''.$cardUserKey.'\', + \''.$apiKey.'\')'; + + return Db::getInstance()->execute($sql); + } + + /** + * @param $iyzicoLocalOrder + * @return mixed + */ + public static function insertIyzicoOrder($iyzicoLocalOrder) + { + + $tableName = 'iyzipay_order'; + + $sql = 'INSERT INTO '._DB_PREFIX_.bqSQL($tableName).'(`payment_id`,`order_id`,`total_amount`,`status`) + VALUES + (\''.$iyzicoLocalOrder->orderId.'\', + \''.$iyzicoLocalOrder->paymentId.'\', + \''.$iyzicoLocalOrder->totalAmount.'\', + \''.$iyzicoLocalOrder->status.'\')'; + + return Db::getInstance()->execute($sql); + } + + /** + * @param $price + * @param $order_id + * @return mixed + */ + public static function updateOrderTotal($price, $order_id) + { + + $tableName = 'orders'; + $order_id = (int) $order_id; + + $sql = 'UPDATE '._DB_PREFIX_.bqSQL($tableName).' + SET `total_paid` = \''.$price.'\', + `total_paid_tax_incl` = \''.$price.'\', + `total_paid_tax_excl` = \''.$price.'\', + `total_paid_real` = \''.$price.'\' + WHERE `id_order` = \''.$order_id.'\''; + + return Db::getInstance()->execute($sql); + } + + /** + * @param $price + * @param $reference + * @return mixed + */ + public static function updateOrderPayment($price, $reference) + { + $tableName = 'order_payment'; + $reference = $reference; + + $sql = 'UPDATE '._DB_PREFIX_.bqSQL($tableName).' + SET `amount` = \''.$price.'\' + WHERE `order_reference` = \''.$reference.'\''; + + return Db::getInstance()->execute($sql); + } + + /** + * @param $price + * @param $order_id + * @return mixed + */ + public static function updateOrderInvoiceTotal($price, $order_id) + { + + $tableName = 'order_invoice'; + $order_id = (int) $order_id; + + $sql = 'UPDATE '._DB_PREFIX_.bqSQL($tableName).' + SET `total_paid_tax_incl` = \''.$price.'\', + `total_products_wt` = \''.$price.'\' + WHERE `id_order` = \''.$order_id.'\''; + + return Db::getInstance()->execute($sql); + } +} \ No newline at end of file diff --git a/iyzicocheckoutform/classes/IyzipayOverlayScript.php b/iyzicocheckoutform/classes/IyzipayOverlayScript.php new file mode 100644 index 0000000..3344786 --- /dev/null +++ b/iyzicocheckoutform/classes/IyzipayOverlayScript.php @@ -0,0 +1,44 @@ + +* @copyright 2018 iyzico +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of iyzico +*/ + +class IyzipayOverlayScript +{ + /** + * @param $isoCode + * @param $randNumer + * @return stdClass + */ + public static function generateOverlayScriptObject($isoCode, $randNumer) + { + + $overlayObject = new stdClass(); + $overlayObject->locale = $isoCode; + $overlayObject->conversationId = $randNumer; + $overlayObject->position = Tools::getValue('iyzipay_overlay_position'); + + return $overlayObject; + } +} diff --git a/iyzicocheckoutform/classes/IyzipayPkiStringBuilder.php b/iyzicocheckoutform/classes/IyzipayPkiStringBuilder.php new file mode 100644 index 0000000..0852c43 --- /dev/null +++ b/iyzicocheckoutform/classes/IyzipayPkiStringBuilder.php @@ -0,0 +1,120 @@ + + * @copyright 2018 iyzico + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + * International Registered Trademark & Property of iyzico + */ + +class IyzipayPkiStringBuilder +{ + /** + * @param $objectData + * @return string + */ + public static function pkiStringGenerate($objectData) + { + $pki_value = '['; + + foreach ($objectData as $key => $data) { + if (is_object($data)) { + $name = var_export($key, true); + $name = str_replace("'", '', $name); + $pki_value .= $name.'=['; + $end_key = count(get_object_vars($data)); + $count = 0; + + foreach ($data as $key => $value) { + ++$count; + $name = var_export($key, true); + $name = str_replace("'", '', $name); + $pki_value .= $name.'='.''.$value; + if ($end_key != $count) { + $pki_value .= ','; + } + } + + $pki_value .= ']'; + } elseif (is_array($data)) { + $name = var_export($key, true); + $name = str_replace("'", '', $name); + $pki_value .= $name.'=['; + $end_key = count($data); + $count = 0; + + foreach ($data as $key => $result) { + ++$count; + $pki_value .= '['; + + foreach ($result as $key => $item) { + $name = var_export($key, true); + $name = str_replace("'", '', $name); + $pki_value .= $name.'='.''.$item; + if (end($result) != $item) { + $pki_value .= ','; + } + if (end($result) == $item) { + if ($end_key != $count) { + $pki_value .= '], '; + } else { + $pki_value .= ']'; + } + } + } + } + if (end($data) == $result) { + $pki_value .= ']'; + } + } else { + $name = var_export($key, true); + $name = str_replace("'", '', $name); + $pki_value .= $name.'='.''.$data.''; + } + if (end($objectData) != $data) { + $pki_value .= ','; + } + } + $pki_value .= ']'; + + return $pki_value; + } + + /** + * @param $pkiString + * @param $apiKey + * @param $secretKey + * @param $rand + * @return array + */ + public static function authorization($pkiString, $apiKey, $secretKey, $rand) + { + $hash_value = $apiKey.$rand.$secretKey.$pkiString; + $hash = base64_encode(sha1($hash_value, true)); + $authorizationText = 'IYZWS '.$apiKey.':'.$hash; + + $authorization = array( + 'authorization' => $authorizationText, + 'randValue' => $rand, + ); + + return $authorization; + } +} diff --git a/iyzicocheckoutform/classes/IyzipayRequest.php b/iyzicocheckoutform/classes/IyzipayRequest.php new file mode 100644 index 0000000..f452bb0 --- /dev/null +++ b/iyzicocheckoutform/classes/IyzipayRequest.php @@ -0,0 +1,123 @@ + +* @copyright 2018 iyzico +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of iyzico +*/ + +class IyzipayRequest +{ + /** + * @param $endpoint + * @param $json + * @param $authorization + * @return mixed + */ + public static function iyzipayPostWebhook($endpoint, $json, $authorization) + { + $endpoint .= '/payment/notification/update'; + + return IyzipayRequest::curlPost($json, $authorization, $endpoint); + } + + /** + * @param $endpoint + * @param $json + * @param $authorization + * @return mixed + */ + public static function checkoutFormRequest($endpoint, $json, $authorization) + { + $endpoint .= '/payment/iyzipos/checkoutform/initialize/auth/ecom'; + + return IyzipayRequest::curlPost($json, $authorization, $endpoint); + } + + /** + * @param $endpoint + * @param $json + * @param $authorization + * @return mixed + */ + public static function checkoutFormRequestDetail($endpoint, $json, $authorization) + { + $endpoint .= '/payment/iyzipos/checkoutform/auth/ecom/detail'; + + return IyzipayRequest::curlPost($json, $authorization, $endpoint); + } + + /** + * @param bool $endpoint + * @param $overlayScriptJson + * @param $authorization + * @return mixed + */ + public static function callOverlayScript($overlayScriptJson, $authorization, $endpoint = false) + { + $endpoint = 'https://iyziup.iyzipay.com/v1/iyziup/protected/shop/detail/overlay-script'; + + return IyzipayRequest::curlPost($overlayScriptJson, $authorization, $endpoint); + } + + /** + * @param $endpoint + * @param $json + * @param $authorization + * @return mixed + */ + public static function paymentCancel($endpoint, $authorization, $json) + { + $endpoint .= '/payment/cancel'; + + return IyzipayRequest::curlPost($json, $authorization, $endpoint); + } + + /** + * @param $json + * @param $authorization + * @param $endpoint + * @return mixed + */ + public static function curlPost($json, $authorization, $endpoint) + { + $phpVersion = phpversion(); + + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $endpoint); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($curl, CURLOPT_POSTFIELDS, $json); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0); + curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); + curl_setopt($curl, CURLOPT_TIMEOUT, 150); + curl_setopt($curl, CURLOPT_HTTPHEADER, array( + "Authorization:".$authorization['authorization'], + "x-iyzi-rnd:".$authorization['randValue'], + "presta-php-version:".$phpVersion, + "Content-Type: application/json", + )); + $result = json_decode(curl_exec($curl)); + curl_close($curl); + + return $result; + } +} diff --git a/iyzicocheckoutform/classes/index.php b/iyzicocheckoutform/classes/index.php new file mode 100644 index 0000000..f1a0df9 --- /dev/null +++ b/iyzicocheckoutform/classes/index.php @@ -0,0 +1,35 @@ + +* @copyright 2018 iyzico +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of iyzico +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../'); +exit; \ No newline at end of file diff --git a/iyzicocheckoutform/config.xml b/iyzicocheckoutform/config.xml index 3664d6d..505baf5 100644 --- a/iyzicocheckoutform/config.xml +++ b/iyzicocheckoutform/config.xml @@ -2,7 +2,7 @@ iyzicocheckoutform - + @@ -10,4 +10,4 @@ 1 1 - \ No newline at end of file + diff --git a/iyzicocheckoutform/config_tr.xml b/iyzicocheckoutform/config_tr.xml index eee6403..0ed6388 100644 --- a/iyzicocheckoutform/config_tr.xml +++ b/iyzicocheckoutform/config_tr.xml @@ -1,8 +1,8 @@ iyzicocheckoutform - - + + diff --git a/iyzicocheckoutform/controllers/front/result.php b/iyzicocheckoutform/controllers/front/result.php index 552e8a0..5dba385 100644 --- a/iyzicocheckoutform/controllers/front/result.php +++ b/iyzicocheckoutform/controllers/front/result.php @@ -40,7 +40,7 @@ public function initResult($webhook = null, $webhookToken = null) { $options = new \Iyzipay\Options(); $options->setApiKey(Configuration::get('IYZICO_FORM_LIVE_API_ID')); $options->setSecretKey(Configuration::get('IYZICO_FORM_LIVE_SECRET')); - $options->setBaseUrl("https://sandbox-api.iyzipay.com"); + $options->setBaseUrl(Configuration::get('IYZICO_FORM_BASEURL')); $request = new \Iyzipay\Request\RetrieveCheckoutFormRequest(); $request->setLocale($locale); diff --git a/iyzicocheckoutform/iyzicocheckoutform.php b/iyzicocheckoutform/iyzicocheckoutform.php index 8f75481..b965344 100644 --- a/iyzicocheckoutform/iyzicocheckoutform.php +++ b/iyzicocheckoutform/iyzicocheckoutform.php @@ -4,6 +4,11 @@ require_once _PS_MODULE_DIR_ . 'iyzicocheckoutform/includer.php'; require_once _PS_MODULE_DIR_ . 'iyzicocheckoutform/IyzipayBootstrap.php'; +include_once _PS_MODULE_DIR_ . 'iyzicocheckoutformclasses/IyzipayOverlayScript.php'; +include_once _PS_MODULE_DIR_ . 'iyzicocheckoutformclasses/IyzipayPkiStringBuilder.php'; +include_once _PS_MODULE_DIR_ . 'iyzicocheckoutformclasses/IyzipayRequest.php'; +include_once _PS_MODULE_DIR_ . 'iyzicocheckoutformclasses/IyzipayCheckoutFormObject.php'; + class Iyzicocheckoutform extends PaymentModule { @@ -15,19 +20,19 @@ class Iyzicocheckoutform extends PaymentModule public $address; public $extra_mail_vars; public $_prestashop = '_ps'; - public $_ModuleVersion = '1.1.0'; + public $_ModuleVersion = '1.2.0'; protected $hooks = array( 'payment', 'backOfficeHeader', 'displayAdminOrder' ); - + public function __construct() { $this->name = 'iyzicocheckoutform'; $this->tab = 'payments_gateways'; - $this->version = '1.1.0'; + $this->version = '1.2.0'; $this->author = 'KahveDigital'; $this->controllers = array('payment', 'validation'); $this->is_eu_compatible = 1; @@ -62,8 +67,8 @@ public function install() PRIMARY KEY (`id`) ) ENGINE= ' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8')) return false; - - + + if (!Db::getInstance()->Execute('CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'iyzico_cart_save` ( `card_save_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `customer_id` int(11) unsigned NOT NULL, @@ -72,7 +77,7 @@ public function install() PRIMARY KEY (`card_save_id`) ) ENGINE= ' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8')) return false; - + if (!Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . 'iyzico_order_form` CHANGE `installment_fee` `installment_fee` DOUBLE NOT NULL;')) return false; @@ -160,36 +165,18 @@ protected function _postProcess() Configuration::updateValue('IYZICO_FORM_LIVE_API_ID', Tools::getValue('IYZICO_FORM_LIVE_API_ID')); Configuration::updateValue('IYZICO_FORM_LIVE_SECRET', Tools::getValue('IYZICO_FORM_LIVE_SECRET')); Configuration::updateValue('IYZICO_FORM_CLASS', Tools::getValue('IYZICO_FORM_CLASS')); + Configuration::updateValue('IYZICO_FORM_BASEURL', Tools::getValue('IYZICO_FORM_BASEURL')); } $this->_html .= $this->displayConfirmation($this->l('Settings updated')); } protected function _displayIyzicoInfo() - { - $version=$this->_ModuleVersion; - $psver=_PS_VERSION_; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'http://iyzico.kahvedigital.com/version'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch,CURLOPT_TIMEOUT,10); - curl_setopt($ch, CURLOPT_POSTFIELDS, "psversion=$psver&iyzico=$version&type=prestashop"); - $response = curl_exec($ch); - $response = json_decode($response, true); - $this->context->smarty->assign('version', $response); - - $this->context->smarty->assign('moduleVersion', $this->_ModuleVersion); - - $this->context->smarty->assign('languageIsoCode', $this->context->language->iso_code); - - $this->context->smarty->assign('webhookUrlKey', $this->getIyziWebhookUrlKey()); - - $this->context->smarty->assign('websiteBaseUrl',Tools::getHttpHost(true) . __PS_BASE_URI__); + { $pwi_status_after_enabled_pwi = Configuration::get('iyzipay_pwi_first_enabled_status'); if (!Module::isEnabled(paywithiyzico) && $pwi_status_after_enabled_pwi != 1){ - var_dump($pwi_status_after_enabled_pwi); - var_dump("sadadasd"); + $this->context->smarty->assign('iyzipay_pwi_first_enabled_status', 0); } else{ @@ -199,75 +186,7 @@ protected function _displayIyzicoInfo() $test=$this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name; $this->context->smarty->assign('link', $test); - if ($version == $response['iyzico_version']) { - if (isset($_GET['updated_iyzico'])) { - $version_updatable = $_GET['updated_iyzico']; - function recurse_copy($src, $dst) { - $dir = opendir($src); - @mkdir($dst); - while (false !== ( $file = readdir($dir))) { - if (( $file != '.' ) && ( $file != '..' )) { - if (is_dir($src . '/' . $file)) { - recurse_copy($src . '/' . $file, $dst . '/' . $file); - } else { - copy($src . '/' . $file, $dst . '/' . $file); - } - } - } - closedir($dir); - } - function rrmdir($dir) { - if (is_dir($dir)) { - $objects = scandir($dir); - foreach ($objects as $object) { - if ($object != "." && $object != "..") { - if (filetype($dir . "/" . $object) == "dir") - rrmdir($dir . "/" . $object); - else - unlink($dir . "/" . $object); - } - } - reset($objects); - rmdir($dir); - } - } - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'http://iyzico.kahvedigital.com/update'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, "new_version=$version_updatable"); - $response = curl_exec($ch); - $response = json_decode($response, true); - curl_close($ch); - $serveryol = $_SERVER['DOCUMENT_ROOT']; - $ch = curl_init(); - $source = $response['file_dest']; - curl_setopt($ch, CURLOPT_URL, $source); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - $data = curl_exec($ch); - curl_close($ch); - $foldername = $response['version_name']; - $fullfoldername = $serveryol . '/' . $foldername; - if (!file_exists($fullfoldername)) { - mkdir($fullfoldername); - } - $unzipfilename = 'iyzicoupdated.zip'; - $file = fopen($fullfoldername . '/' . $unzipfilename, "w+"); - fputs($file, $data); - fclose($file); - $path = pathinfo(realpath($fullfoldername . '/' . $unzipfilename), PATHINFO_DIRNAME); - if (class_exists('ZipArchive')) { - $zip = new ZipArchive; - $res = $zip->open($fullfoldername . '/' . $unzipfilename); - if ($res === TRUE) { - $zip->extractTo($path); - $zip->close(); - $zip_name_folder = $response['zip_name_folder']; - recurse_copy($fullfoldername . '/' . $zip_name_folder, _PS_MODULE_DIR_ . '/' . $zip_name_folder); - rrmdir($fullfoldername); - } - } - } - } + return $this->display(__FILE__, 'infos.tpl'); } @@ -298,7 +217,7 @@ public function getContent() { public function hookPayment($params) { try { - + $currency_query = 'SELECT * FROM `' . _DB_PREFIX_ . 'currency` WHERE `id_currency`= "' . $params['cookie']->id_currency . '"'; $currency = Db::getInstance()->ExecuteS($currency_query); $cart_id = $this->context->cookie->id_cart; @@ -307,16 +226,16 @@ public function hookPayment($params) $product_id_contain_discount = array(); $iso_code = $this->context->language->iso_code; $erorr_msg = ($iso_code == "tr") ? 'Girdiğiniz kur değeri sistem tarafından desteklenmemektedir. Lütfen kur değerinin TL, USD, EUR, GBP veya IRR olduğundan emin olunuz.' : 'The current exchange rate you entered is not supported by the system. Please use TRY, USD, EUR, GBP, IRR exchange rate.'; - + IyzipayBootstrap::init(); $options = new \Iyzipay\Options(); $options->setApiKey(Configuration::get('IYZICO_FORM_LIVE_API_ID')); $options->setSecretKey(Configuration::get('IYZICO_FORM_LIVE_SECRET')); - $options->setBaseUrl("https://sandbox-api.iyzipay.com"); + $options->setBaseUrl(Configuration::get('IYZICO_FORM_BASEURL')); $form_class = Configuration::get('IYZICO_FORM_CLASS'); - + $locale = ($iso_code == "tr") ? Iyzipay\Model\Locale::TR : Iyzipay\Model\Locale::EN; - + $query = 'SELECT * FROM `' . _DB_PREFIX_ . 'address` WHERE `id_customer`= "' . $params['cookie']->id_customer . '"'; $guest_user_detail = Db::getInstance()->ExecuteS($query); @@ -330,7 +249,7 @@ public function hookPayment($params) $order_amount = (double) number_format($params['cart']->getOrderTotal(true, Cart::BOTH), 2, '.', ''); $product_sub_total = number_format($params['cart']->getOrderTotal(true, Cart::ONLY_PRODUCTS), 2, '.', ''); $shipping_price = number_format($params['cart']->getOrderTotal(true, Cart::ONLY_SHIPPING), 2, '.', ''); - + $first_name = !empty($params['cookie']->customer_firstname) ? $params['cookie']->customer_firstname : 'NOT PROVIDED'; $last_name = !empty($params['cookie']->customer_lastname) ? $params['cookie']->customer_lastname : 'NOT PROVIDED'; @@ -357,7 +276,7 @@ public function hookPayment($params) $shipping_country = !empty($shipping_detail->country) ? $shipping_detail->country : 'NOT PROVIDED'; $shipping_postcode = !empty($shipping_detail->postcode) ? $shipping_detail->postcode : 'NOT PROVIDED'; - + $request = new \Iyzipay\Request\CreateCheckoutFormInitializeRequest(); $request->setLocale($locale); $request->setConversationId(uniqid() . $this->_prestashop); @@ -367,7 +286,7 @@ public function hookPayment($params) $request->setPaymentGroup(\Iyzipay\Model\PaymentGroup::PRODUCT); $request->setCallbackUrl((Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'index.php?module_action=result&fc=module&module=iyzicocheckoutform&controller=result'); $request->setPaymentSource('PRESTASHOP-' . _PS_VERSION_ ."-". $this->_ModuleVersion); - + $buyer = new \Iyzipay\Model\Buyer(); $buyer->setId($params['cookie']->id_customer); @@ -377,17 +296,17 @@ public function hookPayment($params) $buyer->setEmail($email); $buyer->setIdentityNumber($params['cookie']->id_customer . uniqid()); $buyer->setIp((string) Tools::getRemoteAddr()); - + $billing_address = new \Iyzipay\Model\Address(); $billing_address->setContactName($first_name . ' ' . $last_name); - + $shipping_address = new \Iyzipay\Model\Address(); $credit_card = ($iso_code == "tr") ? "Kredi Kartı" : "Credit Card"; $module_dir=__PS_BASE_URI__; - if ($params['cookie']->is_guest == 1) { + if ($params['cookie']->is_guest == 1) { $buyer->setLastLoginDate($last_login); $buyer->setRegistrationDate($registration_date); - $buyer->setRegistrationAddress($guest_user_detail[0]['address1'] . ' ' . $guest_user_detail[0]['address2']); + $buyer->setRegistrationAddress($guest_user_detail[0]['address1'] . ' ' . $guest_user_detail[0]['address2']); $buyer->setGsmNumber($phone_mobile); $buyer->setCity($city); $buyer->setCountry($country); @@ -425,7 +344,7 @@ public function hookPayment($params) $shipping_address->setAddress($shipping_detail->address1 . ' ' . $shipping_detail->address2); $shipping_address->setZipCode($shipping_postcode); } - + foreach ($products as $product) { $productsIds[] = $product['id_product']; } @@ -578,10 +497,10 @@ public function hookPayment($params) )); $last_insert_id = Db::getInstance()->Insert_ID(); - + if (isset($params['cookie']->id_customer)) { - if ($params['cookie']->is_guest !== 1) { - + if ($params['cookie']->is_guest !== 1) { + $cardcustomer = 'SELECT * FROM `' . _DB_PREFIX_ . 'iyzico_cart_save` WHERE `customer_id`= "' . $params['cookie']->id_customer . '"'; if ($row = Db::getInstance()->getRow($cardcustomer)) if ( !(strlen($row['card_key']) == 0) || ($row['card_key'] !== '0') || ($row['card_key'] !== 'null') ){ @@ -621,7 +540,7 @@ public function hookPayment($params) 'this_path' => $this->_path, 'this_path_bw' => $this->_path, 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/', - + )); return $this->display(__FILE__, 'payment.tpl'); } else { @@ -721,6 +640,7 @@ public function renderForm() 'title' => $this->l('Settings'), 'icon' => 'icon-cogs' ), + 'input' => array( array( 'type' => 'text', @@ -749,7 +669,23 @@ public function renderForm() ), ) ), + array( + 'type' => 'radio', + 'label' => 'API TYPE', + 'name' => 'IYZICO_FORM_BASEURL', + 'values' => array( + array( + 'value' => 'https://api.iyzipay.com', + 'label' => 'Lıve' + ), + array( + 'value' => 'https://sandbox-api.iyzipay.com', + 'label' => 'Sandbox' + ), + ) + ), ), + 'submit' => array( 'title' => $this->l('Save'), ) @@ -790,6 +726,7 @@ public function getConfigFieldsValues() 'IYZICO_FORM_LIVE_API_ID' => Tools::getValue('IYZICO_FORM_LIVE_API_ID', Configuration::get('IYZICO_FORM_LIVE_API_ID')), 'IYZICO_FORM_LIVE_SECRET' => Tools::getValue('IYZICO_FORM_LIVE_SECRET', Configuration::get('IYZICO_FORM_LIVE_SECRET')), 'IYZICO_FORM_CLASS' => Tools::getValue('IYZICO_FORM_CLASS', Configuration::get('IYZICO_FORM_CLASS')), + 'IYZICO_FORM_BASEURL' => Tools::getValue('IYZICO_FORM_BASEURL', Configuration::get('IYZICO_FORM_BASEURL')), ); } diff --git a/iyzicocheckoutform/refund.php b/iyzicocheckoutform/refund.php index a7ff348..087d64d 100644 --- a/iyzicocheckoutform/refund.php +++ b/iyzicocheckoutform/refund.php @@ -21,9 +21,9 @@ if(Tools::getValue('token')) { - if(Tools::getValue('token')!==$token ) { - - + if(Tools::getValue('token')!==$token ) { + + echo json_encode($message); exit; } @@ -31,7 +31,7 @@ $cookie = new Cookie('psAdmin'); if(!$cookie->id_employee){ - + $message['response'] = 'Admin girişiniz zaman aşımına uğramış olabilir.'; echo json_encode($message); exit; @@ -47,17 +47,17 @@ try { IyzipayBootstrap::init(); $error_msg = ''; - + $payment_id = pSQL(Tools::getValue('payment_id')); $refunded = pSQL(Tools::getValue('refunded')); $refund_price = pSQL(Tools::getValue('refund_price')); $language = Tools::getValue('language'); - + $query = 'SELECT * FROM ' . _DB_PREFIX_ . 'iyzico_cart_detail WHERE payment_transaction_id = "' . $payment_id . '"'; $refund_amount = Db::getInstance()->ExecuteS($query); - + //iyzico order details not found if (empty($refund_amount)) { $message = array( @@ -67,26 +67,26 @@ echo json_encode($message); exit; } - + $total_refund = $refund_amount[0]['paid_price'] - $refund_amount[0]['total_refunded_amount']; $refund = number_format($refund_price, 2, '.', ''); - + //Set api,secret and base url $options = new \Iyzipay\Options(); $options->setApiKey(Configuration::get('IYZICO_FORM_LIVE_API_ID')); $options->setSecretKey(Configuration::get('IYZICO_FORM_LIVE_SECRET')); - $options->setBaseUrl("https://api.iyzipay.com"); + $options->setBaseUrl(Configuration::get('IYZICO_FORM_BASEURL')); //refund amount validation. if ($refund > number_format($total_refund, 2, '.', '')) { $message = array( 'msg' => 'Fail', - 'response' => 'You cannot refund more than ' . $total_refund . ' ' . $refund_amount[0]['currency'] + 'response' => 'You cannot refund more than ' . $total_refund . ' ' . $refund_amount[0]['currency'] ); echo json_encode($message); exit; } - + //refund order if (empty($payment_id)) { $message = array( @@ -96,15 +96,15 @@ echo json_encode($message); exit; } - + if (!empty($language) && $language == 'tr') { $lang = 'tr'; } else { $lang = 'en'; } - + $locale = ($lang == "tr") ? Iyzipay\Model\Locale::TR : Iyzipay\Model\Locale::EN; - + $redirect_url = $_SERVER['HTTP_REFERER']; // create request class @@ -115,7 +115,7 @@ $request->setPrice($refund_price); $request->setCurrency($refund_amount[0]['currency']); $request->setIp((string) Tools::getRemoteAddr()); - + //request form api log $insert_api_log = Db::getInstance()->insert("iyzico_api_log", array( 'id' => Tools::getValue('id'), @@ -179,4 +179,4 @@ ); echo json_encode($message); exit; -} \ No newline at end of file +}