Changeset 2995512
- Timestamp:
- 11/14/2023 04:27:28 AM (2 years ago)
- Location:
- bread-finance/trunk
- Files:
-
- 5 added
- 2 deleted
- 11 edited
-
README.md (modified) (2 diffs)
-
assets/image/rbc_payplan_logo.png (deleted)
-
bread-finance.php (modified) (4 diffs)
-
classes/class-bread-finance-ajax.php (modified) (3 diffs)
-
classes/class-bread-finance-button.php (modified) (4 diffs)
-
classes/class-bread-finance-gateway.php (modified) (14 diffs)
-
classes/class-bread-finance-options-cart-checkout.php (modified) (3 diffs)
-
classes/class-bread-finance-options-category.php (modified) (1 diff)
-
classes/class-bread-finance-options-checkout.php (modified) (1 diff)
-
classes/class-bread-finance-options-product.php (modified) (1 diff)
-
classes/class-bread-finance-utilities.php (modified) (1 diff)
-
classes/compat (added)
-
classes/compat/class-bread-finance-currency-abstract.php (added)
-
classes/compat/class-bread-finance-currency-pboc.php (added)
-
classes/compat/class-bread-finance-currency-woocs.php (added)
-
classes/compat/class-bread-finance-currency.php (added)
-
classes/config/config.yml (modified) (2 diffs)
-
classes/config/config.yml.dist (deleted)
Legend:
- Unmodified
- Added
- Removed
-
bread-finance/trunk/README.md
r2984693 r2995512 4 4 Requires at least: 4.9 5 5 Tested up to: 6.1.1 6 Stable tag: 3.4. 06 Stable tag: 3.4.1 7 7 Requires PHP: 5.6 8 8 WC requires at least: 3.0 … … 72 72 73 73 == Changelog == 74 = 3.4.1 75 * Current release 76 * Compatiblity with WooCommerce Price Based on Country 74 77 75 78 = 3.4.0 76 * Current release77 79 * Fix for variant pricing changes 78 80 * Fix for modal not showing up when cart is updated -
bread-finance/trunk/bread-finance.php
r2984693 r2995512 4 4 * Plugin Name: Bread Pay 5 5 * Description: Adds the Bread Pay Gateway to your WooCommerce site. 6 * Author: Bread Pay6 * Author: Bread Financial 7 7 * Author URI: https://payments.breadfinancial.com/ 8 * Version: 3.4. 09 * Text Domain: bread -finance8 * Version: 3.4.1 9 * Text Domain: bread_finance 10 10 * Domain Path: /i18n/languages/ 11 11 * WC requires at least: 3.0.0 … … 22 22 } 23 23 24 if (!class_exists(\Bread_Finance\ classes\Spyc::class)) {24 if (!class_exists(\Bread_Finance\Classes\Spyc::class)) { 25 25 # Including this first so it can be used in Config.php 26 26 require_once untrailingslashit(plugin_dir_path(__FILE__)) . '/classes/Spyc.php'; … … 206 206 207 207 //Require minimums and constants 208 define('WC_' . $tenant . '_VERSION', '3.4. 0');208 define('WC_' . $tenant . '_VERSION', '3.4.1'); 209 209 define('WC_' . $tenant . '_MIN_PHP_VER', '5.6.0'); 210 210 define('WC_' . $tenant . '_MIN_WC_VER', '3.4.0'); … … 212 212 define('WC_' . $tenant . '_PLUGIN_PATH', $this->plugin_path); 213 213 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'; 214 220 215 221 //Classes -
bread-finance/trunk/classes/class-bread-finance-ajax.php
r2984693 r2995512 3 3 namespace Bread_Finance\Classes; 4 4 5 use Bread_Finance\Classes\Config\Bread_Config;6 5 7 6 if (!defined('ABSPATH')) { … … 479 478 $order->add_meta_data('bread_tx_id', $tx_id); 480 479 $order->add_meta_data('bread_api_version', $bread_finance_gateway->load_bread_env()); 480 $order->add_meta_data('payment_method', $bread_finance_gateway->id); 481 481 /* Set billing address */ 482 482 $order->set_address(array( … … 586 586 } 587 587 /* 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); 589 590 if (strtoupper($transaction['status']) !== 'AUTHORIZED') { 590 591 $errorDescription = $transaction["description"]; -
bread-finance/trunk/classes/class-bread-finance-button.php
r2984693 r2995512 59 59 $this->tenant_prefix = $this->bread_config->get('tenant_prefix'); 60 60 } 61 add_action('wp',array($this, 'add_template_hooks'));62 61 } 63 62 … … 132 131 if ($button_location_cart) { 133 132 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); 135 134 }); 136 135 } … … 142 141 if($bread_version === 'bread_2' && $this->bread_finance_utilities->getPageType() === 'checkout') { 143 142 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(); 146 145 }); 147 146 } … … 261 260 262 261 } 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 48 48 public function __construct() { 49 49 $this->bread_config = \Bread_Finance\Classes\Config\Bread_Config::instance(); 50 $this->bread_finance_utilities = \Bread_Finance\Classes\Bread_Finance_Utilities::instance(); 50 51 $this->id = $this->bread_config->get('gateway_id'); 51 52 $this->plugin_version = constant('WC_' . strtoupper($this->bread_config->get('gateway_id')) . '_VERSION'); … … 70 71 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'validate_product_id_list')); 71 72 72 //Valid ityAPI keys73 //Validate API keys 73 74 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'validate_api_keys'), 11); 74 75 75 //Add76 76 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')); 78 81 add_action('woocommerce_after_checkout_validation', array($this, 'prevent_order_creation_during_validation'), 10, 2); 79 82 add_action('before_woocommerce_init', array($this, 'anonymize_tax_and_shipping_ajax')); … … 98 101 add_action('woocommerce_order_action_create_bread_cart_link', array($this, 'create_bread_cart_link')); 99 102 add_action('woocommerce_order_action_email_bread_cart_link', array($this, 'email_bread_cart_link')); 100 103 101 104 add_filter( 'query_vars', array($this, 'custom_bread_vars')); 102 103 105 //add_filter('all_plugins', array($this, 'update_plugin_meta')); 104 106 … … 115 117 } 116 118 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 117 139 public function enqueue_scripts() { 118 if (!$this->bread_finance_utilities) {119 $this->bread_finance_utilities = Bread_Finance_Utilities::instance();120 }121 140 122 141 if ('yes' !== $this->enabled) { … … 124 143 } 125 144 126 if (!$this->bread_finance_utilities-> can_show_button()) {145 if (!$this->bread_finance_utilities->tenant_currency_equals_woocommerce_currency()) { 127 146 return; 128 147 } … … 402 421 public function settle_order($order_id) { 403 422 $order = wc_get_order( $order_id ); 423 $gateway_id = $this->bread_config->get('gateway_id'); 424 $payment_method = $order->get_payment_method(); 404 425 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 ); 407 430 return; 408 431 } … … 545 568 public function process_bread_2_checkout($order_id) { 546 569 try { 547 if (!$this->bread_finance_utilities) {548 $this->bread_finance_utilities = Bread_Finance_Utilities::instance();549 }550 570 551 571 if (!$this->bread_finance_plugin) { … … 575 595 $order->add_meta_data('bread_tx_id', $transaction['id']); 576 596 $order->add_meta_data('bread_api_version', 'bread_2'); 597 $order->add_meta_data('payment_method', $this->id); 577 598 $order->save(); 578 599 … … 722 743 public function process_bread_classic_checkout($order_id) { 723 744 try { 724 if (!$this->bread_finance_utilities) {725 $this->bread_finance_utilities = Bread_Finance_Utilities::instance();726 }727 745 728 746 if (!$this->bread_finance_plugin) { … … 1750 1768 1751 1769 // @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']) )) { 1753 1771 return; 1754 1772 } … … 1766 1784 return $check; 1767 1785 } 1768 1786 1769 1787 // @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']) )) { 1771 1789 return $check; 1772 1790 } … … 1796 1814 ob_start(); 1797 1815 $this->bread_finance_plugin = Bread_Finance_Plugin::instance(); 1798 $this->bread_finance_utilities = Bread_Finance_Utilities::instance();1799 1816 if (!$this->enabled) { 1800 1817 return; … … 2047 2064 2048 2065 switch ($_POST['action']) { 2049 case $this->bread_config->get('tenant_prefix') . '_get_options':2066 case 'admin_ajax_get_options': 2050 2067 wp_send_json_success($buttonHelper->get_bread_options()); 2051 2068 break; … … 2256 2273 */ 2257 2274 public function create_bread_cart_link($order) { 2258 $this->bread_finance_utilities = Bread_Finance_Utilities::instance();2259 2275 $env = $this->load_bread_env(); 2260 2276 $bread_api = $this->load_bread_api_version(); -
bread-finance/trunk/classes/class-bread-finance-options-cart-checkout.php
r2853897 r2995512 47 47 } 48 48 49 $this->updateCartQuantities($form); 49 if ($form) { 50 $this->updateCartQuantities($form); 51 } 50 52 51 53 $options['items'] = $this->getItems(); … … 53 55 $cartTotal = $this->bread_finance_utilities->priceToCents(WC()->cart->get_total('float')); 54 56 $options['customTotal'] = $cartTotal; 55 $options['currency'] = get_woocommerce_currency(); 57 $active_currency = $gateway->bread_finance_utilities->get_active_currency(); 58 $options['currency'] = $active_currency; 56 59 57 60 return array_merge($options, $this->getShippingContact(), $this->getBillingContact(), $this->getDiscounts()); … … 69 72 $options['customCSS'] = $customCSS; 70 73 } 71 72 $this->updateCartQuantities($form); 74 if ($form) { 75 $this->updateCartQuantities($form); 76 } 73 77 74 78 $enableHealthcareMode = $gateway->is_healthcare_mode(); -
bread-finance/trunk/classes/class-bread-finance-options-category.php
r2984693 r2995512 46 46 $items = $this->getItemsCategory($options, $config); 47 47 $options['items'] = $items; 48 $options['currency'] = get_woocommerce_currency(); 48 $active_currency = $gateway->bread_finance_utilities->get_active_currency(); 49 $options['currency'] = $active_currency; 49 50 50 51 return array_merge($options, $this->getBillingContact(), $this->getShippingContact()); -
bread-finance/trunk/classes/class-bread-finance-options-checkout.php
r2984693 r2995512 86 86 $bread_config = $gateway->bread_config; 87 87 //Currency options 88 $options['currency'] = get_woocommerce_currency(); 88 $active_currency = $gateway->bread_finance_utilities->get_active_currency(); 89 $options['currency'] = $active_currency; 89 90 90 91 return array_merge($options, $this->getBillingContact(), $this->getShippingContact(), $discountResponse, $taxResponse, $shippingResponse); -
bread-finance/trunk/classes/class-bread-finance-options-product.php
r2975391 r2995512 98 98 'allowCheckout' => false 99 99 ); 100 101 $options['currency'] = get_woocommerce_currency();100 $active_currency = $this->bread_finance_utilities->get_active_currency(); 101 $options['currency'] = $active_currency; 102 102 103 103 $productType = $config['productType']; -
bread-finance/trunk/classes/class-bread-finance-utilities.php
r2984693 r2995512 260 260 } 261 261 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; 289 277 } 290 278 } -
bread-finance/trunk/classes/config/config.yml
r2984696 r2995512 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.