Skip to content

Commit

Permalink
update new version
Browse files Browse the repository at this point in the history
  • Loading branch information
feyzullahdemir committed Dec 27, 2022
1 parent d4f0487 commit 8cf5184
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 20 deletions.
6 changes: 3 additions & 3 deletions iyzipay/classes/IyzipayModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'\',
Expand Down Expand Up @@ -141,4 +141,4 @@ public static function updateOrderInvoiceTotal($price, $order_id)

return Db::getInstance()->execute($sql);
}
}
}
13 changes: 13 additions & 0 deletions iyzipay/classes/IyzipayRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions iyzipay/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<module>
<name>iyzipay</name>
<displayName><![CDATA[iyzico Checkout Form Module]]></displayName>
<version><![CDATA[1.1.2]]></version>
<version><![CDATA[2.0.0]]></version>
<description><![CDATA[iyzico Checkout Form Module for PrestaShop]]></description>
<author><![CDATA[iyzipay]]></author>
<tab><![CDATA[payments_gateways]]></tab>
<confirmUninstall><![CDATA[are you sure ?]]></confirmUninstall>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>
</module>
4 changes: 2 additions & 2 deletions iyzipay/config_tr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<module>
<name>iyzipay</name>
<displayName><![CDATA[iyzico &Ouml;deme Formu Mod&uuml;l&uuml;]]></displayName>
<version><![CDATA[1.2.0]]></version>
<version><![CDATA[2.0.0]]></version>
<description><![CDATA[PrestaShop i&ccedil;in iyzico &Ouml;deme Formu Mod&uuml;l&uuml;]]></description>
<author><![CDATA[iyzico]]></author>
<tab><![CDATA[payments_gateways]]></tab>
<confirmUninstall><![CDATA[emin misiniz ?]]></confirmUninstall>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>
</module>
Binary file added iyzipay/controllers/.DS_Store
Binary file not shown.
54 changes: 50 additions & 4 deletions iyzipay/controllers/front/callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -291,4 +337,4 @@ private function cancelPayment($locale, $paymentId, $remoteIpAddr, $apiKey, $sec
$errorMessage = $this->l('uniqError');
throw new \Exception($errorMessage);
}
}
}
11 changes: 9 additions & 2 deletions iyzipay/controllers/front/webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;

}

}
Loading

0 comments on commit 8cf5184

Please sign in to comment.