Plugin Directory

Changeset 3186417


Ignore:
Timestamp:
11/12/2024 10:46:02 AM (14 months ago)
Author:
payuplugin
Message:

Variation functionality update

Location:
payu-india
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • payu-india/tags/3.8.3/includes/class-payu-payment-validation.php

    r3163861 r3186417  
    436436            'city'     => $order->get_shipping_city(), // (optional value)
    437437        );
     438        foreach($order->get_items('shipping') as $item_id => $item) {       
     439               $order->remove_item($item_id);
     440        }
    438441        $added_shipping = array();
    439442        foreach ($order->get_items('shipping') as $item) {
  • payu-india/tags/3.8.3/includes/class-payu-shipping-tax-api-calculation.php

    r3163861 r3186417  
    5959        }
    6060        $response_code = $response['status'] == 'false' ? 400 : 200;
    61         error_log('shipping api call response ' . wp_json_encode($response));
     61        error_log('shipping api call response ' . json_encode($response));
    6262        return new WP_REST_Response($response, $response_code);
    6363    }
     
    134134        $order->set_address($new_address, 'shipping');
    135135        $order->set_address($new_address, 'billing');
    136         error_log('set order address ' . wp_json_encode($new_address));
     136        error_log('set order address ' . json_encode($new_address));
    137137        $order->set_billing_email($email);
    138138        $order->save();
     
    206206                        $shipping_data[$shipping_method_count]['amount']        = $shipping_rate->get_cost();
    207207                        $shipping_data[$shipping_method_count]['error_message']        = "";
    208                         $shipping_data[$shipping_method_count]['tax_price']    = $tax_amount;
     208                        $plugin_data = get_option('woocommerce_payubiz_settings');
     209                        $payu_dynamic_charges_flag = $plugin_data['dynamic_charges_flag'];
     210       
     211                        if($payu_dynamic_charges_flag=="yes" && wc_prices_include_tax()){
     212                            if(WC()->cart->get_shipping_tax()){
     213                            $shipping_data[$shipping_method_count]['tax_price']    = round(WC()->cart->get_shipping_tax(), 2);
     214                            $shipping_data[$shipping_method_count]['tax_price_inclusive'] = round($tax_amount, 2);
     215                            }
     216                            else{
     217                            $shipping_data[$shipping_method_count]['tax_price']    = 0;
     218                            $shipping_data[$shipping_method_count]['tax_price_inclusive'] = round($tax_amount, 2);   
     219                            }
     220                           
     221                        }
     222                        else{
     223                            $shipping_data[$shipping_method_count]['tax_price']    = round($tax_amount, 2);
     224                        }
     225                       
    209226                        $shipping_data[$shipping_method_count]['subtotal']   = WC()->cart->get_subtotal();
    210                         $shipping_data[$shipping_method_count]['grand_total']   = WC()->cart->get_subtotal() + $shipping_rate->get_cost() + $tax_amount;
     227                        $shipping_data[$shipping_method_count]['grand_total']   = round(WC()->cart->get_subtotal() + $shipping_rate->get_cost()+ $tax_amount, 2);
    211228                        $shipping_method_count++;
    212229                    }
    213230                } else if(WC()->cart->get_tax_totals()){
    214231                    foreach (WC()->cart->get_tax_totals() as $tax) {
    215                         $tax_amount   = $tax->amount + $tax_amount;
     232                        $tax_amount   = $tax->amount + $tax_amount; 
    216233                    }
    217234                    $shipping_data[0]['carrier_code']   = '';
  • payu-india/tags/3.8.3/includes/class-wc-gateway-payu.php

    r3171075 r3186417  
    2929    protected $site_url;
    3030    protected $dynamic_charges_flag;
     31   
     32    protected $_skuWiseTotal = 0;
    3133
    3234
     
    153155        $this->manage_session(); //Update cookies with samesite
    154156        $thankyou_msg = 'Thank you for your order, please wait as you will be automatically redirected to PayUBiz.';
    155         echo '<p>' . esc_html($thankyou_msg, 'payubiz') . '</p>';
     157        echo '<p>' . esc_html__($thankyou_msg, 'payubiz') . '</p>';
    156158        echo $this->generatePayubizForm($order);
    157159    }
     
    285287        $redirect_url = add_query_arg('wc-api', get_class($this), $redirect_url);
    286288        WC()->session->set('orderid_awaiting_payubiz', $order_id);
    287         //$txnid = $order_id . '_' . date("ymd") . ':' . random_int(1, 100);
    288         $txnid = $order_id . '_' . gmdate("ymd") . '_' . random_int(1, 100);
     289        $txnid = $order_id . '_' . date("ymd") . '_' . random_int(1, 100);
    289290        update_post_meta($order_id, 'order_txnid', $txnid);
    290291       
     
    294295        //get currency
    295296        $address = sanitize_text_field($order->billing_address_1); {
    296             $address = $address . ' ' . sanitize_text_field($order->billing_address_2);
     297        $address = $address . ' ' . sanitize_text_field($order->billing_address_2);
    297298        }
    298299
     
    309310            $action = esc_url(PAYU_HOSTED_PAYMENT_URL_UAT);
    310311        }
    311 
    312         $order_subtotal = sanitize_text_field($order->get_subtotal());
    313         $amount = $this->checkout_express=='checkout_express'?$order_subtotal:sanitize_text_field($order->order_total);
     312        /**Disable & enable shipping charges.**/
     313        $plugin_data = get_option('woocommerce_payubiz_settings');
     314        $payu_dynamic_charges_flag = $plugin_data['dynamic_charges_flag'];
     315        $order_subtotal = sanitize_text_field($order->get_subtotal());   
     316        $order_total_tax = sanitize_text_field($order->order_total);
     317        if($payu_dynamic_charges_flag=="no"){
     318        $amount = $this->checkout_express=='checkout_express'?$order_total_tax:sanitize_text_field($order->order_total);
     319        }
     320        else{
     321        $amount = $this->checkout_express=='checkout_express'?$order_subtotal:sanitize_text_field($order->order_total);   
     322        }
    314323        $amount=number_format($amount,2);
    315324        $amount=str_replace(",", "", $amount);
     325        //echo $amount; exit;
    316326        $firstname = sanitize_text_field($order->billing_first_name);
    317327        $lastname = sanitize_text_field($order->billing_last_name);
     
    388398            $ramdom_str = bin2hex($random_bytes);
    389399            $c_date = gmdate('D, d M Y H:i:s T');
     400            //$tax_info_data=$order->order_total-$order->get_subtotal();
     401            $tax_info_data=WC()->cart->get_total_tax();
     402            //$tax_info_data=round($tax_info_data, 2);           
     403            $taxinfo=array(
     404                'breakup'=>array(
     405                    'Standard' => "$tax_info_data"
     406                ),
     407                'total'=> "$tax_info_data"
     408            ); 
     409
     410            $order_amount = 0;
     411            if($payu_dynamic_charges_flag=="no"){
     412                if(wc_prices_include_tax()){
     413                    $taxinfo=NULL;
     414                    $order_amount  = $order->order_total;
     415                   
     416                }else{
     417                    $taxinfo=$taxinfo;
     418                    $order_amount  = $order->get_subtotal();
     419                }
     420               
     421            } else {
     422                $taxinfo=NULL;
     423                $order_amount  = $order->get_subtotal();               
     424            }
    390425           
     426           
     427            if($payu_dynamic_charges_flag=="yes" && wc_prices_include_tax()){
     428                $order_amount  = $order->order_total;
     429                $amount  = $order->order_total;
     430            }           
    391431            $amount=str_replace(",", "", $amount);
     432           
    392433            $data_array = array(
    393434                'key' => $payu_key,
     
    421462                    'cod_fee' => 0, // cash on delivery fee.
    422463                    'other_charges' => NULL,
    423                     'tax_info' => NULL,
     464                    'tax_info' => $taxinfo,
     465                   
    424466                ),
    425467                'cart_details' => array(
    426                     'amount' => $order_subtotal,
     468                    'amount' => $order_amount,
    427469                    'items' => (string)$item_count,
    428470                    'sku_details' => $sku_details_array,
     
    446488        $productInfo = '';
    447489        $logo = 'https://payu.in/demo/checkoutExpress/utils/images/MicrosoftTeams-image%20(31).png';
     490       
    448491        foreach ($order->get_items() as $item) {
     492            $variation_id = $item->get_variation_id();
     493            $_product = new WC_Product_Variation($variation_id);
     494            $single_sku_price=$_product->get_price();
     495            $single_sku_name=$_product->get_name();
     496            $single_sku=$_product->get_sku();
     497            $single_sku=($single_sku!="") ? $single_sku : $variation_id;
     498            $single_sku_price=str_replace(",", "", $single_sku_price);
    449499            $product = wc_get_product($item->get_product_id());
    450500            $productInfo .= $product->get_sku() . ':';
    451501            $amount_per_sku=(string)number_format($product->get_price(), 2);
    452502            $amount_per_sku=str_replace(",", "", $amount_per_sku);
    453             $sku_details_array[] = array(
     503            if($variation_id==0){
     504                $sku_id=($product->get_sku()!="") ? $product->get_sku():$product->get_id();
     505                $amount_per_sku=$amount_per_sku;
     506                $product_name=$product->get_name();
     507            }
     508            else{
     509             $sku_id=$single_sku;
     510             $amount_per_sku=$single_sku_price;
     511             $product_name=$single_sku_name;                 
     512            }
     513            $sku_details_array[] = array(
    454514                'offer_key' => array(),
    455515                'amount_per_sku' => $amount_per_sku,
    456516                'quantity' => (string)$item->get_quantity(),
    457                 //'sku_id' => $product->get_sku(),
    458                 'sku_id' => ($product->get_sku()!="") ? $product->get_sku():$product->get_id(),
    459                 'sku_name' => $product->get_name(),
     517                'sku_id' => $sku_id,
     518                'sku_name' => $product_name,
    460519                'logo' => $logo
    461             );
     520            );           
    462521        }
    463522
     
    510569            </form>
    511570            ";
    512         $data = wp_json_encode($requestArr, JSON_UNESCAPED_SLASHES);
     571        $data = json_encode($requestArr, JSON_UNESCAPED_SLASHES);
    513572        $javascriptCode = <<<EOD
    514573            <script type='text/javascript'>
     
    543602        $payu_key = $this->currency1_payu_key;
    544603        $payu_salt = $this->currency1_payu_salt;
    545         $data_array_json = wp_json_encode($data_array, JSON_UNESCAPED_SLASHES);
     604        $data_array_json = json_encode($data_array, JSON_UNESCAPED_SLASHES);
    546605        $v2hash = hash('sha512', $data_array_json . "|" . $c_date . "|" . $payu_salt);
    547606        $username = "hmac username=\"$payu_key\"";
     
    567626        $redirect_url = $args_express_checkout['redirect_url'];
    568627        $payu_payment_nonce = $args_express_checkout['payu_payment_nonce'];
    569         $data_array_json = $args_express_checkout['data_array_json'];
     628        $data_array_json = json_encode($args_express_checkout['data_array_json']);
    570629        $c_date = $args_express_checkout['c_date'];
    571630        $auth_header_string = $args_express_checkout['auth_header_string'];
     
    580639        function handleSubmit() {
    581640            const  expressRequestObj = {
    582                 data: '$data_array_json',
     641                data: $data_array_json,
    583642                date: '$c_date',
    584643                isCheckoutExpress: true,
     
    587646            var handlers = {
    588647                responseHandler: function (BOLT) {
    589                     console.log('response from payu');                 
     648                    console.log('response from payu');
     649                    console.log(BOLT.response.amount);
     650                    console.log(JSON.stringify(BOLT.response));
     651                   
    590652                        if (BOLT.response.txnStatus == 'FAILED') {
    591653                        alert('Payment failed. Please try again.');
     
    661723        return false;
    662724    }
    663 
    664    
    665 
    666725}
  • payu-india/trunk/includes/class-payu-payment-validation.php

    r3163861 r3186417  
    436436            'city'     => $order->get_shipping_city(), // (optional value)
    437437        );
     438        foreach($order->get_items('shipping') as $item_id => $item) {       
     439               $order->remove_item($item_id);
     440        }
    438441        $added_shipping = array();
    439442        foreach ($order->get_items('shipping') as $item) {
  • payu-india/trunk/includes/class-payu-shipping-tax-api-calculation.php

    r3163861 r3186417  
    5959        }
    6060        $response_code = $response['status'] == 'false' ? 400 : 200;
    61         error_log('shipping api call response ' . wp_json_encode($response));
     61        error_log('shipping api call response ' . json_encode($response));
    6262        return new WP_REST_Response($response, $response_code);
    6363    }
     
    134134        $order->set_address($new_address, 'shipping');
    135135        $order->set_address($new_address, 'billing');
    136         error_log('set order address ' . wp_json_encode($new_address));
     136        error_log('set order address ' . json_encode($new_address));
    137137        $order->set_billing_email($email);
    138138        $order->save();
     
    206206                        $shipping_data[$shipping_method_count]['amount']        = $shipping_rate->get_cost();
    207207                        $shipping_data[$shipping_method_count]['error_message']        = "";
    208                         $shipping_data[$shipping_method_count]['tax_price']    = $tax_amount;
     208                        $plugin_data = get_option('woocommerce_payubiz_settings');
     209                        $payu_dynamic_charges_flag = $plugin_data['dynamic_charges_flag'];
     210       
     211                        if($payu_dynamic_charges_flag=="yes" && wc_prices_include_tax()){
     212                            if(WC()->cart->get_shipping_tax()){
     213                            $shipping_data[$shipping_method_count]['tax_price']    = round(WC()->cart->get_shipping_tax(), 2);
     214                            $shipping_data[$shipping_method_count]['tax_price_inclusive'] = round($tax_amount, 2);
     215                            }
     216                            else{
     217                            $shipping_data[$shipping_method_count]['tax_price']    = 0;
     218                            $shipping_data[$shipping_method_count]['tax_price_inclusive'] = round($tax_amount, 2);   
     219                            }
     220                           
     221                        }
     222                        else{
     223                            $shipping_data[$shipping_method_count]['tax_price']    = round($tax_amount, 2);
     224                        }
     225                       
    209226                        $shipping_data[$shipping_method_count]['subtotal']   = WC()->cart->get_subtotal();
    210                         $shipping_data[$shipping_method_count]['grand_total']   = WC()->cart->get_subtotal() + $shipping_rate->get_cost() + $tax_amount;
     227                        $shipping_data[$shipping_method_count]['grand_total']   = round(WC()->cart->get_subtotal() + $shipping_rate->get_cost()+ $tax_amount, 2);
    211228                        $shipping_method_count++;
    212229                    }
    213230                } else if(WC()->cart->get_tax_totals()){
    214231                    foreach (WC()->cart->get_tax_totals() as $tax) {
    215                         $tax_amount   = $tax->amount + $tax_amount;
     232                        $tax_amount   = $tax->amount + $tax_amount; 
    216233                    }
    217234                    $shipping_data[0]['carrier_code']   = '';
  • payu-india/trunk/includes/class-wc-gateway-payu.php

    r3171075 r3186417  
    2929    protected $site_url;
    3030    protected $dynamic_charges_flag;
     31   
     32    protected $_skuWiseTotal = 0;
    3133
    3234
     
    153155        $this->manage_session(); //Update cookies with samesite
    154156        $thankyou_msg = 'Thank you for your order, please wait as you will be automatically redirected to PayUBiz.';
    155         echo '<p>' . esc_html($thankyou_msg, 'payubiz') . '</p>';
     157        echo '<p>' . esc_html__($thankyou_msg, 'payubiz') . '</p>';
    156158        echo $this->generatePayubizForm($order);
    157159    }
     
    285287        $redirect_url = add_query_arg('wc-api', get_class($this), $redirect_url);
    286288        WC()->session->set('orderid_awaiting_payubiz', $order_id);
    287         //$txnid = $order_id . '_' . date("ymd") . ':' . random_int(1, 100);
    288         $txnid = $order_id . '_' . gmdate("ymd") . '_' . random_int(1, 100);
     289        $txnid = $order_id . '_' . date("ymd") . '_' . random_int(1, 100);
    289290        update_post_meta($order_id, 'order_txnid', $txnid);
    290291       
     
    294295        //get currency
    295296        $address = sanitize_text_field($order->billing_address_1); {
    296             $address = $address . ' ' . sanitize_text_field($order->billing_address_2);
     297        $address = $address . ' ' . sanitize_text_field($order->billing_address_2);
    297298        }
    298299
     
    309310            $action = esc_url(PAYU_HOSTED_PAYMENT_URL_UAT);
    310311        }
    311 
    312         $order_subtotal = sanitize_text_field($order->get_subtotal());
    313         $amount = $this->checkout_express=='checkout_express'?$order_subtotal:sanitize_text_field($order->order_total);
     312        /**Disable & enable shipping charges.**/
     313        $plugin_data = get_option('woocommerce_payubiz_settings');
     314        $payu_dynamic_charges_flag = $plugin_data['dynamic_charges_flag'];
     315        $order_subtotal = sanitize_text_field($order->get_subtotal());   
     316        $order_total_tax = sanitize_text_field($order->order_total);
     317        if($payu_dynamic_charges_flag=="no"){
     318        $amount = $this->checkout_express=='checkout_express'?$order_total_tax:sanitize_text_field($order->order_total);
     319        }
     320        else{
     321        $amount = $this->checkout_express=='checkout_express'?$order_subtotal:sanitize_text_field($order->order_total);   
     322        }
    314323        $amount=number_format($amount,2);
    315324        $amount=str_replace(",", "", $amount);
     325        //echo $amount; exit;
    316326        $firstname = sanitize_text_field($order->billing_first_name);
    317327        $lastname = sanitize_text_field($order->billing_last_name);
     
    388398            $ramdom_str = bin2hex($random_bytes);
    389399            $c_date = gmdate('D, d M Y H:i:s T');
     400            //$tax_info_data=$order->order_total-$order->get_subtotal();
     401            $tax_info_data=WC()->cart->get_total_tax();
     402            //$tax_info_data=round($tax_info_data, 2);           
     403            $taxinfo=array(
     404                'breakup'=>array(
     405                    'Standard' => "$tax_info_data"
     406                ),
     407                'total'=> "$tax_info_data"
     408            ); 
     409
     410            $order_amount = 0;
     411            if($payu_dynamic_charges_flag=="no"){
     412                if(wc_prices_include_tax()){
     413                    $taxinfo=NULL;
     414                    $order_amount  = $order->order_total;
     415                   
     416                }else{
     417                    $taxinfo=$taxinfo;
     418                    $order_amount  = $order->get_subtotal();
     419                }
     420               
     421            } else {
     422                $taxinfo=NULL;
     423                $order_amount  = $order->get_subtotal();               
     424            }
    390425           
     426           
     427            if($payu_dynamic_charges_flag=="yes" && wc_prices_include_tax()){
     428                $order_amount  = $order->order_total;
     429                $amount  = $order->order_total;
     430            }           
    391431            $amount=str_replace(",", "", $amount);
     432           
    392433            $data_array = array(
    393434                'key' => $payu_key,
     
    421462                    'cod_fee' => 0, // cash on delivery fee.
    422463                    'other_charges' => NULL,
    423                     'tax_info' => NULL,
     464                    'tax_info' => $taxinfo,
     465                   
    424466                ),
    425467                'cart_details' => array(
    426                     'amount' => $order_subtotal,
     468                    'amount' => $order_amount,
    427469                    'items' => (string)$item_count,
    428470                    'sku_details' => $sku_details_array,
     
    446488        $productInfo = '';
    447489        $logo = 'https://payu.in/demo/checkoutExpress/utils/images/MicrosoftTeams-image%20(31).png';
     490       
    448491        foreach ($order->get_items() as $item) {
     492            $variation_id = $item->get_variation_id();
     493            $_product = new WC_Product_Variation($variation_id);
     494            $single_sku_price=$_product->get_price();
     495            $single_sku_name=$_product->get_name();
     496            $single_sku=$_product->get_sku();
     497            $single_sku=($single_sku!="") ? $single_sku : $variation_id;
     498            $single_sku_price=str_replace(",", "", $single_sku_price);
    449499            $product = wc_get_product($item->get_product_id());
    450500            $productInfo .= $product->get_sku() . ':';
    451501            $amount_per_sku=(string)number_format($product->get_price(), 2);
    452502            $amount_per_sku=str_replace(",", "", $amount_per_sku);
    453             $sku_details_array[] = array(
     503            if($variation_id==0){
     504                $sku_id=($product->get_sku()!="") ? $product->get_sku():$product->get_id();
     505                $amount_per_sku=$amount_per_sku;
     506                $product_name=$product->get_name();
     507            }
     508            else{
     509             $sku_id=$single_sku;
     510             $amount_per_sku=$single_sku_price;
     511             $product_name=$single_sku_name;                 
     512            }
     513            $sku_details_array[] = array(
    454514                'offer_key' => array(),
    455515                'amount_per_sku' => $amount_per_sku,
    456516                'quantity' => (string)$item->get_quantity(),
    457                 //'sku_id' => $product->get_sku(),
    458                 'sku_id' => ($product->get_sku()!="") ? $product->get_sku():$product->get_id(),
    459                 'sku_name' => $product->get_name(),
     517                'sku_id' => $sku_id,
     518                'sku_name' => $product_name,
    460519                'logo' => $logo
    461             );
     520            );           
    462521        }
    463522
     
    510569            </form>
    511570            ";
    512         $data = wp_json_encode($requestArr, JSON_UNESCAPED_SLASHES);
     571        $data = json_encode($requestArr, JSON_UNESCAPED_SLASHES);
    513572        $javascriptCode = <<<EOD
    514573            <script type='text/javascript'>
     
    543602        $payu_key = $this->currency1_payu_key;
    544603        $payu_salt = $this->currency1_payu_salt;
    545         $data_array_json = wp_json_encode($data_array, JSON_UNESCAPED_SLASHES);
     604        $data_array_json = json_encode($data_array, JSON_UNESCAPED_SLASHES);
    546605        $v2hash = hash('sha512', $data_array_json . "|" . $c_date . "|" . $payu_salt);
    547606        $username = "hmac username=\"$payu_key\"";
     
    567626        $redirect_url = $args_express_checkout['redirect_url'];
    568627        $payu_payment_nonce = $args_express_checkout['payu_payment_nonce'];
    569         $data_array_json = $args_express_checkout['data_array_json'];
     628        $data_array_json = json_encode($args_express_checkout['data_array_json']);
    570629        $c_date = $args_express_checkout['c_date'];
    571630        $auth_header_string = $args_express_checkout['auth_header_string'];
     
    580639        function handleSubmit() {
    581640            const  expressRequestObj = {
    582                 data: '$data_array_json',
     641                data: $data_array_json,
    583642                date: '$c_date',
    584643                isCheckoutExpress: true,
     
    587646            var handlers = {
    588647                responseHandler: function (BOLT) {
    589                     console.log('response from payu');                 
     648                    console.log('response from payu');
     649                    console.log(BOLT.response.amount);
     650                    console.log(JSON.stringify(BOLT.response));
     651                   
    590652                        if (BOLT.response.txnStatus == 'FAILED') {
    591653                        alert('Payment failed. Please try again.');
     
    661723        return false;
    662724    }
    663 
    664    
    665 
    666725}
Note: See TracChangeset for help on using the changeset viewer.