Plugin Directory

Changeset 2089141


Ignore:
Timestamp:
05/16/2019 01:12:37 PM (7 years ago)
Author:
CardGate
Message:

fix: cartitem tax rate

Location:
cardgate
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • cardgate/tags/3.1.13/cardgate-clientlib-php/src/Client.php

    r2046053 r2089141  
    298298            if (
    299299                ! is_string( $sIp_ )
    300                 || FALSE === filter_var( $sIp_, FILTER_VALIDATE_IP ) // NOTE ipv6
     300                || FALSE === filter_var( $sIp_, FILTER_VALIDATE_IP)
    301301            ) {
    302302                throw new Exception( 'Client.Ip.Invalid', 'invalid IP address: ' . $sIp_ );
  • cardgate/tags/3.1.13/cardgate.php

    r2052675 r2089141  
    77 * Text Domain: cardgate
    88 * Domain Path: /i18n/languages
    9  * Version: 3.1.12
     9 * Version: 3.1.13
    1010 * Requires at least: 4.4
    1111 * Author: CardGate
  • cardgate/tags/3.1.13/classes/CGP_Common_Gateway.php

    r2052675 r2089141  
    1616
    1717    var $bankOption;
    18 
    1918    var $logo;
     19    var $bSeperateSalesTax;
    2020
    2121    // ////////////////////////////////////////////////
     
    187187           
    188188            $oCardGate->setIp($_SERVER['REMOTE_ADDR']);
     189 
    189190            $oCardGate->setLanguage($sLanguage);
    190191            $oCardGate->version()->setPlatformName('Woocommerce');
     
    433434    private function getCartItems($iOrderId) {
    434435        global $woocommerce;
     436
     437        $sDefaultCountry = get_option( 'woocommerce_default_country' );
     438
     439        $this->bSeperateSalesTax = (stripos($sDefaultCountry,'US') === false ? false : true);
    435440       
    436441        $nr = 0;
     
    454459                $iTax = round(($oItem->get_total_tax() * 100) / $iQty);
    455460                $iTotal = round($iPrice + $iTax);
    456                 $iTaxrate = ($iTax > 0 ? round((($oItem->get_total_tax() * 100) / $iQty) / (($oItem->get_total()) / $iQty), 1) : 0);
     461                $iTaxrate = $this->get_tax_rate($oProduct);
    457462            } else {
    458                
     463
    459464                $aItem = $oItem;
    460465                $sName = $aItem['name'];
    461466                $sModel = 'product_' . $aItem['item_meta']['_product_id'][0];
    462467                $oProduct = $oOrder->get_product_from_item($aItem);
    463                 $iQty = (int) $aItem['item_meta']['_qty'][0];
     468                $iQty = (int)$aItem['item_meta']['_qty'][0];
    464469                $iPrice = round(($oOrder->get_item_total($aItem, false, false) * 100));
    465470                $iTax = round(($oOrder->get_item_tax($aItem, false) * 100));
     
    489494            foreach ($aShipping_methods as $oShipping) {
    490495                if (is_object($oShipping)) {
     496
    491497                    $sName = $oShipping->get_name();
    492498                    $sModel = $oShipping->get_type();
     
    494500                    $iTax = round($oShipping->get_total_tax() * 100);
    495501                    $iTotal = round($iPrice + $iTax);
    496                     $iTaxrate = ($iTax > 0 ? round(($oShipping->get_total_tax() / $oShipping->get_total()) * 100, 1) : 0);
    497502                } else {
    498503                    $aShipping = $oShipping;
     
    502507                    $iTax = round($oOrder->get_shipping_tax() * 100);
    503508                    $iTotal = round($iPrice + $iTax);
    504                     $iTaxrate = ($iTax > 0 ? round(($oOrder->get_shipping_tax() / $oOrder->get_total_shipping()) * 100, 1) : 0);
    505509                }
     510                $iTaxrate = $this->get_shipping_tax_rate($iTotal);
     511
    506512                $nr ++;
    507513                $items[$nr]['type'] = 'shipping';
     
    517523            }
    518524        }
    519        
     525
    520526        $fpExtraFee = (empty($woocommerce->session->extra_cart_fee) ? 0 : $woocommerce->session->extra_cart_fee);
    521527        $iExtraFee = round($fpExtraFee * 100);
     
    584590            return true;
    585591        }
     592    }
     593
     594
     595
     596    public function get_tax_rate($oProduct){
     597        $sDefaultCountry = get_option( 'woocommerce_default_country' );
     598        if (stripos($sDefaultCountry,'US') === false){
     599            $oTax       = new WC_Tax();
     600            $aTempRates = $oTax->get_rates( $oProduct->get_tax_class() );
     601            $aVat       = array_shift( $aTempRates );
     602            if ( isset( $aVat['rate'] ) ) {
     603                $dItemTaxRate = round( $aVat['rate'],2 );
     604            } else {
     605                $dItemTaxRate = 0;
     606            }
     607        } else {
     608            $dItemTaxRate = 0;
     609        }
     610
     611        return $dItemTaxRate;
     612    }
     613
     614    public function get_shipping_tax_rate($iTotal) {
     615
     616        if ( $iTotal > 0 && ! $this->bSeperateSalesTax ) {
     617            $oTax = new WC_Tax();
     618            $aShippingRates     = $oTax->get_shipping_tax_rates();
     619            $aVat               = array_shift( $aShippingRates );
     620            if ( isset( $aVat['rate'] ) ) {
     621                $dShippingTaxRate = round( $aVat['rate'], 2);
     622            } else {
     623                $dShippingTaxRate = 0;
     624            }
     625        } else {
     626            $dShippingTaxRate = 0;
     627        }
     628
     629        return $dShippingTaxRate;
    586630    }
    587631
  • cardgate/tags/3.1.13/readme.txt

    r2078573 r2089141  
    55Requires at least: 4.2
    66Tested up to: 5.2
    7 Stable tag: 3.1.12
     7Stable tag: 3.1.13
    88License: GPLv3 or later
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
  • cardgate/trunk/cardgate-clientlib-php/src/Client.php

    r2046053 r2089141  
    298298            if (
    299299                ! is_string( $sIp_ )
    300                 || FALSE === filter_var( $sIp_, FILTER_VALIDATE_IP ) // NOTE ipv6
     300                || FALSE === filter_var( $sIp_, FILTER_VALIDATE_IP)
    301301            ) {
    302302                throw new Exception( 'Client.Ip.Invalid', 'invalid IP address: ' . $sIp_ );
  • cardgate/trunk/cardgate.php

    r2052675 r2089141  
    77 * Text Domain: cardgate
    88 * Domain Path: /i18n/languages
    9  * Version: 3.1.12
     9 * Version: 3.1.13
    1010 * Requires at least: 4.4
    1111 * Author: CardGate
  • cardgate/trunk/classes/CGP_Common_Gateway.php

    r2052675 r2089141  
    1616
    1717    var $bankOption;
    18 
    1918    var $logo;
     19    var $bSeperateSalesTax;
    2020
    2121    // ////////////////////////////////////////////////
     
    187187           
    188188            $oCardGate->setIp($_SERVER['REMOTE_ADDR']);
     189 
    189190            $oCardGate->setLanguage($sLanguage);
    190191            $oCardGate->version()->setPlatformName('Woocommerce');
     
    433434    private function getCartItems($iOrderId) {
    434435        global $woocommerce;
     436
     437        $sDefaultCountry = get_option( 'woocommerce_default_country' );
     438
     439        $this->bSeperateSalesTax = (stripos($sDefaultCountry,'US') === false ? false : true);
    435440       
    436441        $nr = 0;
     
    454459                $iTax = round(($oItem->get_total_tax() * 100) / $iQty);
    455460                $iTotal = round($iPrice + $iTax);
    456                 $iTaxrate = ($iTax > 0 ? round((($oItem->get_total_tax() * 100) / $iQty) / (($oItem->get_total()) / $iQty), 1) : 0);
     461                $iTaxrate = $this->get_tax_rate($oProduct);
    457462            } else {
    458                
     463
    459464                $aItem = $oItem;
    460465                $sName = $aItem['name'];
    461466                $sModel = 'product_' . $aItem['item_meta']['_product_id'][0];
    462467                $oProduct = $oOrder->get_product_from_item($aItem);
    463                 $iQty = (int) $aItem['item_meta']['_qty'][0];
     468                $iQty = (int)$aItem['item_meta']['_qty'][0];
    464469                $iPrice = round(($oOrder->get_item_total($aItem, false, false) * 100));
    465470                $iTax = round(($oOrder->get_item_tax($aItem, false) * 100));
     
    489494            foreach ($aShipping_methods as $oShipping) {
    490495                if (is_object($oShipping)) {
     496
    491497                    $sName = $oShipping->get_name();
    492498                    $sModel = $oShipping->get_type();
     
    494500                    $iTax = round($oShipping->get_total_tax() * 100);
    495501                    $iTotal = round($iPrice + $iTax);
    496                     $iTaxrate = ($iTax > 0 ? round(($oShipping->get_total_tax() / $oShipping->get_total()) * 100, 1) : 0);
    497502                } else {
    498503                    $aShipping = $oShipping;
     
    502507                    $iTax = round($oOrder->get_shipping_tax() * 100);
    503508                    $iTotal = round($iPrice + $iTax);
    504                     $iTaxrate = ($iTax > 0 ? round(($oOrder->get_shipping_tax() / $oOrder->get_total_shipping()) * 100, 1) : 0);
    505509                }
     510                $iTaxrate = $this->get_shipping_tax_rate($iTotal);
     511
    506512                $nr ++;
    507513                $items[$nr]['type'] = 'shipping';
     
    517523            }
    518524        }
    519        
     525
    520526        $fpExtraFee = (empty($woocommerce->session->extra_cart_fee) ? 0 : $woocommerce->session->extra_cart_fee);
    521527        $iExtraFee = round($fpExtraFee * 100);
     
    584590            return true;
    585591        }
     592    }
     593
     594
     595
     596    public function get_tax_rate($oProduct){
     597        $sDefaultCountry = get_option( 'woocommerce_default_country' );
     598        if (stripos($sDefaultCountry,'US') === false){
     599            $oTax       = new WC_Tax();
     600            $aTempRates = $oTax->get_rates( $oProduct->get_tax_class() );
     601            $aVat       = array_shift( $aTempRates );
     602            if ( isset( $aVat['rate'] ) ) {
     603                $dItemTaxRate = round( $aVat['rate'],2 );
     604            } else {
     605                $dItemTaxRate = 0;
     606            }
     607        } else {
     608            $dItemTaxRate = 0;
     609        }
     610
     611        return $dItemTaxRate;
     612    }
     613
     614    public function get_shipping_tax_rate($iTotal) {
     615
     616        if ( $iTotal > 0 && ! $this->bSeperateSalesTax ) {
     617            $oTax = new WC_Tax();
     618            $aShippingRates     = $oTax->get_shipping_tax_rates();
     619            $aVat               = array_shift( $aShippingRates );
     620            if ( isset( $aVat['rate'] ) ) {
     621                $dShippingTaxRate = round( $aVat['rate'], 2);
     622            } else {
     623                $dShippingTaxRate = 0;
     624            }
     625        } else {
     626            $dShippingTaxRate = 0;
     627        }
     628
     629        return $dShippingTaxRate;
    586630    }
    587631
  • cardgate/trunk/readme.txt

    r2078573 r2089141  
    55Requires at least: 4.2
    66Tested up to: 5.2
    7 Stable tag: 3.1.12
     7Stable tag: 3.1.13
    88License: GPLv3 or later
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
Note: See TracChangeset for help on using the changeset viewer.