Plugin Directory

Changeset 3054427


Ignore:
Timestamp:
03/19/2024 12:24:00 PM (2 years ago)
Author:
CardGate
Message:

added: woocommerce block compatibility

Location:
cardgate
Files:
154 added
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • cardgate/tags/3.1.28/cardgate.php

    r3008166 r3054427  
    77 * Author: CardGate
    88 * Author URI: https://www.cardgate.com
    9  * Version: 3.1.27
     9 * Version: 3.1.28
    1010 * Text Domain: cardgate
    1111 * Domain Path: /i18n/languages
    1212 * Requires at least: 4.4
    1313 * WC requires at least: 3.0.0
    14  * WC tested up to: 8.1.1
     14 * WC tested up to: 8.6.1
    1515 * License: GPLv3 or later
    1616 */
     
    3636            if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
    3737                \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
     38                \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, true );
    3839            }
    3940        } );
    40         add_action('admin_head', array($this,'add_cgform_fields'));
    41         add_action('woocommerce_cart_calculate_fees', array($this,'calculate_totals'), 10, 1);
    42         add_action('wp_enqueue_scripts', array($this,'load_cg_script'));
     41
     42
     43        add_action('admin_head', array($this,'add_cgform_fields'));
     44        add_action('woocommerce_cart_calculate_fees', array($this,'calculate_totals'));
     45        add_action('wp_enqueue_scripts', array($this,'load_cg_script'),10, 1);
    4346        add_action('admin_menu', array(&$this,'CGPAdminMenu'));
    4447        add_action('init', array(&$this,'cardgate_callback'), 20);
    45        
     48        add_action( 'woocommerce_blocks_loaded', array($this,'woocommerce_cardgate_blocks_support' ));
     49        add_action('wp_loaded', array($this,'cardgate_checkout_fees'));
     50
    4651        register_activation_hook(__FILE__, array(&$this,'cardgate_install')); // hook for install
    4752        register_deactivation_hook(__FILE__, array(&$this,'cardgate_uninstall')); // hook for uninstall
     
    5055        update_option('is_callback_status_change', false);
    5156        add_action('woocommerce_cancelled_order', array(&$this,'capture_payment_failed'));
     57
    5258        if (! $this->cardgate_settings())
    5359            add_action('admin_notices', array(&$this,'my_error_notice'));
     
    468474        // check that the callback came from CardGate
    469475        if (isset($_GET['cgp_notify']) && $_GET['cgp_notify'] == 'true' && empty($_REQUEST['cgp_sitesetup'])) {
    470            
    471476            // hash check
    472477            $bIsTest = (get_option('cgp_mode') == 1 ? true : false);
     
    708713        $methods[] = 'WC_CardgateSofortbanking';
    709714        $methods[] = 'WC_CardgateSpraypay';
    710        
    711715        return $methods;
    712716    }
     
    772776        }
    773777    }
    774 
    775778    public function calculate_totals($totals) {
    776779        global $woocommerce;
    777        
     780
    778781        $woocommerce->session->extra_cart_fee = 0;
    779782        $available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
     
    789792            }
    790793        }
     794
    791795        if ($current_gateway != '') {
    792796            $current_gateway_id = $current_gateway->id;
     
    819823                    $t6 = $this->current_gateway_title . '  Extra Charges -  ';
    820824                }
     825
    821826                $woocommerce->cart->add_fee(__($t6 . $t5), $t1);
    822827                $woocommerce->session->extra_cart_fee = $t1;
     
    824829        }
    825830        return $totals;
     831    }
     832    public function is_ajax_block_update($post){
     833        return ( isset( $post['action'] ) && $post['action'] == 'wp_ajax_cardgate_checkout_fees' ) ? true : false;
    826834    }
    827835
     
    832840    }
    833841
     842    function woocommerce_cardgate_blocks_support(){
     843        // Check if the required class exists
     844        if ( ! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
     845            return;
     846        }
     847
     848        // Include the custom Blocks Checkout class
     849        require_once 'classes/woocommerce-blocks/giropay/GiropayCardgate.php';
     850        add_action(
     851            'woocommerce_blocks_payment_method_type_registration',
     852            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     853                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\GiropayCardgate() );
     854            }
     855        );
     856        require_once 'classes/woocommerce-blocks/bancontact/BancontactCardgate.php';
     857        add_action(
     858            'woocommerce_blocks_payment_method_type_registration',
     859            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     860                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\BancontactCardgate() );
     861            }
     862        );
     863        require_once 'classes/woocommerce-blocks/afterpay/AfterpayCardgate.php';
     864        add_action(
     865            'woocommerce_blocks_payment_method_type_registration',
     866            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     867                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\AfterpayCardgate() );
     868            }
     869        );
     870        require_once 'classes/woocommerce-blocks/banktransfer/BanktransferCardgate.php';
     871        add_action(
     872            'woocommerce_blocks_payment_method_type_registration',
     873            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     874                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\BanktransferCardgate() );
     875            }
     876        );
     877        require_once 'classes/woocommerce-blocks/billink/BillinkCardgate.php';
     878        add_action(
     879            'woocommerce_blocks_payment_method_type_registration',
     880            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     881                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\BillinkCardgate() );
     882            }
     883        );
     884        require_once 'classes/woocommerce-blocks/bitcoin/BitcoinCardgate.php';
     885        add_action(
     886            'woocommerce_blocks_payment_method_type_registration',
     887            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     888                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\BitcoinCardgate() );
     889            }
     890        );
     891        require_once 'classes/woocommerce-blocks/creditcard/CreditcardCardgate.php';
     892        add_action(
     893            'woocommerce_blocks_payment_method_type_registration',
     894            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     895                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\CreditcardCardgate() );
     896            }
     897        );
     898        require_once 'classes/woocommerce-blocks/directdebit/DirectDebitCardgate.php';
     899        add_action(
     900            'woocommerce_blocks_payment_method_type_registration',
     901            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     902                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\DirectDebitCardgate() );
     903            }
     904        );
     905        require_once 'classes/woocommerce-blocks/giftcard/GiftcardCardgate.php';
     906        add_action(
     907            'woocommerce_blocks_payment_method_type_registration',
     908            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     909                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\GiftcardCardgate() );
     910            }
     911        );
     912        require_once 'classes/woocommerce-blocks/ideal/IdealCardgate.php';
     913        add_action(
     914            'woocommerce_blocks_payment_method_type_registration',
     915            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     916                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\IdealCardgate() );
     917            }
     918        );
     919        require_once 'classes/woocommerce-blocks/idealqr/IdealqrCardgate.php';
     920        add_action(
     921            'woocommerce_blocks_payment_method_type_registration',
     922            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     923                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\IdealqrCardgate() );
     924            }
     925        );
     926        require_once 'classes/woocommerce-blocks/klarna/KlarnaCardgate.php';
     927        add_action(
     928            'woocommerce_blocks_payment_method_type_registration',
     929            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     930                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\KlarnaCardgate() );
     931            }
     932        );
     933        require_once 'classes/woocommerce-blocks/onlineueberweisen/OnlineueberweisenCardgate.php';
     934        add_action(
     935            'woocommerce_blocks_payment_method_type_registration',
     936            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     937                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\OnlineueberweisenCardgate() );
     938            }
     939        );
     940        require_once 'classes/woocommerce-blocks/paypal/PaypalCardgate.php';
     941        add_action(
     942            'woocommerce_blocks_payment_method_type_registration',
     943            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     944                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\PaypalCardgate() );
     945            }
     946        );
     947        require_once 'classes/woocommerce-blocks/paysafecard/PaysafecardCardgate.php';
     948        add_action(
     949            'woocommerce_blocks_payment_method_type_registration',
     950            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     951                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\PaysafecardCardgate() );
     952            }
     953        );
     954        require_once 'classes/woocommerce-blocks/paysafecash/PaysafecashCardgate.php';
     955        add_action(
     956            'woocommerce_blocks_payment_method_type_registration',
     957            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     958                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\PaysafecashCardgate() );
     959            }
     960        );
     961        require_once 'classes/woocommerce-blocks/przelewy24/Przelewy24Cardgate.php';
     962        add_action(
     963            'woocommerce_blocks_payment_method_type_registration',
     964            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     965                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\Przelewy24Cardgate() );
     966            }
     967        );
     968        require_once 'classes/woocommerce-blocks/sofortbanking/SofortbankingCardgate.php';
     969        add_action(
     970            'woocommerce_blocks_payment_method_type_registration',
     971            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     972                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\SofortbankingCardgate() );
     973            }
     974        );
     975        require_once 'classes/woocommerce-blocks/spraypay/SpraypayCardgate.php';
     976        add_action(
     977            'woocommerce_blocks_payment_method_type_registration',
     978            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     979                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\SpraypayCardgate() );
     980            }
     981        );
     982    }
     983
     984    public function cardgate_checkout_fees() {
     985        global $woocommerce;
     986        if ( isset( $_POST ) && $this->is_ajax_block_update( $_POST ) ) {
     987            $method = $_POST['method'];
     988            $feeData = $this->getFeeData($method);
     989
     990            $this->cartRemoveFee( $feeData['label'] );
     991            $newTotal = (float) $woocommerce->cart->get_totals()['total'];
     992            $totalTax = $woocommerce->cart->get_totals()['total_tax'];
     993            $noSurchargeData = [
     994
     995                'amount' => false,
     996                'name' => '',
     997                'currency' => get_woocommerce_currency_symbol(),
     998                'newTotal' => $newTotal,
     999                'totalTax' => $totalTax,
     1000            ];
     1001            if (!$feeData['fee'] || $feeData['fee'] == 0) {
     1002                wp_send_json_success($noSurchargeData);
     1003                return;
     1004            }
     1005
     1006            $feeAmount = $feeData['fee'];
     1007            $label = $feeData['label'];
     1008            add_action('woocommerce_cart_calculate_fees', static function () use ($label, $feeAmount) {
     1009                global $woocommerce;
     1010                $woocommerce->cart->add_fee($label, $feeAmount, true, 'standard');
     1011            });
     1012
     1013            //add global woocommerce.
     1014
     1015            $woocommerce->cart->calculate_totals();
     1016
     1017            $feeAmountTaxed = (float) $woocommerce->cart->get_totals()['fee_total'];
     1018            $taxDisplayMode = get_option('woocommerce_tax_display_shop');
     1019            if ($taxDisplayMode === 'incl') {
     1020                $feeAmountTaxed = $feeAmountTaxed + (float) $woocommerce->cart->get_totals()['fee_tax'];
     1021            }
     1022            $newTotal = (float) $woocommerce->cart->get_totals()['total'];
     1023            $totalTax = $woocommerce->cart->get_totals()['total_tax'];
     1024            $data = [
     1025                'amount' => $feeAmountTaxed,
     1026                'name' => $feeData['label'],
     1027                'currency' => get_woocommerce_currency_symbol(),
     1028                'newTotal' => $newTotal,
     1029                'totalTax' => $totalTax,
     1030                'cart' => $woocommerce->cart->get_totals(),
     1031            ];
     1032
     1033            wp_send_json_success($data);
     1034        }
     1035    }
     1036    protected function cartRemoveFee($label)
     1037    {
     1038        add_action('woocommerce_before_calculate_totals', static function () use ($label) {
     1039            $fees = WC()->cart->get_fees();
     1040            foreach ($fees as $key => $fee) {
     1041                if ($fees[$key]->name === $label) {
     1042                    unset($fees[$key]);
     1043                }
     1044            }
     1045            WC()->cart->fees_api()->set_fees($fees);
     1046        });
     1047    }
     1048    protected function getFeeData($method) {
     1049        global $woocommerce;
     1050        $woocommerce->cart;
     1051        $woocommerce->cart->calculate_totals();
     1052        $data = [];
     1053        $fee = get_option('woocommerce_' . $method . '_extra_charges');
     1054        $fee = $fee == "" ? 0: $fee;
     1055        $label = get_option( 'woocommerce_' . $method . '_extra_charges_label');
     1056        $type = get_option('woocommerce_' . $method . '_extra_charges_type');
     1057        if (isset($label) && strlen($label) > 2) {
     1058            if ($type == 'percentage'){
     1059                $label .= ' '. $fee.'%';
     1060            }
     1061        } else {
     1062            $label= $this->current_gateway_title . '  Payment Charges ';
     1063        }
     1064
     1065        if ($type == "percentage") {
     1066            $cart_total = (float) $woocommerce->cart->get_subtotal('edit');
     1067            $payment_fee = ($cart_total * $fee) / 100;
     1068        } else {
     1069            $payment_fee = $fee;
     1070        }
     1071        $data['fee'] = $payment_fee;
     1072        $data['type'] = ($type == "percentage" ? $fee . '%' : 'Fixed');
     1073        $data['label'] = $label;
     1074        return $data;
     1075    }
    8341076    public function set_plugin_url() {
    8351077        $this->plugin_url = untrailingslashit(plugins_url('/', __FILE__));
     
    8901132    spl_autoload_register('cardgate_autoload');
    8911133endif;
    892 
    8931134?>
  • cardgate/tags/3.1.28/classes/CGP_Common_Gateway.php

    r2975181 r3054427  
    8484     * Fetch bank options from Card Gate
    8585     */
    86     private function getBankOptions() {
     86    public function getBankOptions() {
    8787        $this->checkBankOptions();
    8888        $aIssuers = get_option( 'sIssuers' );
     
    200200        global $woocommerce;
    201201        try {
    202 
     202            $oOrder = new WC_Order( $iOrderId );
     203            $this->correct_payment_fee($oOrder);
     204            $oOrder->save();
    203205            $this->savePaymentData( $iOrderId );
    204206
     
    207209            $bIsTest         = ( get_option( 'cgp_mode' ) == 1 ? true : false );
    208210            $sLanguage       = substr( get_locale(), 0, 2 );
    209             $oOrder          = new WC_Order( $iOrderId );
    210211
    211212            $sVersion = ( $this->get_woocommerce_version() == '' ? 'unkown' : $this->get_woocommerce_version() );
     
    369370                return [
    370371                    'result'   => 'success',
    371                     'redirect' => $woocommerce->cart->get_checkout_url()
     372                    'redirect' => wc_get_checkout_url()
    372373                ];
    373374            }
     
    378379            return [
    379380                'result'   => 'success',
    380                 'redirect' => $woocommerce->cart->get_checkout_url()
     381                'redirect' => wc_get_checkout_url()
    381382            ];
    382383        }
    383384    }
     385
     386    protected function correct_payment_fee(&$oOrder) {
     387        if ($this->has_block_checkout()){
     388            $fees = $oOrder->get_fees();
     389            $feeData = $this->getFeeData($oOrder->get_payment_method());
     390            $hasFee = array_key_exists('fee',$feeData) && $feeData['fee'] !== 0.0;
     391            $correctedFee = false;
     392            foreach ($fees as $fee) {
     393                $feeName = $fee->get_name();
     394                $feeId = $fee->get_id();
     395                $hasCardgateFee = strpos($feeName, $feeData['label']) !== false;
     396                if ($hasCardgateFee) {
     397                    if ($feeData['amount'] == (float)$fee->get_amount('edit')) {
     398                        $correctedFee = true;
     399                        continue;
     400                    }
     401                    if (!$correctedFee) {
     402                        $this->removeOrderFee($oOrder, $feeId);
     403                        $correctedFee = true;
     404                        continue;
     405                    }
     406                    $this->removeOrderFee($oOrder, $feeId);
     407                    $this->orderAddFee($oOrder, $feeData['fee'], $feeData['label']);
     408                    $correctedFee = true;
     409                }
     410            }
     411            if (!$correctedFee) {
     412                if ($hasFee) {
     413                    $this->orderAddFee($oOrder, $feeData['fee'], $feeData['label']);
     414                }
     415            }
     416        }
     417        if ($hasFee) {
     418            $feeName = $feeData['label'];
     419            $this->setSessionfee( $oOrder, $feeName );
     420        }
     421        return $oOrder;
     422    }
     423
     424    function setSessionFee($oOrder, $feeName){
     425        WC()->session->extra_cart_fee = WC()->session->extra_cart_fee_tax = 0;
     426        $aFees = $oOrder->get_fees();
     427        foreach($aFees as $fee){
     428            if($fee['name'] == $feeName){
     429                WC()->session->extra_cart_fee = $fee->get_total();
     430                WC()->session->extra_cart_fee_tax = $fee->get_total_tax();
     431            }
     432        }
     433    }
     434
     435    protected function removeOrderFee(&$oOrder, int $feeId) {
     436        $oOrder->remove_item($feeId);
     437        wc_delete_order_item($feeId);
     438        $oOrder->calculate_totals();
     439    }
     440
     441    protected function orderAddFee(&$oOrder, $amount, $feeName) {
     442        $item_fee = new \WC_Order_Item_Fee();
     443        $item_fee->set_name($feeName);
     444        $item_fee->set_amount($amount);
     445        $item_fee->set_total($amount);
     446        $item_fee->set_tax_status(true);
     447        $oOrder->add_item($item_fee);
     448        $oOrder->calculate_totals();
     449    }
     450
     451    protected function getFeeData($method) {
     452        global $woocommerce;
     453        $woocommerce->cart;
     454        $woocommerce->cart->calculate_totals();
     455        $data = [];
     456        $fee = get_option('woocommerce_' . $method . '_extra_charges');
     457        $fee = $fee == "" ? 0: $fee;
     458        $label = get_option( 'woocommerce_' . $method . '_extra_charges_label');
     459        $type = get_option('woocommerce_' . $method . '_extra_charges_type');
     460        if (isset($label) && strlen($label) > 2) {
     461            if ($type == 'percentage'){
     462                $label .= ' '. $fee.'%';
     463            }
     464        } else {
     465            $label= $this->current_gateway_title . '  Payment Charges ';
     466        }
     467
     468        if ($type == "percentage") {
     469            $cart_total = (float) $woocommerce->cart->get_subtotal('edit');
     470            $payment_fee = ($cart_total * $fee) / 100;
     471        } else {
     472            $payment_fee = $fee;
     473        }
     474        $data['fee'] = $payment_fee;
     475        $data['type'] = ($type == "percentage" ? $fee . '%' : 'Fixed');
     476        $data['label'] = $label;
     477        return $data;
     478    }
     479
     480    public function has_block_checkout(){
     481        $uses_blocks = class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType');
     482        $isClassicCheckout = isset($_REQUEST["wc-ajax"]) && $_REQUEST["wc-ajax"] === "checkout";
     483        return ($uses_blocks && !$isClassicCheckout);
     484    }
    384485
    385486    // ////////////////////////////////////////////////
     
    479580            }
    480581        }
    481         if ( WC()->version < '3.0.0' ) {
    482             $order_id = $order->id;
    483         } else {
    484             $order_id = $order->get_id();
    485         }
     582
     583        $order_id = $order->get_id();
    486584
    487585        $data = [
     
    634732        $fpExtraFee = ( empty( $woocommerce->session->extra_cart_fee ) ? 0 : $woocommerce->session->extra_cart_fee );
    635733        $iExtraFee  = round( $fpExtraFee * 100 );
    636 
    637         if ( $iExtraFee > 0 ) {
     734        $fpExtraFeeTax = ( empty( $woocommerce->session->extra_cart_fee_tax ) ? 0 : $woocommerce->session->extra_cart_fee_tax );
     735        $iExtraFeeTax  = round( $fpExtraFeeTax * 100 );
     736
     737        if ($iExtraFeeTax > 0){
     738            $iTaxRate = round($iExtraFeeTax / $fpExtraFee,2);
     739            $nr ++;
     740            $items[ $nr ]['type']       = 'paymentfee';
     741            $items[ $nr ]['model']      = 'extra_costs';
     742            $items[ $nr ]['name']       = 'payment_fee';
     743            $items[ $nr ]['quantity']   = 1;
     744            $items[ $nr ]['price_wt']   = $iExtraFee;
     745            $items[ $nr ]['vat']        = $iTaxRate;
     746            $items[ $nr ]['vat_amount'] = $iExtraFeeTax;
     747
     748        } elseif ( $iExtraFee > 0 ) {
    638749
    639750            $nr ++;
     
    666777        }
    667778
    668         $iTaxDifference = round( $oOrder->get_total_tax() * 100 ) - $iCartItemTaxTotal - $ishippingTaxTotal - $iDiscountTaxTotal;
     779        $iTaxDifference = round( $oOrder->get_total_tax() * 100 ) - $iCartItemTaxTotal - $ishippingTaxTotal - $iExtraFeeTax - $iDiscountTaxTotal;
    669780        if ( $iTaxDifference != 0 ) {
    670781            $nr ++;
     
    678789        }
    679790
    680         $iCorrection = round( $iOrderTotal - $iCartItemTotal - $iCartItemTaxTotal - $iShippingTotal - $ishippingTaxTotal - $iExtraFee - $iTaxDifference - $iDiscountTotal - $iDiscountTaxTotal);
     791        $iCorrection = round( $iOrderTotal - $iCartItemTotal - $iCartItemTaxTotal - $iShippingTotal - $ishippingTaxTotal - $iExtraFee - $iExtraFeeTax - $iTaxDifference - $iDiscountTotal - $iDiscountTaxTotal);
    681792
    682793        if ( $iCorrection != 0 ) {
     
    706817    public function validate_fields() {
    707818        global $woocommerce;
    708 
    709         if ( $_POST['payment_method'] == 'cardgateideal' ) {
     819        if (key_exists('wc-cardgateideal-new-payment-method',$_POST)) {
     820            if ( empty( $_POST['cardgateideal_issuer'] ) || $_POST['cardgateideal_issuer'] == '0' ) {
     821                wc_add_notice( __( ' Choose your bank first, please', 'cardgate' ), 'error' );
     822                return false;
     823            } else {
     824                $this->bankOption = $_POST['cardgateideal_issuer'];
     825            }
     826        } elseif (key_exists('payment_method', $_POST) &&  $_POST['payment_method'] == 'cardgateideal' ) {
    710827            if ( empty( $_POST['cgp_bank_options'] ) || $_POST['cgp_bank_options'] == '0' ) {
    711828                wc_add_notice( __( ' Choose your bank first, please', 'cardgate' ), 'error' );
    712 
    713829                return false;
    714830            } else {
  • cardgate/tags/3.1.28/classes/WC_CardgateIdealqr.php

    r2491968 r3054427  
    1111class WC_CardgateIdealqr extends CGP_Common_Gateway {
    1212
    13     var $id = 'cardgateaIdealqr';
     13    var $id = 'cardgateidealqr';
    1414    var $title = '';
    1515    var $method_title = 'Cardgate iDEAL QR';
  • cardgate/tags/3.1.28/readme.txt

    r3008166 r3054427  
    55Requires at least: 4.4
    66Tested up to: 6.4
    7 Stable tag: 3.1.27
     7Stable tag: 3.1.28
    88License: GPLv3 or later
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    7575
    7676== Changelog ==
     77
     78= 3.1.28 =
     79* Added: Woocommerce block compatibility
    7780
    7881= 3.1.27 =
  • cardgate/trunk/cardgate.php

    r3008166 r3054427  
    77 * Author: CardGate
    88 * Author URI: https://www.cardgate.com
    9  * Version: 3.1.27
     9 * Version: 3.1.28
    1010 * Text Domain: cardgate
    1111 * Domain Path: /i18n/languages
    1212 * Requires at least: 4.4
    1313 * WC requires at least: 3.0.0
    14  * WC tested up to: 8.1.1
     14 * WC tested up to: 8.6.1
    1515 * License: GPLv3 or later
    1616 */
     
    3636            if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
    3737                \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
     38                \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, true );
    3839            }
    3940        } );
    40         add_action('admin_head', array($this,'add_cgform_fields'));
    41         add_action('woocommerce_cart_calculate_fees', array($this,'calculate_totals'), 10, 1);
    42         add_action('wp_enqueue_scripts', array($this,'load_cg_script'));
     41
     42
     43        add_action('admin_head', array($this,'add_cgform_fields'));
     44        add_action('woocommerce_cart_calculate_fees', array($this,'calculate_totals'));
     45        add_action('wp_enqueue_scripts', array($this,'load_cg_script'),10, 1);
    4346        add_action('admin_menu', array(&$this,'CGPAdminMenu'));
    4447        add_action('init', array(&$this,'cardgate_callback'), 20);
    45        
     48        add_action( 'woocommerce_blocks_loaded', array($this,'woocommerce_cardgate_blocks_support' ));
     49        add_action('wp_loaded', array($this,'cardgate_checkout_fees'));
     50
    4651        register_activation_hook(__FILE__, array(&$this,'cardgate_install')); // hook for install
    4752        register_deactivation_hook(__FILE__, array(&$this,'cardgate_uninstall')); // hook for uninstall
     
    5055        update_option('is_callback_status_change', false);
    5156        add_action('woocommerce_cancelled_order', array(&$this,'capture_payment_failed'));
     57
    5258        if (! $this->cardgate_settings())
    5359            add_action('admin_notices', array(&$this,'my_error_notice'));
     
    468474        // check that the callback came from CardGate
    469475        if (isset($_GET['cgp_notify']) && $_GET['cgp_notify'] == 'true' && empty($_REQUEST['cgp_sitesetup'])) {
    470            
    471476            // hash check
    472477            $bIsTest = (get_option('cgp_mode') == 1 ? true : false);
     
    708713        $methods[] = 'WC_CardgateSofortbanking';
    709714        $methods[] = 'WC_CardgateSpraypay';
    710        
    711715        return $methods;
    712716    }
     
    772776        }
    773777    }
    774 
    775778    public function calculate_totals($totals) {
    776779        global $woocommerce;
    777        
     780
    778781        $woocommerce->session->extra_cart_fee = 0;
    779782        $available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
     
    789792            }
    790793        }
     794
    791795        if ($current_gateway != '') {
    792796            $current_gateway_id = $current_gateway->id;
     
    819823                    $t6 = $this->current_gateway_title . '  Extra Charges -  ';
    820824                }
     825
    821826                $woocommerce->cart->add_fee(__($t6 . $t5), $t1);
    822827                $woocommerce->session->extra_cart_fee = $t1;
     
    824829        }
    825830        return $totals;
     831    }
     832    public function is_ajax_block_update($post){
     833        return ( isset( $post['action'] ) && $post['action'] == 'wp_ajax_cardgate_checkout_fees' ) ? true : false;
    826834    }
    827835
     
    832840    }
    833841
     842    function woocommerce_cardgate_blocks_support(){
     843        // Check if the required class exists
     844        if ( ! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
     845            return;
     846        }
     847
     848        // Include the custom Blocks Checkout class
     849        require_once 'classes/woocommerce-blocks/giropay/GiropayCardgate.php';
     850        add_action(
     851            'woocommerce_blocks_payment_method_type_registration',
     852            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     853                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\GiropayCardgate() );
     854            }
     855        );
     856        require_once 'classes/woocommerce-blocks/bancontact/BancontactCardgate.php';
     857        add_action(
     858            'woocommerce_blocks_payment_method_type_registration',
     859            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     860                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\BancontactCardgate() );
     861            }
     862        );
     863        require_once 'classes/woocommerce-blocks/afterpay/AfterpayCardgate.php';
     864        add_action(
     865            'woocommerce_blocks_payment_method_type_registration',
     866            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     867                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\AfterpayCardgate() );
     868            }
     869        );
     870        require_once 'classes/woocommerce-blocks/banktransfer/BanktransferCardgate.php';
     871        add_action(
     872            'woocommerce_blocks_payment_method_type_registration',
     873            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     874                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\BanktransferCardgate() );
     875            }
     876        );
     877        require_once 'classes/woocommerce-blocks/billink/BillinkCardgate.php';
     878        add_action(
     879            'woocommerce_blocks_payment_method_type_registration',
     880            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     881                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\BillinkCardgate() );
     882            }
     883        );
     884        require_once 'classes/woocommerce-blocks/bitcoin/BitcoinCardgate.php';
     885        add_action(
     886            'woocommerce_blocks_payment_method_type_registration',
     887            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     888                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\BitcoinCardgate() );
     889            }
     890        );
     891        require_once 'classes/woocommerce-blocks/creditcard/CreditcardCardgate.php';
     892        add_action(
     893            'woocommerce_blocks_payment_method_type_registration',
     894            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     895                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\CreditcardCardgate() );
     896            }
     897        );
     898        require_once 'classes/woocommerce-blocks/directdebit/DirectDebitCardgate.php';
     899        add_action(
     900            'woocommerce_blocks_payment_method_type_registration',
     901            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     902                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\DirectDebitCardgate() );
     903            }
     904        );
     905        require_once 'classes/woocommerce-blocks/giftcard/GiftcardCardgate.php';
     906        add_action(
     907            'woocommerce_blocks_payment_method_type_registration',
     908            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     909                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\GiftcardCardgate() );
     910            }
     911        );
     912        require_once 'classes/woocommerce-blocks/ideal/IdealCardgate.php';
     913        add_action(
     914            'woocommerce_blocks_payment_method_type_registration',
     915            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     916                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\IdealCardgate() );
     917            }
     918        );
     919        require_once 'classes/woocommerce-blocks/idealqr/IdealqrCardgate.php';
     920        add_action(
     921            'woocommerce_blocks_payment_method_type_registration',
     922            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     923                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\IdealqrCardgate() );
     924            }
     925        );
     926        require_once 'classes/woocommerce-blocks/klarna/KlarnaCardgate.php';
     927        add_action(
     928            'woocommerce_blocks_payment_method_type_registration',
     929            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     930                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\KlarnaCardgate() );
     931            }
     932        );
     933        require_once 'classes/woocommerce-blocks/onlineueberweisen/OnlineueberweisenCardgate.php';
     934        add_action(
     935            'woocommerce_blocks_payment_method_type_registration',
     936            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     937                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\OnlineueberweisenCardgate() );
     938            }
     939        );
     940        require_once 'classes/woocommerce-blocks/paypal/PaypalCardgate.php';
     941        add_action(
     942            'woocommerce_blocks_payment_method_type_registration',
     943            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     944                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\PaypalCardgate() );
     945            }
     946        );
     947        require_once 'classes/woocommerce-blocks/paysafecard/PaysafecardCardgate.php';
     948        add_action(
     949            'woocommerce_blocks_payment_method_type_registration',
     950            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     951                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\PaysafecardCardgate() );
     952            }
     953        );
     954        require_once 'classes/woocommerce-blocks/paysafecash/PaysafecashCardgate.php';
     955        add_action(
     956            'woocommerce_blocks_payment_method_type_registration',
     957            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     958                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\PaysafecashCardgate() );
     959            }
     960        );
     961        require_once 'classes/woocommerce-blocks/przelewy24/Przelewy24Cardgate.php';
     962        add_action(
     963            'woocommerce_blocks_payment_method_type_registration',
     964            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     965                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\Przelewy24Cardgate() );
     966            }
     967        );
     968        require_once 'classes/woocommerce-blocks/sofortbanking/SofortbankingCardgate.php';
     969        add_action(
     970            'woocommerce_blocks_payment_method_type_registration',
     971            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     972                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\SofortbankingCardgate() );
     973            }
     974        );
     975        require_once 'classes/woocommerce-blocks/spraypay/SpraypayCardgate.php';
     976        add_action(
     977            'woocommerce_blocks_payment_method_type_registration',
     978            function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     979                $payment_method_registry->register( new \Automattic\WooCommerce\Blocks\Payments\Integrations\SpraypayCardgate() );
     980            }
     981        );
     982    }
     983
     984    public function cardgate_checkout_fees() {
     985        global $woocommerce;
     986        if ( isset( $_POST ) && $this->is_ajax_block_update( $_POST ) ) {
     987            $method = $_POST['method'];
     988            $feeData = $this->getFeeData($method);
     989
     990            $this->cartRemoveFee( $feeData['label'] );
     991            $newTotal = (float) $woocommerce->cart->get_totals()['total'];
     992            $totalTax = $woocommerce->cart->get_totals()['total_tax'];
     993            $noSurchargeData = [
     994
     995                'amount' => false,
     996                'name' => '',
     997                'currency' => get_woocommerce_currency_symbol(),
     998                'newTotal' => $newTotal,
     999                'totalTax' => $totalTax,
     1000            ];
     1001            if (!$feeData['fee'] || $feeData['fee'] == 0) {
     1002                wp_send_json_success($noSurchargeData);
     1003                return;
     1004            }
     1005
     1006            $feeAmount = $feeData['fee'];
     1007            $label = $feeData['label'];
     1008            add_action('woocommerce_cart_calculate_fees', static function () use ($label, $feeAmount) {
     1009                global $woocommerce;
     1010                $woocommerce->cart->add_fee($label, $feeAmount, true, 'standard');
     1011            });
     1012
     1013            //add global woocommerce.
     1014
     1015            $woocommerce->cart->calculate_totals();
     1016
     1017            $feeAmountTaxed = (float) $woocommerce->cart->get_totals()['fee_total'];
     1018            $taxDisplayMode = get_option('woocommerce_tax_display_shop');
     1019            if ($taxDisplayMode === 'incl') {
     1020                $feeAmountTaxed = $feeAmountTaxed + (float) $woocommerce->cart->get_totals()['fee_tax'];
     1021            }
     1022            $newTotal = (float) $woocommerce->cart->get_totals()['total'];
     1023            $totalTax = $woocommerce->cart->get_totals()['total_tax'];
     1024            $data = [
     1025                'amount' => $feeAmountTaxed,
     1026                'name' => $feeData['label'],
     1027                'currency' => get_woocommerce_currency_symbol(),
     1028                'newTotal' => $newTotal,
     1029                'totalTax' => $totalTax,
     1030                'cart' => $woocommerce->cart->get_totals(),
     1031            ];
     1032
     1033            wp_send_json_success($data);
     1034        }
     1035    }
     1036    protected function cartRemoveFee($label)
     1037    {
     1038        add_action('woocommerce_before_calculate_totals', static function () use ($label) {
     1039            $fees = WC()->cart->get_fees();
     1040            foreach ($fees as $key => $fee) {
     1041                if ($fees[$key]->name === $label) {
     1042                    unset($fees[$key]);
     1043                }
     1044            }
     1045            WC()->cart->fees_api()->set_fees($fees);
     1046        });
     1047    }
     1048    protected function getFeeData($method) {
     1049        global $woocommerce;
     1050        $woocommerce->cart;
     1051        $woocommerce->cart->calculate_totals();
     1052        $data = [];
     1053        $fee = get_option('woocommerce_' . $method . '_extra_charges');
     1054        $fee = $fee == "" ? 0: $fee;
     1055        $label = get_option( 'woocommerce_' . $method . '_extra_charges_label');
     1056        $type = get_option('woocommerce_' . $method . '_extra_charges_type');
     1057        if (isset($label) && strlen($label) > 2) {
     1058            if ($type == 'percentage'){
     1059                $label .= ' '. $fee.'%';
     1060            }
     1061        } else {
     1062            $label= $this->current_gateway_title . '  Payment Charges ';
     1063        }
     1064
     1065        if ($type == "percentage") {
     1066            $cart_total = (float) $woocommerce->cart->get_subtotal('edit');
     1067            $payment_fee = ($cart_total * $fee) / 100;
     1068        } else {
     1069            $payment_fee = $fee;
     1070        }
     1071        $data['fee'] = $payment_fee;
     1072        $data['type'] = ($type == "percentage" ? $fee . '%' : 'Fixed');
     1073        $data['label'] = $label;
     1074        return $data;
     1075    }
    8341076    public function set_plugin_url() {
    8351077        $this->plugin_url = untrailingslashit(plugins_url('/', __FILE__));
     
    8901132    spl_autoload_register('cardgate_autoload');
    8911133endif;
    892 
    8931134?>
  • cardgate/trunk/classes/CGP_Common_Gateway.php

    r2975181 r3054427  
    8484     * Fetch bank options from Card Gate
    8585     */
    86     private function getBankOptions() {
     86    public function getBankOptions() {
    8787        $this->checkBankOptions();
    8888        $aIssuers = get_option( 'sIssuers' );
     
    200200        global $woocommerce;
    201201        try {
    202 
     202            $oOrder = new WC_Order( $iOrderId );
     203            $this->correct_payment_fee($oOrder);
     204            $oOrder->save();
    203205            $this->savePaymentData( $iOrderId );
    204206
     
    207209            $bIsTest         = ( get_option( 'cgp_mode' ) == 1 ? true : false );
    208210            $sLanguage       = substr( get_locale(), 0, 2 );
    209             $oOrder          = new WC_Order( $iOrderId );
    210211
    211212            $sVersion = ( $this->get_woocommerce_version() == '' ? 'unkown' : $this->get_woocommerce_version() );
     
    369370                return [
    370371                    'result'   => 'success',
    371                     'redirect' => $woocommerce->cart->get_checkout_url()
     372                    'redirect' => wc_get_checkout_url()
    372373                ];
    373374            }
     
    378379            return [
    379380                'result'   => 'success',
    380                 'redirect' => $woocommerce->cart->get_checkout_url()
     381                'redirect' => wc_get_checkout_url()
    381382            ];
    382383        }
    383384    }
     385
     386    protected function correct_payment_fee(&$oOrder) {
     387        if ($this->has_block_checkout()){
     388            $fees = $oOrder->get_fees();
     389            $feeData = $this->getFeeData($oOrder->get_payment_method());
     390            $hasFee = array_key_exists('fee',$feeData) && $feeData['fee'] !== 0.0;
     391            $correctedFee = false;
     392            foreach ($fees as $fee) {
     393                $feeName = $fee->get_name();
     394                $feeId = $fee->get_id();
     395                $hasCardgateFee = strpos($feeName, $feeData['label']) !== false;
     396                if ($hasCardgateFee) {
     397                    if ($feeData['amount'] == (float)$fee->get_amount('edit')) {
     398                        $correctedFee = true;
     399                        continue;
     400                    }
     401                    if (!$correctedFee) {
     402                        $this->removeOrderFee($oOrder, $feeId);
     403                        $correctedFee = true;
     404                        continue;
     405                    }
     406                    $this->removeOrderFee($oOrder, $feeId);
     407                    $this->orderAddFee($oOrder, $feeData['fee'], $feeData['label']);
     408                    $correctedFee = true;
     409                }
     410            }
     411            if (!$correctedFee) {
     412                if ($hasFee) {
     413                    $this->orderAddFee($oOrder, $feeData['fee'], $feeData['label']);
     414                }
     415            }
     416        }
     417        if ($hasFee) {
     418            $feeName = $feeData['label'];
     419            $this->setSessionfee( $oOrder, $feeName );
     420        }
     421        return $oOrder;
     422    }
     423
     424    function setSessionFee($oOrder, $feeName){
     425        WC()->session->extra_cart_fee = WC()->session->extra_cart_fee_tax = 0;
     426        $aFees = $oOrder->get_fees();
     427        foreach($aFees as $fee){
     428            if($fee['name'] == $feeName){
     429                WC()->session->extra_cart_fee = $fee->get_total();
     430                WC()->session->extra_cart_fee_tax = $fee->get_total_tax();
     431            }
     432        }
     433    }
     434
     435    protected function removeOrderFee(&$oOrder, int $feeId) {
     436        $oOrder->remove_item($feeId);
     437        wc_delete_order_item($feeId);
     438        $oOrder->calculate_totals();
     439    }
     440
     441    protected function orderAddFee(&$oOrder, $amount, $feeName) {
     442        $item_fee = new \WC_Order_Item_Fee();
     443        $item_fee->set_name($feeName);
     444        $item_fee->set_amount($amount);
     445        $item_fee->set_total($amount);
     446        $item_fee->set_tax_status(true);
     447        $oOrder->add_item($item_fee);
     448        $oOrder->calculate_totals();
     449    }
     450
     451    protected function getFeeData($method) {
     452        global $woocommerce;
     453        $woocommerce->cart;
     454        $woocommerce->cart->calculate_totals();
     455        $data = [];
     456        $fee = get_option('woocommerce_' . $method . '_extra_charges');
     457        $fee = $fee == "" ? 0: $fee;
     458        $label = get_option( 'woocommerce_' . $method . '_extra_charges_label');
     459        $type = get_option('woocommerce_' . $method . '_extra_charges_type');
     460        if (isset($label) && strlen($label) > 2) {
     461            if ($type == 'percentage'){
     462                $label .= ' '. $fee.'%';
     463            }
     464        } else {
     465            $label= $this->current_gateway_title . '  Payment Charges ';
     466        }
     467
     468        if ($type == "percentage") {
     469            $cart_total = (float) $woocommerce->cart->get_subtotal('edit');
     470            $payment_fee = ($cart_total * $fee) / 100;
     471        } else {
     472            $payment_fee = $fee;
     473        }
     474        $data['fee'] = $payment_fee;
     475        $data['type'] = ($type == "percentage" ? $fee . '%' : 'Fixed');
     476        $data['label'] = $label;
     477        return $data;
     478    }
     479
     480    public function has_block_checkout(){
     481        $uses_blocks = class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType');
     482        $isClassicCheckout = isset($_REQUEST["wc-ajax"]) && $_REQUEST["wc-ajax"] === "checkout";
     483        return ($uses_blocks && !$isClassicCheckout);
     484    }
    384485
    385486    // ////////////////////////////////////////////////
     
    479580            }
    480581        }
    481         if ( WC()->version < '3.0.0' ) {
    482             $order_id = $order->id;
    483         } else {
    484             $order_id = $order->get_id();
    485         }
     582
     583        $order_id = $order->get_id();
    486584
    487585        $data = [
     
    634732        $fpExtraFee = ( empty( $woocommerce->session->extra_cart_fee ) ? 0 : $woocommerce->session->extra_cart_fee );
    635733        $iExtraFee  = round( $fpExtraFee * 100 );
    636 
    637         if ( $iExtraFee > 0 ) {
     734        $fpExtraFeeTax = ( empty( $woocommerce->session->extra_cart_fee_tax ) ? 0 : $woocommerce->session->extra_cart_fee_tax );
     735        $iExtraFeeTax  = round( $fpExtraFeeTax * 100 );
     736
     737        if ($iExtraFeeTax > 0){
     738            $iTaxRate = round($iExtraFeeTax / $fpExtraFee,2);
     739            $nr ++;
     740            $items[ $nr ]['type']       = 'paymentfee';
     741            $items[ $nr ]['model']      = 'extra_costs';
     742            $items[ $nr ]['name']       = 'payment_fee';
     743            $items[ $nr ]['quantity']   = 1;
     744            $items[ $nr ]['price_wt']   = $iExtraFee;
     745            $items[ $nr ]['vat']        = $iTaxRate;
     746            $items[ $nr ]['vat_amount'] = $iExtraFeeTax;
     747
     748        } elseif ( $iExtraFee > 0 ) {
    638749
    639750            $nr ++;
     
    666777        }
    667778
    668         $iTaxDifference = round( $oOrder->get_total_tax() * 100 ) - $iCartItemTaxTotal - $ishippingTaxTotal - $iDiscountTaxTotal;
     779        $iTaxDifference = round( $oOrder->get_total_tax() * 100 ) - $iCartItemTaxTotal - $ishippingTaxTotal - $iExtraFeeTax - $iDiscountTaxTotal;
    669780        if ( $iTaxDifference != 0 ) {
    670781            $nr ++;
     
    678789        }
    679790
    680         $iCorrection = round( $iOrderTotal - $iCartItemTotal - $iCartItemTaxTotal - $iShippingTotal - $ishippingTaxTotal - $iExtraFee - $iTaxDifference - $iDiscountTotal - $iDiscountTaxTotal);
     791        $iCorrection = round( $iOrderTotal - $iCartItemTotal - $iCartItemTaxTotal - $iShippingTotal - $ishippingTaxTotal - $iExtraFee - $iExtraFeeTax - $iTaxDifference - $iDiscountTotal - $iDiscountTaxTotal);
    681792
    682793        if ( $iCorrection != 0 ) {
     
    706817    public function validate_fields() {
    707818        global $woocommerce;
    708 
    709         if ( $_POST['payment_method'] == 'cardgateideal' ) {
     819        if (key_exists('wc-cardgateideal-new-payment-method',$_POST)) {
     820            if ( empty( $_POST['cardgateideal_issuer'] ) || $_POST['cardgateideal_issuer'] == '0' ) {
     821                wc_add_notice( __( ' Choose your bank first, please', 'cardgate' ), 'error' );
     822                return false;
     823            } else {
     824                $this->bankOption = $_POST['cardgateideal_issuer'];
     825            }
     826        } elseif (key_exists('payment_method', $_POST) &&  $_POST['payment_method'] == 'cardgateideal' ) {
    710827            if ( empty( $_POST['cgp_bank_options'] ) || $_POST['cgp_bank_options'] == '0' ) {
    711828                wc_add_notice( __( ' Choose your bank first, please', 'cardgate' ), 'error' );
    712 
    713829                return false;
    714830            } else {
  • cardgate/trunk/classes/WC_CardgateIdealqr.php

    r2491968 r3054427  
    1111class WC_CardgateIdealqr extends CGP_Common_Gateway {
    1212
    13     var $id = 'cardgateaIdealqr';
     13    var $id = 'cardgateidealqr';
    1414    var $title = '';
    1515    var $method_title = 'Cardgate iDEAL QR';
  • cardgate/trunk/readme.txt

    r3008166 r3054427  
    55Requires at least: 4.4
    66Tested up to: 6.4
    7 Stable tag: 3.1.27
     7Stable tag: 3.1.28
    88License: GPLv3 or later
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    7575
    7676== Changelog ==
     77
     78= 3.1.28 =
     79* Added: Woocommerce block compatibility
    7780
    7881= 3.1.27 =
Note: See TracChangeset for help on using the changeset viewer.