Changeset 3065172
- Timestamp:
- 04/05/2024 04:13:25 AM (2 years ago)
- Location:
- bread-finance/trunk
- Files:
-
- 11 edited
-
README.md (modified) (2 diffs)
-
assets/js/v2/checkout-blocks.js (modified) (6 diffs)
-
assets/js/v2/main.js (modified) (5 diffs)
-
bread-finance.php (modified) (2 diffs)
-
classes/class-bread-finance-blocks.php (modified) (3 diffs)
-
classes/class-bread-finance-button.php (modified) (3 diffs)
-
classes/class-bread-finance-gateway.php (modified) (2 diffs)
-
classes/class-bread-finance-options-cart.php (modified) (1 diff)
-
classes/class-bread-finance-options-checkout.php (modified) (1 diff)
-
classes/class-bread-finance-utilities.php (modified) (2 diffs)
-
classes/config/config.yml (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bread-finance/trunk/README.md
r3047587 r3065172 4 4 Requires at least: 4.9 5 5 Tested up to: 6.1.1 6 Stable tag: 3.5. 06 Stable tag: 3.5.1 7 7 Requires PHP: 5.6 8 8 WC requires at least: 3.0 … … 72 72 73 73 == Changelog == 74 = 3.5.1 75 * Current release 76 * Fix RBC Checkout Block 77 74 78 = 3.5.0 75 * Current release76 79 * Add support for Checkout Blocks and BOPIS 77 80 -
bread-finance/trunk/assets/js/v2/checkout-blocks.js
r3047587 r3065172 1 const settings = window.wc.wcSettings.getSetting('bread_finance_data', {}); 1 const plugin_settings = window.mw_localized_data; 2 const settings = window.wc.wcSettings.getSetting(`${plugin_settings.gateway_token}_data`, {}); 2 3 const label = window.wp.htmlEntities.decodeEntities(settings.title); 3 const plugin_settings = window.mw_localized_data;4 4 const element = window.wp.element 5 5 const FORM_ELEMENT = 'wc-block-components-form'; … … 104 104 }; 105 105 106 const onCustomerClose = (application, reject) => { 107 let zoid = document.querySelector('[id^="zoid-checkout-component"]'); 108 if (zoid) { 109 try { 110 zoid.remove(); 111 } catch (e) {} 112 } 113 reject(application); 114 115 }; 106 116 107 117 const checkoutWithOpts = (opts) => { … … 195 205 bread_sdk.on('INSTALLMENT:APPLICATION_DECISIONED', onApproved); 196 206 bread_sdk.on('INSTALLMENT:APPLICATION_CHECKOUT', (application) => onCheckout(application, resolve)); 207 bread_sdk.on('INSTALLMENT:CUSTOMER_CLOSE', (application) => onCustomerClose(application, reject)); 197 208 198 209 bread_sdk.setEmbedded(opts.setEmbedded); … … 252 263 try { 253 264 const applicationId = await fetchBreadOptions(billing, shippingData); 254 console.log("Application ID:", applicationId); 255 return { 256 type: emitResponse.responseTypes.SUCCESS, 257 meta: { 258 paymentMethodData: { 259 bread_tx_token: applicationId 260 }, 261 } 262 }; 263 265 if (applicationId) { 266 console.log("Application ID:", applicationId); 267 return { 268 type: emitResponse.responseTypes.SUCCESS, 269 meta: { 270 paymentMethodData: { 271 bread_tx_token: applicationId 272 }, 273 } 274 }; 275 } 264 276 } catch (e) { 265 277 return { … … 294 306 } 295 307 308 /** 309 * Determine whether Bread Pay is available for this cart 310 * 311 * @param {Object} props Incoming props for the component 312 * 313 * @return {boolean} True if Bread Pay payment method should be displayed as a payment option. 314 */ 315 const canMakePayment = ({selectedShippingMethods}) => { 316 if (!settings.enabled_for_shipping.length) { 317 // Payment method does not limit Bread Pay to specific shipping methods 318 return true; 319 } 320 321 const selected_methods = Object.values(selectedShippingMethods); 322 return settings.enabled_for_shipping.some((shipping_method_id) => { 323 return selected_methods.some((selected_method) => { 324 return selected_method.includes(shipping_method_id); 325 }); 326 }); 327 }; 328 296 329 const Block_Gateway = { 297 330 name: plugin_settings.gateway_token, … … 299 332 content: Object(window.wp.element.createElement)(Content, null), 300 333 edit: Object(window.wp.element.createElement)(Content, null), 301 canMakePayment : () => true,334 canMakePayment, 302 335 ariaLabel: label, 303 336 supports: { -
bread-finance/trunk/assets/js/v2/main.js
r3047587 r3065172 1 1 /** 2 * Bread v3. 1.62 * Bread v3.5.1 3 3 * 4 4 * @author Maritim, Kiprotich … … 51 51 this.breadCheckoutHandler = new CartHandler(); 52 52 break; 53 case 'checkout_block': 53 54 case 'checkout': 54 55 this.breadCheckoutHandler = new CheckoutHandler(); … … 565 566 }); 566 567 568 // updated_shipping_method fired only on cart page 567 569 $(document.body).on('updated_shipping_method', function(event) { 568 this.$button = $(`div.${tenantPrefix}-checkout-button`); 569 breadController.breadCheckoutHandler.updateButton(); 570 this.timeout = window.setTimeout(function() { 571 this.$button = $(`div.${tenantPrefix}-checkout-button`); 572 breadController.breadCheckoutHandler.updateButton(); 573 }, 1000); 570 574 }); 571 575 }; … … 721 725 var self = this, 722 726 isOrderPayForm = $('form#order_review').length > 0; 727 728 $('form.checkout').on('change', 'input[name^="shipping_method"]', self.checkShippingAndHidePayment); 729 setTimeout(function() { 730 self.checkShippingAndHidePayment(); 731 }, 1000); 723 732 724 733 if (isOrderPayForm) { … … 743 752 }); 744 753 } 745 746 }; 754 }; 755 756 /** 757 * Determine whether Bread Pay is available for this cart in 758 * legacy shortcode based checkout page 759 */ 760 CheckoutHandler.prototype.checkShippingAndHidePayment = function() { 761 const selected_method = $('input[name^="shipping_method"]:checked').val(); 762 763 // dont hide payment if enabled_for_shipping is not set 764 if (breadController.local.enabled_for_shipping.length === 0) { 765 return false; 766 } 767 768 if (!selected_method || breadController.local.page_type === 'checkout_block') { 769 return false; 770 } 771 const payment_method = 'li.payment_method_' + breadController.local.gateway_token; 772 const enabled_for_shipping = breadController.local.enabled_for_shipping.some((shipping_method_id) => { 773 return selected_method.includes(shipping_method_id); 774 }); 775 if (!enabled_for_shipping) { 776 console.info(`${breadController.local.gateway_token} is not available for ${selected_method}`); 777 $(payment_method).hide(); 778 } else { 779 $(payment_method).show(); 780 } 781 } 747 782 748 783 CheckoutHandler.prototype.getViewModel = function() { -
bread-finance/trunk/bread-finance.php
r3047587 r3065172 6 6 * Author: Bread Pay 7 7 * Author URI: https://payments.breadfinancial.com/ 8 * Version: 3.5. 08 * Version: 3.5.1 9 9 * Text Domain: bread-finance 10 10 * Domain Path: /i18n/languages/ … … 206 206 207 207 //Require minimums and constants 208 define('WC_' . $tenant . '_VERSION', '3.5. 0');208 define('WC_' . $tenant . '_VERSION', '3.5.1'); 209 209 define('WC_' . $tenant . '_MIN_PHP_VER', '5.6.0'); 210 210 define('WC_' . $tenant . '_MIN_WC_VER', '3.4.0'); -
bread-finance/trunk/classes/class-bread-finance-blocks.php
r3047587 r3065172 10 10 protected $settings; 11 11 12 protected $bread_config; 13 12 14 public function initialize() { 13 $this->settings = get_option( 'woocommerce_bread_finance_settings', []);15 $this->settings = get_option("woocommerce_{$this->name}_settings", []); 14 16 $this->gateway = new \Bread_Finance\Classes\Bread_Finance_Gateway(); 17 $this->bread_config = $this->gateway->bread_config; 15 18 } 16 19 17 18 20 /** 19 * Returns if this payment method should be active. If false, the scripts will not be enqueued. 20 * 21 * @return boolean 22 */ 23 public function is_active() { 24 return !empty( $this->settings['enabled'] ) && 'yes' === $this->settings['enabled']; 21 * Returns if this payment method should be active. If false, the scripts will not be enqueued. 22 * 23 * @return boolean 24 */ 25 public function is_active() { 26 if (!$this->gateway->bread_finance_utilities->tenant_currency_equals_woocommerce_currency()) { 27 return false; 28 } 29 return !empty( $this->settings['enabled'] ) && 'yes' === $this->settings['enabled']; 25 30 } 26 31 27 32 public function get_payment_method_script_handles() { 28 $tenant = strtoupper($this-> gateway->bread_config->get('gateway_id'));33 $tenant = strtoupper($this->name); 29 34 wp_register_script( 30 'bread-finance-gateway-blocks-integration',35 "{$this->bread_config->get('text_domain')}-gateway-blocks-integration", 31 36 plugins_url('assets/js/v2/checkout-blocks.js', constant('WC_' . $tenant . '_MAIN_FILE')), 32 37 [ … … 36 41 'wp-html-entities', 37 42 'wp-i18n', 43 "{$this->bread_config->get('tenant_prefix')}-main" 38 44 ], 39 45 filemtime(plugin_dir_path( __FILE__ ) . '../assets/js/v2/checkout-blocks.js'), 40 46 true 41 47 ); 42 return [ 'bread-finance-gateway-blocks-integration'];48 return [ "{$this->bread_config->get('text_domain')}-gateway-blocks-integration" ]; 43 49 } 44 50 … … 52 58 'description' => $this->gateway->description, 53 59 'embedded' => $this->get_embedded(), 54 'tenant_sdk' => $this->gateway->bread_config->get('tenant_sdk') 60 'tenant_sdk' => $this->bread_config->get('tenant_sdk'), 61 'enabled_for_shipping' => $this->bread_config->get('enabled_for_shipping', []) 55 62 ]; 56 63 } -
bread-finance/trunk/classes/class-bread-finance-button.php
r3047587 r3065172 90 90 */ 91 91 if ($button_location_product == 'get_price_html') { 92 add_filter('woocommerce_get_price_html', function($price) use ($use CustomSize) {92 add_filter('woocommerce_get_price_html', function($price) use ($use_custom_size) { 93 93 return $price . '<br />' . 94 94 $this->conditionally_render_bread_button($use_custom_size); … … 160 160 * 161 161 * @global type $product 162 * @param type$use_custom_size162 * @param bool $use_custom_size 163 163 * @return type 164 164 */ … … 199 199 * @param type $product_id 200 200 * @param type $product_type 201 * @param type$use_custom_size201 * @param bool $use_custom_size 202 202 * @return string 203 203 */ -
bread-finance/trunk/classes/class-bread-finance-gateway.php
r3047587 r3065172 212 212 'set_embedded' => $this->bread_finance_utilities->toBool($this->get_configuration_setting('set_embedded')), 213 213 'ajaxurl' => admin_url('admin-ajax.php'), 214 'ajaxnonce' => wp_create_nonce('mwp-ajax-nonce') 214 'ajaxnonce' => wp_create_nonce('mwp-ajax-nonce'), 215 'enabled_for_shipping' => $this->bread_config->get('enabled_for_shipping', []) 215 216 ); 216 217 … … 1986 1987 $this->log( 1987 1988 __FUNCTION__, 1988 'Authori sation request details. #' . json_encode($authorized_transaction)1989 'Authorization request details. #' . json_encode($authorized_transaction) 1989 1990 ); 1990 1991 if ($this->has_error($authorized_transaction)) { -
bread-finance/trunk/classes/class-bread-finance-options-cart.php
r3047587 r3065172 272 272 $pickupLocationIds = ['pickup_location', 'local_pickup']; 273 273 if (count($chosenMethods) === 1) { 274 $chosenMethod = WC()->shipping()->get_shipping_methods()[explode(':', $chosenMethods[0])[0]]; 274 $shippingMethods = $this->bread_finance_utilities->get_wc_shipping_methods(); 275 $chosenMethod = $shippingMethods[explode(':', $chosenMethods[0])[0]]; 275 276 if (in_array($chosenMethod->id, $pickupLocationIds)) { 276 277 $is_checkout_block = $this->bread_finance_utilities->is_checkout_block(); -
bread-finance/trunk/classes/class-bread-finance-options-checkout.php
r2995512 r3065172 159 159 WC()->shipping()->calculate_shipping(WC()->cart->get_shipping_packages()); 160 160 if (count($chosenMethods) === 1) { 161 $chosenMethod = WC()->shipping()->get_shipping_methods()[explode(':', $chosenMethods[0])[0]]; 162 $shipping[] = array( 163 'typeId' => $chosenMethod->id, 164 'cost' => $this->bread_finance_utilities->priceToCents(WC()->cart->shipping_total), 165 'type' => $chosenMethod->method_title 166 ); 161 $shippingMethods = $this->bread_finance_utilities->get_wc_shipping_methods(); 162 if ($shippingMethods) { 163 $chosenMethod = $shippingMethods[explode(':', $chosenMethods[0])[0]]; 164 $shipping[] = array( 165 'typeId' => $chosenMethod->id, 166 'cost' => $this->bread_finance_utilities->priceToCents(WC()->cart->shipping_total), 167 'type' => $chosenMethod->method_title 168 ); 169 } else { 170 $shipping[] = array(); 171 } 167 172 } else { 168 173 $shipping[] = array( -
bread-finance/trunk/classes/class-bread-finance-utilities.php
r3047587 r3065172 146 146 if (is_cart()) { 147 147 return 'cart_summary'; 148 } 149 150 if ($this->is_checkout_block()) { 151 return 'checkout_block'; 148 152 } 149 153 … … 324 328 return $checkout_page_id && has_block( 'woocommerce/checkout', $checkout_page_id ); 325 329 } 330 331 function get_wc_shipping_methods() { 332 return WC()->shipping()->get_shipping_methods(); 333 } 326 334 327 335 } -
bread-finance/trunk/classes/config/config.yml
r3047587 r3065172 2 2 gateway_id: bread_finance 3 3 tenant_prefix: bread 4 tenant_sdk: BreadPayments5 4 tenant_author_uri: https://payments.breadfinancial.com/ 6 5 tenant_docs_uri: https://www.breadpayments.com/documentation/ 6 tenant_sdk: BreadPayments 7 7 plugin_description: Adds the Bread Pay Gateway to your WooCommerce site. 8 plugin_author: Bread Pay8 plugin_author: Bread Financial 9 9 checkout_host_sandbox: https://checkout-sandbox.getbread.com 10 10 checkout_host: https://checkout.getbread.com 11 sdk_core_sandbox: https://connect-preview.breadpayments.com/sdk.js 11 bread_host: https://api.getbread.com 12 bread_host_sandbox: https://api-sandbox.getbread.com 13 sdk_core_sandbox: https://connect-preview.breadpayments.com/sdk.js 12 14 sdk_core: https://connect.breadpayments.com/sdk.js 13 15 platform_domain_api_sandbox: https://api-preview.platform.breadpayments.com/api 14 16 platform_domain_api: https://api.platform.breadpayments.com/api 15 bread_host: https://api.getbread.com16 bread_host_sandbox: https://api-sandbox.getbread.com17 17 sentry_sdk: https://browser.sentry-cdn.com/5.9.1/bundle.min.js 18 18 default_sdk_version: classic … … 22 22 classic: Classic 23 23 bread_2: Platform 24
Note: See TracChangeset
for help on using the changeset viewer.