Plugin Directory

Changeset 2381907


Ignore:
Timestamp:
09/15/2020 01:08:40 PM (6 years ago)
Author:
alonezcount
Message:

move session to URL param

Location:
ezcount/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ezcount/trunk/EZcount.php

    r2380267 r2381907  
    44 * Plugin URI:
    55 * Description: invoicing, clearing and paypal integration plugin.
    6  * Version: 1.10.7
     6 * Version: 1.11.2
    77 * Author: EZcount
    88 * Author URI:
     
    2424add_action( 'plugins_loaded', 'init_ezcount_gateway_class', 0 );
    2525
    26 // if the user will set the ?TEST_COOKIES=1 param, we will show the cookies
    27 if(@$_GET['EZ_TEST_COOKIES']){
    28     header('Content-Type: text/plain; charset=utf-8');
    29     var_dump($_COOKIE);
    30     var_dump($_SERVER);
    31     die();
    32 }
    3326
    3427function init_ezcount_gateway_class() {
     
    9992
    10093            $this->form_fields = array(
    101                 'environment'       => array(
     94                'environment'      => array(
    10295                    'title'       => __( 'Environment', $this->environment ),
    10396                    'type'        => 'select',
     
    107100                    'desc_tip'    => true,
    108101                ),
    109                 'api_key'           => array(
     102                'api_key'          => array(
    110103                    'title'       => __( 'API Key', $this->api_key ),
    111104                    'type'        => 'text',
     
    115108                    'required'    => true
    116109                ),
    117                 'user_email'        => array(
    118                     'title'       => __( 'Email Address', $this->user_email ),
     110                'user_email'       => array(
     111                    'title'       => __( 'Developer(!) email address', $this->user_email ),
    119112                    'type'        => 'text',
    120                     'description' => __( 'Please insert developer email address.', $this->user_email ),
     113                    'description' => __( 'We will send technical emails, to this address.', $this->user_email ),
    121114                    'default'     => $defaultEmail,
    122115                    'desc_tip'    => true,
    123116                    'required'    => true
    124117                ),
    125                 'checkout_window'   => array(
     118                'checkout_window'  => array(
    126119                    'title'       => __( 'Checkout Window Option', $this->environment ),
    127120                    'type'        => 'select',
     
    134127                    'desc_tip'    => true,
    135128                ),
    136                 'doc_type'          => array(
     129                'doc_type'         => array(
    137130                    'title'       => __( 'Doc Type', $this->doc_type ),
    138131                    'type'        => 'select',
     
    145138                    'desc_tip'    => true,
    146139                ),
    147 
    148140                'language_list'    => array(
    149141                    'title'       => __( 'Defult language list', $this->language_list ),
     
    216208            );
    217209
    218             $runIntegrationTest =  @$_GET['page'] == 'wc-settings' && @$_GET['tab'] == 'checkout' && @$_GET['section'] == "ezcount";
    219             if ($runIntegrationTest){
    220                 $integrationStatus = EZcount_helpers::testIntegration($this->environment,$this->api_key,$defaultEmail);
    221                 $arr = array();
    222                 $arr['integrationStatus'] =  array(
    223                     'title' => $integrationStatus[0]?"INTEGRATION TEST SUCCESS":"INTEGRATION TESTING ERROR! please fix the next issue",
     210            $runIntegrationTest = @$_GET['page'] == 'wc-settings' && @$_GET['tab'] == 'checkout' && @$_GET['section'] == "ezcount";
     211            if ( $runIntegrationTest ) {
     212                $integrationStatus        = EZcount_helpers::testIntegration( $this->environment, $this->api_key, $defaultEmail );
     213                $arr                      = array();
     214                $arr['integrationStatus'] = array(
     215                    'title'       => $integrationStatus[0] ? "INTEGRATION TEST SUCCESS" : "INTEGRATION TESTING ERROR! please fix the next issue",
    224216                    'description' => $integrationStatus[1],
    225                     'type' => 'title',
     217                    'type'        => 'title',
    226218                );
    227                 $this->form_fields = array_merge($arr, $this->form_fields);
    228             }
    229 
     219                $this->form_fields        = array_merge( $arr, $this->form_fields );
     220            }
    230221        }
    231222
     
    274265            $sum        = number_format( $order->get_total(), 2, '.', '' );
    275266
    276             $tab_id = base_convert( microtime(), 10, 32 );
    277267            //create a one time token...
    278             // some users open the clearing twice, and we want to user the right cookie for it
    279 
    280             $api_url = EZcount_helpers::getApiBase() . 'payment/prepareSafeUrl/clearingFormForWeb';
    281             $data    = array(
    282                 "sum"        => $sum,
    283                 "payments"   => $this->maxpayments_list,
    284                 "currency"   => "ILS",
    285                 "successUrl" => get_site_url() . '?wc-api=WC_Gateway_EZcount&response=success&order_id=' . $order_id . '&tab_id=' . $tab_id,
    286                 "failedUrl"  => get_site_url() . '?wc-api=WC_Gateway_EZcount&response=failed&order_id=' . $order_id . '&tab_id=' . $tab_id,
     268            //  some users open the clearing twice, and we want to user the right cookie for it
     269            $secretTransactionId  = wp_generate_uuid4();
     270            $session              = EZcount_helpers::encrypt( $secretTransactionId . "|" . $order_id, $api_key );
     271            $sessionBase64Encoded = base64_encode( $session );
     272            $api_url              = EZcount_helpers::getApiBase() . 'payment/prepareSafeUrl/clearingFormForWeb';
     273            $data                 = array(
     274                "sum"                 => $sum,
     275                "payments"            => $this->maxpayments_list,
     276                "currency"            => "ILS",
     277                "secretTransactionId" => $secretTransactionId,
     278                "successUrl"          => get_site_url() . '?wc-api=WC_Gateway_EZcount&response=success&order_id=' . $order_id . '&ezs=' . $sessionBase64Encoded,
     279                "failedUrl"           => get_site_url() . '?wc-api=WC_Gateway_EZcount&response=failed&order_id=' . $order_id . '&ezs=' . $sessionBase64Encoded,
    287280            );
    288 
    289281
    290282            $result = EZcount_helpers::sendJsonRequest( $api_url, $data );
     
    302294            }
    303295
    304             $data = json_encode( array(
    305                                      'order_id'            => $order_id,
    306                                      'tab_id'              => $tab_id,
    307                                      "secretTransactionId" => $result->secretTransactionId,
    308                                      "creation"            => time()
    309                                  ) );
    310             //encrypt the data
    311             $dataEncrypted = EZcount_helpers::encrypt( $data, $api_key );
    312 
    313             $name= "wc-ez-order-$order_id-$tab_id";
    314             $value=$dataEncrypted;
    315             //store for 5 days
    316             $expire= time() + 60 * 60 * 24 * 5;
    317 
    318             setcookie($name, $value, $expire, '/', null, is_ssl(), true);
    319 
    320             //https://stackoverflow.com/a/59654832/2992810
    321 //          if (PHP_VERSION_ID < 70300) {
    322 //              setcookie($name, $value, $expire, "/; samesite=Lax", null, is_ssl(), true);
    323 //          }
    324 //          else {
    325 //              setcookie($name, $value, [
    326 //                  'expires' => $expire,
    327 //                  'path' => '/',
    328 //                  'domain' => null,
    329 //                  'samesite' => 'Lax',
    330 //                  'secure' => is_ssl(),
    331 //                  'httponly' => true,
    332 //              ]);
    333 //          }
    334 
    335 
    336296            return $result->url;
    337297        }
     
    364324            }
    365325
     326
    366327            $zc_payment = new WC_Gateway_EZcount();
    367328            $zc_payment->init_form_fields();
    368329            $zc_payment->init_settings();
    369             $api_key = $zc_payment->get_option( 'api_key' );
    370 
     330            $api_key  = $zc_payment->get_option( 'api_key' );
    371331            $order_id = (int) @$_GET['order_id'];
    372             $tab_id   = $_GET['tab_id'];
    373 
    374332            //get order by id
    375333            $order = new WC_Order( $order_id );
    376334
    377 
    378             $cookieName    = "wc-ez-order-$order_id-$tab_id";
    379             $dataEncrypted = $_COOKIE[ $cookieName ];
     335            $sessionBase64Encoded = $_GET["ezs"];
    380336
    381337            // we have an error unless we found the transaction id
    382338            $errType = 2;
    383339
    384             if ( ! $dataEncrypted ) {
     340            if ( ! $sessionBase64Encoded ) {
    385341                $errType = 2.1;
    386342            } else {
     343                $dataEncrypted = base64_decode( $sessionBase64Encoded );
    387344                $dataDecrypted = EZcount_helpers::decrypt( $dataEncrypted, $api_key );
    388345                if ( ! $dataDecrypted ) {
    389346                    $errType = 2.2;
    390347                } else {
    391                     $data = json_decode( $dataDecrypted ,true);
    392                     if ( ! is_array( $data ) ) {
     348                    list( $secretTransactionId, $sessionOrderId ) = explode( "|", $dataDecrypted );
     349                    if ( ! $secretTransactionId ) {
    393350                        $errType = 2.3;
    394                     } elseif ( $data['order_id'] != $order_id || $data['tab_id'] != $tab_id ) {
    395                         $errType = 2.4;
    396                     } elseif ( ! $data['secretTransactionId'] ) {
     351                    } elseif ( $sessionOrderId != $order_id ) {
    397352                        $errType = 2.5;
    398353                    } else {
    399                         $secretTransactionId = $data['secretTransactionId'];
    400354                        //everything is OK, no error
    401355                        $errType = 0;
     
    410364                 אנא הכנסו אל ממשק הדוחות->סליקה באיזיקאונט, וודאו שהסליקה עברה לפני שאתם נותנים ללקוח את הטובין\n
    411365                  כרגע ההזמנה נכנסה לhold ולא יצאה לה חשבונית.\n\n
    412                 טכנית - נראה שהמשתמש שלכם איבד את העוגיה של הסליקה בגלל אחת מהסיבות הבאות:\n
    413                 * הוא ניקה עוגיות בדפדפן.\n
    414                 * המתין יותר מיומיים עד סיום הסליקה.\n
    415                 * משתמש בחסימת עוגיות בדפדפן.\n
    416                 ללא העוגיה של הסליקה לא נוכל לבצע לה אימות. \n
     366                טכנית - ההודעה הזו יכולה לקרות או במקרה של FRAUD או במקרה שעדכנתם את התוסף תוך כדי שהמשתמש היה בתהליך רכישה:\n
    417367                \n
    418368                מצורף מידע טכני
     
    421371                       json_encode( [
    422372                                        'order_id'            => $_GET['order_id'],
    423                                         'tab_id'              => $_GET['tab_id'],
    424                                         "cookieName"          => $cookieName,
     373                                        "sessionBase64Encoded"   => $sessionBase64Encoded,
    425374                                        "dataEncrypted"       => $dataEncrypted,
    426375                                        "api_key"             => "..." . substr( $api_key, - 10 ),
    427376                                        "dataDecrypted"       => $dataDecrypted,
    428                                         "data"                => json_encode( $data, 128 ),
    429377                                        'secretTransactionId' => $secretTransactionId,
     378                                        'sessionOrderId'      => $sessionOrderId,
    430379                                        'timezone'            => date_default_timezone_get(),
    431380                                        'server_date'         => date( DATE_ATOM ),
    432                                         '$_COOKIE'            => $_COOKIE,
    433                                         '$_SERVER'            => $_SERVER
     381                                        '$_SERVER'            => $_SERVER,
     382                                        'siteurl'             => get_site_url()
    434383                                    ],
    435384                                    128 );
    436385                wp_mail( $this->user_email, "VALIDATION ERROR #$errType,  לא הצלחנו לבצע אישור לסליקה עבור הזמנה מספר $order_id", $msg );
    437386                echo "VALIDATION ERROR #$errType לא הצלחנו לבצע אישור לסליקה, אבל יתכן והיא עברה, אנא צרו קשר עם בעל החנות";
    438                  $order->update_status( 'on-hold' );
     387                $order->update_status( 'on-hold' );
    439388                die();
    440389            }
    441390
    442             $api_url = EZcount_helpers::getApiBase() . 'payment/validate/' . $secretTransactionId;
     391            $api_url = EZcount_helpers::getApiBase() . 'payment/validate/'.$secretTransactionId;
    443392            $result  = EZcount_helpers::sendJsonRequest( $api_url );
    444 
    445393            $sum = number_format( $order->get_total(), 2, '.', '' );
    446394
     
    506454                    $item['price']          = $itemPrice;
    507455                } else {//WC>3
    508                     $qty                    = $item_data->get_quantity();
    509                     $product                = $item_data->get_product();
     456                    $qty         = $item_data->get_quantity();
     457                    $product     = $item_data->get_product();
    510458                    $productName = $product->get_name();
    511                     if(!$productName){
    512                         $productName="General item";
     459                    if ( ! $productName ) {
     460                        $productName = "General item";
    513461                    }
    514462                    $item['catalog_number'] = $product->get_id();
     
    572520                array(
    573521                    // CUSTOMER credentials
    574                     'api_key'          => $zc_payment->get_option( 'api_key' ),
    575                     'developer_email'  => $zc_payment->get_option( 'user_email' ),
    576                     'type'             => $zc_payment->get_option( 'doc_type' ),
    577                     'lang'             => $zc_payment->get_option( 'language_list' ),
    578                     'customer_name'    => $customer_first_name . " " . $customer_last_name,
    579                     'customer_email'   => $customer_email,
    580                     'customer_address' => $customer_address,
    581                     'item'             => $itemArray,
    582                     'payment'          =>
     522                    'api_key'                        => $zc_payment->get_option( 'api_key' ),
     523                    'developer_email'                => $zc_payment->get_option( 'user_email' ),
     524                    'type'                           => $zc_payment->get_option( 'doc_type' ),
     525                    'lang'                           => $zc_payment->get_option( 'language_list' ),
     526                    'customer_name'                  => $customer_first_name . " " . $customer_last_name,
     527                    'customer_email'                 => $customer_email,
     528                    'customer_address'               => $customer_address,
     529                    'item'                           => $itemArray,
     530                    'payment'                        =>
    583531                        array(
    584532                            array(
     
    591539                            )
    592540                        ),
    593                     'price_total'      => $paymentTotal,
    594                     'comment'          => "",
    595                     'transaction_id'   => $secretTransactionId,
    596                     "cgp_ids"          => array( $cgp_id ),
    597                     'ua_uuid'          => $this->different_account_uuid,
    598                     "send_copy"        => true,
     541                    'price_total'                    => $paymentTotal,
     542                    'comment'                        => "",
     543                    'transaction_id'                 => $secretTransactionId,
     544                    "cgp_ids"                        => array( $cgp_id ),
     545                    'ua_uuid'                        => $this->different_account_uuid,
     546                    "send_copy"                      => true,
    599547                    // reciept will include
    600548                    "forceItemsIntoNonItemsDocument" => true,
    601                 // rebalance the values
    602                     "auto_balance"     => true,
    603             );
     549                    // rebalance the values
     550                    "auto_balance"                   => true,
     551                );
    604552
    605553            //invoice!
  • ezcount/trunk/readme.txt

    r2380267 r2381907  
    44Tags        : Invoicing and clearing for Woocommerce, by EasyCount.
    55Tested up to: 4.9.8
    6 Version     : 1.10.7
     6Version     : 1.11.2
    77Stable tag: trunk
    88Requires PHP: 5.4
     
    55551.10.4 - add items back to receipts
    56561.10.5 - add $_COOKIE to the debug data
     571.11.2 - move cookies to url encrypted session
    5758== Upgrade notice ==
    5859nothing speacial about upgrading
Note: See TracChangeset for help on using the changeset viewer.