Plugin Directory

Changeset 3036107

Timestamp:
02/15/2024 09:10:49 AM (5 months ago)
Author:
iyzico
Message:

+new version 3.4.0
+woocommerce blocks support

Location:
iyzico-woocommerce/trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • iyzico-woocommerce/trunk/library/iyzico-for-woocommerce-gateway-formobjectgenerate.php

    r2934987 r3036107  
    4242        $iyzico->callbackUrl                  = add_query_arg('wc-api', 'WC_Gateway_Iyzico', $data->get_checkout_order_received_url());
    4343        $iyzico->cardUserKey                  = $iyziModel->findUserCardKey($user->ID,$apiKey);
    44         $iyzico->paymentSource                = 'WOOCOMMERCE|'.WOOCOMMERCE_VERSION.'|CARRERA-3.2.6'.$affiliate;
    45         //$iyzico->goBackUrl                    = "test.php";
     44        $iyzico->paymentSource                = 'WOOCOMMERCE|'.WOOCOMMERCE_VERSION.'|CARRERA-3.4.0'.$affiliate;
    4645
    4746
     
    7776        $iyzico->callbackUrl                  = add_query_arg('wc-api', 'WC_Gateway_Iyzico', $data->get_checkout_order_received_url());
    7877        $iyzico->cancelUrl                            = get_site_url();
    79         $iyzico->paymentSource                = 'WOOCOMMERCE|'.WOOCOMMERCE_VERSION.'|CARRERA-PWI-3.2.6'.$affiliate;
     78        $iyzico->paymentSource                = 'WOOCOMMERCE|'.WOOCOMMERCE_VERSION.'|CARRERA-PWI-3.'.$affiliate;
    8079
    8180
  • iyzico-woocommerce/trunk/library/iyzico-for-woocommerce-gateway-pkibuilder.php

    r2934987 r3036107  
    11<?php
    2 if ( ! defined( 'ABSPATH' ) ) {
     2if () {
    33    exit;
    44}
    55
    6 class Iyzico_Checkout_For_WooCommerce_PkiBuilder {
     6class Iyzico_Checkout_For_WooCommerce_PkiBuilder
     7{
    78
    8 public function pkiStringGenerate($objectData) {
     9    public function pkiStringGenerate($objectData)
     10    {
    911        $pki_value = "[";
    1012        foreach ($objectData as $key => $data) {
    11             if(is_object($data)) {
     13            if(is_object($data)) {
    1214                $name = var_export($key, true);
    1315                $name = str_replace("'", "", $name);
    14                 $pki_value .= $name."=[";
     16                $pki_value .= $name"=[";
    1517                $end_key = count(get_object_vars($data));
    1618                $count   = 0;
     
    1921                    $name = var_export($key, true);
    2022                    $name = str_replace("'", "", $name);
    21                     $pki_value .= $name."="."".$value;
    22                     if($end_key != $count)
     23                    $pki_value .= $name$value;
     24                    if($end_key != $count)
    2325                        $pki_value .= ",";
    2426                }
    2527                $pki_value .= "]";
    26             } else if(is_array($data)) {
     28            } else if(is_array($data)) {
    2729                $name = var_export($key, true);
    2830                $name = str_replace("'", "", $name);
    29                 $pki_value .= $name."=[";
     31                $pki_value .= $name"=[";
    3032                $end_key = count($data);
    3133                $count   = 0;
     
    3840                        $name = str_replace("'", "", $name);
    3941
    40                         $pki_value .= $name."="."".$item;
    41                         if(end($result) != $item) {
     42                        $pki_value .= $name . "=" . "" . $item;
     43                        $reResult = (array) $result;
     44                        $newResult = $reResult[array_key_last($reResult)];
     45
     46                        if ($newResult != $item) {
    4247                            $pki_value .= ",";
    4348                        }
    44                         if(end($result) == $item) {
    45                             if($end_key != $count) {
     49
     50                        if ($newResult == $item) {
     51
     52                            if ($end_key != $count) {
    4653                                $pki_value .= "], ";
    47 
    4854                            } else {
    4955                                $pki_value .= "]";
     
    5258                    }
    5359                }
    54                 if(end($data) == $result)
     60
     61                $reData = (array) $data;
     62                $newData = $reData[array_key_last($reData)];
     63                if ($newData == $result)
    5564                    $pki_value .= "]";
    56 
    5765            } else {
    5866                $name = var_export($key, true);
    5967                $name = str_replace("'", "", $name);
    6068
    61                 $pki_value .= $name."="."".$data."";
     69                $pki_value .= $name"";
    6270            }
    63             if(end($objectData) != $data)
     71
     72            $reObjectData = (array)$objectData;
     73            $newobjectData = $reObjectData[array_key_last($reObjectData)];
     74
     75            if ($newobjectData != $data)
    6476                $pki_value .= ",";
    6577        }
     
    6880    }
    6981
    70     public function createFormObjectSort($objectData) {
     82    public function createFormObjectSort($objectData)
     83    {
    7184
    7285
     
    92105            $form_object->basketItems[$key] = new stdClass();
    93106            $form_object->basketItems[$key] = $item;
    94 
    95107        }
    96108
     
    101113        $form_object->forceThreeDS          = $objectData->forceThreeDS;
    102114        $form_object->cardUserKey           = $objectData->cardUserKey;
    103         //$form_object->goBackUrl           = $objectData->goBackUrl;
    104115
    105116        return $form_object;
    106117    }
    107118
    108     public function createFormObjectSortPwi($objectData) {
     119    public function createFormObjectSortPwi($objectData)
     120    {
    109121
    110122
     
    130142            $form_object->basketItems[$key] = new stdClass();
    131143            $form_object->basketItems[$key] = $item;
    132 
    133144        }
    134145
     
    142153    }
    143154
    144     public function authorizationGenerate($pkiString,$apiKey,$secretKey,$rand) {
     155    public function authorizationGenerate($pkiString, $apiKey, $secretKey, $rand)
     156    {
    145157
    146         $hash_value = $apiKey.$rand.$secretKey.$pkiString;
    147         $hash       = base64_encode(sha1($hash_value,true));
     158        $hash_value = $apiKey$pkiString;
     159        $hash       = base64_encode(sha1($hash_value,true));
    148160
    149         $authorization  = 'IYZWS '.$apiKey.':'.$hash;
     161        $authorization  = 'IYZWS '$hash;
    150162
    151163        $authorization_data = array(
     
    156168        return $authorization_data;
    157169    }
    158 
    159170}
  • iyzico-woocommerce/trunk/library/iyzico-for-woocommerce-gateway.php

    r2934987 r3036107  
    11<?php
    22
    3 if ( ! defined( 'ABSPATH' ) ) {
     3if () {
    44    exit;
    55}
    66
    7 class Iyzico_Checkout_For_WooCommerce_Gateway extends WC_Payment_Gateway {
    8 
    9     public function __construct() {
    10 
     7class Iyzico_Checkout_For_WooCommerce_Gateway extends WC_Payment_Gateway
     8{
     9
     10    public function __construct()
     11    {
    1112
    1213        $this->id = 'iyzico';
    13         $this->iyziV = '3.2.6';
     14        $this->iyziV = '3.';
    1415        $this->method_title = __('iyzico Checkout', 'woocommerce-iyzico');
    1516        $this->method_description = __('Best Payment Solution', 'woocommerce-iyzico');
     
    2122        $this->init_settings();
    2223
    23         $this->title        = __($this->get_option( 'title' ),'woocommerce-iyzico');
    24         $this->description  = __($this->get_option( 'description'),'woocommerce-iyzico');
    25         $this->enabled      = $this->get_option( 'enabled' );
    26         $this->affiliate    = $this->get_option( 'affiliate_network' );
    27         $this->icon         = plugins_url().IYZICO_PLUGIN_NAME.'/image/cards.png?v=3';
     24        $this->title        = __($this->get_option('woocommerce-iyzico');
     25        $this->description  = __($this->get_option('woocommerce-iyzico');
     26        $this->enabled      = $this->get_option();
     27        $this->affiliate    = $this->get_option();
     28        $this->icon         = plugins_url()'/image/cards.png?v=3';
    2829        add_action('init', array(&$this, 'iyzico_response'));
    29         add_action('admin_init', array($this , 'initIyzicoWebhookUrl') );
     30        add_action('admin_init', array($this);
    3031        add_action('woocommerce_api_wc_gateway_iyzico', array($this, 'iyzico_response'));
    31         add_action( 'woocommerce_thankyou', array( $this, 'thankYouSubtitle' ), 5, 1 );
    32 
    33         add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array(
     32        add_action();
     33
     34        add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(
    3435            $this,
    3536            'process_admin_options',
    36         ) );
    37 
    38         add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array(
     37        ));
     38
     39        add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(
    3940            $this,
    4041            'admin_overlay_script',
    41         ) );
     42        ));
    4243
    4344        add_action('woocommerce_receipt_iyzico', array($this, 'iyzico_loading_bar'));
    4445        add_action('woocommerce_receipt_iyzico', array($this, 'iyzico_payment_form'));
    4546
    46 
    47 
    48 
    49 
    50         if(isset($_GET['section']) && $_GET['section'] == 'iyzico') {
     47        if (isset($_GET['section']) && $_GET['section'] == 'iyzico') {
    5148
    5249            $this->valid_js();
    5350        }
    54 
    55     }
    56 
    57     public function getApiKey(){
     51    }
     52
     53    public function getApiKey()
     54    {
    5855        return $this->settings['api_key'];
    5956    }
    6057
    6158
    62     public function admin_overlay_script() {
     59    public function admin_overlay_script()
     60    {
    6361
    6462        $helper                     = new Iyzico_Checkout_For_WooCommerce_Helper();
     
    6967        $secretKey                  = $this->settings['secret_key'];
    7068        $baseUrl                    = $this->settings['api_type'];
    71         $randNumer                  = rand(100000,99999999);
     69        $randNumer                  = rand(100000,99999999);
    7270
    7371        $overlayObject = new stdClass();
     
    7775
    7876        $pkiString                = $pkiBuilder->pkiStringGenerate($overlayObject);
    79         $authorizationData        = $pkiBuilder->authorizationGenerate($pkiString,$apiKey,$secretKey,$randNumer);
    80 
    81 
    82         $iyzicoJson               = json_encode($overlayObject,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
    83 
    84         $requestResponse          = $iyzicoRequest->iyzicoOverlayScriptRequest($baseUrl,$iyzicoJson,$authorizationData);
     77        $authorizationData        = $pkiBuilder->authorizationGenerate($pkiString,$randNumer);
     78
     79
     80        $iyzicoJson               = json_encode($overlayObject,JSON_UNESCAPED_UNICODE);
     81
     82        $requestResponse          = $iyzicoRequest->iyzicoOverlayScriptRequest($baseUrl,$authorizationData);
    8583
    8684
     
    8987
    9088
    91         if(isset($requestResponse->protectedShopId)) {
     89        if(isset($requestResponse->protectedShopId)) {
    9290
    9391            $requestResponse->protectedShopId = esc_js($requestResponse->protectedShopId);
    9492
    95             if(empty($iyzicoOverlayToken) && empty($iyzicoOverlayPosition)) {
    96 
    97                 add_option('iyzico_overlay_token',$requestResponse->protectedShopId,'','no');
    98                 add_option('iyzico_overlay_position',$this->settings['overlay_script'],'','no');
    99 
     93            if (empty($iyzicoOverlayToken) && empty($iyzicoOverlayPosition)) {
     94
     95                add_option('iyzico_overlay_token', $requestResponse->protectedShopId, '', 'no');
     96                add_option('iyzico_overlay_position', $this->settings['overlay_script'], '', 'no');
    10097            } else {
    10198
    102                 update_option('iyzico_overlay_token',$requestResponse->protectedShopId);
    103                 update_option('iyzico_overlay_position',$this->settings['overlay_script']);
    104             }
    105 
     99                update_option('iyzico_overlay_token', $requestResponse->protectedShopId);
     100                update_option('iyzico_overlay_position', $this->settings['overlay_script']);
     101            }
    106102        } else {
    107103
    108             if(empty($iyzicoOverlayPosition)) {
    109 
    110                 add_option('iyzico_overlay_position',$this->settings['overlay_script'],'','no');
    111 
     104            if (empty($iyzicoOverlayPosition)) {
     105
     106                add_option('iyzico_overlay_position', $this->settings['overlay_script'], '', 'no');
    112107            } else {
    113108
    114                 update_option('iyzico_overlay_position',$this->settings['overlay_script']);
    115 
    116             }
    117 
     109                update_option('iyzico_overlay_position', $this->settings['overlay_script']);
     110            }
    118111        }
    119112        return true;
    120 
    121     }
    122 
    123 
    124 
    125     public function admin_options() {
     113    }
     114
     115
     116
     117    public function admin_options()
     118    {
    126119        ob_start();
    127120        parent::admin_options();
     
    130123
    131124        echo $parent_options;
    132         $pluginUrl = plugins_url().IYZICO_PLUGIN_NAME;
    133 
    134         $html = '<style scoped>@media (max-width:768px){.iyziBrand{position:fixed;bottom:0;top:auto!important;right:0!important}}</style><div class="iyziBrandWrap"><div class="iyziBrand" style="clear:both;position:absolute;right: 50px;top:440px;display: flex;flex-direction: column;justify-content: center;"><img src='.$pluginUrl.'/image/iyzico_logo.png style="width: 250px;margin-left: auto;"><p style="text-align:center;"><strong>V: </strong>'.$this->iyziV.'</p></div></div>';
     125        $pluginUrl = plugins_url()IYZICO_PLUGIN_NAME;
     126
     127        $html = '<style scoped>@media (max-width:768px){.iyziBrand{position:fixed;bottom:0;top:auto!important;right:0!important}}</style><div class="iyziBrandWrap"><div class="iyziBrand" style="clear:both;position:absolute;right: 50px;top:440px;display: flex;flex-direction: column;justify-content: center;"><img src=''</p></div></div>';
    135128        echo $html;
    136129    }
    137130
    138     public function valid_js() {
    139 
    140         wp_enqueue_script('script', plugins_url().IYZICO_PLUGIN_NAME.'/media/js/valid_api.js',true,'1.0','all');
    141 
    142     }
    143     public function init_form_fields() {
     131    public function valid_js()
     132    {
     133
     134        wp_enqueue_script('script', plugins_url() . IYZICO_PLUGIN_NAME . '/media/js/valid_api.js', true, '1.0', 'all');
     135    }
     136    public function init_form_fields()
     137    {
    144138
    145139        $this->form_fields = Iyzico_Checkout_For_WooCommerce_Fields::iyzicoAdminFields();
    146 
    147     }
    148 
    149     public function process_payment($order_id) {
     140    }
     141
     142    public function process_payment($order_id)
     143    {
    150144
    151145        $order = wc_get_order($order_id);
     
    155149            'redirect' => $order->get_checkout_payment_url(true)
    156150        );
    157 
    158     }
    159 
    160     public function iyzico_loading_bar() {
     151    }
     152
     153    public function iyzico_loading_bar()
     154    {
    161155
    162156        echo '<style>.loading{width:40px;height:40px;background-color:#1E64FF;margin:auto;-webkit-animation:sk-rotateplane 1.2s infinite ease-in-out;animation:sk-rotateplane 1.2s infinite ease-in-out}@-webkit-keyframes sk-rotateplane{0%{-webkit-transform:perspective(120px)}50%{-webkit-transform:perspective(120px) rotateY(180deg)}100%{-webkit-transform:perspective(120px) rotateY(180deg) rotateX(180deg)}}@keyframes sk-rotateplane{0%{transform:perspective(120px) rotateX(0) rotateY(0);-webkit-transform:perspective(120px) rotateX(0) rotateY(0)}50%{transform:perspective(120px) rotateX(-180.1deg) rotateY(0);-webkit-transform:perspective(120px) rotateX(-180.1deg) rotateY(0)}100%{transform:perspective(120px) rotateX(-180deg) rotateY(-179.9deg);-webkit-transform:perspective(120px) rotateX(-180deg) rotateY(-179.9deg)}}</style>';
     
    169163                </div>
    170164             </div>';
    171 
    172     }
    173 
    174     private function setcookieSameSite($name, $value, $expire, $path, $domain, $secure, $httponly) {
     165    }
     166
     167    private function setcookieSameSite($name, $value, $expire, $path, $domain, $secure, $httponly)
     168    {
    175169
    176170        if (PHP_VERSION_ID < 70300) {
    177171
    178172            setcookie($name, $value, $expire, "$path; samesite=None", $domain, $secure, $httponly);
    179         }
    180         else {
     173        } else {
    181174            setcookie($name, $value, [
    182175                'expires' => $expire,
     
    187180                'httponly' => $httponly,
    188181            ]);
    189 
    190 
    191         }
    192     }
    193 
    194 
    195     public function iyzico_payment_form($order_id,$payMethod = null) {
     182        }
     183    }
     184
     185
     186    public function iyzico_payment_form($order_id, $payMethod = null)
     187    {
    196188
    197189        $wooCommerceCookieKey = 'wp_woocommerce_session_';
    198190        foreach ($_COOKIE as $name => $value) {
    199             if (stripos($name,$wooCommerceCookieKey) === 0) {
     191            if (stripos($name,$wooCommerceCookieKey) === 0) {
    200192                $wooCommerceCookieKey = $name;
    201193            }
    202194        }
    203195
    204         $setCookie = $this->setcookieSameSite($wooCommerceCookieKey,$_COOKIE[$wooCommerceCookieKey], time() + 86400, "/", $_SERVER['SERVER_NAME'],true, true);
     196        $setCookie = $this->setcookieSameSite($wooCommerceCookieKey,true, true);
    205197
    206198        $this->versionCheck();
     
    216208        $baseUrl                   = $this->settings['api_type'];
    217209        $language                  = $this->settings['form_language'];
    218         $rand                      = rand(1,99999);
     210        $rand                      = rand(1,99999);
    219211        $user                      = wp_get_current_user();
    220         $iyzicoConversationId      = WC()->session->set('iyzicoConversationId',$order_id);
    221         $iyzicoCustomerId          = WC()->session->set('iyzicoCustomerId',$user->ID);
    222         $totalAmount               = WC()->session->set('iyzicoOrderTotalAmount',$getOrder->get_total());
     212        $iyzicoConversationId      = WC()->session->set('iyzicoConversationId',$order_id);
     213        $iyzicoCustomerId          = WC()->session->set('iyzicoCustomerId',$user->ID);
     214        $totalAmount               = WC()->session->set('iyzicoOrderTotalAmount',$getOrder->get_total());
    223215
    224216
     
    228220        $iyzicoRequest             = new Iyzico_Checkout_For_WooCommerce_iyzicoRequest();
    229221
    230         if($payMethod != "pwi") {
    231             $iyzico                   = $formObjectGenerate->generateOption($customerCart,$language,$getOrder,$apiKey,$this->affiliate);
     222        if($payMethod != "pwi") {
     223            $iyzico                   = $formObjectGenerate->generateOption($customerCart,$this->affiliate);
    232224        } else {
    233             $iyzico                   = $formObjectGenerate->generateOptionPwi($customerCart,$language,$getOrder,$apiKey,$this->affiliate);
     225            $iyzico                   = $formObjectGenerate->generateOptionPwi($customerCart,$this->affiliate);
    234226        }
    235227
     
    237229        $iyzico->shippingAddress  = $formObjectGenerate->generateShippingAddress($getOrder);
    238230        $iyzico->billingAddress   = $formObjectGenerate->generateBillingAddress($getOrder);
    239         $iyzico->basketItems      = $formObjectGenerate->generateBasketItems($customerCart,$getOrder);
    240 
    241         if($payMethod != "pwi") {
     231        $iyzico->basketItems      = $formObjectGenerate->generateBasketItems($customerCart,$getOrder);
     232
     233        if($payMethod != "pwi") {
    242234            $orderObject              = $pkiBuilder->createFormObjectSort($iyzico);
    243235        } else {
     
    247239        $pkiString                = $pkiBuilder->pkiStringGenerate($orderObject);
    248240
    249         $authorizationData        = $pkiBuilder->authorizationGenerate($pkiString,$apiKey,$secretKey,$rand);
    250 
    251         $iyzicoJson               = json_encode($iyzico,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
    252 
    253 
    254 
    255 
    256         if($payMethod != "pwi") {
    257             $requestResponse          = $iyzicoRequest->iyzicoCheckoutFormRequest($baseUrl,$iyzicoJson,$authorizationData);
     241        $authorizationData        = $pkiBuilder->authorizationGenerate($pkiString,$rand);
     242
     243        $iyzicoJson               = json_encode($iyzico,JSON_UNESCAPED_UNICODE);
     244
     245
     246
     247
     248        if($payMethod != "pwi") {
     249            $requestResponse          = $iyzicoRequest->iyzicoCheckoutFormRequest($baseUrl,$authorizationData);
    258250        } else {
    259251
    260             $requestResponse          = $iyzicoRequest->iyzicoPwiRequest($baseUrl,$iyzicoJson,$authorizationData);
     252            $requestResponse          = $iyzicoRequest->iyzicoPwiRequest($baseUrl,$authorizationData);
    261253
    262254            return $requestResponse->payWithIyzicoPageUrl;
     
    264256
    265257        $className                = $this->get_option('form_class');
    266         $message =  '<p id="infoBox" style="display:none;">' .$this->settings['payment_checkout_value']. '</p>';
     258        $message =  '<p id="infoBox" style="display:none;">' .. '</p>';
    267259
    268260
    269261        echo '<script>jQuery(window).on("load", function(){document.getElementById("loadingBar").style.display="none",document.getElementById("infoBox").style.display="block",document.getElementById("iyzipay-checkout-form").style.display="block"});</script>';
    270262
    271         if(isset($requestResponse->status)) {
    272             if($requestResponse->status == 'success') {
     263        if(isset($requestResponse->status)) {
     264            if($requestResponse->status == 'success') {
    273265                echo $message;
    274                 echo ' <div style="display:none" id="iyzipay-checkout-form" class='.$className.'>' . $requestResponse->checkoutFormContent . '</div>';
    275                 echo '<p style="display:none;" id="iyziVersion">'.$this->iyziV.'</p>';
     266
     267                echo ' <div style="display:none" id="iyzipay-checkout-form" class=' . $className . '>' . $requestResponse->checkoutFormContent . '</div>';
     268                echo '<p style="display:none;" id="iyziVersion">' . $this->iyziV . '</p>';
    276269            } else {
    277270                echo $requestResponse->errorMessage;
    278271            }
    279 
    280272        } else {
    281273            echo 'Not Connection...';
    282274        }
    283 
    284     }
    285 
    286     public function iyzico_response($webhook = null, $webhookPaymentConversationId = null, $webhookToken = null, $webhookIyziEventType = null) {
     275    }
     276
     277    public function iyzico_response($webhook = null, $webhookPaymentConversationId = null, $webhookToken = null, $webhookIyziEventType = null)
     278    {
    287279
    288280        global $woocommerce;
    289281
    290 
    291282        try {
    292           if(!isset($_POST['token']) && $webhook != 'webhook')
    293           {
    294             exit;
    295           }
    296           if(!isset($webhookToken) && $webhook == 'webhook')
    297           {
    298             exit;
    299           }
     283            if (!isset($_POST['token']) && $webhook != 'webhook') {
     284                exit;
     285            }
     286            if (!isset($webhookToken) && $webhook == 'webhook') {
     287                exit;
     288            }
    300289
    301290            $token           = $_POST['token'];
     
    303292            $secretKey       = $this->settings['secret_key'];
    304293            $baseUrl         = $this->settings['api_type'];
    305             $rand            = rand(1,99999);
     294            $rand            = rand(1,99999);
    306295            $conversationId  = "";
    307296
    308             if ($webhook == 'webhook'){
     297            if ($webhook == 'webhook'){
    309298                $token = $webhookToken;
    310299                $conversationId = $webhookPaymentConversationId;
     
    312301
    313302
    314             $iyziModel       = new Iyzico_Checkout_For_WooCommerce_Model();
     303            $iyziModel       = new Iyzico_Checkout_For_WooCommerce_Model();
    315304
    316305            $responseObjectGenerate    = new Iyzico_Checkout_For_WooCommerce_ResponseObjectGenerate();
     
    318307            $iyzicoRequest             = new Iyzico_Checkout_For_WooCommerce_iyzicoRequest();
    319308
    320             $tokenDetailObject         = $responseObjectGenerate->generateTokenDetailObject($conversationId,$token);
     309            $tokenDetailObject         = $responseObjectGenerate->generateTokenDetailObject($conversationId,$token);
    321310            $pkiString                 = $pkiBuilder->pkiStringGenerate($tokenDetailObject);
    322             $authorizationData         = $pkiBuilder->authorizationGenerate($pkiString,$apiKey,$secretKey,$rand);
    323             $tokenDetailObject         = json_encode($tokenDetailObject,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
    324             $requestResponse           = $iyzicoRequest->iyzicoCheckoutFormDetailRequest($baseUrl,$tokenDetailObject,$authorizationData);
    325 
    326             if(!isset($requestResponse->basketId))
    327             {
    328                     exit;
    329                 }
     311            $authorizationData         = $pkiBuilder->authorizationGenerate($pkiString, $apiKey, $secretKey, $rand);
     312            $tokenDetailObject         = json_encode($tokenDetailObject, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     313            $requestResponse           = $iyzicoRequest->iyzicoCheckoutFormDetailRequest($baseUrl, $tokenDetailObject, $authorizationData);
     314
     315            if (!isset($requestResponse->basketId)) {
     316                exit;
     317            }
    330318            $order = new WC_Order($requestResponse->basketId);
    331319
     
    333321
    334322
    335             if ($webhook == 'webhook' && $requestResponse->status == 'failure'){
    336                 return new WP_Error( $requestResponse->errorCode, $requestResponse->errorMessage, array( 'status' => 404 ) );
    337             }
    338 
    339             if($webhook == 'webhook')
    340             {
    341               if($webhookIyziEventType == 'CREDIT_PAYMENT_PENDING' && $requestResponse->paymentStatus == 'PENDING_CREDIT')
    342               {
    343                 $orderMessage = 'Alışveriş kredisi başvurusu sürecindedir.';
    344                 $order->add_order_note($orderMessage,0,true);
    345                 $order->update_status("on-hold");
     323            if ($webhook == 'webhook' && $requestResponse->status == 'failure') {
     324                return new WP_Error($requestResponse->errorCode, $requestResponse->errorMessage, array('status' => 404));
     325            }
     326
     327            if ($webhook == 'webhook') {
     328                if ($webhookIyziEventType == 'CREDIT_PAYMENT_PENDING' && $requestResponse->paymentStatus == 'PENDING_CREDIT') {
     329                    $orderMessage = 'Alışveriş kredisi başvurusu sürecindedir.';
     330                    $order->add_order_note($orderMessage, 0, true);
     331                    $order->update_status("on-hold");
     332                    return http_response_code(200);
     333                }
     334                if ($webhookIyziEventType == 'CREDIT_PAYMENT_AUTH' && $requestResponse->status == 'success') {
     335                    $orderMessage = 'Alışveriş kredisi işlemi başarıyla tamamlandı.';
     336                    $order->add_order_note($orderMessage, 0, true);
     337                    $order->update_status("processing");
     338                    return http_response_code(200);
     339                }
     340                if ($webhookIyziEventType == 'CREDIT_PAYMENT_INIT' && $requestResponse->status == 'INIT_CREDIT') {
     341                    $orderMessage = 'Alışveriş kredisi işlemi başlatıldı.';
     342                    $order->add_order_note($orderMessage, 0, true);
     343                    $order->update_status("on-hold");
     344                    return http_response_code(200);
     345                }
     346            }
     347
     348            if ($webhook == 'webhook' && $order->get_status() == 'processing') {
    346349                return http_response_code(200);
    347               }
    348               if($webhookIyziEventType == 'CREDIT_PAYMENT_AUTH' && $requestResponse->status == 'success')
    349               {
    350                  $orderMessage = 'Alışveriş kredisi işlemi başarıyla tamamlandı.';
    351                  $order->add_order_note($orderMessage,0,true);
    352                  $order->update_status("processing");
    353                  return http_response_code(200);
    354               }
    355               if($webhookIyziEventType =='CREDIT_PAYMENT_INIT' && $requestResponse->status == 'INIT_CREDIT')
    356               {
    357                  $orderMessage = 'Alışveriş kredisi işlemi başlatıldı.';
    358                  $order->add_order_note($orderMessage,0,true);
    359                  $order->update_status("on-hold");
    360                  return http_response_code(200);
    361               }
    362 
    363 
    364             }
    365 
    366             if ($webhook == 'webhook' && $order->get_status() == 'processing'){
    367                 return http_response_code(200);
    368             }
    369 
    370             if(!$order->get_payment_method_title()) {
     350            }
     351
     352            if (!$order->get_payment_method_title()) {
    371353                $order->set_payment_method_title("iyzico ile Öde");
    372354            }
    373355
    374             if($requestResponse->paymentStatus == 'INIT_BANK_TRANSFER' && $requestResponse->status == 'success') {
     356            if($requestResponse->paymentStatus == 'INIT_BANK_TRANSFER' && $requestResponse->status == 'success') {
    375357
    376358                $order->update_status("on-hold");
    377359                $orderMessage = 'iyzico Banka havalesi/EFT ödemesi bekleniyor.';
    378                 $order->add_order_note($orderMessage,0,true);
     360                $order->add_order_note($orderMessage,true);
    379361                $woocommerce->cart->empty_cart();
    380                 update_option('iyzico_thank_you',0);
     362                update_option('iyzico_thank_you',0);
    381363                $checkoutOrderUrl = $order->get_checkout_order_received_url();
    382364                $redirectUrl = add_query_arg(array('msg' => 'Thank You', 'type' => 'woocommerce-message'), $checkoutOrderUrl);
     
    384366            }
    385367            $thankYouPage = get_option('iyzico_thank_you');
    386             if(!$thankYouPage)
    387             {
    388                 add_option('iyzico_thank_you',0,'','no');
    389             }
    390             if($webhook != 'webhook' && $requestResponse->paymentStatus == 'PENDING_CREDIT' && $requestResponse->status == 'success') {
     368            if (!$thankYouPage) {
     369                add_option('iyzico_thank_you', 0, '', 'no');
     370            }
     371            if ($webhook != 'webhook' && $requestResponse->paymentStatus == 'PENDING_CREDIT' && $requestResponse->status == 'success') {
    391372
    392373                $order->update_status("on-hold");
    393                 $orderMessage = 'PAYMENT ID:'.$requestResponse->paymentId;
    394                 $order->add_order_note($orderMessage,0,true);
     374                $orderMessage = 'PAYMENT ID:'$requestResponse->paymentId;
     375                $order->add_order_note($orderMessage,true);
    395376                $woocommerce->cart->empty_cart();
    396377                $checkoutOrderUrl = $order->get_checkout_order_received_url();
    397                 update_option('iyzico_thank_you',1);
    398                 $redirectUrl = add_query_arg(array('msg' => 'Thank You', 'type' => 'woocommerce-message' ), $checkoutOrderUrl );
     378                update_option('iyzico_thank_you',1);
     379                $redirectUrl = add_query_arg(array('msg' => 'Thank You', 'type' => 'woocommerce-message');
    399380                return wp_redirect($redirectUrl);
    400381            }
     
    414395
    415396
    416             if($requestResponse->paymentStatus != 'SUCCESS' || $requestResponse->status != 'success' || $orderId != $requestResponse->basketId ) {
    417 
    418                 if($requestResponse->status == 'success' && $requestResponse->paymentStatus == 'FAILURE') {
     397            if) {
     398
     399                if($requestResponse->status == 'success' && $requestResponse->paymentStatus == 'FAILURE') {
    419400
    420401                    throw new  \Exception(__("3D security has not been validated for your card.", 'woocommerce-iyzico'));
    421 
    422402                }
    423403                /* Redirect Error */
     
    428408
    429409            /* Save Card */
    430             if(isset($requestResponse->cardUserKey)) {
    431 
    432                 if($customerId) {
    433 
    434                     $cardUserKey = $iyziModel->findUserCardKey($customerId,$apiKey);
    435 
    436                     if($requestResponse->cardUserKey != $cardUserKey) {
    437 
    438                         $insertCardUserKey = $iyziModel->insertCardUserKey($customerId,$requestResponse->cardUserKey,$apiKey);
    439 
     410            if (isset($requestResponse->cardUserKey)) {
     411
     412                if ($customerId) {
     413
     414                    $cardUserKey = $iyziModel->findUserCardKey($customerId, $apiKey);
     415
     416                    if ($requestResponse->cardUserKey != $cardUserKey) {
     417
     418                        $insertCardUserKey = $iyziModel->insertCardUserKey($customerId, $requestResponse->cardUserKey, $apiKey);
    440419                    }
    441 
    442420                }
    443 
    444             }
    445 
    446 
    447 
    448             $orderMessage = 'PAYMENT ID:'.$requestResponse->paymentId;
    449             $order->add_order_note($orderMessage,0,true);
    450 
    451             if($baseUrl == 'https://sandbox-api.iyzipay.com') {
     421            }
     422
     423            $orderMessage = 'PAYMENT ID:' . $requestResponse->paymentId;
     424            $order->add_order_note($orderMessage, 0, true);
     425
     426            if ($baseUrl == 'https://sandbox-api.iyzipay.com') {
    452427
    453428                $orderMessage = '<strong><p style="color:red">TEST ÖDEMESİ</a></strong>';
    454                 $order->add_order_note($orderMessage,0,true);
     429                $order->add_order_note($orderMessage,true);
    455430            }
    456431
     
    463438
    464439                $item_fee = new WC_Order_Item_Fee();
    465                 $item_fee->set_name($requestResponse->installment . " " .__("Installment Commission", 'woocommerce-iyzico'));
     440                $item_fee->set_name($requestResponse->installment . " " .__("Installment Commission", 'woocommerce-iyzico'));
    466441                $item_fee->set_amount($installment_fee);
    467                 $item_fee->set_tax_class( '' );
    468                 $item_fee->set_tax_status( 'none' );
     442                $item_fee->set_tax_class();
     443                $item_fee->set_tax_status();
    469444                $item_fee->set_total($installment_fee);
    470445
    471                 $order->add_item( $item_fee );
     446                $order->add_item();
    472447                $order->calculate_totals(true);
    473448
    474                 update_post_meta($orderId, 'iyzico_no_of_installment',$requestResponse->installment);
     449                update_post_meta($orderId, 'iyzico_no_of_installment',$requestResponse->installment);
    475450                update_post_meta($orderId, 'iyzico_installment_fee', $installment_fee);
    476451            }
     
    482457            $orderStatus = $this->settings['order_status'];
    483458
    484             if($orderStatus != 'default' && !empty($orderStatus)) {
     459            if($orderStatus != 'default' && !empty($orderStatus)) {
    485460                $order->update_status($orderStatus);
    486461            }
    487462
    488463
    489             if($webhook == 'webhook'){
     464            if{
    490465                return http_response_code(200);
    491466            }
    492467
    493468            $woocommerce->cart->empty_cart();
    494             update_option('iyzico_thank_you',0);
     469            update_option('iyzico_thank_you',0);
    495470
    496471            $checkoutOrderUrl = $order->get_checkout_order_received_url();
    497             $redirectUrl = add_query_arg(array('msg' => 'Thank You', 'type' => 'woocommerce-message' ), $checkoutOrderUrl);
     472            $redirectUrl = add_query_arg(array('msg' => 'Thank You', 'type' => 'woocommerce-message'), $checkoutOrderUrl);
    498473
    499474
    500475
    501476            return wp_redirect($redirectUrl);
    502 
    503477        } catch (Exception $e) {
    504478
    505             if ($webhook == 'webhook'){
    506                 return new WP_Error( $requestResponse->errorCode, $requestResponse->errorMessage, array( 'status' => 404 ) );
     479            if ($webhook == 'webhook'){
     480                return new WP_Error();
    507481            }
    508482
     
    510484            $order = new WC_Order($orderId);
    511485            $order->update_status('failed');
    512             $order->add_order_note($respMsg,0,true);
     486            $order->add_order_note($respMsg,true);
    513487
    514488            wc_add_notice(__($respMsg, 'woocommerce-message'), 'error');
     
    517491            return wp_redirect($redirectUrl);
    518492        }
    519 
    520493    }
    521494
    522495
    523496    /*ThankYou Page Edit */
    524    public function thankYouSubtitle() {
    525      $thankYouPage = get_option('iyzico_thank_you');
    526 
    527      if($thankYouPage == 1)
    528      {
    529        $thankYouPageText = 'Alışveriş Kredisi için başvurunuz alınmıştır. Başvurunuz, en kısa sürede sonuçlandırılacaktır.';
    530 
    531        $sh = '<h4><center>'.$thankYouPageText.'</center></h4><br></br>';
    532        $sh .='<div class="tx_account"></div>';
    533 
    534         echo $sh;
    535 
    536      }
    537 
    538        }
    539 
    540     public function initIyzicoWebhookUrl() {
     497    public function thankYouSubtitle()
     498    {
     499        $thankYouPage = get_option('iyzico_thank_you');
     500
     501        if ($thankYouPage == 1) {
     502            $thankYouPageText = 'Alışveriş Kredisi için başvurunuz alınmıştır. Başvurunuz, en kısa sürede sonuçlandırılacaktır.';
     503
     504            $sh = '<h4><center>' . $thankYouPageText . '</center></h4><br></br>';
     505            $sh .= '<div class="tx_account"></div>';
     506
     507            echo $sh;
     508        }
     509    }
     510
     511    public function initIyzicoWebhookUrl()
     512    {
    541513
    542514        $initInstallWebhookUrl = get_option('init_active_webhook_url');
    543         if(!$initInstallWebhookUrl){
    544 
    545             add_option('init_active_webhook_url',0,'','no');
     515        if{
     516
     517            add_option('init_active_webhook_url','no');
    546518        }
    547519
    548520        return self::initSetWebhookUrlKey();
    549           }
    550 
    551 
    552        /*Set Webhook request */
    553     public function initSetWebhookUrlKey() {
    554 
    555       $initInstallWebhookUrl = get_option('init_active_webhook_url');
    556       $iyzicoWebhookUrlKey = IyzicoWebhook::getIyziUrlId();
    557       if($initInstallWebhookUrl == 0)
    558       {
    559         if(isset($this->settings['api_key']) && isset($this->settings['secret_key'])  && isset($iyzicoWebhookUrlKey) && isset($_SERVER['HTTPS']))
    560       {
    561 
    562           $pkiBuilder                 = new Iyzico_Checkout_For_WooCommerce_PkiBuilder();
    563           $iyzicoRequest              = new Iyzico_Checkout_For_WooCommerce_iyzicoRequest();
    564 
    565           $apiKey                     = $this->settings['api_key'];
    566           $secretKey                  = $this->settings['secret_key'];
    567           $baseUrl                    = $this->settings['api_type'];
    568           $randNumer                  = rand(100000,99999999);
    569 
    570           $setWebhookUrl = new stdClass();
    571           $setWebhookUrl->webhookUrl        = get_site_url()."/wp-json/iyzico/v1/webhook/". IyzicoWebhook::getIyziUrlId();
    572 
    573           $pkiString                = $pkiBuilder->pkiStringGenerate($setWebhookUrl);
    574           $authorizationData        = $pkiBuilder->authorizationGenerate($pkiString,$apiKey,$secretKey,$randNumer);
    575 
    576 
    577           $iyzicoJson               = json_encode($setWebhookUrl,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
    578 
    579           $requestResponseWebhook          = $iyzicoRequest->iyzicoPostWebhookUrlKey($baseUrl,$iyzicoJson,$authorizationData);
    580 
    581 
    582 
    583           if($requestResponseWebhook->merchantNotificationUpdateStatus == 'UPDATED' || $requestResponseWebhook->merchantNotificationUpdateStatus == 'CREATED')
    584           {
    585             update_option('init_active_webhook_url',1);
    586             return true;
    587           }
    588           elseif ($requestResponseWebhook->merchantNotificationUpdateStatus == 'NOT_UPDATED') {
    589             update_option('init_active_webhook_url',2);
    590             return false;
    591           }
    592           else {
    593             update_option('init_active_webhook_url',2);
    594           }
    595       }
    596          }
    597       return true;
    598        }
    599 
    600        /* Submit  Webhook*/
    601        public static function iyzicoWebhookSubmitbutton($submitSave = null)
    602       {
     521    }
     522
     523
     524    /*Set Webhook request */
     525    public function initSetWebhookUrlKey()
     526    {
     527
    603528        $initInstallWebhookUrl = get_option('init_active_webhook_url');
    604         if($initInstallWebhookUrl == 2)
    605         {
    606           if($submitSave == 'submit')
    607           {
    608                 return update_option('init_active_webhook_url',0);
    609           }
    610 
    611         }
    612 
    613       }
    614 
    615 
    616     private function versionCheck() {
     529        $iyzicoWebhookUrlKey = IyzicoWebhook::getIyziUrlId();
     530        if ($initInstallWebhookUrl == 0) {
     531            if (isset($this->settings['api_key']) && isset($this->settings['secret_key'])  && isset($iyzicoWebhookUrlKey) && isset($_SERVER['HTTPS'])) {
     532
     533                $pkiBuilder                 = new Iyzico_Checkout_For_WooCommerce_PkiBuilder();
     534                $iyzicoRequest              = new Iyzico_Checkout_For_WooCommerce_iyzicoRequest();
     535
     536                $apiKey                     = $this->settings['api_key'];
     537                $secretKey                  = $this->settings['secret_key'];
     538                $baseUrl                    = $this->settings['api_type'];
     539                $randNumer                  = rand(100000, 99999999);
     540
     541                $setWebhookUrl = new stdClass();
     542                $setWebhookUrl->webhookUrl        = get_site_url() . "/wp-json/iyzico/v1/webhook/" . IyzicoWebhook::getIyziUrlId();
     543
     544                $pkiString                = $pkiBuilder->pkiStringGenerate($setWebhookUrl);
     545                $authorizationData        = $pkiBuilder->authorizationGenerate($pkiString, $apiKey, $secretKey, $randNumer);
     546
     547
     548                $iyzicoJson               = json_encode($setWebhookUrl, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     549
     550                $requestResponseWebhook          = $iyzicoRequest->iyzicoPostWebhookUrlKey($baseUrl, $iyzicoJson, $authorizationData);
     551
     552
     553
     554                if ($requestResponseWebhook->merchantNotificationUpdateStatus == 'UPDATED' || $requestResponseWebhook->merchantNotificationUpdateStatus == 'CREATED') {
     555                    update_option('init_active_webhook_url', 1);
     556                    return true;
     557                } elseif ($requestResponseWebhook->merchantNotificationUpdateStatus == 'NOT_UPDATED') {
     558                    update_option('init_active_webhook_url', 2);
     559                    return false;
     560                } else {
     561                    update_option('init_active_webhook_url', 2);
     562                }
     563            }
     564        }
     565        return true;
     566    }
     567
     568    /* Submit  Webhook*/
     569    public static function iyzicoWebhookSubmitbutton($submitSave = null)
     570    {
     571        $initInstallWebhookUrl = get_option('init_active_webhook_url');
     572        if ($initInstallWebhookUrl == 2) {
     573            if ($submitSave == 'submit') {
     574                return update_option('init_active_webhook_url', 0);
     575            }
     576        }
     577    }
     578
     579    public function is_available()
     580    {
     581        return true;
     582    }
     583
     584
     585    private function versionCheck()
     586    {
    617587
    618588        $phpVersion = phpversion();
     
    623593        /* Required PHP */
    624594        $warningMessage = 'Required PHP 5.4 and greater for iyzico WooCommerce Payment Gateway';
    625         if($locale == 'tr') {
     595        if($locale == 'tr') {
    626596            $warningMessage = 'iyzico WooCommerce eklentisini çalıştırabilmek için, PHP 5.4 veya üzeri versiyonları kullanmanız gerekmektedir. ';
    627597        }
    628598
    629         if($phpVersion < $requiredPhpVersion) {
     599        if($phpVersion < $requiredPhpVersion) {
    630600            echo $warningMessage;
    631601            exit;
     
    638608        $warningMessage = 'Required WooCommerce 3.0 and greater for iyzico WooCommerce Payment Gateway';
    639609
    640         if($locale == 'tr') {
     610        if($locale == 'tr') {
    641611            $warningMessage = 'iyzico WooCommerce eklentisini çalıştırabilmek için, WooCommerce 3.0 veya üzeri versiyonları kullanmanız gerekmektedir. ';
    642612        }
    643613
    644         if($wooCommerceVersion < $requiredWoocommerceVersion) {
     614        if($wooCommerceVersion < $requiredWoocommerceVersion) {
    645615            echo $warningMessage;
    646616            exit;
     
    651621        $tlsVersion = get_option('iyziTLS');
    652622
    653         if(!$tlsVersion) {
     623        if(!$tlsVersion) {
    654624
    655625            $result = $this->verifyTLS($tlsUrl);
    656             if($result) {
    657                 add_option('iyziTLS',1.2,'','no');
     626            if($result) {
     627                add_option('iyziTLS','no');
    658628                $tlsVersion = get_option('iyziTLS');
    659629            }
    660 
    661         } elseif($tlsVersion != 1.2) {
     630        } elseif ($tlsVersion != 1.2) {
    662631
    663632            $result = $this->verifyTLS($tlsUrl);
    664             if($result) {
    665                 update_option('iyziTLS',1.2);
     633            if($result) {
     634                update_option('iyziTLS',1.2);
    666635                $tlsVersion = get_option('iyziTLS');
    667636            }
     
    673642        $warningMessage = 'WARNING! Minimum TLS v1.2 will be supported after March 2018. Please upgrade your openssl version to minimum 1.0.1.';
    674643
    675         if($locale == 'tr') {
     644        if($locale == 'tr') {
    676645            $warningMessage = "UYARI! Ödeme formunuzu görüntüleyebilmeniz için, TLS versiyonunuzun minimum TLS v1.2 olması gerekmektedir. Lütfen servis sağlayıcınız ile görüşerek openssl versiyonunuzu minimum 1.0.1'e yükseltin.";
    677646        }
    678647
    679         if($tlsVersion < $requiredTlsVersion) {
     648        if($tlsVersion < $requiredTlsVersion) {
    680649            echo $warningMessage;
    681650            exit;
     
    683652    }
    684653
    685     private function verifyTLS($url) {
     654    private function verifyTLS($url)
     655    {
    686656
    687657        $curl = curl_init();
  • iyzico-woocommerce/trunk/library/iyzico-pwi-for-woocommerce-gateway.php

    r2893353 r3036107  
    1010
    1111        $this->id    = 'iyzico_pwi';
    12         $this->iyziV = '1.0.5';
     12        $this->iyziV = '';
    1313        $this->method_title = __('Pay with iyzico', 'woocommerce-iyzico');
    1414        $this->method_description = __('Best Payment Solution', 'woocommerce-iyzico');
     
    135135        echo $html;
    136136    }
     137
     138
     139
     140
     141
    137142}
  • iyzico-woocommerce/trunk/readme.txt

    r2934987 r3036107  
    11=== iyzico WooCommerce ===
    22Contributors: iyzico,mehmetselim,sozgat,feyzullahdemir
    3 Tags: payment, ecommerce,credit card,checkout woocommerce,iyzico,wordpress ecommerce
    4 Tested up to: 6.2.2
    5 Stable tag: 3.2.6
     3Tags: payment, ecommerce,wordpress ecommerce
     4Tested up to: 6.
     5Stable tag: 3.
    66Requires at least: 4.7
    77Requires PHP: 5.4
     
    5858
    5959== Changelog ==
     60
     61
     62
     63
    6064
    6165= 3.2.6 =
  • iyzico-woocommerce/trunk/woocommerce-gateway-iyzico.php

    r2934987 r3036107  
    11<?php
     2
    23/**
    34 * Plugin Name: iyzico WooCommerce
     
    67 * Author: iyzico
    78 * Author URI: https://iyzico.com
    8  * Version: 3.2.6
     9 * Version: 3.
    910 * Text Domain: iyzico WooCommerce
    1011 * Domain Path: /i18n/languages/
    1112 * WC requires at least: 3.0.0
    12  * WC tested up to: 7.8.0
     13 * WC tested up to:
    1314 */
    14 define('IYZICO_PATH',untrailingslashit( plugin_dir_path( __FILE__ )));
    15 define('IYZICO_LANG_PATH',plugin_basename(dirname(__FILE__)) . '/i18n/languages/');
    16 define('IYZICO_PLUGIN_NAME','/'.plugin_basename(dirname(__FILE__)));
     15
     16use Automattic\WooCommerce\Utilities\FeaturesUtil;
     17
     18define('IYZICO_PATH', untrailingslashit(plugin_dir_path(__FILE__)));
     19define('IYZICO_LANG_PATH', plugin_basename(dirname(__FILE__)) . '/i18n/languages/');
     20define('IYZICO_PLUGIN_NAME', '/' . plugin_basename(dirname(__FILE__)));
    1721define('IYZICO_WEBHOOK_URL_KEY', 'iyzicoWebhookUrlKey');
    1822
     
    2024    exit;
    2125}
    22 if ( ! class_exists( 'Iyzico_For_WooCommerce' ) ) {
    23 
    24     class Iyzico_For_WooCommerce {
     26if (!class_exists('Iyzico_For_WooCommerce')) {
     27
     28    class Iyzico_For_WooCommerce
     29    {
    2530
    2631        public static $webhookUrlValue;
    2732        protected static $instance;
    2833
    29         public static function get_instance() {
    30 
    31             if ( null === self::$instance ) {
     34        public static function get_instance()
     35        {
     36
     37            if (null === self::$instance) {
    3238                self::$instance = new self();
    3339            }
     
    3642        }
    3743
    38         protected function __construct() {
    39 
    40             add_action('plugins_loaded', array($this,'init'));
    41 
    42         }
    43 
    44         public static function IyzicoActive() {
     44        protected function __construct()
     45        {
     46            add_action('plugins_loaded', array($this, 'init'));
     47            // Blocks Support
     48            add_action('woocommerce_blocks_loaded', array($this, 'iyzico_woocommerce_blocks_support'));
     49            add_action('before_woocommerce_init', array($this, 'iyzico_cart_checkout_blocks_compatibility'));
     50        }
     51
     52        public static function IyzicoActive()
     53        {
    4554
    4655            global $wpdb;
     
    5968            ) $charset_collate;";
    6069
    61             require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     70            require_once();
    6271            dbDelta($sql);
    6372
     
    7281            ) $charset_collate;";
    7382            dbDelta($sql);
    74 
    75 
    76         }
    77 
    78         public static function IyzicoDeactive() {
     83        }
     84
     85        public static function IyzicoDeactive()
     86        {
    7987
    8088            global $wpdb;
     
    96104        }
    97105
    98         public static function paymentIdAlterTable(){
    99           global $wpdb;
    100           $table = $wpdb->prefix . 'iyzico_order';
    101           $sql = "ALTER TABLE `{$table}`
     106        public static function paymentIdAlterTable()
     107        {
     108            global $wpdb;
     109            $table = $wpdb->prefix . 'iyzico_order';
     110            $sql = "ALTER TABLE `{$table}`
    102111                MODIFY COLUMN `payment_id` bigint(11) NOT NULL;";
    103           require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    104           $query_result = $wpdb->query( $sql );
    105         }
    106 
    107         public function init() {
    108 
     112          );
     113          );
     114        }
     115
     116        public function init()
     117        {
    109118            $this->InitIyzicoPaymentGateway();
    110119            self::createIyzicoWebhookUrlKey();
    111120            self::paymentIdAlterTable();
    112 
    113 
    114         }
    115 
    116 
    117         public static function installLanguage() {
    118 
    119           load_plugin_textdomain('woocommerce-iyzico',false,IYZICO_LANG_PATH);
    120 
    121         }
    122 
    123         public function InitIyzicoPaymentGateway() {
    124 
    125             if ( ! class_exists('WC_Payment_Gateway')) {
     121        }
     122
     123
     124        /**
     125         *
     126         * @since 3.2.0
     127         * @version 1.0.0
     128         * action: before_woocommerce_init
     129         *
     130         */
     131        public function iyzico_cart_checkout_blocks_compatibility()
     132        {
     133            if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) {
     134                FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true);
     135            }
     136        }
     137
     138        /**
     139         *
     140         * @since 3.2.0
     141         * @version 1.0.0
     142         * action: woocommerce_blocks_loaded
     143         *
     144         */
     145        public function iyzico_woocommerce_blocks_support()
     146        {
     147            if (!class_exists('Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType')) {
     148                return;
     149            }
     150
     151            include_once IYZICO_PATH . '/library/iyzico-for-woocommerce-blocks.php';
     152
     153            add_action(
     154                'woocommerce_blocks_payment_method_type_registration',
     155                function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) {
     156                    $payment_method_registry->register(new Iyzico_For_WooCommerce_Blocks);
     157                }
     158            );
     159        }
     160
     161
     162
     163        public static function installLanguage()
     164        {
     165
     166            load_plugin_textdomain('woocommerce-iyzico', false, IYZICO_LANG_PATH);
     167        }
     168
     169        public function InitIyzicoPaymentGateway()
     170        {
     171
     172            if (!class_exists('WC_Payment_Gateway')) {
    126173                return;
    127174            }
     
    141188            include_once IYZICO_PATH . '/library/iyzico-pwi-for-woocommerce-gateway-fields.php';
    142189
    143             add_action( 'rest_api_init', array('IyzicoWebhook','iyzicoRegisterRestRoutes') );
    144 
    145             add_filter('woocommerce_payment_gateways',array($this,'AddIyzicoGateway'));
    146 
    147             add_action( 'wp_footer',
    148                 array('Iyzico_Checkout_For_WooCommerce_Buyer_Protection',
    149                     'iyzicoOverlayScriptMobileCss') );
    150 
    151 
    152 
    153 
    154             add_action('wp_footer',
    155                         array('Iyzico_Checkout_For_WooCommerce_Buyer_Protection',
    156                         'getOverlayScript'));
    157 
    158             add_action('woocommerce_admin_order_data_after_shipping_address',
    159                         array('Iyzico_Checkout_For_WooCommerce_Buyer_Protection',
    160                         'iyziCargoTracking'));
    161 
    162             add_action('woocommerce_process_shop_order_meta',
    163                         array('Iyzico_Checkout_For_WooCommerce_Buyer_Protection',
    164                         'iyziCargoTrackingSave'));
    165 
    166             if (is_admin()){
    167                 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ),
    168                     array($this,
    169                         'actionLinks' ) );
    170             }
    171         }
    172 
    173         public function AddIyzicoGateway($methods) {
     190            add_action('rest_api_init', array('IyzicoWebhook', 'iyzicoRegisterRestRoutes'));
     191
     192            add_filter('woocommerce_payment_gateways', array($this, 'AddIyzicoGateway'));
     193
     194            add_action(
     195                'wp_footer',
     196                array(
     197                    'Iyzico_Checkout_For_WooCommerce_Buyer_Protection',
     198                    'iyzicoOverlayScriptMobileCss'
     199                )
     200            );
     201
     202            add_action(
     203                'wp_footer',
     204                array(
     205                    'Iyzico_Checkout_For_WooCommerce_Buyer_Protection',
     206                    'getOverlayScript'
     207                )
     208            );
     209
     210            add_action(
     211                'woocommerce_admin_order_data_after_shipping_address',
     212                array(
     213                    'Iyzico_Checkout_For_WooCommerce_Buyer_Protection',
     214                    'iyziCargoTracking'
     215                )
     216            );
     217
     218            add_action(
     219                'woocommerce_process_shop_order_meta',
     220                array(
     221                    'Iyzico_Checkout_For_WooCommerce_Buyer_Protection',
     222                    'iyziCargoTrackingSave'
     223                )
     224            );
     225
     226            if (is_admin()) {
     227                add_filter(
     228                    'plugin_action_links_' . plugin_basename(__FILE__),
     229                    array(
     230                        $this,
     231                        'actionLinks'
     232                    )
     233                );
     234            }
     235        }
     236
     237        public function AddIyzicoGateway($methods)
     238        {
    174239
    175240            $methods[] = 'Iyzico_Checkout_For_WooCommerce_Gateway';
     
    187252         * @return  array
    188253         */
    189         public function actionLinks( $links ) {
     254        public function actionLinks($links)
     255        {
    190256            $custom_links   = array();
    191             $custom_links[] = '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout&section=iyzico' ) . '">' . __( 'Settings', 'woocommerce' ) . '</a>';
    192             $custom_links[] = '<a target="_blank" href="https://dev.iyzipay.com/tr/acik-kaynak/woocommerce">' . __( 'Docs', 'woocommerce' ) . '</a>';
    193             $custom_links[] = '<a target="_blank" href="https://www.iyzico.com/destek/iletisim">' . __( 'Support', 'woocommerce-iyzico' ) . '</a>';
    194             return array_merge( $custom_links, $links );
     257            $custom_links[] = '<a href="' . admin_url() . '</a>';
     258            $custom_links[] = '<a target="_blank" href="https://dev.iyzipay.com/tr/acik-kaynak/woocommerce">' . __() . '</a>';
     259            $custom_links[] = '<a target="_blank" href="https://www.iyzico.com/destek/iletisim">' . __() . '</a>';
     260            return array_merge();
    195261        }
    196262
     
    201267         * @since   3.1.0
    202268         */
    203         private function createIyzicoWebhookUrlKey(){
    204             $uniqueUrlId = substr(base64_encode(time() . mt_rand()),15,6);
     269        private function createIyzicoWebhookUrlKey()
     270        {
     271            $uniqueUrlId = substr(base64_encode(time() . mt_rand()), 15, 6);
    205272            $iyziUrlId = get_option(IYZICO_WEBHOOK_URL_KEY);
    206             if (!$iyziUrlId){
    207                 add_option(IYZICO_WEBHOOK_URL_KEY, $uniqueUrlId , '' ,'no');
    208             }
    209 
    210         }
    211 
    212 
     273            if (!$iyziUrlId) {
     274                add_option(IYZICO_WEBHOOK_URL_KEY, $uniqueUrlId, '', 'no');
     275            }
     276        }
    213277    }
    214278
    215 Iyzico_For_WooCommerce::get_instance();
    216 add_action('plugins_loaded',array('Iyzico_For_WooCommerce','installLanguage'));
    217 add_action( 'before_woocommerce_init', function() {
    218     if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
    219         \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
    220     }
    221 } );
    222 register_activation_hook(__FILE__, array('Iyzico_For_WooCommerce','IyzicoActive'));
    223 register_deactivation_hook(__FILE__,array('Iyzico_For_WooCommerce','IyzicoDeactive'));
     279    Iyzico_For_WooCommerce::get_instance();
     280    add_action('plugins_loaded', array('Iyzico_For_WooCommerce', 'installLanguage'));
     281    register_activation_hook(__FILE__, array('Iyzico_For_WooCommerce', 'IyzicoActive'));
     282    register_deactivation_hook(__FILE__, array('Iyzico_For_WooCommerce', 'IyzicoDeactive'));
    224283}
Note: See TracChangeset for help on using the changeset viewer.