diff --git a/iyzipay/classes/IyzipayModel.php b/iyzipay/classes/IyzipayModel.php index 91ccd88..b279410 100644 --- a/iyzipay/classes/IyzipayModel.php +++ b/iyzipay/classes/IyzipayModel.php @@ -73,9 +73,9 @@ public static function insertCardUserKey($customerId, $cardUserKey, $apiKey) public static function insertIyzicoOrder($iyzicoLocalOrder) { - $tableName = 'iyzipay_order'; + - $sql = 'INSERT INTO '._DB_PREFIX_.bqSQL($tableName).'(`payment_id`,`order_id`,`total_amount`,`status`) + $sql = 'INSERT INTO '._DB_PREFIX_.'iyzipay_order (`payment_id`,`order_id`,`total_amount`,`status`) VALUES (\''.$iyzicoLocalOrder->orderId.'\', \''.$iyzicoLocalOrder->paymentId.'\', @@ -141,4 +141,4 @@ public static function updateOrderInvoiceTotal($price, $order_id) return Db::getInstance()->execute($sql); } -} \ No newline at end of file +} diff --git a/iyzipay/classes/IyzipayRequest.php b/iyzipay/classes/IyzipayRequest.php index d0f045d..f452bb0 100644 --- a/iyzipay/classes/IyzipayRequest.php +++ b/iyzipay/classes/IyzipayRequest.php @@ -26,6 +26,19 @@ 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 diff --git a/iyzipay/config.xml b/iyzipay/config.xml index 52dfdc7..2aa23eb 100644 --- a/iyzipay/config.xml +++ b/iyzipay/config.xml @@ -2,7 +2,7 @@ iyzipay - + @@ -10,4 +10,4 @@ 1 1 - \ No newline at end of file + diff --git a/iyzipay/config_tr.xml b/iyzipay/config_tr.xml index 57e162c..e064c41 100644 --- a/iyzipay/config_tr.xml +++ b/iyzipay/config_tr.xml @@ -2,7 +2,7 @@ iyzipay - + @@ -10,4 +10,4 @@ 1 1 - \ No newline at end of file + diff --git a/iyzipay/controllers/.DS_Store b/iyzipay/controllers/.DS_Store new file mode 100644 index 0000000..6a5987b Binary files /dev/null and b/iyzipay/controllers/.DS_Store differ diff --git a/iyzipay/controllers/front/callback.php b/iyzipay/controllers/front/callback.php index c6a7172..d0f724e 100644 --- a/iyzipay/controllers/front/callback.php +++ b/iyzipay/controllers/front/callback.php @@ -40,7 +40,7 @@ public function __construct() $this->context = Context::getContext(); } - public function init($webhook = null, $webhookPaymentConversationId = null ,$webhookToken = null) + public function init($webhook = null, $webhookPaymentConversationId = null ,$webhookToken = null ,$webhookIyziEventType = null) { parent::init(); @@ -87,11 +87,18 @@ public function init($webhook = null, $webhookPaymentConversationId = null ,$web $responseObject = json_encode($responseObject, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE); $requestResponse = IyzipayRequest::checkoutFormRequestDetail($endpoint, $responseObject, $authorization); - if ($webhook == "webhook" && $requestResponse->status == 'failure'){ + + $thankYouPage = Configuration::get('thankyou_page_text',0); + if(!$thankYouPage) + { + Configuration::updateValue('thankyou_page_text',0); + } + + if ($webhook == "webhook" && $webhookIyziEventType != 'CREDIT_PAYMENT_AUTH' && $requestResponse->status == 'failure'){ return IyzipayWebhookModuleFrontController::webhookHttpResponse("errorCode: ".$requestResponse->errorCode ." - " . $requestResponse->errorMessage, 404); } - if ($webhook == "webhook"){ + if ($webhook == "webhook" ){ $orderId = $requestResponse->basketId; $cartId = $requestResponse->basketId; $cart = new Cart($cartId); @@ -101,6 +108,31 @@ public function init($webhook = null, $webhookPaymentConversationId = null ,$web $order = Order::getByCartId($cart->id); + if($webhookIyziEventType == 'CREDIT_PAYMENT_PENDING' && $requestResponse->paymentStatus == 'PENDING_CREDIT') + { + $orderMessage = 'Alışveriş kredisi başvurusu sürecindedir.'; + IyzipayWebhookModuleFrontController::webhookResponseOrderNote($orderMessage ,3 , $requestResponse->basketId); + return IyzipayWebhookModuleFrontController::webhookHttpResponse("Order Status Updated - Alışveriş kredisi başvurusu sürecindedir.", 200); + } + if($webhookIyziEventType == 'CREDIT_PAYMENT_AUTH' && $requestResponse->status == 'success') + { + $orderMessage = 'Alışveriş kredisi işlemi başarıyla tamamlandı.'; + IyzipayWebhookModuleFrontController::webhookResponseOrderNote($orderMessage , 2 ,$requestResponse->basketId); + return IyzipayWebhookModuleFrontController::webhookHttpResponse("Order Status Updated - Alışveriş kredisi işlemi başarıyla tamamlandı.", 200); + } + if($webhookIyziEventType =='CREDIT_PAYMENT_INIT' && $requestResponse->status == 'INIT_CREDIT') + { + $orderMessage = 'Alışveriş kredisi işlemi başlatıldı.'; + IyzipayWebhookModuleFrontController::webhookResponseOrderNote($orderMessage , 3 , $requestResponse->basketId); + return IyzipayWebhookModuleFrontController::webhookHttpResponse("Order Status Updated - Alışveriş kredisi işlemi başlatıldı.", 200); + } + if($webhookIyziEventType == 'CREDIT_PAYMENT_AUTH' && $requestResponse->status == 'FAILURE') + { + $orderMessage = 'Alışveriş kredisi işlemi başarısız sonuçlandı.'; + IyzipayWebhookModuleFrontController::webhookResponseOrderNote($orderMessage , 6 , $requestResponse->basketId); + return IyzipayWebhookModuleFrontController::webhookHttpResponse("Order Status Updated - Alışveriş kredisi işlemi başarısız sonuçlandı.", 200); + } + if ($order && $order->getCurrentState() == (int)Configuration::get('PS_OS_PAYMENT')){ return IyzipayWebhookModuleFrontController::webhookHttpResponse("Order Exist - Sipariş zaten var.", 200); } @@ -113,11 +145,23 @@ public function init($webhook = null, $webhookPaymentConversationId = null ,$web if($requestResponse->paymentStatus == 'INIT_BANK_TRANSFER' && $requestResponse->status == 'success') { $orderMessage = 'iyzico Banka havalesi/EFT ödemesi bekleniyor.'; + Configuration::updateValue('thankyou_page_text',0); $this->module->validateOrder($orderId, Configuration::get('PS_OS_BANKWIRE'), $cartTotal, $this->module->displayName, $orderMessage, $extraVars, NULL, false, $customerSecureKey); + Tools::redirect('index.php?controller=order-confirmation&id_cart='.$orderId.'&id_module='.(int)$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key); + } + if($webhook != 'webhook' && $requestResponse->paymentStatus == 'PENDING_CREDIT' && $requestResponse->status == 'success') { + Configuration::updateValue('thankyou_page_text',1); + $orderMessage = 'Alışveriş kredisi başvurusu sürecindedir.'; + //Configuration::updateValue('iyzipay_active_webhook_url', $requestResponse->token); + $this->module->validateOrder($orderId, Configuration::get('PS_OS_PREPARATION'), $cartTotal, $this->module->displayName, $orderMessage, $extraVars, NULL, false, $customerSecureKey); Tools::redirect('index.php?controller=order-confirmation&id_cart='.$orderId.'&id_module='.(int)$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key); } + Configuration::updateValue('thankyou_page_text',0); + + + $requestResponse->installment = (int) $requestResponse->installment; $requestResponse->paidPrice = (float) $requestResponse->paidPrice; @@ -210,6 +254,7 @@ public function init($webhook = null, $webhookPaymentConversationId = null ,$web $this->module->validateOrder($orderId, Configuration::get('PS_OS_PAYMENT'), $cartTotal, $this->module->displayName, $installmentMessage, $extraVars, NULL, false, $customerSecureKey); + if (isset($requestResponse->installment) && !empty($requestResponse->installment) && $requestResponse->installment > 1) { /* Invoice true */ @@ -250,6 +295,7 @@ public function init($webhook = null, $webhookPaymentConversationId = null ,$web return IyzipayWebhookModuleFrontController::webhookHttpResponse("Order Created by Webhook - Sipariş webhook tarafından oluşturuldu.", 200); } + Tools::redirect('index.php?controller=order-confirmation&id_cart='.$orderId.'&id_module='.(int)$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key); } catch (Exception $e) { $errorMessage = $e->getMessage(); @@ -291,4 +337,4 @@ private function cancelPayment($locale, $paymentId, $remoteIpAddr, $apiKey, $sec $errorMessage = $this->l('uniqError'); throw new \Exception($errorMessage); } -} \ No newline at end of file +} diff --git a/iyzipay/controllers/front/webhook.php b/iyzipay/controllers/front/webhook.php index 68f01c6..9a9cee6 100644 --- a/iyzipay/controllers/front/webhook.php +++ b/iyzipay/controllers/front/webhook.php @@ -56,7 +56,7 @@ public function orderControlViaWebhook($params){ public function iyzicoWebhookResponse(){ $iyzicoCallback = new IyzipayCallBackModuleFrontController(); - $responseCode = $iyzicoCallback->init("webhook", $this->paymentConversationId, $this->token); + $responseCode = $iyzicoCallback->init("webhook", $this->paymentConversationId, $this->token , $this->iyziEventType); return $responseCode; } @@ -67,5 +67,12 @@ public static function webhookHttpResponse($message,$status){ exit(); } -} + public static function webhookResponseOrderNote($message,$orderStatus,$orderId){ + + $query = "UPDATE `"._DB_PREFIX_."orders` SET note='".$message."', current_state = '".$orderStatus."' WHERE id_cart =".$orderId; //end of the query + Db::getInstance()->Execute($query); + return $query; + } + +} diff --git a/iyzipay/iyzipay.php b/iyzipay/iyzipay.php index af3b47e..30662f5 100644 --- a/iyzipay/iyzipay.php +++ b/iyzipay/iyzipay.php @@ -44,7 +44,7 @@ public function __construct() { $this->name = 'iyzipay'; $this->tab = 'payments_gateways'; - $this->version = '1.2.0'; + $this->version = '2.0.0'; $this->author = 'iyzico'; $this->need_instance = 1; @@ -89,7 +89,11 @@ public function __construct() { $this->checkAndSetCookieSameSite(); } - Configuration::updateValue('PS_CONDITIONS_CMS_ID',0); + + + + + Configuration::updateValue('PS_CONDITIONS_CMS_ID',0); @@ -112,6 +116,10 @@ public function install() $this->setIyziWebhookUrlKey(); + $this->iyzipaySetWebhookUrlKey(); + + + include(dirname(__FILE__).'/sql/install.php'); @@ -158,10 +166,14 @@ public function uninstall() && Configuration::deleteByName('iyzipay_overlay_token') && Configuration::deleteByName('iyzipay_pwi_first_enabled_status') && Configuration::deleteByName('iyzipay_language') + && Configuration::deleteByName('thankyou_page_text') + && Configuration::deleteByName('iyzipay_active_webhook_url') && Configuration::updateValue('PS_CONDITIONS_CMS_ID',3) && parent::uninstall(); } + + /** * Load the configuration form */ @@ -173,13 +185,15 @@ public function getContent() if (((bool)Tools::isSubmit('submitIyzipayModule')) == true) { $this->postProcess(); } - $sslControl = $_SERVER['HTTPS'] ; $this->registerHook('ModuleRoutes'); $this->setIyziWebhookUrlKey(); + $this->initSetWebhookUrlKey(); + + $this->context->smarty->assign('module_dir', $this->_path); $this->context->smarty->assign('webhookUrlKey', $this->getIyziWebhookUrlKey()); @@ -190,12 +204,18 @@ public function getContent() $this->context->smarty->assign('languageIsoCode', $this->context->language->iso_code); - $this->context->smarty->assign('sslEnabled', $sslControl); + $httpsProtocol = empty($_SERVER['HTTPS']); + + $this->context->smarty->assign('sslEnabled', $httpsProtocol); $this->context->smarty->assign('iyziApiType', Configuration::get('iyzipay_api_type')); $this->context->smarty->assign('cookieSamesite', Configuration::get('PS_COOKIE_SAMESITE')); + $webhookActiveButton = Configuration::get('iyzipay_active_webhook_url'); + $this->context->smarty->assign('webhookActiveButton', $this->iyzicoWebhookSubmitbutton()); + + $pwi_status_after_enabled_pwi = Configuration::get('iyzipay_pwi_first_enabled_status', true); if (!Module::isEnabled('paywithiyzico') && $pwi_status_after_enabled_pwi != 1){ $this->context->smarty->assign('iyzipay_pwi_first_enabled_status', 0); @@ -257,7 +277,7 @@ protected function getConfigForm() return array( 'form' => array( 'legend' => array( - 'title' => $this->l('Settings'), + 'title' => $this->l('Settings') , 'icon' => 'icon-cogs', ), 'input' => array( @@ -374,6 +394,7 @@ protected function getConfigForm() 'type' => 'hidden', 'name' => 'iyzipay_overlay_token', ), + array( 'type' => 'hidden', 'name' => 'iyzipay_webhook_url_key', @@ -403,6 +424,7 @@ protected function getConfigFormValues() 'iyzipay_display' => Configuration::get('iyzipay_display', true), 'iyzipay_overlay_position' => Configuration::get('iyzipay_overlay_position', true), 'iyzipay_overlay_token' => Configuration::get('iyzipay_overlay_token', true), + 'iyzipay_active_webhook_url' => Configuration::get('iyzipay_active_webhook_url', true), 'iyzipay_language' => Configuration::get('iyzipay_language', true), 'PS_COOKIE_SAMESITE' => Configuration::get('PS_COOKIE_SAMESITE' , true), @@ -509,6 +531,7 @@ public function hookFooter($params) array( 'token' => Configuration::get('iyzipay_overlay_token'), 'position' => Configuration::get('iyzipay_overlay_position'), + ) ); @@ -595,6 +618,77 @@ public function checkoutFormGenerate($params) return $requestResponse; } + + + public function iyzipaySetWebhookUrlKey() { + + $webhookActive = Configuration::get('iyzipay_active_webhook_url'); + if(empty($webhookActive)) + { + Configuration::updateValue('iyzipay_active_webhook_url',0); + } + + + + } + + public function initSetWebhookUrlKey() { + + $apiKey = Configuration::get('iyzipay_api_key'); + $secretKey = Configuration::get('iyzipay_secret_key'); + + + if(isset($apiKey) && isset($secretKey) && isset($_SERVER['HTTPS'])) + { + if(Configuration::get('iyzipay_active_webhook_url') == 0) + { + $randNumer = rand(100000, 99999999); + $endpoint = Configuration::get('iyzipay_api_type'); + $setWebhookUrl = new stdClass(); + $setWebhookUrl->webhookUrl = Tools::getHttpHost(true) . __PS_BASE_URI__ .'iyzico/api/webhook/'. $this->getIyziWebhookUrlKey(); + + $pkiString = IyzipayPkiStringBuilder::pkiStringGenerate($setWebhookUrl); + $authorization = IyzipayPkiStringBuilder::authorization($pkiString, $apiKey, $secretKey, $randNumer); + + $iyzipaywebhookJson = json_encode($setWebhookUrl, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + $requestResponseWebhook = IyzipayRequest::iyzipayPostWebhook($endpoint ,$iyzipaywebhookJson, $authorization); + + if(isset($requestResponseWebhook->merchantNotificationUpdateStatus)) + { + if($requestResponseWebhook->merchantNotificationUpdateStatus == 'UPDATED' || $requestResponseWebhook->merchantNotificationUpdateStatus == 'CREATED') + { + Configuration::updateValue('iyzipay_active_webhook_url',1); + return true; + + } else { + Configuration::updateValue('iyzipay_active_webhook_url',2); + return true; + } + + } + } + } + + } + + /* Submit Button Webhook */ + public static function iyzicoWebhookSubmitbutton() + { + $webhookActiveButton = Configuration::get('iyzipay_active_webhook_url'); + if($webhookActiveButton == 2) + { + $htmlButton = '
+ *Problem yaşıyorsanız, iyzico webhook sistemini aktif etmek için iletişime geçiniz. + entegrasyon@iyzico.com
'; + if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['button'])) + { + Configuration::updateValue('iyzipay_active_webhook_url',0); + } + return $htmlButton; + } + + } + /** * This hook is used to display the order confirmation page. */ @@ -611,14 +705,19 @@ public function hookPaymentReturn($params) $this->smarty->assign('status', 'ok'); } + $thankYouPage = Configuration::get('thankyou_page_text') ; + $this->smarty->assign(array( 'id_order' => $order->id, 'reference' => $order->reference, 'params' => $params, + 'thankYouPage' => $thankYouPage, 'total' => Tools::displayPrice($this->context->cookie->totalPrice, $this->context->currency, false), 'installmentFee' => Tools::displayPrice($this->context->cookie->installmentFee, $this->context->currency, false), )); + + return $this->display(__FILE__, 'views/templates/front/confirmation.tpl'); } diff --git a/iyzipay/translations/tr.php b/iyzipay/translations/tr.php index ee99c7b..a3cdc60 100644 --- a/iyzipay/translations/tr.php +++ b/iyzipay/translations/tr.php @@ -42,6 +42,7 @@ $_MODULE['<{iyzipay}prestashop>iyzipay_6f0170fbfae85ec13f565665b8d74f3b'] = 'Lax '; $_MODULE['<{iyzipay}prestashop>iyzipay_2e979835dd62324f5bfe217449ba4974'] = 'Strict'; $_MODULE['<{iyzipay}prestashop>iyzipay_c9cc8cce247e49bae79f15173ce97354'] = 'Kaydet'; +$_MODULE['<{iyzipay}prestashop>iyzipay_ad43d708caf29a4a0e605a83aff046fe'] = '*Problem yaşıyorsanız, iyzico webhook sistemini aktif etmek için iletişime geçiniz.'; $_MODULE['<{iyzipay}prestashop>iyzipay_62d3e6f706cd08753269d1e7cb82acc0'] = 'Ödeme formunun aktif olması için sözleşme onayı gereklidir.'; $_MODULE['<{iyzipay}prestashop>callback_6a42b5c65308d870ac1ea113c9ee5fd0'] = 'Token Değeri Bulunamadı'; $_MODULE['<{iyzipay}prestashop>callback_e7e914b797ae5c9f8efc09f5b4817e6b'] = 'Sipariş Bulunamadı'; @@ -53,6 +54,7 @@ $_MODULE['<{iyzipay}prestashop>callback_8f09da02ab72ea112fafefed99f3eb11'] = 'Taksit ile ödenmiştir.'; $_MODULE['<{iyzipay}prestashop>callback_1ceebcbe9b57cd93212e4ca8945a894d'] = 'Komisyon Tutarı:'; $_MODULE['<{iyzipay}prestashop>callback_868478716c083f38439fb9865bfad3f7'] = 'Ödemeniz alındı fakat siparişiniz oluşturulamadı. Lütfen site yöneticisi ile iletişime geçiniz.'; +$_MODULE['<{iyzipay}prestashop>confirmation_16db12705a24d7808488f06587e62729'] = 'Alışveriş Kredisi için başvurunuz alınmıştır. Başvurunuz, en kısa sürede sonuçlandırılacaktır.'; $_MODULE['<{iyzipay}prestashop>confirmation_bddd470742bc2329733e489ed05a8ba1'] = 'Siparişiniz Tamamlandı.'; $_MODULE['<{iyzipay}prestashop>confirmation_b2f40690858b404ed10e62bdf422c704'] = 'Ücret'; $_MODULE['<{iyzipay}prestashop>confirmation_e5b8f00cb48fe623703902d21ed16f6f'] = 'Taksit Ücreti'; diff --git a/iyzipay/views/templates/admin/template_1.tpl b/iyzipay/views/templates/admin/template_1.tpl index 97ddf16..6da2a7c 100644 --- a/iyzipay/views/templates/admin/template_1.tpl +++ b/iyzipay/views/templates/admin/template_1.tpl @@ -103,7 +103,8 @@

https://merchant.iyzipay.com veya https://sandbox-merchant.iyzipay.com adresi üzerinden müşteri bilgileriniz ile giriş yapınız. Panele eriştiğiniz sırada sağ üst köşede profil bilgilerinizi göreceksiniz. Profil bilgilerinizin üzerine tıkladıktan sonra “Ayarlar” menüsüne tıklayınız. “API Anahtları" alanından “API Anahtarı ve Güvenlik Anahtarı" bilgilerinizi kopyalayıp PrestaShop iyzico panelinde bulunan “API Anahtarı” ve “Güvenlik Anahtarı” alanlarına yapıştırınız..

*PrestaShop admin paneli içnde Yapılandır > Gelişmiş Parametler > Yönetim > Genel > Cookie SameSite Hiçbiri(None) yapmayı unutmayınız.


-

Webhook URL : {$websiteBaseUrl}iyzico/api/webhook/{$webhookUrlKey}

+

Webhook URL : {$websiteBaseUrl}iyzico/api/webhook/{$webhookUrlKey}
+ {$webhookActiveButton}

*Webhook entegrasyonunu yapmayı unutmayınız.


{else} @@ -112,10 +113,11 @@

*Configure > Advanced Parameters > General > Cookie SameSite Don't forget to set None.


Webhook URL : {$websiteBaseUrl}iyzico/api/webhook/{$webhookUrlKey} + {$webhookActiveButton}

*Don't forget to do webhook Integration.


{/if} - {if empty($sslEnabled) && $iyziApiType == 'https://api.iyzipay.com'} + {if $sslEnabled && $iyziApiType == 'https://api.iyzipay.com'} {if $languageIsoCode == 'tr'}