Plugin Directory

Changeset 2941041


Ignore:
Timestamp:
07/20/2023 11:27:09 PM (3 years ago)
Author:
breadintegrations
Message:

Version 3.3.5 changes

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

Legend:

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

    r2916822 r2941041  
    7272
    7373== Changelog ==
     74
     75= 3.3.5
     76* Current release
     77* Added unit tests
     78* Added Embedded Checkout feature to display on same page instead of modal
     79* Remove healthcare mode from Bread 2.0
     80
    7481= 3.3.4
    75 * Current release
    7682* Bread Admin carts support
    7783
  • bread-finance/trunk/assets/js/v2/main.js

    r2907371 r2941041  
    828828        bread_sdk.setup({
    829829            integrationKey: breadController.local.integration_key,
     830            containerID: "bread-checkout-embedded",
    830831            buyer: {
    831832                givenName: opts.billingContact.firstName,
     
    908909            }
    909910        }];
     911        bread_sdk.setEmbedded(opts.setEmbedded)
    910912        bread_sdk.__internal__.setAutoRender(false);
    911913        bread_sdk.registerPlacements(data);
    912914        bread_sdk.setInitMode('manual'); 
    913915        bread_sdk.init();
     916        if (opts.setEmbedded) {
     917            this.scroll_to_embedded_checkout();
     918        }
    914919    };
    915920
     
    10071012    };
    10081013
     1014    CheckoutHandler.prototype.scroll_to_embedded_checkout = function () {
     1015        var scrollElement = $('#bread-checkout-embedded');
     1016        if (scrollElement.length) {
     1017            $('html, body').animate({
     1018                scrollTop: (scrollElement.offset().top)
     1019            }, 1000);
     1020        }
     1021    };
     1022
    10091023
    10101024})(jQuery);
  • bread-finance/trunk/bread-finance.php

    r2916822 r2941041  
    66 * Author: Bread Pay
    77 * Author URI: https://payments.breadfinancial.com/
    8  * Version: 3.3.4
     8 * Version: 3.3.5
    99 * Text Domain: bread-finance
    1010 * Domain Path: /i18n/languages/
     
    2222
    2323//Require minimums and constants
    24 define('WC_BREAD_FINANCE_VERSION', '3.3.4');
     24define('WC_BREAD_FINANCE_VERSION', '3.3.5');
    2525define('WC_BREAD_FINANCE_MIN_PHP_VER', '5.6.0');
    2626define('WC_BREAD_FINANCE_MIN_WC_VER', '3.4.0');
  • bread-finance/trunk/classes/class-bread-finance-ajax.php

    r2897614 r2941041  
    195195        $bread_version  = $bread_finance_gateway->load_bread_env();
    196196
     197        $bread_checkout_options = Bread_Finance_Options_Checkout::instance();
     198
    197199        if($bread_version === 'bread_2') {
    198             self::bread_complete_checkout_bread_2($bread_finance_plugin, $bread_finance_gateway);
     200            self::bread_complete_checkout_bread_2($bread_finance_plugin, $bread_finance_gateway, $bread_checkout_options);
    199201        } else {
    200202            self::bread_complete_checkout_classic($bread_finance_plugin, $bread_finance_gateway);
     
    204206
    205207    public static function bread_complete_checkout_classic($bread_finance_plugin, $bread_finance_gateway) {
    206         $bread_finance_api = $bread_finance_gateway->load_bread_api_version();
    207         $bread_finance_utilities = Bread_Finance_Utilities::instance();
     208        $bread_finance_api = $bread_finance_gateway->bread_finance_api;
     209        $bread_finance_utilities = $bread_finance_gateway->bread_finance_utilities;
    208210        if (!$bread_finance_plugin->get_bread_gateway()->enabled) {
    209211            return;
     
    356358
    357359                /* Validate calculated totals */
    358                 $validateTotalsResponse = $bread_finance_utilities->validateCalculatedTotals($order, $transaction);
     360                $validateTotalsResponse = $bread_finance_utilities->validateCalculatedTotals($order, $transaction, $bread_finance_plugin);
    359361                if (is_wp_error($validateTotalsResponse)) {
    360362                    $message = esc_html__("ALERT: Transaction amount does not equal order total.", $bread_finance_plugin->get_text_domain());
     
    418420    }
    419421
    420     public static function bread_complete_checkout_bread_2($bread_finance_plugin, $bread_finance_gateway) {
    421         $bread_finance_api = Bread_Finance_V2_Api::instance();
    422         $bread_finance_utilities = Bread_Finance_Utilities::instance();
     422    public static function bread_complete_checkout_bread_2($bread_finance_plugin, $bread_finance_gateway, $bread_finance_checkout_options) {
     423        $bread_finance_api = $bread_finance_gateway->bread_finance_api;
     424        $bread_finance_utilities = $bread_finance_gateway->bread_finance_utilities;
    423425        if (!$bread_finance_plugin->get_bread_gateway()->enabled) {
    424426            return;
     
    446448               
    447449                //Get the list of cart items
    448                 $bread_finance_checkout_options = Bread_Finance_Options_Checkout::instance();
    449450                $checkout_options = $bread_finance_checkout_options->get_options();
    450451               
     
    559560                            $message = esc_html__("Error: " . $coupon_response->get_error_message(), $bread_finance_plugin->get_text_domain());
    560561                            $order->update_status("failed", $message);
    561                             wp_send_json_error(__($message, $bread_finance_plugin->get_text_domain()));
     562                            $bread_finance_utilities->json_error(__($message, $bread_finance_plugin->get_text_domain()));
    562563                        }
    563564                    }
     
    576577                $bread_finance_gateway->add_order_note($order, $transaction);
    577578                /* Validate calculated totals */
    578                 $validateTotalsResponse = $bread_finance_utilities->validateCalculatedTotals($order, $transaction);
     579                $validateTotalsResponse = $bread_finance_utilities->validateCalculatedTotals($order, $transaction, $bread_finance_plugin);
    579580                if (is_wp_error($validateTotalsResponse)) {
    580581                    $message = esc_html__("ALERT: Transaction amount does not equal order total.", $bread_finance_plugin->get_text_domain());
    581582                    $order->update_status("failed", $message);
    582                     wp_send_json_error(__("ALERT: Bread transaction total does not match order total.", $bread_finance_plugin->get_text_domain()));
     583                    $bread_finance_utilities->json_error(__("ALERT: Bread transaction total does not match order total.", $bread_finance_plugin->get_text_domain()));
    583584                }
    584585                /* Authorize Bread transaction */
     
    592593                    $bread_finance_gateway->log_Bread_issue("error", "[AjaxHandlers] Transaction failed to authorize.", $errorInfo);
    593594
    594                     wp_send_json_error(array(
     595                    $bread_finance_utilities->json_error(array(
    595596                        'message' => __("Transaction FAILED to authorize.", $bread_finance_plugin->get_text_domain()),
    596597                        'response' => $errorDescription,
     
    617618                }
    618619
    619                 wp_send_json_success(array(
     620                $bread_finance_utilities->json_success(array(
    620621                    'transaction' => $order->get_meta_data('bread_tx_status'),
    621622                    'order_id' => $order->get_id(),
     
    623624                ));
    624625            } else {
    625                 wp_send_json_error(array(
     626                $bread_finance_utilities->json_error(array(
    626627                    'message' => __('Transaction has already been recorded to order #', $bread_finance_plugin->get_text_domain()) . $transaction['merchantOrderId']
    627628                ));
    628629            }
    629630        } else {
    630             wp_send_json_error(array(
     631            $bread_finance_utilities->json_error(array(
    631632                'message' => $transaction['description']
    632633            ));
  • bread-finance/trunk/classes/class-bread-finance-button.php

    r2853897 r2941041  
    129129        //Checkout page
    130130        $bread_version = $gateway->get_configuration_setting('env_bread_api');
     131        $set_embedded = $this->bread_finance_plugin->get_bread_gateway()->get_configuration_setting('set_embedded') ?: false;
    131132        if($bread_version === 'bread_2' && $this->bread_finance_utilities->getPageType() === 'checkout') {
    132133            add_action( 'woocommerce_after_checkout_form', function() {
    133134                print('<div id="bread_checkout_placeholder"></div>');
    134             }, 10 );
     135                print($this->render_embedded_container());
     136            });
    135137        }
    136138    }
     
    237239    }
    238240
     241    public function render_embedded_container() {
     242        return '<div id="bread-checkout-embedded"</div>';
     243    }
     244
    239245}
    240246
  • bread-finance/trunk/classes/class-bread-finance-form-fields.php

    r2916822 r2941041  
    6262                'title' => esc_html__('Send Error Information to Bread', $text_domain),
    6363                'label' => esc_html__('Proactively send information about any Bread related issues.', $text_domain),
     64                'type' => 'checkbox',
     65                'default' => 'no',
     66            ),
     67            'set_embedded' => array(
     68                'title' => esc_html__('Embedded Checkout', $text_domain),
     69                'label' => esc_html__('The embedded functionality renders the bread checkout experience directly on the page instead of as a pop-up modal.', $text_domain),
    6470                'type' => 'checkbox',
    6571                'default' => 'no',
  • bread-finance/trunk/classes/class-bread-finance-gateway.php

    r2916822 r2941041  
    7474         */
    7575        public $bread_finance_api = false;
     76
     77        public $bread_finance_plugin = false;
    7678       
    7779        /**
     
    202204                        plugins_url('assets/js/v2/main.js', WC_BREAD_FINANCE_MAIN_FILE),
    203205                        array('bread-sdk', 'mwp'),
    204                         WC_BREAD_FINANCE_VERSION,
     206                        $this->is_production() ? WC_BREAD_FINANCE_VERSION: null,
    205207                        true
    206208                );
     
    213215                    'gateway_token' => self::WC_BREAD_GATEWAY_ID,
    214216                    'debug' => $this->bread_finance_utilities->toBool($this->get_configuration_setting('debug')),
    215                     'sentry_enabled' => $this->bread_finance_utilities->toBool($this->get_configuration_setting('sentry_enabled'))
     217                    'sentry_enabled' => $this->bread_finance_utilities->toBool($this->get_configuration_setting('sentry_enabled')),
     218                    'set_embedded' => $this->bread_finance_utilities->toBool($this->get_configuration_setting('set_embedded'))
    216219                );
    217220
     
    565568                    $this->bread_finance_utilities = Bread_Finance_Utilities::instance();
    566569                }
    567            
    568            
     570
     571                if (!$this->bread_finance_plugin) {
     572                    $this->bread_finance_plugin = Bread_Finance_Plugin::instance();
     573                }
     574
    569575                $this->log(
    570576                        __FUNCTION__,
     
    572578                );
    573579
    574                 $this->bread_finance_api = Bread_Finance_V2_Api::instance();
     580                $this->bread_finance_api = $this->load_bread_api_version("bread_2");
     581                #$this->bread_finance_api = Bread_Finance_V2_Api::instance();
    575582
    576583                $txToken = $_REQUEST['bread_tx_token'];
     
    591598
    592599                // Validate Transaction Amount is within 2 cents
    593                 $validate_totals_response = $this->bread_finance_utilities->validateCalculatedTotals($order, $transaction);
     600                $validate_totals_response = $this->bread_finance_utilities->validateCalculatedTotals($order, $transaction, $this->bread_finance_plugin);
    594601                $this->log(
    595602                        __FUNCTION__,
     
    738745                    $this->bread_finance_utilities = Bread_Finance_Utilities::instance();
    739746                }
     747
     748                if (!$this->bread_finance_plugin) {
     749                    $this->bread_finance_plugin = Bread_Finance_Plugin::instance();
     750                }
     751
    740752                $this->log(
    741753                        __FUNCTION__,
     
    767779                        "Order Total: " . $order->get_total() . " .. Trx Total: " . $transaction['adjustedTotal']
    768780                );
    769                 $validate_totals_response = $this->bread_finance_utilities->validateCalculatedTotals($order, $transaction);
     781                $validate_totals_response = $this->bread_finance_utilities->validateCalculatedTotals($order, $transaction, $this->bread_finance_plugin);
    770782                $this->log(
    771783                        __FUNCTION__,
     
    11451157        public function create_cart_opts($order) {
    11461158            $orderRef = strval($order->get_id());
    1147             $enableHealthcareMode = ( $this->get_option('healthcare_mode') === 'yes' ) ? true : false;
     1159            $enableHealthcareMode = $this->is_healthcare_mode();
    11481160
    11491161            $opts = array(
     
    14441456        public function is_healthcare_mode() {
    14451457            $settings = $this->get_option('advanced_settings');
    1446             return isset($settings[0]['healthcare_mode_enabled']) && $settings[0]['healthcare_mode_enabled'] === 'on';
     1458            $bread_version = $this->get_option('env_bread_api') ? $this->get_option('env_bread_api') : 'classic';
     1459            return $bread_version === 'classic' && isset($settings[0]['healthcare_mode_enabled']) && $settings[0]['healthcare_mode_enabled'] === 'on';
    14471460        }
    14481461
     
    15611574            </tr>
    15621575            <tr class="bread-advanced-settings">
    1563                 <th><?php echo esc_html__('Enable Healthcare Mode', self::TEXT_DOMAIN); ?></th>
     1576                <th><?php echo esc_html__('Enable Healthcare Mode (Classic)', self::TEXT_DOMAIN); ?></th>
    15641577                <td>
    15651578                    <?php
     
    18021815        public function process_bread_cart_order() {
    18031816            ob_start();
     1817            $this->bread_finance_plugin = Bread_Finance_Plugin::instance();
    18041818            $this->bread_finance_utilities = Bread_Finance_Utilities::instance();
    18051819            if (!$this->enabled) {
  • bread-finance/trunk/classes/class-bread-finance-options-checkout.php

    r2916822 r2941041  
    3737        $gateway = $this->bread_finance_plugin->get_bread_gateway();
    3838        $bread_version = $gateway->get_configuration_setting('env_bread_api');
     39        $source = isset($_REQUEST['source']) ? $_REQUEST['source'] : '';
    3940        if($bread_version === 'bread_2') {
    4041            $options = array(
    4142                'allowCheckout' => true,
    42                 'buttonLocation' => isset($_REQUEST['source']) ? $_REQUEST['source'] : '',
     43                'setEmbedded' => $this->bread_finance_utilities->toBool($gateway->get_configuration_setting('set_embedded')),
     44                'buttonLocation' => $source
    4345            );
    4446
     
    4951            //Get Discounts
    5052            $discountResponse = $this->getDiscounts();
    51             $discountTotal = $this->bread_finance_utilities->getDiscountTotal($discountResponse["discounts"] ?: array());
     53            $discountTotal = $this->bread_finance_utilities->getDiscountTotal($discountResponse["discounts"] ?? array());
    5254           
    5355            /*
     
    6769         
    6870            //Get items
     71
    6972            $options['items'] = $this->getItems();
    7073
     
    9295                'asLowAs' => $this->bread_finance_utilities->toBool($gateway->get_configuration_setting('button_as_low_as_checkout')),
    9396                'actAsLabel' => false,
    94                 'buttonLocation' => $_REQUEST['source'],
     97                'buttonLocation' => $source,
    9598                'showInWindow' => $gateway->default_show_in_window(),
    9699                'disableEditShipping' => true,
  • bread-finance/trunk/classes/class-bread-finance-utilities.php

    r2907371 r2941041  
    8080         * @since 3.3.0
    8181         */
    82         $floatPrice = floatval($price);
    83         $split_price = explode(wc_get_price_decimal_separator(), number_format($floatPrice, 2, '.', ''));
    84 
    85         $dollars = intval($split_price[0]) * 100;
    86         $cents = ( count($split_price) > 1 ) ? intval(str_pad($split_price[1], 2, '0')) : 0;
    87 
    88         return $dollars + $cents;
     82        try {
     83            $decimal_separator = wc_get_price_decimal_separator();
     84            if (!is_numeric(str_replace([',', $decimal_separator], ['', '.'], $price))) {
     85                throw new \InvalidArgumentException("Invalid price format");
     86            }
     87            $price = str_replace(',', '', $price);
     88            $floatPrice = floatval($price);
     89
     90            if ($floatPrice < 0) {
     91                throw new \InvalidArgumentException("Negative price value");
     92            }
     93
     94            $split_price = explode($decimal_separator, number_format($floatPrice, 2, '.', ''));
     95
     96            $dollars = intval($split_price[0]) * 100;
     97            $cents = ( count($split_price) > 1 ) ? intval(str_pad($split_price[1], 2, '0')) : 0;
     98
     99            return $dollars + $cents;
     100        } catch (\InvalidArgumentException $e) {
     101            throw $e;
     102        } catch (\Exception $e) {
     103            Bread_Finance_Logger::log( 'Error in priceToCents: ' . $e->getMessage() );
     104            return 0;
     105        }
    89106    }
    90107
     
    154171    }
    155172
    156     public function validateCalculatedTotals($order, $transaction) {
    157         $bread_finance_plugin = Bread_Finance_Plugin::instance();
     173    public function validateCalculatedTotals($order, $transaction, $bread_finance_plugin) {
    158174        $bread_api_version = $bread_finance_plugin->get_bread_gateway()->load_bread_env();
    159175        if($bread_api_version === 'bread_2') {
     
    162178                $message = esc_html__("Transaction amount does not equal order total.", $bread_finance_plugin->get_text_domain());
    163179                $order->update_status("failed", $message);
    164                 wp_send_json_error(__("Bread transaction total does not match order total.", $bread_finance_plugin->get_text_domain()));
     180               
     181                $this->json_error("Bread transaction total does not match order total.", $bread_finance_plugin->get_text_domain());
    165182            }
    166183
     
    178195                $message = esc_html__("Transaction amount does not equal order total.", $bread_finance_plugin->get_text_domain());
    179196                $order->update_status("failed", $message);
    180                 wp_send_json_error(__("Bread transaction total does not match order total.", $bread_finance_plugin->get_text_domain()));
     197                $this->json_error("Bread transaction total does not match order total.", $bread_finance_plugin->get_text_domain());
    181198            }
    182199
     
    189206            }
    190207        }
     208    }
     209
     210    /**
     211     * wp_send_json_error sends json response back and halts further execution.
     212     */
     213    public function json_error($message, $text_domain = "") {
     214        wp_send_json_error(__($message, $text_domain));
     215    }
     216
     217    /**
     218     * wp_send_json_success sends json response back and halts further execution.
     219     */
     220    public function json_success($message) {
     221        wp_send_json_success($message);
    191222    }
    192223
  • bread-finance/trunk/composer.json

    r2726687 r2941041  
    1 
    21{
    32    "name": "bread/woocommercegateway",
     
    54    "type": "project",
    65    "require": {
    7         "sentry/sdk": "2.0"
     6        "sentry/sdk": "2.0",
     7        "http-interop/http-factory-guzzle": "^1.2"
    88    },
    9     "autoload": {
    10         "psr-4": {
    11           "Bread_Finance\\Classes\\": "classes/"
    12         }
    13     }
     9    "autoload": {
     10        "psr-4": {
     11            "Bread_Finance\\Classes\\": "classes/"
     12        }
     13    },
     14    "config": {
     15        "platform": {
     16            "php": "7.3"
     17        },
     18        "allow-plugins": {
     19            "php-http/discovery": true
     20        }
     21    },
     22    "require-dev": {
     23        "phpunit/phpunit": ">=8.5.23",
     24        "yoast/phpunit-polyfills": "^1.0"
     25    }
    1426}
Note: See TracChangeset for help on using the changeset viewer.