Plugin Directory

Changeset 3047587


Ignore:
Timestamp:
03/08/2024 05:05:02 AM (2 years ago)
Author:
breadintegrations
Message:

Version 3.5.0 changes

Location:
bread-finance/trunk
Files:
3 added
10 edited

Legend:

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

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

    r2997246 r3047587  
    723723
    724724        if (isOrderPayForm) {
    725             this.$form.on('submit', function() {
     725            self.$form.on('submit', function() {
    726726                if ($('#payment_method_' + breadController.local.gateway_token).is(':checked')) {
    727727                    /*  If the hidden input `bread_tx_token` exists, checkout has been completed and the form should be submitted */
     
    734734            });
    735735        } else {
    736             this.$form.on('checkout_place_order_' + breadController.local.gateway_token, function() {
     736            self.$form.on('checkout_place_order_' + breadController.local.gateway_token, function() {
    737737                /*  If the hidden input `bread_tx_token` exists, checkout has been completed and the form should be submitted */
    738738                let isCompletedBreadCheckout = self.$form.find('input[name="bread_tx_token"]').length > 0;
     
    842842
    843843    CheckoutHandler.prototype.checkoutWithOpts = function(opts) {
     844        let self = this;
     845        let bopisPayload = BreadUtil.createBopisPayload(opts);
     846
    844847        let setup = {
    845848            integrationKey: breadController.local.integration_key,
     
    900903                currency: opts.currency,
    901904                items: items,
     905                ...bopisPayload,
    902906                totalPrice: {
    903907                    value: opts.customTotal,
  • bread-finance/trunk/bread-finance.php

    r3027202 r3047587  
    66 * Author: Bread Pay
    77 * Author URI: https://payments.breadfinancial.com/
    8  * Version: 3.4.3
     8 * Version: 3.5.0
    99 * Text Domain: bread-finance
    1010 * Domain Path: /i18n/languages/
     
    206206           
    207207            //Require minimums and constants
    208             define('WC_' . $tenant . '_VERSION', '3.4.3');
     208            define('WC_' . $tenant . '_VERSION', '3.5.0');
    209209            define('WC_' . $tenant . '_MIN_PHP_VER', '5.6.0');
    210210            define('WC_' . $tenant . '_MIN_WC_VER', '3.4.0');
     
    256256}
    257257
     258// Declare Blocks compatibility
     259add_action('before_woocommerce_init', function () {
     260    if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) {
     261        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true);
     262    }
     263});
     264
     265// Hook in WooC Blocks integration.
     266add_action( 'woocommerce_blocks_loaded', function () {
     267    if ( ! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
     268        return;
     269    }
     270
     271    require_once plugin_dir_path(__FILE__) . 'classes/class-bread-finance-blocks.php';
     272
     273    // Hook the registration function to the 'woocommerce_blocks_payment_method_type_registration' action
     274    add_action(
     275        'woocommerce_blocks_payment_method_type_registration',
     276        function( \Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
     277            $payment_method_registry->register( new \Bread_Finance\Classes\Bread_Finance_Blocks() );
     278        }
     279    );
     280});
     281
    258282$instance_name = 'wc_' . $bread_config->get('gateway_id');
    259283
  • bread-finance/trunk/classes/class-bread-finance-ajax.php

    r2997246 r3047587  
    114114        } catch (\Exception $e) {
    115115            Bread_Finance_Logger::log( 'Error: ' . $e->getMessage() );
    116             wp_send_json_error(__("Error getting Bread options.", self::$bread_finance_plugin->get_text_domain()));
     116            wp_send_json_error(__("Error getting Bread options.", $bread_finance_plugin->get_text_domain()));
    117117        }
    118118    }
  • bread-finance/trunk/classes/class-bread-finance-button.php

    r3027202 r3047587  
    6666     */
    6767    public function add_template_hooks() {
     68        if (!$this->bread_finance_utilities->tenant_currency_equals_woocommerce_currency()) {
     69            return;
     70        }
    6871        $use_custom_size = $this->bread_finance_plugin->get_bread_gateway()->get_configuration_setting('button_size') === 'custom';
    6972        $wcAjax        = defined( 'WC_DOING_AJAX' ) ? $_GET['wc-ajax'] : false;
     
    140143        $bread_version = $gateway->get_configuration_setting('env_bread_api');
    141144        $set_embedded = $this->bread_finance_plugin->get_bread_gateway()->get_configuration_setting('set_embedded') ?: false;
    142         if($bread_version === 'bread_2' && $this->bread_finance_utilities->getPageType() === 'checkout') {
     145        $is_checkout_block = $this->bread_finance_utilities->is_checkout_block();
     146        if($bread_version === 'bread_2' && ($this->bread_finance_utilities->getPageType() === 'checkout' || $is_checkout_block)) {
    143147            add_action( 'woocommerce_after_checkout_form', function() {
     148                print "<div id='{$this->tenant_prefix}_checkout_placeholder'></div>";
     149                print $this->render_embedded_container();
     150            });
     151            add_action( 'woocommerce_blocks_enqueue_checkout_block_scripts_before', function() {
    144152                print "<div id='{$this->tenant_prefix}_checkout_placeholder'></div>";
    145153                print $this->render_embedded_container();
  • bread-finance/trunk/classes/class-bread-finance-gateway.php

    r3027202 r3047587  
    183183                ));
    184184
     185                wp_register_script(
     186                    "{$this->bread_config->get('tenant_prefix')}-util",
     187                    plugins_url('assets/js/v2/util.js', $this->main_file_path),
     188                    array("{$this->bread_config->get('tenant_prefix')}-sdk", 'mwp'),
     189                    $this->is_production() ? $this->plugin_version: filemtime(plugin_dir_path( __FILE__ ) . '../assets/js/v2/util.js'),
     190                    true
     191                );
     192
    185193                //Add JS Helper
    186194                wp_register_script(
     
    202210                    'tenant_prefix' => $this->bread_config->get('tenant_prefix'),
    203211                    'tenant_sdk' => $this->bread_config->get('tenant_sdk'),
    204                     'set_embedded' => $this->bread_finance_utilities->toBool($this->get_configuration_setting('set_embedded'))
     212                    'set_embedded' => $this->bread_finance_utilities->toBool($this->get_configuration_setting('set_embedded')),
     213                    'ajaxurl' => admin_url('admin-ajax.php'),
     214                    'ajaxnonce' => wp_create_nonce('mwp-ajax-nonce')
    205215                );
    206216
     
    217227               
    218228                wp_enqueue_script("{$this->bread_config->get('tenant_prefix')}-sdk");
     229                wp_enqueue_script("{$this->bread_config->get('tenant_prefix')}-util");
    219230                wp_enqueue_script("{$this->bread_config->get('tenant_prefix')}-main");
    220231                wp_enqueue_style("{$this->bread_config->get('tenant_prefix')}-main");
     
    320331         */
    321332        public function process_payment($order_id) {
    322             if (!array_key_exists('bread_tx_token', $_REQUEST)) {
     333            if (!array_key_exists('bread_tx_token', $_REQUEST) && !array_key_exists('bread_tx_token', $_POST)) {
    323334                $this->log(
    324335                        __FUNCTION__,
     
    568579                #$this->bread_finance_api = Bread_Finance_V2_Api::instance();
    569580
    570                 $txToken = $_REQUEST['bread_tx_token'];
     581                $txToken = null;
     582                if (isset($_REQUEST['bread_tx_token'])) {
     583                    $txToken = $_REQUEST['bread_tx_token'];
     584                } elseif (isset($_POST['bread_tx_token'])) {
     585                    $txToken = $_POST['bread_tx_token'];
     586                }
     587
    571588                $order = wc_get_order($order_id);
    572589
  • bread-finance/trunk/classes/class-bread-finance-options-cart.php

    r2862484 r3047587  
    267267                }
    268268            }
     269
     270            // Return store address as the pickup address for local pickup
     271            $chosenMethods = WC()->session->get('chosen_shipping_methods') ?? [];
     272            $pickupLocationIds = ['pickup_location', 'local_pickup'];
     273            if (count($chosenMethods) === 1) {
     274                $chosenMethod = WC()->shipping()->get_shipping_methods()[explode(':', $chosenMethods[0])[0]];
     275                if (in_array($chosenMethod->id, $pickupLocationIds)) {
     276                    $is_checkout_block = $this->bread_finance_utilities->is_checkout_block();
     277                    $store_address = $this->bread_finance_utilities->get_base_store_address();
     278                    if ($is_checkout_block) {
     279                        $pickupLocations = get_option( 'pickup_location_pickup_locations', [] );
     280                        $store_address = $this->bread_finance_utilities->get_checkout_block_pickup_location($pickupLocations);
     281                    }
     282                    $shipping_contact = [
     283                        'firstName' => $customer->get_shipping_first_name(),
     284                        'lastName'  => $customer->get_shipping_last_name(),
     285                        'address'   => $store_address['address'],
     286                        'address2'  => $store_address['address2'],
     287                        'zip'       => $store_address['zip'],
     288                        'city'      => $store_address['city'],
     289                        'state'     => $store_address['state'],
     290                        'country'   => $store_address['country'],
     291                        'phone'     => substr(preg_replace('/[^0-9]/', '', get_option('woocommerce_store_phone')), - 10),
     292                    ];
     293
     294                    try {
     295                        if ($this->bread_finance_utilities->keys_present_and_not_null($shipping_contact, ['address', 'city', 'state', 'zip'])) {
     296                            return [
     297                                'shippingContact' => $shipping_contact
     298                            ];
     299                        }
     300                    } catch (\Exception $e) {
     301                        throw new \Exception(__FUNCTION__ . ": Chosen method: {$chosenMethod->id}, " . $e->getMessage(), 0, $e);
     302                    }
     303                }
     304            }
     305            // Return customer shipping address for deliveries
    269306            return array(
    270307                'shippingContact' => array(
  • bread-finance/trunk/classes/class-bread-finance-utilities.php

    r2995512 r3047587  
    276276        return strcasecmp($active_currency, $bread_config_currency) == 0;
    277277    }
     278
     279    function get_base_store_address() {
     280        return [
     281            'address'   => WC()->countries->get_base_address(),
     282            'address2'  => WC()->countries->get_base_address_2(),
     283            'city'      => WC()->countries->get_base_city(),
     284            'zip'       => WC()->countries->get_base_postcode(),
     285            'country'   => WC()->countries->get_base_country(),
     286            'state'     => WC()->countries->get_base_state()
     287        ];
     288    }
     289
     290    function get_checkout_block_pickup_location($pickupLocations) {
     291        if (count($pickupLocations) >= 1 && isset($pickupLocations[0]['address'])) {
     292            $address = $pickupLocations[0]['address'];
     293            return [
     294                'address'   => $address['address_1'],
     295                'address2'  => $address['address_2'] ?? '',
     296                'city'      => $address['city'],
     297                'zip'       => $address['postcode'],
     298                'country'   => $address['country'],
     299                'state'     => $address['state']
     300            ];
     301        }
     302    }
     303
     304    function keys_present_and_not_null($data, $keys) {
     305        $missingOrNullKeys = [];
     306
     307        foreach ($keys as $key) {
     308            if (!array_key_exists($key, $data) || is_null($data[$key])) {
     309                $missingOrNullKeys[] = $key;
     310            }
     311        }
     312
     313        if (!empty($missingOrNullKeys)) {
     314            throw new \Exception("The following keys are missing or have null values: " . implode(', ', $missingOrNullKeys) . ".");
     315        }
     316        return true;
     317    }
     318
     319    function is_checkout_block() {
     320        if (!function_exists('has_block')) {
     321            return false;
     322        }
     323        $checkout_page_id = wc_get_page_id( 'checkout' );
     324        return $checkout_page_id && has_block( 'woocommerce/checkout', $checkout_page_id );
     325    }
     326   
    278327}
  • bread-finance/trunk/classes/config/config.yml

    r2995512 r3047587  
    22gateway_id: bread_finance
    33tenant_prefix: bread
     4tenant_sdk: BreadPayments
    45tenant_author_uri: https://payments.breadfinancial.com/
    56tenant_docs_uri: https://www.breadpayments.com/documentation/
    6 tenant_sdk: BreadPayments
    77plugin_description: Adds the Bread Pay Gateway to your WooCommerce site.
    8 plugin_author: Bread Financial
     8plugin_author: Bread Pay
    99checkout_host_sandbox: https://checkout-sandbox.getbread.com
    1010checkout_host: https://checkout.getbread.com
    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
     11sdk_core_sandbox:  https://connect-preview.breadpayments.com/sdk.js
    1412sdk_core: https://connect.breadpayments.com/sdk.js
    1513platform_domain_api_sandbox: https://api-preview.platform.breadpayments.com/api
    1614platform_domain_api: https://api.platform.breadpayments.com/api
     15bread_host: https://api.getbread.com
     16bread_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
  • bread-finance/trunk/composer.json

    r2984693 r3047587  
    1010        "phpunit/phpunit": ">=8.5.23",
    1111        "yoast/phpunit-polyfills": "^1.0",
    12         "rector/rector": "^0.18.5"
     12        "rector/rector": "0.18.4"
    1313    },
    1414    "autoload": {
Note: See TracChangeset for help on using the changeset viewer.