Plugin Directory

Changeset 2995512


Ignore:
Timestamp:
11/14/2023 04:27:28 AM (2 years ago)
Author:
breadintegrations
Message:

v3.4.1 - Duplicate products in cart fix, multi-currency, other fixes

Location:
bread-finance/trunk
Files:
5 added
2 deleted
11 edited

Legend:

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

    r2984693 r2995512  
    44Requires at least: 4.9
    55Tested up to: 6.1.1
    6 Stable tag: 3.4.0
     6Stable tag: 3.4.1
    77Requires PHP: 5.6
    88WC requires at least: 3.0
     
    7272
    7373== Changelog ==
     74= 3.4.1
     75* Current release
     76* Compatiblity with WooCommerce Price Based on Country
    7477
    7578= 3.4.0
    76 * Current release
    7779* Fix for variant pricing changes
    7880* Fix for modal not showing up when cart is updated
  • bread-finance/trunk/bread-finance.php

    r2984693 r2995512  
    44 * Plugin Name: Bread Pay
    55 * Description: Adds the Bread Pay Gateway to your WooCommerce site.
    6  * Author: Bread Pay
     6 * Author: Bread Financial
    77 * Author URI: https://payments.breadfinancial.com/
    8  * Version: 3.4.0
    9  * Text Domain: bread-finance
     8 * Version: 3.4.1
     9 * Text Domain: bread_finance
    1010 * Domain Path: /i18n/languages/
    1111 * WC requires at least: 3.0.0
     
    2222}
    2323
    24 if (!class_exists(\Bread_Finance\classes\Spyc::class)) {
     24if (!class_exists(\Bread_Finance\Classes\Spyc::class)) {
    2525    # Including this first so it can be used in Config.php
    2626    require_once untrailingslashit(plugin_dir_path(__FILE__)) . '/classes/Spyc.php';
     
    206206           
    207207            //Require minimums and constants
    208             define('WC_' . $tenant . '_VERSION', '3.4.0');
     208            define('WC_' . $tenant . '_VERSION', '3.4.1');
    209209            define('WC_' . $tenant . '_MIN_PHP_VER', '5.6.0');
    210210            define('WC_' . $tenant . '_MIN_WC_VER', '3.4.0');
     
    212212            define('WC_' . $tenant . '_PLUGIN_PATH', $this->plugin_path);
    213213            define('WC_' . $tenant . '_PLUGIN_URL', untrailingslashit(plugin_dir_url(__FILE__)));
     214
     215            //Compability classes
     216            include_once $this->plugin_path . '/classes/compat/class-bread-finance-currency-abstract.php';
     217            include_once $this->plugin_path . '/classes/compat/class-bread-finance-currency-pboc.php';
     218            include_once $this->plugin_path . '/classes/compat/class-bread-finance-currency-woocs.php';
     219            include_once $this->plugin_path . '/classes/compat/class-bread-finance-currency.php';
    214220
    215221            //Classes
  • bread-finance/trunk/classes/class-bread-finance-ajax.php

    r2984693 r2995512  
    33namespace Bread_Finance\Classes;
    44
    5 use Bread_Finance\Classes\Config\Bread_Config;
    65
    76if (!defined('ABSPATH')) {
     
    479478                $order->add_meta_data('bread_tx_id', $tx_id);
    480479                $order->add_meta_data('bread_api_version', $bread_finance_gateway->load_bread_env());
     480                $order->add_meta_data('payment_method', $bread_finance_gateway->id);
    481481                /* Set billing address */
    482482                $order->set_address(array(
     
    586586                }
    587587                /* Authorize Bread transaction */
    588                 $transaction = $bread_finance_api->authorizeTransaction($tx_id, $transaction['totalAmount']['value'], get_woocommerce_currency());
     588                $active_currency = $bread_finance_utilities->get_active_currency();
     589                $transaction = $bread_finance_api->authorizeTransaction($tx_id, $transaction['totalAmount']['value'], $active_currency);
    589590                if (strtoupper($transaction['status']) !== 'AUTHORIZED') {
    590591                    $errorDescription = $transaction["description"];
  • bread-finance/trunk/classes/class-bread-finance-button.php

    r2984693 r2995512  
    5959            $this->tenant_prefix = $this->bread_config->get('tenant_prefix');
    6060        }
    61         add_action('wp',array($this, 'add_template_hooks'));
    6261    }
    6362   
     
    132131            if ($button_location_cart) {
    133132                add_action('woocommerce_' . $button_location_cart, function () use ($use_custom_size) {
    134                     print $this->render_bread_button(array('buttonId' => 'bread_checkout_button', 'buttonLocation' => $this->bread_finance_utilities->getPageType()), array(), $use_custom_size);
     133                    print $this->render_bread_button(array('buttonId' => "{$this->tenant_prefix}_checkout_button", 'buttonLocation' => $this->bread_finance_utilities->getPageType()), array(), $use_custom_size);
    135134                });
    136135            }
     
    142141        if($bread_version === 'bread_2' && $this->bread_finance_utilities->getPageType() === 'checkout') {
    143142            add_action( 'woocommerce_after_checkout_form', function() {
    144                 print("<div id='{$this->tenant_prefix}_checkout_placeholder'></div>");
    145                 print($this->render_embedded_container());
     143                print "<div id='{$this->tenant_prefix}_checkout_placeholder'></div>";
     144                print $this->render_embedded_container();
    146145            });
    147146        }
     
    261260
    262261}
    263 
    264 $bread_utilities = Bread_Finance_Utilities::instance();
    265 if ($bread_utilities->can_show_button()) {
    266     Bread_Finance_Button::instance();
    267 }
  • bread-finance/trunk/classes/class-bread-finance-gateway.php

    r2984693 r2995512  
    4848        public function __construct() {
    4949            $this->bread_config = \Bread_Finance\Classes\Config\Bread_Config::instance();
     50            $this->bread_finance_utilities = \Bread_Finance\Classes\Bread_Finance_Utilities::instance();
    5051            $this->id = $this->bread_config->get('gateway_id');
    5152            $this->plugin_version = constant('WC_' . strtoupper($this->bread_config->get('gateway_id')) . '_VERSION');
     
    7071            add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'validate_product_id_list'));
    7172
    72             //Validity API keys
     73            //Validate API keys
    7374            add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'validate_api_keys'), 11);
    7475
    75             //Add
    7676            add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
    77 
     77            add_action('wp_enqueue_scripts', array($this, 'init_bread_button'));
     78            add_action('wp_enqueue_scripts', array($this, 'init_ajax_events'));
     79
     80            add_action('woocommerce_checkout_update_order_review', array($this, 'handle_checkout_update_order_review'));
    7881            add_action('woocommerce_after_checkout_validation', array($this, 'prevent_order_creation_during_validation'), 10, 2);
    7982            add_action('before_woocommerce_init', array($this, 'anonymize_tax_and_shipping_ajax'));
     
    98101            add_action('woocommerce_order_action_create_bread_cart_link', array($this, 'create_bread_cart_link'));
    99102            add_action('woocommerce_order_action_email_bread_cart_link', array($this, 'email_bread_cart_link'));
    100            
     103
    101104            add_filter( 'query_vars', array($this, 'custom_bread_vars'));
    102 
    103105            //add_filter('all_plugins', array($this, 'update_plugin_meta'));
    104106
     
    115117        }
    116118
     119        public function init_bread_button() {
     120            if ($this->bread_finance_utilities->tenant_currency_equals_woocommerce_currency()) {
     121                $bread_finance_button = Bread_Finance_Button::instance();
     122                $bread_finance_button->add_template_hooks();
     123            }
     124        }
     125
     126        public function init_ajax_events() {
     127            $bread_finance_ajax = Bread_Finance_Ajax::instance();
     128        }
     129
     130        public function handle_checkout_update_order_review() {
     131            if(!$this->bread_finance_utilities->tenant_currency_equals_woocommerce_currency() && $this->bread_finance_utilities->getPageType() === 'checkout') {
     132                add_filter('woocommerce_available_payment_gateways', function($available_gateways) {
     133                    unset($available_gateways[$this->id]);
     134                    return $available_gateways;
     135                });
     136            }
     137        }
     138
    117139        public function enqueue_scripts() {
    118             if (!$this->bread_finance_utilities) {
    119                 $this->bread_finance_utilities = Bread_Finance_Utilities::instance();
    120             }
    121140
    122141            if ('yes' !== $this->enabled) {
     
    124143            }
    125144
    126             if (!$this->bread_finance_utilities->can_show_button()) {
     145            if (!$this->bread_finance_utilities->tenant_currency_equals_woocommerce_currency()) {
    127146                return;
    128147            }
     
    402421        public function settle_order($order_id) {
    403422            $order   = wc_get_order( $order_id );
     423            $gateway_id = $this->bread_config->get('gateway_id');
     424            $payment_method = $order->get_payment_method();
    404425            if ($order->get_payment_method() !== $this->bread_config->get('gateway_id')) {
    405                 $order->add_order_note("Order payment method " . $order->get_payment_method());
    406                 $order->add_order_note("Gateway id " . $this->bread_config->get('gateway_id'));
     426                $this->log(
     427                    __FUNCTION__,
     428                    "Skipping settle $this->method_title on platform order: $order_id because payment_method: $payment_method does not match Gateway Id: $gateway_id"
     429            );
    407430                return;
    408431            }
     
    545568        public function process_bread_2_checkout($order_id) {
    546569            try {
    547                 if (!$this->bread_finance_utilities) {
    548                     $this->bread_finance_utilities = Bread_Finance_Utilities::instance();
    549                 }
    550570
    551571                if (!$this->bread_finance_plugin) {
     
    575595                $order->add_meta_data('bread_tx_id', $transaction['id']);
    576596                $order->add_meta_data('bread_api_version', 'bread_2');
     597                $order->add_meta_data('payment_method', $this->id);
    577598                $order->save();
    578599
     
    722743        public function process_bread_classic_checkout($order_id) {
    723744            try {
    724                 if (!$this->bread_finance_utilities) {
    725                     $this->bread_finance_utilities = Bread_Finance_Utilities::instance();
    726                 }
    727745
    728746                if (!$this->bread_finance_plugin) {
     
    17501768
    17511769            // @formatter:off
    1752             if (!( array_key_exists('action', $_REQUEST) && in_array($_REQUEST['action'], [$this->bread_config->get('tenant_prefix') . '_get_options', 'bread_calculate_tax', 'bread_calculate_shipping']) )) {
     1770            if (!( array_key_exists('action', $_REQUEST) && in_array($_REQUEST['action'], ['admin_ajax_get_options', 'bread_calculate_tax', 'bread_calculate_shipping']) )) {
    17531771                return;
    17541772            }
     
    17661784                return $check;
    17671785            }
    1768 
     1786           
    17691787            // @formatter:off
    1770             if (!( array_key_exists('action', $_REQUEST) && in_array($_REQUEST['action'], [$this->bread_config->get('tenant_prefix') . '_get_options', 'bread_calculate_tax', 'bread_calculate_shipping']) )) {
     1788            if (!( array_key_exists('action', $_REQUEST) && in_array($_REQUEST['action'], ['admin_ajax_get_options', 'bread_calculate_tax', 'bread_calculate_shipping']) )) {
    17711789                return $check;
    17721790            }
     
    17961814            ob_start();
    17971815            $this->bread_finance_plugin = Bread_Finance_Plugin::instance();
    1798             $this->bread_finance_utilities = Bread_Finance_Utilities::instance();
    17991816            if (!$this->enabled) {
    18001817                return;
     
    20472064
    20482065                switch ($_POST['action']) {
    2049                     case $this->bread_config->get('tenant_prefix') . '_get_options':
     2066                    case 'admin_ajax_get_options':
    20502067                        wp_send_json_success($buttonHelper->get_bread_options());
    20512068                        break;
     
    22562273         */
    22572274        public function create_bread_cart_link($order) {
    2258             $this->bread_finance_utilities = Bread_Finance_Utilities::instance();
    22592275            $env = $this->load_bread_env();
    22602276            $bread_api = $this->load_bread_api_version();
  • bread-finance/trunk/classes/class-bread-finance-options-cart-checkout.php

    r2853897 r2995512  
    4747            }
    4848
    49             $this->updateCartQuantities($form);
     49            if ($form) {
     50                $this->updateCartQuantities($form);
     51            }
    5052
    5153            $options['items'] = $this->getItems();
     
    5355            $cartTotal = $this->bread_finance_utilities->priceToCents(WC()->cart->get_total('float'));
    5456            $options['customTotal'] = $cartTotal;
    55             $options['currency'] = get_woocommerce_currency();
     57            $active_currency = $gateway->bread_finance_utilities->get_active_currency();
     58            $options['currency'] = $active_currency;
    5659
    5760            return array_merge($options, $this->getShippingContact(), $this->getBillingContact(), $this->getDiscounts());
     
    6972                $options['customCSS'] = $customCSS;
    7073            }
    71 
    72             $this->updateCartQuantities($form);
     74            if ($form) {
     75                $this->updateCartQuantities($form);
     76            }
    7377
    7478            $enableHealthcareMode = $gateway->is_healthcare_mode();
  • bread-finance/trunk/classes/class-bread-finance-options-category.php

    r2984693 r2995512  
    4646            $items = $this->getItemsCategory($options, $config);
    4747            $options['items'] = $items;
    48             $options['currency'] = get_woocommerce_currency();
     48            $active_currency = $gateway->bread_finance_utilities->get_active_currency();
     49            $options['currency'] = $active_currency;
    4950
    5051            return array_merge($options, $this->getBillingContact(), $this->getShippingContact());
  • bread-finance/trunk/classes/class-bread-finance-options-checkout.php

    r2984693 r2995512  
    8686            $bread_config = $gateway->bread_config;
    8787            //Currency options
    88             $options['currency'] = get_woocommerce_currency();
     88            $active_currency = $gateway->bread_finance_utilities->get_active_currency();
     89            $options['currency'] = $active_currency;
    8990
    9091            return array_merge($options, $this->getBillingContact(), $this->getShippingContact(), $discountResponse, $taxResponse, $shippingResponse);
  • bread-finance/trunk/classes/class-bread-finance-options-product.php

    r2975391 r2995512  
    9898            'allowCheckout' => false
    9999        );
    100        
    101         $options['currency'] = get_woocommerce_currency();
     100        $active_currency = $this->bread_finance_utilities->get_active_currency();
     101        $options['currency'] = $active_currency;
    102102       
    103103        $productType = $config['productType'];
  • bread-finance/trunk/classes/class-bread-finance-utilities.php

    r2984693 r2995512  
    260260    }
    261261
    262     function getCurrencies() {
    263         $configCurrency = CURRENCY;
    264         $woocommerceCurrency = get_woocommerce_currency();
    265 
    266         if (!is_array($configCurrency)) {
    267             $configCurrency = [$configCurrency];
    268         }
    269    
    270         if (!is_array($woocommerceCurrency)) {
    271             $woocommerceCurrency = [$woocommerceCurrency];
    272         }
    273    
    274         $merged = array_unique(array_merge($configCurrency, $woocommerceCurrency));
    275    
    276         // Filter out empty strings
    277         $merged = array_filter($merged, function($value) {
    278             return $value !== "";
    279         });
    280    
    281         return $merged;
    282     }
    283 
    284     public function can_show_button() {
    285         $woocommerce_currency = get_woocommerce_currency();
    286         $bread_currency = $this->bread_config->get('currency', 'USD');
    287 
    288         return strcasecmp($woocommerce_currency, $bread_currency) == 0;
     262    /**
     263     * Get the active currency from third-party currency plugins.
     264     * Defaults to currency set in config.yaml or 'USD' if its not set
     265     */
     266    public function get_active_currency() {
     267        $bread_currency_instance = \Bread_Finance\Classes\Compat\Bread_Finance_Currency::instance();
     268        $bread_config_currency = $this->bread_config->get('currency', 'USD');
     269        return $bread_currency_instance->get_active_currency($bread_config_currency);
     270    }
     271
     272    public function tenant_currency_equals_woocommerce_currency() {
     273        $active_currency = $this->get_active_currency();
     274        $bread_config_currency = $this->bread_config->get('currency', 'USD');
     275
     276        return strcasecmp($active_currency, $bread_config_currency) == 0;
    289277    }
    290278}
  • bread-finance/trunk/classes/config/config.yml

    r2984696 r2995512  
    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.