Plugin Directory

Changeset 3065172


Ignore:
Timestamp:
04/05/2024 04:13:25 AM (2 years ago)
Author:
breadintegrations
Message:

Version 3.5.1 changes

Location:
bread-finance/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • bread-finance/trunk/README.md

    r3047587 r3065172  
    44Requires at least: 4.9
    55Tested up to: 6.1.1
    6 Stable tag: 3.5.0
     6Stable tag: 3.5.1
    77Requires PHP: 5.6
    88WC requires at least: 3.0
     
    7272
    7373== Changelog ==
     74= 3.5.1
     75* Current release
     76* Fix RBC Checkout Block
     77
    7478= 3.5.0
    75 * Current release
    7679* Add support for Checkout Blocks and BOPIS
    7780
  • bread-finance/trunk/assets/js/v2/checkout-blocks.js

    r3047587 r3065172  
    1 const settings = window.wc.wcSettings.getSetting('bread_finance_data', {});
     1const plugin_settings = window.mw_localized_data;
     2const settings = window.wc.wcSettings.getSetting(`${plugin_settings.gateway_token}_data`, {});
    23const label = window.wp.htmlEntities.decodeEntities(settings.title);
    3 const plugin_settings = window.mw_localized_data;
    44const element = window.wp.element
    55const FORM_ELEMENT = 'wc-block-components-form';
     
    104104};
    105105
     106const 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};
    106116
    107117const checkoutWithOpts = (opts) => {
     
    195205            bread_sdk.on('INSTALLMENT:APPLICATION_DECISIONED', onApproved);
    196206            bread_sdk.on('INSTALLMENT:APPLICATION_CHECKOUT', (application) => onCheckout(application, resolve));
     207            bread_sdk.on('INSTALLMENT:CUSTOMER_CLOSE', (application) => onCustomerClose(application, reject));
    197208
    198209            bread_sdk.setEmbedded(opts.setEmbedded);
     
    252263            try {
    253264                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                }
    264276            } catch (e) {
    265277                return {
     
    294306}
    295307
     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 */
     315const 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
    296329const Block_Gateway = {
    297330    name: plugin_settings.gateway_token,
     
    299332    content: Object(window.wp.element.createElement)(Content, null),
    300333    edit: Object(window.wp.element.createElement)(Content, null),
    301     canMakePayment: () => true,
     334    canMakePayment,
    302335    ariaLabel: label,
    303336    supports: {
  • bread-finance/trunk/assets/js/v2/main.js

    r3047587 r3065172  
    11/**
    2  * Bread v3.1.6
     2 * Bread v3.5.1
    33 *
    44 * @author Maritim, Kiprotich
     
    5151                    this.breadCheckoutHandler = new CartHandler();
    5252                    break;
     53                case 'checkout_block':
    5354                case 'checkout':
    5455                    this.breadCheckoutHandler = new CheckoutHandler();
     
    565566        });
    566567
     568        // updated_shipping_method fired only on cart page
    567569        $(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);
    570574        });
    571575    };
     
    721725        var self = this,
    722726            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);
    723732
    724733        if (isOrderPayForm) {
     
    743752            });
    744753        }
    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    }
    747782
    748783    CheckoutHandler.prototype.getViewModel = function() {
  • bread-finance/trunk/bread-finance.php

    r3047587 r3065172  
    66 * Author: Bread Pay
    77 * Author URI: https://payments.breadfinancial.com/
    8  * Version: 3.5.0
     8 * Version: 3.5.1
    99 * Text Domain: bread-finance
    1010 * Domain Path: /i18n/languages/
     
    206206           
    207207            //Require minimums and constants
    208             define('WC_' . $tenant . '_VERSION', '3.5.0');
     208            define('WC_' . $tenant . '_VERSION', '3.5.1');
    209209            define('WC_' . $tenant . '_MIN_PHP_VER', '5.6.0');
    210210            define('WC_' . $tenant . '_MIN_WC_VER', '3.4.0');
  • bread-finance/trunk/classes/class-bread-finance-blocks.php

    r3047587 r3065172  
    1010    protected $settings;
    1111
     12    protected $bread_config;
     13
    1214    public function initialize() {
    13         $this->settings = get_option( 'woocommerce_bread_finance_settings', [] );
     15        $this->settings = get_option("woocommerce_{$this->name}_settings", []);
    1416        $this->gateway = new \Bread_Finance\Classes\Bread_Finance_Gateway();
     17        $this->bread_config = $this->gateway->bread_config;
    1518    }
    1619
    17 
    1820    /**
    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'];
    2530    }
    2631
    2732    public function get_payment_method_script_handles() {
    28         $tenant = strtoupper($this->gateway->bread_config->get('gateway_id'));
     33        $tenant = strtoupper($this->name);
    2934        wp_register_script(
    30             'bread-finance-gateway-blocks-integration',
     35            "{$this->bread_config->get('text_domain')}-gateway-blocks-integration",
    3136            plugins_url('assets/js/v2/checkout-blocks.js', constant('WC_' . $tenant . '_MAIN_FILE')),
    3237            [
     
    3641                'wp-html-entities',
    3742                'wp-i18n',
     43                "{$this->bread_config->get('tenant_prefix')}-main"
    3844            ],
    3945            filemtime(plugin_dir_path( __FILE__ ) . '../assets/js/v2/checkout-blocks.js'),
    4046            true
    4147        );
    42         return [ 'bread-finance-gateway-blocks-integration' ];
     48        return [ "{$this->bread_config->get('text_domain')}-gateway-blocks-integration" ];
    4349    }
    4450
     
    5258            'description' => $this->gateway->description,
    5359            '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', [])
    5562        ];
    5663    }
  • bread-finance/trunk/classes/class-bread-finance-button.php

    r3047587 r3065172  
    9090             */
    9191            if ($button_location_product == 'get_price_html') {
    92                 add_filter('woocommerce_get_price_html', function($price) use ($useCustomSize) {
     92                add_filter('woocommerce_get_price_html', function($price) use ($use_custom_size) {
    9393                    return $price . '<br />' .
    9494                            $this->conditionally_render_bread_button($use_custom_size);
     
    160160     *
    161161     * @global type $product
    162      * @param type $use_custom_size
     162     * @param bool $use_custom_size
    163163     * @return type
    164164     */
     
    199199     * @param type $product_id
    200200     * @param type $product_type
    201      * @param type $use_custom_size
     201     * @param bool $use_custom_size
    202202     * @return string
    203203     */
  • bread-finance/trunk/classes/class-bread-finance-gateway.php

    r3047587 r3065172  
    212212                    'set_embedded' => $this->bread_finance_utilities->toBool($this->get_configuration_setting('set_embedded')),
    213213                    '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', [])
    215216                );
    216217
     
    19861987            $this->log(
    19871988                    __FUNCTION__,
    1988                     'Authorisation request details. #' . json_encode($authorized_transaction)
     1989                    'Authorization request details. #' . json_encode($authorized_transaction)
    19891990            );
    19901991            if ($this->has_error($authorized_transaction)) {
  • bread-finance/trunk/classes/class-bread-finance-options-cart.php

    r3047587 r3065172  
    272272            $pickupLocationIds = ['pickup_location', 'local_pickup'];
    273273            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]];
    275276                if (in_array($chosenMethod->id, $pickupLocationIds)) {
    276277                    $is_checkout_block = $this->bread_finance_utilities->is_checkout_block();
  • bread-finance/trunk/classes/class-bread-finance-options-checkout.php

    r2995512 r3065172  
    159159        WC()->shipping()->calculate_shipping(WC()->cart->get_shipping_packages());
    160160        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            }
    167172        } else {
    168173            $shipping[] = array(
  • bread-finance/trunk/classes/class-bread-finance-utilities.php

    r3047587 r3065172  
    146146        if (is_cart()) {
    147147            return 'cart_summary';
     148        }
     149
     150        if ($this->is_checkout_block()) {
     151            return 'checkout_block';
    148152        }
    149153
     
    324328        return $checkout_page_id && has_block( 'woocommerce/checkout', $checkout_page_id );
    325329    }
     330
     331    function get_wc_shipping_methods() {
     332        return WC()->shipping()->get_shipping_methods();
     333    }
    326334   
    327335}
  • bread-finance/trunk/classes/config/config.yml

    r3047587 r3065172  
    22gateway_id: bread_finance
    33tenant_prefix: bread
    4 tenant_sdk: BreadPayments
    54tenant_author_uri: https://payments.breadfinancial.com/
    65tenant_docs_uri: https://www.breadpayments.com/documentation/
     6tenant_sdk: BreadPayments
    77plugin_description: Adds the Bread Pay Gateway to your WooCommerce site.
    8 plugin_author: Bread Pay
     8plugin_author: Bread Financial
    99checkout_host_sandbox: https://checkout-sandbox.getbread.com
    1010checkout_host: https://checkout.getbread.com
    11 sdk_core_sandbox:  https://connect-preview.breadpayments.com/sdk.js
     11bread_host: https://api.getbread.com
     12bread_host_sandbox: https://api-sandbox.getbread.com
     13sdk_core_sandbox: https://connect-preview.breadpayments.com/sdk.js
    1214sdk_core: https://connect.breadpayments.com/sdk.js
    1315platform_domain_api_sandbox: https://api-preview.platform.breadpayments.com/api
    1416platform_domain_api: https://api.platform.breadpayments.com/api
    15 bread_host: https://api.getbread.com
    16 bread_host_sandbox: https://api-sandbox.getbread.com
    1717sentry_sdk: https://browser.sentry-cdn.com/5.9.1/bundle.min.js
    1818default_sdk_version: classic
     
    2222  classic: Classic
    2323  bread_2: Platform
    24 
Note: See TracChangeset for help on using the changeset viewer.