Changeset 3049660
- Timestamp:
- 03/12/2024 09:55:22 AM (2 years ago)
- Location:
- tabby-checkout
- Files:
-
- 16 added
- 6 edited
- 26 copied
-
tags/4.10.0 (copied) (copied from tabby-checkout/trunk)
-
tags/4.10.0/assets (added)
-
tags/4.10.0/assets/blocks (added)
-
tags/4.10.0/assets/blocks/tabby-cart-promotion (added)
-
tags/4.10.0/assets/blocks/tabby-cart-promotion/index.js (added)
-
tags/4.10.0/assets/blocks/tabby-installments (added)
-
tags/4.10.0/assets/blocks/tabby-installments/index.js (added)
-
tags/4.10.0/css (copied) (copied from tabby-checkout/trunk/css)
-
tags/4.10.0/css/tabby.css (copied) (copied from tabby-checkout/trunk/css/tabby.css)
-
tags/4.10.0/i18n (copied) (copied from tabby-checkout/trunk/i18n)
-
tags/4.10.0/i18n/languages/tabby-checkout-ar.mo (copied) (copied from tabby-checkout/trunk/i18n/languages/tabby-checkout-ar.mo)
-
tags/4.10.0/i18n/languages/tabby-checkout-ar.po (copied) (copied from tabby-checkout/trunk/i18n/languages/tabby-checkout-ar.po)
-
tags/4.10.0/i18n/languages/tabby-checkout.pot (copied) (copied from tabby-checkout/trunk/i18n/languages/tabby-checkout.pot)
-
tags/4.10.0/images (copied) (copied from tabby-checkout/trunk/images)
-
tags/4.10.0/includes (copied) (copied from tabby-checkout/trunk/includes)
-
tags/4.10.0/includes/class-wc-blocks-tabby-cart-promotion.php (added)
-
tags/4.10.0/includes/class-wc-blocks-tabby-installments.php (added)
-
tags/4.10.0/includes/class-wc-gateway-tabby-checkout-base.php (copied) (copied from tabby-checkout/trunk/includes/class-wc-gateway-tabby-checkout-base.php) (13 diffs)
-
tags/4.10.0/includes/class-wc-gateway-tabby-credit-card-installments.php (copied) (copied from tabby-checkout/trunk/includes/class-wc-gateway-tabby-credit-card-installments.php)
-
tags/4.10.0/includes/class-wc-gateway-tabby-installments.php (copied) (copied from tabby-checkout/trunk/includes/class-wc-gateway-tabby-installments.php)
-
tags/4.10.0/includes/class-wc-rest-tabby-controller.php (copied) (copied from tabby-checkout/trunk/includes/class-wc-rest-tabby-controller.php)
-
tags/4.10.0/includes/class-wc-settings-tab-tabby.php (copied) (copied from tabby-checkout/trunk/includes/class-wc-settings-tab-tabby.php)
-
tags/4.10.0/includes/class-wc-tabby-ajax.php (copied) (copied from tabby-checkout/trunk/includes/class-wc-tabby-ajax.php) (1 diff)
-
tags/4.10.0/includes/class-wc-tabby-api.php (copied) (copied from tabby-checkout/trunk/includes/class-wc-tabby-api.php)
-
tags/4.10.0/includes/class-wc-tabby-config.php (copied) (copied from tabby-checkout/trunk/includes/class-wc-tabby-config.php)
-
tags/4.10.0/includes/class-wc-tabby-cron.php (copied) (copied from tabby-checkout/trunk/includes/class-wc-tabby-cron.php)
-
tags/4.10.0/includes/class-wc-tabby-promo.php (copied) (copied from tabby-checkout/trunk/includes/class-wc-tabby-promo.php) (6 diffs)
-
tags/4.10.0/includes/class-wc-tabby-webhook.php (copied) (copied from tabby-checkout/trunk/includes/class-wc-tabby-webhook.php)
-
tags/4.10.0/includes/class-wc-tabby.php (copied) (copied from tabby-checkout/trunk/includes/class-wc-tabby.php) (3 diffs)
-
tags/4.10.0/js (copied) (copied from tabby-checkout/trunk/js)
-
tags/4.10.0/js/tabby.js (copied) (copied from tabby-checkout/trunk/js/tabby.js)
-
tags/4.10.0/log (copied) (copied from tabby-checkout/trunk/log)
-
tags/4.10.0/readme.txt (copied) (copied from tabby-checkout/trunk/readme.txt) (2 diffs)
-
tags/4.10.0/tabby-checkout.php (copied) (copied from tabby-checkout/trunk/tabby-checkout.php) (3 diffs)
-
trunk/assets (added)
-
trunk/assets/blocks (added)
-
trunk/assets/blocks/tabby-cart-promotion (added)
-
trunk/assets/blocks/tabby-cart-promotion/index.js (added)
-
trunk/assets/blocks/tabby-installments (added)
-
trunk/assets/blocks/tabby-installments/index.js (added)
-
trunk/includes/class-wc-blocks-tabby-cart-promotion.php (added)
-
trunk/includes/class-wc-blocks-tabby-installments.php (added)
-
trunk/includes/class-wc-gateway-tabby-checkout-base.php (modified) (13 diffs)
-
trunk/includes/class-wc-tabby-ajax.php (modified) (1 diff)
-
trunk/includes/class-wc-tabby-promo.php (modified) (6 diffs)
-
trunk/includes/class-wc-tabby.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/tabby-checkout.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tabby-checkout/tags/4.10.0/includes/class-wc-gateway-tabby-checkout-base.php
r3034458 r3049660 72 72 // check for disabled_for_sku products 73 73 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 } 74 81 75 82 return $is_available; … … 122 129 } 123 130 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 124 179 public function payment_fields() { 125 180 echo '<input type="hidden" name="'.esc_attr($this->id).'_payment_id" value="">'; … … 128 183 $dtype = strpos(get_option('tabby_checkout_promo_theme', ''), ':') === false ? $this->get_option('description_type', static::METHOD_DESCRIPTION_TYPE) : 2; 129 184 switch ($dtype) { 130 case 0: 131 case 1: 185 case 0: 186 case 1: 132 187 $divId = static::TABBY_METHOD_CODE . 'Card'; 133 188 $jsClass = 'TabbyCard'; … … 184 239 $config['buyer_history'] = $this->getBuyerHistoryObject($customer); 185 240 } elseif ($customer = WC()->customer) { 241 $config['buyer'] = $this->getFrontBuyerObject(); 242 $config['shipping_address'] = $this->getShippingAddressObject($customer); 186 243 $config['buyer_history'] = $this->getBuyerHistoryObject($customer); 187 244 } 188 245 $config['payment'] = $this->getPaymentObject($order); 189 246 $config['merchantUrls'] = $this->getMerchantUrls($order); 190 247 191 248 return json_encode($config); 192 249 } … … 198 255 'loyalty_level' => $this->getLoyaltyLevel($customer) 199 256 ]; 200 } 257 } 201 258 return null; 202 259 } … … 241 298 return $code; 242 299 } 243 300 244 301 public function getMerchantUrls($order) { 245 302 … … 249 306 'failure' => is_checkout_pay_page() && $order ? $order->get_checkout_payment_url() : wc_get_checkout_url() 250 307 ]; 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 ); 251 381 } 252 382 … … 265 395 return [ 266 396 'reference_id' => (string) ( 267 $order == null 397 $order == null 268 398 ? md5(json_encode($this->getOrderItemsObject($order))) 269 399 : woocommerce_tabby_get_order_reference_id($order) 270 400 ), 271 401 '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() : 274 404 ($order->get_shipping_total() + $order->get_shipping_tax()) 275 405 ), … … 280 410 ), 281 411 'tax_amount' => $this->formatAmount( 282 $order == null 412 $order == null 283 413 ? array_sum(WC()->cart->get_taxes()) 284 414 : $order->get_total_tax() … … 365 495 $config = json_decode(static::getTabbyConfig($order), true); 366 496 $request = [ 367 'payment' => $config['payment'], 497 'payment' => $config['payment'], 368 498 'lang' => $this->get_lang(), 369 499 'merchant_code' => $config['merchantCode'], … … 469 599 /* translators: %1$s is replaced with Tabby payment ID, %2$s is replaced with payment currency */ 470 600 $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 472 602 $order->save(); 473 603 … … 616 746 if ($payment->status == 'CLOSED' && property_exists($payment, 'captures') && count($payment->captures) > 0) { 617 747 update_post_meta($order_id, static::TABBY_STATUS_FIELD, static::STATUS_CAPTURED); 618 } 748 } 619 749 } 620 750 … … 626 756 627 757 return $this->request($payment_id); 628 629 758 } 630 759 -
tabby-checkout/tags/4.10.0/includes/class-wc-tabby-ajax.php
r2927757 r3049660 52 52 $ids = array_unique($ids); 53 53 } 54 rsort($ids, SORT_NUMERIC); 55 $ids = array_slice($ids, 0, 10); 54 56 $orders = array_filter( array_map( 'wc_get_order', $ids ) ); 55 57 foreach ($orders as $order) { -
tabby-checkout/tags/4.10.0/includes/class-wc-tabby-promo.php
r3034458 r3049660 6 6 add_action('woocommerce_before_add_to_cart_form', array( __CLASS__, 'product_promotion') ); 7 7 add_action('wp_enqueue_scripts' , array( __CLASS__, 'wp_enqueue_scripts') ); 8 add_action('admin_enqueue_scripts' , array( __CLASS__, 'admin_enqueue_scripts') ); 8 9 } 9 10 public static function wp_enqueue_scripts() { … … 13 14 // js 14 15 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 } 16 19 }; 17 20 18 21 if ((is_product() || is_cart()) && static::is_tabby_promo_enabled()) { 19 22 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 } 21 26 }; 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 } 22 33 } 23 34 public static function is_tabby_promo_enabled() { … … 27 38 (static::getMaxPrice() == 0 || static::getPrice() <= static::getMaxPrice()) && 28 39 (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; 29 50 } 30 51 public static function is_tabby_promo_enabled_for_product() { … … 144 165 } 145 166 public static function getSource() { 146 return is_ product() ? 'product' : 'cart';167 return is_admin() ? 'adminBlockEditor' : (is_product() ? 'product' : 'cart'); 147 168 } 148 169 public static function getMerchantCode() { … … 178 199 179 200 // Gets order total from cart/checkout. 180 } elseif ( 0 < WC()->cart->total) {201 } elseif ( WC()->cart ) { 181 202 $total = (float) WC()->cart->total; 203 } else { 204 $total = 10; 182 205 } 183 206 … … 206 229 } 207 230 } 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 1 1 <?php 2 3 use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry; 4 2 5 class WC_Tabby { 3 6 public static function init() { … … 16 19 } 17 20 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 } 19 43 } 20 44 public static function add_checkout_methods( $methods ) { … … 28 52 return $methods; 29 53 } 54 30 55 public static function on_activation() { 31 56 wp_schedule_single_event( time() + 60 , 'woocommerce_tabby_cancel_unpaid_orders' ); 32 57 WC_Tabby_Webhook::register(); 33 58 } 59 34 60 public static function on_deactivation() { 35 61 wp_clear_scheduled_hook( 'woocommerce_tabby_cancel_unpaid_orders' ); -
tabby-checkout/tags/4.10.0/readme.txt
r3034458 r3049660 4 4 Requires at least: 5.7 5 5 Tested up to: 6.4 6 Stable tag: 4. 9.86 Stable tag: 4.10.0 7 7 Requires PHP: 7.0 8 8 License: GPLv3 … … 28 28 29 29 == Changelog == 30 31 = 4.10.0 = 32 33 * Compatibility with woocommerce blocks on checkout 30 34 31 35 = 4.9.5 = -
tabby-checkout/tags/4.10.0/tabby-checkout.php
r3034458 r3049660 4 4 * Plugin URI: https://tabby.ai/ 5 5 * Description: Tabby Checkout 6 * Version: 4. 9.86 * Version: 4.10.0 7 7 * Author: Tabby 8 8 * Author URI: https://tabby.ai … … 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 define ('MODULE_TABBY_CHECKOUT_VERSION', '4. 9.8');16 define ('MODULE_TABBY_CHECKOUT_VERSION', '4.10.0'); 17 17 define ('TABBY_CHECKOUT_DOMAIN', 'checkout.tabby.ai'); 18 18 define ('TABBY_CHECKOUT_API_DOMAIN', 'api.tabby.ai'); … … 21 21 22 22 WC_Tabby::init(); 23 -
tabby-checkout/trunk/includes/class-wc-gateway-tabby-checkout-base.php
r3034458 r3049660 72 72 // check for disabled_for_sku products 73 73 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 } 74 81 75 82 return $is_available; … … 122 129 } 123 130 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 124 179 public function payment_fields() { 125 180 echo '<input type="hidden" name="'.esc_attr($this->id).'_payment_id" value="">'; … … 128 183 $dtype = strpos(get_option('tabby_checkout_promo_theme', ''), ':') === false ? $this->get_option('description_type', static::METHOD_DESCRIPTION_TYPE) : 2; 129 184 switch ($dtype) { 130 case 0: 131 case 1: 185 case 0: 186 case 1: 132 187 $divId = static::TABBY_METHOD_CODE . 'Card'; 133 188 $jsClass = 'TabbyCard'; … … 184 239 $config['buyer_history'] = $this->getBuyerHistoryObject($customer); 185 240 } elseif ($customer = WC()->customer) { 241 $config['buyer'] = $this->getFrontBuyerObject(); 242 $config['shipping_address'] = $this->getShippingAddressObject($customer); 186 243 $config['buyer_history'] = $this->getBuyerHistoryObject($customer); 187 244 } 188 245 $config['payment'] = $this->getPaymentObject($order); 189 246 $config['merchantUrls'] = $this->getMerchantUrls($order); 190 247 191 248 return json_encode($config); 192 249 } … … 198 255 'loyalty_level' => $this->getLoyaltyLevel($customer) 199 256 ]; 200 } 257 } 201 258 return null; 202 259 } … … 241 298 return $code; 242 299 } 243 300 244 301 public function getMerchantUrls($order) { 245 302 … … 249 306 'failure' => is_checkout_pay_page() && $order ? $order->get_checkout_payment_url() : wc_get_checkout_url() 250 307 ]; 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 ); 251 381 } 252 382 … … 265 395 return [ 266 396 'reference_id' => (string) ( 267 $order == null 397 $order == null 268 398 ? md5(json_encode($this->getOrderItemsObject($order))) 269 399 : woocommerce_tabby_get_order_reference_id($order) 270 400 ), 271 401 '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() : 274 404 ($order->get_shipping_total() + $order->get_shipping_tax()) 275 405 ), … … 280 410 ), 281 411 'tax_amount' => $this->formatAmount( 282 $order == null 412 $order == null 283 413 ? array_sum(WC()->cart->get_taxes()) 284 414 : $order->get_total_tax() … … 365 495 $config = json_decode(static::getTabbyConfig($order), true); 366 496 $request = [ 367 'payment' => $config['payment'], 497 'payment' => $config['payment'], 368 498 'lang' => $this->get_lang(), 369 499 'merchant_code' => $config['merchantCode'], … … 469 599 /* translators: %1$s is replaced with Tabby payment ID, %2$s is replaced with payment currency */ 470 600 $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 472 602 $order->save(); 473 603 … … 616 746 if ($payment->status == 'CLOSED' && property_exists($payment, 'captures') && count($payment->captures) > 0) { 617 747 update_post_meta($order_id, static::TABBY_STATUS_FIELD, static::STATUS_CAPTURED); 618 } 748 } 619 749 } 620 750 … … 626 756 627 757 return $this->request($payment_id); 628 629 758 } 630 759 -
tabby-checkout/trunk/includes/class-wc-tabby-ajax.php
r2927757 r3049660 52 52 $ids = array_unique($ids); 53 53 } 54 rsort($ids, SORT_NUMERIC); 55 $ids = array_slice($ids, 0, 10); 54 56 $orders = array_filter( array_map( 'wc_get_order', $ids ) ); 55 57 foreach ($orders as $order) { -
tabby-checkout/trunk/includes/class-wc-tabby-promo.php
r3034458 r3049660 6 6 add_action('woocommerce_before_add_to_cart_form', array( __CLASS__, 'product_promotion') ); 7 7 add_action('wp_enqueue_scripts' , array( __CLASS__, 'wp_enqueue_scripts') ); 8 add_action('admin_enqueue_scripts' , array( __CLASS__, 'admin_enqueue_scripts') ); 8 9 } 9 10 public static function wp_enqueue_scripts() { … … 13 14 // js 14 15 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 } 16 19 }; 17 20 18 21 if ((is_product() || is_cart()) && static::is_tabby_promo_enabled()) { 19 22 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 } 21 26 }; 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 } 22 33 } 23 34 public static function is_tabby_promo_enabled() { … … 27 38 (static::getMaxPrice() == 0 || static::getPrice() <= static::getMaxPrice()) && 28 39 (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; 29 50 } 30 51 public static function is_tabby_promo_enabled_for_product() { … … 144 165 } 145 166 public static function getSource() { 146 return is_ product() ? 'product' : 'cart';167 return is_admin() ? 'adminBlockEditor' : (is_product() ? 'product' : 'cart'); 147 168 } 148 169 public static function getMerchantCode() { … … 178 199 179 200 // Gets order total from cart/checkout. 180 } elseif ( 0 < WC()->cart->total) {201 } elseif ( WC()->cart ) { 181 202 $total = (float) WC()->cart->total; 203 } else { 204 $total = 10; 182 205 } 183 206 … … 206 229 } 207 230 } 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 1 1 <?php 2 3 use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry; 4 2 5 class WC_Tabby { 3 6 public static function init() { … … 16 19 } 17 20 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 } 19 43 } 20 44 public static function add_checkout_methods( $methods ) { … … 28 52 return $methods; 29 53 } 54 30 55 public static function on_activation() { 31 56 wp_schedule_single_event( time() + 60 , 'woocommerce_tabby_cancel_unpaid_orders' ); 32 57 WC_Tabby_Webhook::register(); 33 58 } 59 34 60 public static function on_deactivation() { 35 61 wp_clear_scheduled_hook( 'woocommerce_tabby_cancel_unpaid_orders' ); -
tabby-checkout/trunk/readme.txt
r3034458 r3049660 4 4 Requires at least: 5.7 5 5 Tested up to: 6.4 6 Stable tag: 4. 9.86 Stable tag: 4.10.0 7 7 Requires PHP: 7.0 8 8 License: GPLv3 … … 28 28 29 29 == Changelog == 30 31 = 4.10.0 = 32 33 * Compatibility with woocommerce blocks on checkout 30 34 31 35 = 4.9.5 = -
tabby-checkout/trunk/tabby-checkout.php
r3034458 r3049660 4 4 * Plugin URI: https://tabby.ai/ 5 5 * Description: Tabby Checkout 6 * Version: 4. 9.86 * Version: 4.10.0 7 7 * Author: Tabby 8 8 * Author URI: https://tabby.ai … … 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 define ('MODULE_TABBY_CHECKOUT_VERSION', '4. 9.8');16 define ('MODULE_TABBY_CHECKOUT_VERSION', '4.10.0'); 17 17 define ('TABBY_CHECKOUT_DOMAIN', 'checkout.tabby.ai'); 18 18 define ('TABBY_CHECKOUT_API_DOMAIN', 'api.tabby.ai'); … … 21 21 22 22 WC_Tabby::init(); 23
Note: See TracChangeset
for help on using the changeset viewer.