Plugin Directory

Changeset 2152998


Ignore:
Timestamp:
09/08/2019 11:41:29 AM (7 years ago)
Author:
alonezcount
Message:

roll back items for reciept
add some more logging points

Location:
ezcount/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ezcount/trunk/EZcount.php

    r2150974 r2152998  
    44 * Plugin URI:
    55 * Description: invoicing, clearing and paypal integration plugin.
    6  * Version: 1.5
     6 * Version: 1.5.1
    77 * Author: EZcount
    88 * Author URI:
     
    256256            //encrypt the transaction ID
    257257            $encrptedTransactionSecret = EZcount_helpers::encrypt($result->secretTransactionId, $this->api_key);
     258
    258259            //set as session cookie
    259260            setcookie('sti_' . $order_id, $encrptedTransactionSecret, null /*session*/, COOKIEPATH, COOKIE_DOMAIN, null, true);
     
    263264                    Here are some technical details:\n
    264265                    \nrequest data:" . var_export($data, true) .
    265                     "\nresponse data:" . var_export($result, true).
     266                    "\nresponse data:" . var_export($result, true) .
    266267                    "\nresponse lastResponseDebugStr:" . var_export(EZcount_helpers::$lastResponseDebugStr, true);
    267268                wp_mail($this->user_email, 'Failed to open gateway', $response);
     
    281282
    282283        public function cc_reponse() {
    283             if (@$_GET['response'] == 'success' && (int)@$_GET['order_id']) {
    284 
    285                 $zc_payment = new WC_Gateway_EZcount();
    286                 $zc_payment->init_form_fields();
    287                 $zc_payment->init_settings();
    288 
    289                 $order_id = (int)@$_GET['order_id'];
    290                 $order = new WC_Order($order_id);
    291                 $encryptedCookie = $_COOKIE['sti_' . $order_id];
    292                 $secretTransactionId = EZcount_helpers::decrypt($encryptedCookie, $zc_payment->get_option('api_key'));
    293                 $api_url = EZcount_helpers::getApiBase() . 'payment/validate/' . $secretTransactionId;
    294                 $result = EZcount_helpers::sendJsonRequest($api_url);
    295                 //this is a valid request
    296                 if ($result->success) {
    297                     //--------------------------------Invoice start----------------------------
    298                     $customer_email = (version_compare(WC_VERSION, '2.7', '<')) ? $order->billing_email : $order->get_billing_email();
    299                     $customer_first_name = (version_compare(WC_VERSION, '2.7', '<')) ? $order->billing_first_name : $order->get_billing_first_name();
    300                     $customer_last_name = (version_compare(WC_VERSION, '2.7', '<')) ? $order->billing_last_name : $order->get_billing_last_name();
    301                     $customer_address_1 = (version_compare(WC_VERSION, '2.7', '<')) ? $order->billing_address_1 : $order->get_billing_address_1();
    302                     $customer_city = (version_compare(WC_VERSION, '2.7', '<')) ? $order->billing_city : $order->get_billing_city();
    303                     $customer_state = (version_compare(WC_VERSION, '2.7', '<')) ? $order->billing_state : $order->get_billing_state();
    304                     $customer_postcode = (version_compare(WC_VERSION, '2.7', '<')) ? $order->customer_postcode : $order->get_billing_postcode();
    305                     $order_key = (version_compare(WC_VERSION, '2.7', '<')) ? $order->order_key : $order->get_order_key();
    306 
    307                     //when the customer is guest and we are having the email only
    308                     if (!$customer_first_name && !$customer_last_name) {
    309                         //take customer name from the CC
    310                         $customer_first_name = $result->cgp_customer_name;
    311                     }
    312                     // ----------------------- Get order items --------------------------------
    313                     $itemArray = array();
    314                     $items = array();
    315                     foreach ($order->get_items() as $item_key => $item_data) {
    316                         //caculate the item
    317                         $itemPrice = number_format($order->get_item_total($item_data, false, false) + $order->get_item_tax($item_data, false, false), 2, '.', '');
    318 
    319                         //WC<3
    320                         if ((version_compare(WC_VERSION, '2.7', '<'))) {
    321                             $item['catalog_number'] = $item_data["product_id"];
    322                             $item['details'] = $item_data['name'];
    323                             $item['amount'] = $item_data['qty'];
    324                             $item['vat_type'] = 'INC';
    325                             $item['price'] = $itemPrice;
    326 
    327                         } else {//WC>3
    328                             $qty = $item_data->get_quantity();
    329                             $product = $item_data->get_product();
    330                             $item['catalog_number'] = $product->get_id();
    331                             $item['details'] = $product->get_name();
    332                             $item['amount'] = $qty;
    333                             $item['vat_type'] = 'INC';
    334                             $item['price'] = $itemPrice;
    335                         }
    336 
    337                         array_push($itemArray, $item);
    338                     }
    339                     // Iterating through order shipping items
    340                     foreach ($order->get_items('shipping') as $item_id => $shipping_item_obj) {
    341                         $shippingPrice = number_format($order->get_total_shipping() + $order->get_shipping_tax(), 2, '.', '');
    342                         if ((version_compare(WC_VERSION, '2.7', '<'))) {
    343                             $item['catalog_number'] = $shipping_item_obj['method_id'];
    344                             $item['vat_type'] = 'INC';
    345                             $item['amount'] = 1;
    346                             $item['details'] = $shipping_item_obj['name'];
    347                             $item['price'] = $shippingPrice;
    348                         } else {//WC>3
    349                             // Get the data in an unprotected array
    350                             $shipping_data = $shipping_item_obj->get_data();
    351                             $item['catalog_number'] = $shipping_data['id'];
    352                             $item['vat_type'] = 'INC';
    353                             $item['amount'] = 1;
    354                             $item['details'] = $shipping_data['name'];
    355                             $item['price'] = $shippingPrice;
    356                         }
    357                         array_push($itemArray, $item);
    358                     }
    359 
    360 
    361                     //-------------------------------Card details----------------------------
    362 
    363                     $cc_number = $_GET['last4digits'];
    364                     $cgp_id = $_GET['cgp_id'];
    365                     $cc_type_name = $_GET['ccTypeName'];
    366                     $cc_num_of_payments = $_GET['numOfPayments'];
    367                     $paymentTotal = $_GET['paymentTotal'];
    368 
    369                     //-------------------------------XXXXXX----------------------------------
    370 
    371                     $customer_address = array();
    372                     if (trim($customer_address_1)) {
    373                         $customer_address[] = $customer_address_1;
    374                     }
    375                     if (trim($customer_city)) {
    376                         $customer_address[] = $customer_city;
    377                     }
    378                     if (trim($customer_state)) {
    379                         $customer_address[] = $customer_state;
    380                     }
    381                     if (trim($customer_postcode)) {
    382                         $customer_address[] = $customer_postcode;
    383                     }
    384                     $customer_address = implode(",", $customer_address);
    385 
    386                     $invoice_post =
     284            if (@$_GET['response'] != 'success' || !(int)@$_GET['order_id']) {
     285                $msg = "Auto invoice from EZcount WC plugin failed\n No order ID, or order failed\n\n" . json_encode($_GET);
     286                wp_mail($this->user_email, 'Failed to create invoice', $msg);
     287                echo "VALIDATION ERROR #1 קרתה בעיה, אנא צרו קשר עם בעל החנות";
     288                die();
     289            }
     290
     291            $zc_payment = new WC_Gateway_EZcount();
     292            $zc_payment->init_form_fields();
     293            $zc_payment->init_settings();
     294
     295            $order_id = (int)@$_GET['order_id'];
     296            //get order by id
     297            $order = new WC_Order($order_id);
     298            $encryptedCookie = $_COOKIE['sti_' . $order_id];
     299            //get the transaction_id from the cookie
     300            $secretTransactionId = EZcount_helpers::decrypt($encryptedCookie, $zc_payment->get_option('api_key'));
     301
     302            if (!$secretTransactionId) {
     303                $msg = "transaction transaction_id failed, is your cookies server correctly?\n\n" . json_encode([
     304                        'secretTransactionId' => $secretTransactionId,
     305                        'encryptedCookie' => $encryptedCookie,
     306                        '$_SERVER' => $_SERVER
     307                    ]);
     308                wp_mail($this->user_email, 'transaction cookie does not exists', $msg);
     309                echo "VALIDATION ERROR #2 לא הצלחנו לבצע אישור לסליקה, אבל יתכן והיא עברה, אנא צרו קשר עם בעל החנות";
     310                die();
     311            }
     312
     313            $api_url = EZcount_helpers::getApiBase() . 'payment/validate/' . $secretTransactionId;
     314            $result = EZcount_helpers::sendJsonRequest($api_url);
     315            //this is a valid request
     316            if (!$result->success) {
     317                $msg = "transaction validation failed, is your Cookies expiry are too short?\n\n" . json_encode($result);
     318                wp_mail($this->user_email, 'Failed to create invoice', $msg);
     319                echo "VALIDATION ERROR #3 הסליקה עברה אבל ההזמנה לא התקבלה,צרו קשר עם בעלי החנות";
     320                die();
     321            }
     322            //--------------------------------Invoice start----------------------------
     323            $customer_email = (version_compare(WC_VERSION, '2.7', '<')) ? $order->billing_email : $order->get_billing_email();
     324            $customer_first_name = (version_compare(WC_VERSION, '2.7', '<')) ? $order->billing_first_name : $order->get_billing_first_name();
     325            $customer_last_name = (version_compare(WC_VERSION, '2.7', '<')) ? $order->billing_last_name : $order->get_billing_last_name();
     326            $customer_address_1 = (version_compare(WC_VERSION, '2.7', '<')) ? $order->billing_address_1 : $order->get_billing_address_1();
     327            $customer_city = (version_compare(WC_VERSION, '2.7', '<')) ? $order->billing_city : $order->get_billing_city();
     328            $customer_state = (version_compare(WC_VERSION, '2.7', '<')) ? $order->billing_state : $order->get_billing_state();
     329            $customer_postcode = (version_compare(WC_VERSION, '2.7', '<')) ? $order->customer_postcode : $order->get_billing_postcode();
     330            $order_key = (version_compare(WC_VERSION, '2.7', '<')) ? $order->order_key : $order->get_order_key();
     331
     332            //when the customer is guest and we are having the email only
     333            if (!$customer_first_name && !$customer_last_name) {
     334                //take customer name from the CC
     335                $customer_first_name = $result->cgp_customer_name;
     336            }
     337            // ----------------------- Get order items --------------------------------
     338            $itemArray = array();
     339            $items = array();
     340            foreach ($order->get_items() as $item_key => $item_data) {
     341                //caculate the item
     342                $itemPrice = number_format($order->get_item_total($item_data, false, false) + $order->get_item_tax($item_data, false, false), 2, '.', '');
     343
     344                //WC<3
     345                if ((version_compare(WC_VERSION, '2.7', '<'))) {
     346                    $item['catalog_number'] = $item_data["product_id"];
     347                    $item['details'] = $item_data['name'];
     348                    $item['amount'] = $item_data['qty'];
     349                    $item['vat_type'] = 'INC';
     350                    $item['price'] = $itemPrice;
     351
     352                } else {//WC>3
     353                    $qty = $item_data->get_quantity();
     354                    $product = $item_data->get_product();
     355                    $item['catalog_number'] = $product->get_id();
     356                    $item['details'] = $product->get_name();
     357                    $item['amount'] = $qty;
     358                    $item['vat_type'] = 'INC';
     359                    $item['price'] = $itemPrice;
     360                }
     361
     362                array_push($itemArray, $item);
     363            }
     364            // Iterating through order shipping items
     365            foreach ($order->get_items('shipping') as $item_id => $shipping_item_obj) {
     366                $shippingPrice = number_format($order->get_total_shipping() + $order->get_shipping_tax(), 2, '.', '');
     367                if ((version_compare(WC_VERSION, '2.7', '<'))) {
     368                    $item['catalog_number'] = $shipping_item_obj['method_id'];
     369                    $item['vat_type'] = 'INC';
     370                    $item['amount'] = 1;
     371                    $item['details'] = $shipping_item_obj['name'];
     372                    $item['price'] = $shippingPrice;
     373                } else {//WC>3
     374                    // Get the data in an unprotected array
     375                    $shipping_data = $shipping_item_obj->get_data();
     376                    $item['catalog_number'] = $shipping_data['id'];
     377                    $item['vat_type'] = 'INC';
     378                    $item['amount'] = 1;
     379                    $item['details'] = $shipping_data['name'];
     380                    $item['price'] = $shippingPrice;
     381                }
     382                array_push($itemArray, $item);
     383            }
     384
     385
     386            //-------------------------------Card details----------------------------
     387
     388            $cc_number = $_GET['last4digits'];
     389            $cgp_id = $_GET['cgp_id'];
     390            $cc_type_name = $_GET['ccTypeName'];
     391            $cc_num_of_payments = $_GET['numOfPayments'];
     392            $paymentTotal = $_GET['paymentTotal'];
     393
     394            //-------------------------------XXXXXX----------------------------------
     395
     396            $customer_address = array();
     397            if (trim($customer_address_1)) {
     398                $customer_address[] = $customer_address_1;
     399            }
     400            if (trim($customer_city)) {
     401                $customer_address[] = $customer_city;
     402            }
     403            if (trim($customer_state)) {
     404                $customer_address[] = $customer_state;
     405            }
     406            if (trim($customer_postcode)) {
     407                $customer_address[] = $customer_postcode;
     408            }
     409            $customer_address = implode(",", $customer_address);
     410
     411            $invoice_post =
     412                array(
     413                    // CUSTOMER credentials
     414                    'api_key' => $zc_payment->get_option('api_key'),
     415                    'developer_email' => $zc_payment->get_option('user_email'),
     416                    'type' => $zc_payment->get_option('doc_type'),
     417                    'lang' => $zc_payment->get_option('language_list'),
     418                    'customer_name' => $customer_first_name . " " . $customer_last_name,
     419                    'customer_email' => $customer_email,
     420                    'customer_address' => $customer_address,
     421                    'item' => $itemArray,
     422                    'payment' =>
    387423                        array(
    388                             // CUSTOMER credentials
    389                             'api_key' => $zc_payment->get_option('api_key'),
    390                             'developer_email' => $zc_payment->get_option('user_email'),
    391                             'type' => $zc_payment->get_option('doc_type'),
    392                             'lang' => $zc_payment->get_option('language_list'),
    393                             'customer_name' => $customer_first_name . " " . $customer_last_name,
    394                             'customer_email' => $customer_email,
    395                             'customer_address' => $customer_address,
    396                             'item' => $itemArray,
    397                             'payment' =>
    398                                 array(
    399                                     array(
    400                                         'payment_type' => 3,/*CC*/
    401                                         'payment' => $paymentTotal,
    402                                         'cc_number' => $cc_number,
    403                                         'cc_type_name' => $cc_type_name,
    404                                         'cc_num_of_payments' => $cc_num_of_payments,
    405                                         'auto_calc_payments' => true
    406                                     )
    407                                 ),
    408                             'price_total' => $paymentTotal,
    409                             'comment' => "",
    410                             'transaction_id' => $secretTransactionId,
    411                             "cgp_id" => $cgp_id,
    412                             'ua_uuid' => $this->different_account_uuid,
    413                             "send_copy"=>true,
    414                             // reciept will include
    415                             "forceItemsIntoNonItemsDocument" => true,
    416                             // rebalance the values
    417                             "auto_balance" => true,
    418                         );
    419 
    420                     //invoice!
    421                     $api_url = EZcount_helpers::getApiBase() . 'createDoc';
    422                     $invoiceResponse = EZcount_helpers::sendJsonRequest($api_url, $invoice_post);
    423                     if (!$invoiceResponse->success) {
    424                         wp_mail($zc_payment->get_option('user_email'), 'Failed to create invoice',
    425                             "Auto invoice from EZcount WC plugin failed\n
     424                            array(
     425                                'payment_type' => 3,/*CC*/
     426                                'payment' => $paymentTotal,
     427                                'cc_number' => $cc_number,
     428                                'cc_type_name' => $cc_type_name,
     429                                'cc_num_of_payments' => $cc_num_of_payments,
     430                                'auto_calc_payments' => true
     431                            )
     432                        ),
     433                    'price_total' => $paymentTotal,
     434                    'comment' => "",
     435                    'transaction_id' => $secretTransactionId,
     436                    "cgp_id" => $cgp_id,
     437                    'ua_uuid' => $this->different_account_uuid,
     438                    "send_copy" => true,
     439                    // reciept will include
     440//                  "forceItemsIntoNonItemsDocument" => true,
     441                    // rebalance the values
     442//                  "auto_balance" => true,
     443                );
     444
     445            //invoice!
     446            $api_url = EZcount_helpers::getApiBase() . 'createDoc';
     447            $invoiceResponse = EZcount_helpers::sendJsonRequest($api_url, $invoice_post);
     448            if (!$invoiceResponse->success) {
     449                wp_mail($zc_payment->get_option('user_email'), 'Failed to create invoice',
     450                    "Auto invoice from EZcount WC plugin failed\n
    426451                            Here are some technical details:\n
    427452                            Invoice data:" . var_export($invoice_post, true) .
    428                             "EZcount response data:" . var_export($invoiceResponse, true) .
    429                             "Order data:" . var_export($order, true));
    430                     }
    431                     //--------------------------------Invoice end----------------------------
    432                     // Set order status
    433                     $order->update_status($this->order_status, __('payment success. ', get_site_url()));
    434                     //Finally redirect page
    435                     $url = get_site_url() . "/checkout/order-received/" . $order_id . "/?key=" . $order_key;
    436                     ?>
    437                     <script type="application/javascript">
    438                         //js redirect because we are maybe inside an Iframe
    439                         window.top.location.href = '<?=$url?>';
    440                     </script>
    441                     <?php
    442                     exit;
    443                 } else {
    444                     echo "VALIDATION ERROR הסליקה עברה אבל ההזמנה לא התקבלה,צרו קשר עם בעלי החנות";
    445                     die();
    446                 }
    447             } else {
    448                 $msg = "Auto invoice from EZcount WC plugin failed\n No order ID, or order failed";
    449                 wp_mail($this->user_email, 'Failed to create invoice', $msg);
    450                 echo "VALIDATION ERROR הסליקה עברה אבל ההזמנה לא התקבלה,צרו קשר עם בעלי החנות";
    451                 die();
    452             }
     453                    "EZcount response data:" . var_export($invoiceResponse, true) .
     454                    "Order data:" . var_export($order, true));
     455            }
     456            //--------------------------------Invoice end----------------------------
     457            // Set order status
     458            $order->update_status($this->order_status, __('payment success. ', get_site_url()));
     459            //Finally redirect page
     460            $url = get_site_url() . "/checkout/order-received/" . $order_id . "/?key=" . $order_key;
     461            ?>
     462            <script type="application/javascript">
     463                //js redirect because we are maybe inside an Iframe
     464                window.top.location.href = '<?=$url?>';
     465            </script>
     466            <?php
     467            exit;
    453468        }
    454469
  • ezcount/trunk/readme.txt

    r2150032 r2152998  
    44Tags        : invoicing, clearing and paypal integration plugin.
    55Tested up to: 4.9.8
    6 Version     : 1.5
     6Version     : 1.5.1
    77Stable tag: trunk
    88Requires PHP: 5.4
Note: See TracChangeset for help on using the changeset viewer.