Plugin Directory

Changeset 3049660


Ignore:
Timestamp:
03/12/2024 09:55:22 AM (2 years ago)
Author:
tabbyai
Message:

Compatibility with woocommerce blocks on checkout

Location:
tabby-checkout
Files:
16 added
6 edited
26 copied

Legend:

Unmodified
Added
Removed
  • tabby-checkout/tags/4.10.0/includes/class-wc-gateway-tabby-checkout-base.php

    r3034458 r3049660  
    7272        // check for disabled_for_sku products
    7373        if (!WC_Tabby_Config::isEnabledForCartSKUs()) $is_available = false;
     74
     75        if (!WC()->cart) return $is_available;
     76
     77        // if available, create session
     78        if ($is_available && !is_admin()) {
     79            $is_available = $this->get_is_available_from_api();
     80        }
    7481
    7582        return $is_available;
     
    122129    }
    123130
     131    public function get_description_config() {
     132        $res = [];
     133        $dtype = strpos(get_option('tabby_checkout_promo_theme', ''), ':') === false ? $this->get_option('description_type', static::METHOD_DESCRIPTION_TYPE) : 2;
     134        switch ($dtype) {
     135            case 0:
     136            case 1:
     137                $divId = static::TABBY_METHOD_CODE . 'Card';
     138                $jsClass = 'TabbyCard';
     139                if (static::TABBY_METHOD_CODE == 'creditCardInstallments') $jsClass = 'TabbyPaymentMethodSnippetCCI';
     140                $res = [
     141                    'id'  => $divId,
     142                    'class' => $jsClass,
     143                    'jsClass' => $jsClass,
     144                    'jsConf' =>  $this->getTabbyCardJsonConfig($divId)
     145                ];
     146                break;
     147            case 2:
     148                $res = [
     149                    'class' => "tabbyDesc",
     150                    'html'  => __(static::METHOD_DESC, 'tabby-checkout')
     151                ];
     152                break;
     153            default:
     154                $res['class'] = 'empty';
     155
     156        }
     157        $res['info'] = [
     158            'style' => [
     159                'verticalAlign' => 'middle',
     160                'cursor'    => 'pointer',
     161                'width'     => '16px',
     162                'margin'    => '5px'
     163            ],
     164            'class' => 'info',
     165            'data-tabby-info'   => esc_attr(static::TABBY_METHOD_CODE),
     166            'data-tabby-price'  => esc_attr($this->formatAmount($this->get_order_total())),
     167            'data-tabby-currency' =>  esc_attr(WC_Tabby_Config::getTabbyCurrency()),
     168            'data-tabby-language' => esc_attr($this->get_lang()),
     169            'data-tabby-installments-count' => WC_Tabby_Promo::getInstallmentsCount(),
     170            'src'   => plugin_dir_url( dirname( __FILE__ ) ) . 'images/info.png',
     171            'alt'   => 'Tabby'
     172        ];
     173        return $res;
     174    }
     175    public function get_order_total() {
     176        return WC()->cart ? parent::get_order_total() : 0;
     177    }
     178
    124179    public function payment_fields() {
    125180        echo '<input type="hidden" name="'.esc_attr($this->id).'_payment_id" value="">';
     
    128183        $dtype = strpos(get_option('tabby_checkout_promo_theme', ''), ':') === false ? $this->get_option('description_type', static::METHOD_DESCRIPTION_TYPE) : 2;
    129184        switch ($dtype) {
    130             case 0: 
    131             case 1: 
     185            case 0:
     186            case 1:
    132187                $divId = static::TABBY_METHOD_CODE . 'Card';
    133188                $jsClass = 'TabbyCard';
     
    184239            $config['buyer_history'] = $this->getBuyerHistoryObject($customer);
    185240        } elseif ($customer = WC()->customer) {
     241            $config['buyer'] = $this->getFrontBuyerObject();
     242            $config['shipping_address'] = $this->getShippingAddressObject($customer);
    186243            $config['buyer_history'] = $this->getBuyerHistoryObject($customer);
    187244        }
    188245        $config['payment'] = $this->getPaymentObject($order);
    189246        $config['merchantUrls'] = $this->getMerchantUrls($order);
    190    
     247
    191248        return json_encode($config);
    192249    }
     
    198255                'loyalty_level'     => $this->getLoyaltyLevel($customer)
    199256            ];
    200         } 
     257        }
    201258        return null;
    202259    }
     
    241298        return $code;
    242299    }
    243    
     300
    244301    public function getMerchantUrls($order) {
    245302
     
    249306            'failure'   => is_checkout_pay_page() && $order ? $order->get_checkout_payment_url() : wc_get_checkout_url()
    250307        ];
     308    }
     309
     310    public static function is_classic_checkout_enabled() {
     311        if ($checkout_id = get_option('woocommerce_checkout_page_id', false)) {
     312            $checkout = get_post($checkout_id);
     313            if (preg_match("/wp:woocommerce\/classic-shortcode|\[woocommerce_checkout\]/is", $checkout->post_content)) {
     314                // old checkout enabled
     315                return true;
     316            };
     317        };
     318        return false;       
     319    }
     320    public function get_is_available_from_api() {
     321        // verify that new checkout active
     322        if (self::is_classic_checkout_enabled()) {
     323            // old checkout enabled, do not check with api
     324            return true;
     325        };
     326        $config = json_decode(static::getTabbyConfig(), true);
     327        $config['payment']['buyer'] = $this->getFrontBuyerObject();
     328        $config['payment']['order_history'] = WC_Tabby_AJAX::getOrderHistoryObject(
     329            $config['payment']['buyer']['email'],
     330            $config['payment']['buyer']['phone']
     331        );
     332        $config['payment']['buyer_history'] = $config['buyer_history'];
     333        $config['payment']['shipping_address'] = $config['shipping_address'];
     334        $modules = [];
     335        $request = [
     336            'payment'       => $config['payment'],
     337            'lang'          => $this->get_lang(),
     338            'merchant_code' => $config['merchantCode'],
     339            'merchant_urls' => $config['merchantUrls']
     340        ];
     341
     342        $result = WC_Tabby_Api::request('checkout', 'POST', $request);
     343
     344        if ($result && property_exists($result, 'status') && $result->status == 'created') {
     345            if (property_exists($result->configuration->available_products, static::TABBY_METHOD_CODE)) {
     346                return true;
     347            }
     348       }
     349
     350        return false;
     351    }
     352
     353    public function getFrontBuyerObject() {
     354        $email = $name = $phone = null;
     355        if (WC()->customer) {
     356            $email = WC()->customer->get_billing_email()
     357                ? WC()->customer->get_billing_email()
     358                : WC()->customer->get_email();
     359            $fname = WC()->customer->get_billing_first_name()
     360                ? WC()->customer->get_billing_first_name()
     361                : (WC()->customer->get_shipping_first_name()
     362                    ? WC()->customer->get_shipping_first_name()
     363                    : WC()->customer->get_first_name());
     364            $lname = WC()->customer->get_billing_last_name()
     365                ? WC()->customer->get_billing_last_name()
     366                : (WC()->customer->get_shipping_last_name()
     367                    ? WC()->customer->get_shipping_last_name()
     368                    : WC()->customer->get_last_name());
     369            $phone = WC()->customer->get_billing_phone()
     370                ? WC()->customer->get_billing_phone()
     371                : (WC()->customer->get_shipping_phone()
     372                    ? WC()->customer->get_shipping_phone()
     373                    : '');
     374        }
     375        return array(
     376            'dob'   => null,
     377            'email' => $email,
     378            'name'  => $fname . ' ' . $lname,
     379            'phone' => str_replace("+", "", $phone)
     380        );
    251381    }
    252382
     
    265395        return [
    266396            'reference_id'      => (string) (
    267                 $order == null 
     397                $order == null
    268398                    ? md5(json_encode($this->getOrderItemsObject($order)))
    269399                    : woocommerce_tabby_get_order_reference_id($order)
    270400            ),
    271401            'shipping_amount'   => $this->formatAmount(
    272                 $order == null 
    273                     ? (float)WC()->cart->get_shipping_total() + (float)WC()->cart->get_shipping_tax() : 
     402                $order == null
     403                    ? (float)WC()->cart->get_shipping_total() + (float)WC()->cart->get_shipping_tax() :
    274404                    ($order->get_shipping_total() + $order->get_shipping_tax())
    275405            ),
     
    280410            ),
    281411            'tax_amount'        => $this->formatAmount(
    282                 $order == null 
     412                $order == null
    283413                    ? array_sum(WC()->cart->get_taxes())
    284414                    : $order->get_total_tax()
     
    365495        $config = json_decode(static::getTabbyConfig($order), true);
    366496        $request = [
    367             'payment'       => $config['payment'], 
     497            'payment'       => $config['payment'],
    368498            'lang'          => $this->get_lang(),
    369499            'merchant_code' => $config['merchantCode'],
     
    469599                  /* translators: %1$s is replaced with Tabby payment ID, %2$s is replaced with payment currency */
    470600                  $order->set_status( 'failed', sprintf( __( 'Payment failed. ID: %1$s. Total missmatch. Transaction amount: %2$s', 'tabby-checkout' ), $payment_id, $res->amount . $res->currency ) );
    471                
     601
    472602                  $order->save();
    473603
     
    616746            if ($payment->status == 'CLOSED' && property_exists($payment, 'captures') && count($payment->captures) > 0) {
    617747                update_post_meta($order_id, static::TABBY_STATUS_FIELD, static::STATUS_CAPTURED);
    618             } 
     748            }
    619749        }
    620750
     
    626756
    627757        return $this->request($payment_id);
    628        
    629758    }
    630759
  • tabby-checkout/tags/4.10.0/includes/class-wc-tabby-ajax.php

    r2927757 r3049660  
    5252            $ids = array_unique($ids);
    5353        }
     54        rsort($ids, SORT_NUMERIC);
     55        $ids = array_slice($ids, 0, 10);
    5456        $orders = array_filter( array_map( 'wc_get_order', $ids ) );
    5557        foreach ($orders as $order) {
  • tabby-checkout/tags/4.10.0/includes/class-wc-tabby-promo.php

    r3034458 r3049660  
    66        add_action('woocommerce_before_add_to_cart_form', array( __CLASS__, 'product_promotion')     );
    77        add_action('wp_enqueue_scripts'                 , array( __CLASS__, 'wp_enqueue_scripts')    );
     8        add_action('admin_enqueue_scripts'              , array( __CLASS__, 'admin_enqueue_scripts') );
    89    }
    910    public static function wp_enqueue_scripts() {
     
    1314            // js
    1415            wp_enqueue_script('tabby-checkout-integration', 'https://'.TABBY_CHECKOUT_DOMAIN.'/cms-plugins.js', [], null, true);
    15             wp_enqueue_script('tabby-checkout-tabby-js', plugins_url('js/tabby.js', dirname(__FILE__)), [], MODULE_TABBY_CHECKOUT_VERSION, true);
     16            if (WC_Gateway_Tabby_Checkout_Base::is_classic_checkout_enabled()) {
     17                wp_enqueue_script('tabby-checkout-tabby-js', plugins_url('js/tabby.js', dirname(__FILE__)), [], MODULE_TABBY_CHECKOUT_VERSION, true);
     18            }
    1619        };
    1720
    1821        if ((is_product() || is_cart()) && static::is_tabby_promo_enabled()) {
    1922            wp_enqueue_script('tabby-checkout-promo', 'https://'.TABBY_CHECKOUT_DOMAIN.'/tabby-promo.js', [], null, true);
    20             static::product_promotion_scripts();
     23            if (!static::is_blocks_cart_enabled() || is_product()) {
     24                static::product_promotion_scripts();
     25            }
    2126        };
     27    }
     28    public static function admin_enqueue_scripts() {
     29        $current_screen = get_current_screen();
     30        if (method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()) {
     31            wp_enqueue_script('tabby-checkout-promo', 'https://'.TABBY_CHECKOUT_DOMAIN.'/tabby-promo.js', [], null, true);
     32        }
    2233    }
    2334    public static function is_tabby_promo_enabled() {
     
    2738            (static::getMaxPrice() == 0 || static::getPrice() <= static::getMaxPrice()) &&
    2839            (static::getMinTotal() == 0 || static::getPrice() >= static::getMinTotal());
     40    }
     41    public static function is_blocks_cart_enabled() {
     42        if ($cart_id = get_option('woocommerce_cart_page_id', false)) {
     43            $cart = get_post($cart_id);
     44            if (preg_match("/wp:woocommerce\/cart/is", $cart->post_content)) {
     45                // new blocks checkout enabled
     46                return true;
     47            };
     48        };
     49        return false;
    2950    }
    3051    public static function is_tabby_promo_enabled_for_product() {
     
    144165    }
    145166    public static function getSource() {
    146         return is_product() ? 'product' : 'cart';
     167        return is_admin() ? 'adminBlockEditor' : (is_product() ? 'product' : 'cart');
    147168    }
    148169    public static function getMerchantCode() {
     
    178199
    179200            // Gets order total from cart/checkout.
    180         } elseif ( 0 < WC()->cart->total ) {
     201        } elseif ( WC()->cart ) {
    181202            $total = (float) WC()->cart->total;
     203        } else {
     204            $total = 10;
    182205        }
    183206
     
    206229            }
    207230        }
    208         return $current_user_id ? implode($delimiter, $phones) : null;
    209     }
    210 }
     231        return $current_user_id ? implode($delimiter, array_filter($phones)) : null;
     232    }
     233}
  • tabby-checkout/tags/4.10.0/includes/class-wc-tabby.php

    r2987288 r3049660  
    11<?php
     2
     3use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
     4
    25class WC_Tabby {
    36    public static function init() {
     
    1619    }
    1720    public static function init_methods() {
    18         add_filter( 'woocommerce_payment_gateways', array( __CLASS__, 'add_checkout_methods') );
     21        add_filter( 'woocommerce_payment_gateways', array(__CLASS__, 'add_checkout_methods'));
     22
     23        add_action( 'woocommerce_blocks_loaded', array(__CLASS__, 'woocommerce_blocks_support'));
     24
     25    }
     26    public static function woocommerce_blocks_support() {
     27        if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
     28            add_action(
     29                'woocommerce_blocks_payment_method_type_registration',
     30                function( PaymentMethodRegistry $payment_method_registry ) {
     31                    $payment_method_registry->register( new WC_Blocks_Tabby_Installments );
     32                }
     33            );
     34        }
     35        if ( interface_exists( 'Automattic\WooCommerce\Blocks\Integrations\IntegrationInterface' ) && (get_option('tabby_promo_cart') !== 'no')) {
     36            add_action(
     37                'woocommerce_blocks_cart_block_registration',
     38                function( $integration_registry ) {
     39                    $integration_registry->register( new WC_Blocks_Tabby_Cart_Promotion() );
     40                }
     41            );
     42        }
    1943    }
    2044    public static function add_checkout_methods( $methods ) {
     
    2852        return $methods;
    2953    }
     54
    3055    public static function on_activation() {
    3156        wp_schedule_single_event( time() + 60 , 'woocommerce_tabby_cancel_unpaid_orders' );
    3257        WC_Tabby_Webhook::register();
    3358    }
     59
    3460    public static function on_deactivation() {
    3561        wp_clear_scheduled_hook( 'woocommerce_tabby_cancel_unpaid_orders' );
  • tabby-checkout/tags/4.10.0/readme.txt

    r3034458 r3049660  
    44Requires at least: 5.7
    55Tested up to: 6.4
    6 Stable tag: 4.9.8
     6Stable tag: 4.10.0
    77Requires PHP: 7.0
    88License: GPLv3
     
    2828
    2929== Changelog ==
     30
     31= 4.10.0 =
     32
     33* Compatibility with woocommerce blocks on checkout
    3034
    3135= 4.9.5 =
  • tabby-checkout/tags/4.10.0/tabby-checkout.php

    r3034458 r3049660  
    44 * Plugin URI: https://tabby.ai/
    55 * Description: Tabby Checkout
    6  * Version: 4.9.8
     6 * Version: 4.10.0
    77 * Author: Tabby
    88 * Author URI: https://tabby.ai
     
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 define ('MODULE_TABBY_CHECKOUT_VERSION', '4.9.8');
     16define ('MODULE_TABBY_CHECKOUT_VERSION', '4.10.0');
    1717define ('TABBY_CHECKOUT_DOMAIN', 'checkout.tabby.ai');
    1818define ('TABBY_CHECKOUT_API_DOMAIN', 'api.tabby.ai');
     
    2121
    2222WC_Tabby::init();
    23 
  • tabby-checkout/trunk/includes/class-wc-gateway-tabby-checkout-base.php

    r3034458 r3049660  
    7272        // check for disabled_for_sku products
    7373        if (!WC_Tabby_Config::isEnabledForCartSKUs()) $is_available = false;
     74
     75        if (!WC()->cart) return $is_available;
     76
     77        // if available, create session
     78        if ($is_available && !is_admin()) {
     79            $is_available = $this->get_is_available_from_api();
     80        }
    7481
    7582        return $is_available;
     
    122129    }
    123130
     131    public function get_description_config() {
     132        $res = [];
     133        $dtype = strpos(get_option('tabby_checkout_promo_theme', ''), ':') === false ? $this->get_option('description_type', static::METHOD_DESCRIPTION_TYPE) : 2;
     134        switch ($dtype) {
     135            case 0:
     136            case 1:
     137                $divId = static::TABBY_METHOD_CODE . 'Card';
     138                $jsClass = 'TabbyCard';
     139                if (static::TABBY_METHOD_CODE == 'creditCardInstallments') $jsClass = 'TabbyPaymentMethodSnippetCCI';
     140                $res = [
     141                    'id'  => $divId,
     142                    'class' => $jsClass,
     143                    'jsClass' => $jsClass,
     144                    'jsConf' =>  $this->getTabbyCardJsonConfig($divId)
     145                ];
     146                break;
     147            case 2:
     148                $res = [
     149                    'class' => "tabbyDesc",
     150                    'html'  => __(static::METHOD_DESC, 'tabby-checkout')
     151                ];
     152                break;
     153            default:
     154                $res['class'] = 'empty';
     155
     156        }
     157        $res['info'] = [
     158            'style' => [
     159                'verticalAlign' => 'middle',
     160                'cursor'    => 'pointer',
     161                'width'     => '16px',
     162                'margin'    => '5px'
     163            ],
     164            'class' => 'info',
     165            'data-tabby-info'   => esc_attr(static::TABBY_METHOD_CODE),
     166            'data-tabby-price'  => esc_attr($this->formatAmount($this->get_order_total())),
     167            'data-tabby-currency' =>  esc_attr(WC_Tabby_Config::getTabbyCurrency()),
     168            'data-tabby-language' => esc_attr($this->get_lang()),
     169            'data-tabby-installments-count' => WC_Tabby_Promo::getInstallmentsCount(),
     170            'src'   => plugin_dir_url( dirname( __FILE__ ) ) . 'images/info.png',
     171            'alt'   => 'Tabby'
     172        ];
     173        return $res;
     174    }
     175    public function get_order_total() {
     176        return WC()->cart ? parent::get_order_total() : 0;
     177    }
     178
    124179    public function payment_fields() {
    125180        echo '<input type="hidden" name="'.esc_attr($this->id).'_payment_id" value="">';
     
    128183        $dtype = strpos(get_option('tabby_checkout_promo_theme', ''), ':') === false ? $this->get_option('description_type', static::METHOD_DESCRIPTION_TYPE) : 2;
    129184        switch ($dtype) {
    130             case 0: 
    131             case 1: 
     185            case 0:
     186            case 1:
    132187                $divId = static::TABBY_METHOD_CODE . 'Card';
    133188                $jsClass = 'TabbyCard';
     
    184239            $config['buyer_history'] = $this->getBuyerHistoryObject($customer);
    185240        } elseif ($customer = WC()->customer) {
     241            $config['buyer'] = $this->getFrontBuyerObject();
     242            $config['shipping_address'] = $this->getShippingAddressObject($customer);
    186243            $config['buyer_history'] = $this->getBuyerHistoryObject($customer);
    187244        }
    188245        $config['payment'] = $this->getPaymentObject($order);
    189246        $config['merchantUrls'] = $this->getMerchantUrls($order);
    190    
     247
    191248        return json_encode($config);
    192249    }
     
    198255                'loyalty_level'     => $this->getLoyaltyLevel($customer)
    199256            ];
    200         } 
     257        }
    201258        return null;
    202259    }
     
    241298        return $code;
    242299    }
    243    
     300
    244301    public function getMerchantUrls($order) {
    245302
     
    249306            'failure'   => is_checkout_pay_page() && $order ? $order->get_checkout_payment_url() : wc_get_checkout_url()
    250307        ];
     308    }
     309
     310    public static function is_classic_checkout_enabled() {
     311        if ($checkout_id = get_option('woocommerce_checkout_page_id', false)) {
     312            $checkout = get_post($checkout_id);
     313            if (preg_match("/wp:woocommerce\/classic-shortcode|\[woocommerce_checkout\]/is", $checkout->post_content)) {
     314                // old checkout enabled
     315                return true;
     316            };
     317        };
     318        return false;       
     319    }
     320    public function get_is_available_from_api() {
     321        // verify that new checkout active
     322        if (self::is_classic_checkout_enabled()) {
     323            // old checkout enabled, do not check with api
     324            return true;
     325        };
     326        $config = json_decode(static::getTabbyConfig(), true);
     327        $config['payment']['buyer'] = $this->getFrontBuyerObject();
     328        $config['payment']['order_history'] = WC_Tabby_AJAX::getOrderHistoryObject(
     329            $config['payment']['buyer']['email'],
     330            $config['payment']['buyer']['phone']
     331        );
     332        $config['payment']['buyer_history'] = $config['buyer_history'];
     333        $config['payment']['shipping_address'] = $config['shipping_address'];
     334        $modules = [];
     335        $request = [
     336            'payment'       => $config['payment'],
     337            'lang'          => $this->get_lang(),
     338            'merchant_code' => $config['merchantCode'],
     339            'merchant_urls' => $config['merchantUrls']
     340        ];
     341
     342        $result = WC_Tabby_Api::request('checkout', 'POST', $request);
     343
     344        if ($result && property_exists($result, 'status') && $result->status == 'created') {
     345            if (property_exists($result->configuration->available_products, static::TABBY_METHOD_CODE)) {
     346                return true;
     347            }
     348       }
     349
     350        return false;
     351    }
     352
     353    public function getFrontBuyerObject() {
     354        $email = $name = $phone = null;
     355        if (WC()->customer) {
     356            $email = WC()->customer->get_billing_email()
     357                ? WC()->customer->get_billing_email()
     358                : WC()->customer->get_email();
     359            $fname = WC()->customer->get_billing_first_name()
     360                ? WC()->customer->get_billing_first_name()
     361                : (WC()->customer->get_shipping_first_name()
     362                    ? WC()->customer->get_shipping_first_name()
     363                    : WC()->customer->get_first_name());
     364            $lname = WC()->customer->get_billing_last_name()
     365                ? WC()->customer->get_billing_last_name()
     366                : (WC()->customer->get_shipping_last_name()
     367                    ? WC()->customer->get_shipping_last_name()
     368                    : WC()->customer->get_last_name());
     369            $phone = WC()->customer->get_billing_phone()
     370                ? WC()->customer->get_billing_phone()
     371                : (WC()->customer->get_shipping_phone()
     372                    ? WC()->customer->get_shipping_phone()
     373                    : '');
     374        }
     375        return array(
     376            'dob'   => null,
     377            'email' => $email,
     378            'name'  => $fname . ' ' . $lname,
     379            'phone' => str_replace("+", "", $phone)
     380        );
    251381    }
    252382
     
    265395        return [
    266396            'reference_id'      => (string) (
    267                 $order == null 
     397                $order == null
    268398                    ? md5(json_encode($this->getOrderItemsObject($order)))
    269399                    : woocommerce_tabby_get_order_reference_id($order)
    270400            ),
    271401            'shipping_amount'   => $this->formatAmount(
    272                 $order == null 
    273                     ? (float)WC()->cart->get_shipping_total() + (float)WC()->cart->get_shipping_tax() : 
     402                $order == null
     403                    ? (float)WC()->cart->get_shipping_total() + (float)WC()->cart->get_shipping_tax() :
    274404                    ($order->get_shipping_total() + $order->get_shipping_tax())
    275405            ),
     
    280410            ),
    281411            'tax_amount'        => $this->formatAmount(
    282                 $order == null 
     412                $order == null
    283413                    ? array_sum(WC()->cart->get_taxes())
    284414                    : $order->get_total_tax()
     
    365495        $config = json_decode(static::getTabbyConfig($order), true);
    366496        $request = [
    367             'payment'       => $config['payment'], 
     497            'payment'       => $config['payment'],
    368498            'lang'          => $this->get_lang(),
    369499            'merchant_code' => $config['merchantCode'],
     
    469599                  /* translators: %1$s is replaced with Tabby payment ID, %2$s is replaced with payment currency */
    470600                  $order->set_status( 'failed', sprintf( __( 'Payment failed. ID: %1$s. Total missmatch. Transaction amount: %2$s', 'tabby-checkout' ), $payment_id, $res->amount . $res->currency ) );
    471                
     601
    472602                  $order->save();
    473603
     
    616746            if ($payment->status == 'CLOSED' && property_exists($payment, 'captures') && count($payment->captures) > 0) {
    617747                update_post_meta($order_id, static::TABBY_STATUS_FIELD, static::STATUS_CAPTURED);
    618             } 
     748            }
    619749        }
    620750
     
    626756
    627757        return $this->request($payment_id);
    628        
    629758    }
    630759
  • tabby-checkout/trunk/includes/class-wc-tabby-ajax.php

    r2927757 r3049660  
    5252            $ids = array_unique($ids);
    5353        }
     54        rsort($ids, SORT_NUMERIC);
     55        $ids = array_slice($ids, 0, 10);
    5456        $orders = array_filter( array_map( 'wc_get_order', $ids ) );
    5557        foreach ($orders as $order) {
  • tabby-checkout/trunk/includes/class-wc-tabby-promo.php

    r3034458 r3049660  
    66        add_action('woocommerce_before_add_to_cart_form', array( __CLASS__, 'product_promotion')     );
    77        add_action('wp_enqueue_scripts'                 , array( __CLASS__, 'wp_enqueue_scripts')    );
     8        add_action('admin_enqueue_scripts'              , array( __CLASS__, 'admin_enqueue_scripts') );
    89    }
    910    public static function wp_enqueue_scripts() {
     
    1314            // js
    1415            wp_enqueue_script('tabby-checkout-integration', 'https://'.TABBY_CHECKOUT_DOMAIN.'/cms-plugins.js', [], null, true);
    15             wp_enqueue_script('tabby-checkout-tabby-js', plugins_url('js/tabby.js', dirname(__FILE__)), [], MODULE_TABBY_CHECKOUT_VERSION, true);
     16            if (WC_Gateway_Tabby_Checkout_Base::is_classic_checkout_enabled()) {
     17                wp_enqueue_script('tabby-checkout-tabby-js', plugins_url('js/tabby.js', dirname(__FILE__)), [], MODULE_TABBY_CHECKOUT_VERSION, true);
     18            }
    1619        };
    1720
    1821        if ((is_product() || is_cart()) && static::is_tabby_promo_enabled()) {
    1922            wp_enqueue_script('tabby-checkout-promo', 'https://'.TABBY_CHECKOUT_DOMAIN.'/tabby-promo.js', [], null, true);
    20             static::product_promotion_scripts();
     23            if (!static::is_blocks_cart_enabled() || is_product()) {
     24                static::product_promotion_scripts();
     25            }
    2126        };
     27    }
     28    public static function admin_enqueue_scripts() {
     29        $current_screen = get_current_screen();
     30        if (method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()) {
     31            wp_enqueue_script('tabby-checkout-promo', 'https://'.TABBY_CHECKOUT_DOMAIN.'/tabby-promo.js', [], null, true);
     32        }
    2233    }
    2334    public static function is_tabby_promo_enabled() {
     
    2738            (static::getMaxPrice() == 0 || static::getPrice() <= static::getMaxPrice()) &&
    2839            (static::getMinTotal() == 0 || static::getPrice() >= static::getMinTotal());
     40    }
     41    public static function is_blocks_cart_enabled() {
     42        if ($cart_id = get_option('woocommerce_cart_page_id', false)) {
     43            $cart = get_post($cart_id);
     44            if (preg_match("/wp:woocommerce\/cart/is", $cart->post_content)) {
     45                // new blocks checkout enabled
     46                return true;
     47            };
     48        };
     49        return false;
    2950    }
    3051    public static function is_tabby_promo_enabled_for_product() {
     
    144165    }
    145166    public static function getSource() {
    146         return is_product() ? 'product' : 'cart';
     167        return is_admin() ? 'adminBlockEditor' : (is_product() ? 'product' : 'cart');
    147168    }
    148169    public static function getMerchantCode() {
     
    178199
    179200            // Gets order total from cart/checkout.
    180         } elseif ( 0 < WC()->cart->total ) {
     201        } elseif ( WC()->cart ) {
    181202            $total = (float) WC()->cart->total;
     203        } else {
     204            $total = 10;
    182205        }
    183206
     
    206229            }
    207230        }
    208         return $current_user_id ? implode($delimiter, $phones) : null;
    209     }
    210 }
     231        return $current_user_id ? implode($delimiter, array_filter($phones)) : null;
     232    }
     233}
  • tabby-checkout/trunk/includes/class-wc-tabby.php

    r2987288 r3049660  
    11<?php
     2
     3use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
     4
    25class WC_Tabby {
    36    public static function init() {
     
    1619    }
    1720    public static function init_methods() {
    18         add_filter( 'woocommerce_payment_gateways', array( __CLASS__, 'add_checkout_methods') );
     21        add_filter( 'woocommerce_payment_gateways', array(__CLASS__, 'add_checkout_methods'));
     22
     23        add_action( 'woocommerce_blocks_loaded', array(__CLASS__, 'woocommerce_blocks_support'));
     24
     25    }
     26    public static function woocommerce_blocks_support() {
     27        if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
     28            add_action(
     29                'woocommerce_blocks_payment_method_type_registration',
     30                function( PaymentMethodRegistry $payment_method_registry ) {
     31                    $payment_method_registry->register( new WC_Blocks_Tabby_Installments );
     32                }
     33            );
     34        }
     35        if ( interface_exists( 'Automattic\WooCommerce\Blocks\Integrations\IntegrationInterface' ) && (get_option('tabby_promo_cart') !== 'no')) {
     36            add_action(
     37                'woocommerce_blocks_cart_block_registration',
     38                function( $integration_registry ) {
     39                    $integration_registry->register( new WC_Blocks_Tabby_Cart_Promotion() );
     40                }
     41            );
     42        }
    1943    }
    2044    public static function add_checkout_methods( $methods ) {
     
    2852        return $methods;
    2953    }
     54
    3055    public static function on_activation() {
    3156        wp_schedule_single_event( time() + 60 , 'woocommerce_tabby_cancel_unpaid_orders' );
    3257        WC_Tabby_Webhook::register();
    3358    }
     59
    3460    public static function on_deactivation() {
    3561        wp_clear_scheduled_hook( 'woocommerce_tabby_cancel_unpaid_orders' );
  • tabby-checkout/trunk/readme.txt

    r3034458 r3049660  
    44Requires at least: 5.7
    55Tested up to: 6.4
    6 Stable tag: 4.9.8
     6Stable tag: 4.10.0
    77Requires PHP: 7.0
    88License: GPLv3
     
    2828
    2929== Changelog ==
     30
     31= 4.10.0 =
     32
     33* Compatibility with woocommerce blocks on checkout
    3034
    3135= 4.9.5 =
  • tabby-checkout/trunk/tabby-checkout.php

    r3034458 r3049660  
    44 * Plugin URI: https://tabby.ai/
    55 * Description: Tabby Checkout
    6  * Version: 4.9.8
     6 * Version: 4.10.0
    77 * Author: Tabby
    88 * Author URI: https://tabby.ai
     
    1414defined( 'ABSPATH' ) || exit;
    1515
    16 define ('MODULE_TABBY_CHECKOUT_VERSION', '4.9.8');
     16define ('MODULE_TABBY_CHECKOUT_VERSION', '4.10.0');
    1717define ('TABBY_CHECKOUT_DOMAIN', 'checkout.tabby.ai');
    1818define ('TABBY_CHECKOUT_API_DOMAIN', 'api.tabby.ai');
     
    2121
    2222WC_Tabby::init();
    23 
Note: See TracChangeset for help on using the changeset viewer.