Changeset 3047587
- Timestamp:
- 03/08/2024 05:05:02 AM (2 years ago)
- Location:
- bread-finance/trunk
- Files:
-
- 3 added
- 10 edited
-
README.md (modified) (2 diffs)
-
assets/js/v2/checkout-blocks.js (added)
-
assets/js/v2/main.js (modified) (4 diffs)
-
assets/js/v2/util.js (added)
-
bread-finance.php (modified) (3 diffs)
-
classes/class-bread-finance-ajax.php (modified) (1 diff)
-
classes/class-bread-finance-blocks.php (added)
-
classes/class-bread-finance-button.php (modified) (2 diffs)
-
classes/class-bread-finance-gateway.php (modified) (5 diffs)
-
classes/class-bread-finance-options-cart.php (modified) (1 diff)
-
classes/class-bread-finance-utilities.php (modified) (1 diff)
-
classes/config/config.yml (modified) (2 diffs)
-
composer.json (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
bread-finance/trunk/README.md
r3027202 r3047587 4 4 Requires at least: 4.9 5 5 Tested up to: 6.1.1 6 Stable tag: 3. 4.36 Stable tag: 3.5.0 7 7 Requires PHP: 5.6 8 8 WC requires at least: 3.0 … … 72 72 73 73 == Changelog == 74 = 3.5.0 75 * Current release 76 * Add support for Checkout Blocks and BOPIS 77 74 78 = 3.4.3 75 * Current release76 79 * Fix duplicate placements on PDP 77 80 -
bread-finance/trunk/assets/js/v2/main.js
r2997246 r3047587 723 723 724 724 if (isOrderPayForm) { 725 this.$form.on('submit', function() {725 self.$form.on('submit', function() { 726 726 if ($('#payment_method_' + breadController.local.gateway_token).is(':checked')) { 727 727 /* If the hidden input `bread_tx_token` exists, checkout has been completed and the form should be submitted */ … … 734 734 }); 735 735 } 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() { 737 737 /* If the hidden input `bread_tx_token` exists, checkout has been completed and the form should be submitted */ 738 738 let isCompletedBreadCheckout = self.$form.find('input[name="bread_tx_token"]').length > 0; … … 842 842 843 843 CheckoutHandler.prototype.checkoutWithOpts = function(opts) { 844 let self = this; 845 let bopisPayload = BreadUtil.createBopisPayload(opts); 846 844 847 let setup = { 845 848 integrationKey: breadController.local.integration_key, … … 900 903 currency: opts.currency, 901 904 items: items, 905 ...bopisPayload, 902 906 totalPrice: { 903 907 value: opts.customTotal, -
bread-finance/trunk/bread-finance.php
r3027202 r3047587 6 6 * Author: Bread Pay 7 7 * Author URI: https://payments.breadfinancial.com/ 8 * Version: 3. 4.38 * Version: 3.5.0 9 9 * Text Domain: bread-finance 10 10 * Domain Path: /i18n/languages/ … … 206 206 207 207 //Require minimums and constants 208 define('WC_' . $tenant . '_VERSION', '3. 4.3');208 define('WC_' . $tenant . '_VERSION', '3.5.0'); 209 209 define('WC_' . $tenant . '_MIN_PHP_VER', '5.6.0'); 210 210 define('WC_' . $tenant . '_MIN_WC_VER', '3.4.0'); … … 256 256 } 257 257 258 // Declare Blocks compatibility 259 add_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. 266 add_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 258 282 $instance_name = 'wc_' . $bread_config->get('gateway_id'); 259 283 -
bread-finance/trunk/classes/class-bread-finance-ajax.php
r2997246 r3047587 114 114 } catch (\Exception $e) { 115 115 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())); 117 117 } 118 118 } -
bread-finance/trunk/classes/class-bread-finance-button.php
r3027202 r3047587 66 66 */ 67 67 public function add_template_hooks() { 68 if (!$this->bread_finance_utilities->tenant_currency_equals_woocommerce_currency()) { 69 return; 70 } 68 71 $use_custom_size = $this->bread_finance_plugin->get_bread_gateway()->get_configuration_setting('button_size') === 'custom'; 69 72 $wcAjax = defined( 'WC_DOING_AJAX' ) ? $_GET['wc-ajax'] : false; … … 140 143 $bread_version = $gateway->get_configuration_setting('env_bread_api'); 141 144 $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)) { 143 147 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() { 144 152 print "<div id='{$this->tenant_prefix}_checkout_placeholder'></div>"; 145 153 print $this->render_embedded_container(); -
bread-finance/trunk/classes/class-bread-finance-gateway.php
r3027202 r3047587 183 183 )); 184 184 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 185 193 //Add JS Helper 186 194 wp_register_script( … … 202 210 'tenant_prefix' => $this->bread_config->get('tenant_prefix'), 203 211 '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') 205 215 ); 206 216 … … 217 227 218 228 wp_enqueue_script("{$this->bread_config->get('tenant_prefix')}-sdk"); 229 wp_enqueue_script("{$this->bread_config->get('tenant_prefix')}-util"); 219 230 wp_enqueue_script("{$this->bread_config->get('tenant_prefix')}-main"); 220 231 wp_enqueue_style("{$this->bread_config->get('tenant_prefix')}-main"); … … 320 331 */ 321 332 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)) { 323 334 $this->log( 324 335 __FUNCTION__, … … 568 579 #$this->bread_finance_api = Bread_Finance_V2_Api::instance(); 569 580 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 571 588 $order = wc_get_order($order_id); 572 589 -
bread-finance/trunk/classes/class-bread-finance-options-cart.php
r2862484 r3047587 267 267 } 268 268 } 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 269 306 return array( 270 307 'shippingContact' => array( -
bread-finance/trunk/classes/class-bread-finance-utilities.php
r2995512 r3047587 276 276 return strcasecmp($active_currency, $bread_config_currency) == 0; 277 277 } 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 278 327 } -
bread-finance/trunk/classes/config/config.yml
r2995512 r3047587 2 2 gateway_id: bread_finance 3 3 tenant_prefix: bread 4 tenant_sdk: BreadPayments 4 5 tenant_author_uri: https://payments.breadfinancial.com/ 5 6 tenant_docs_uri: https://www.breadpayments.com/documentation/ 6 tenant_sdk: BreadPayments7 7 plugin_description: Adds the Bread Pay Gateway to your WooCommerce site. 8 plugin_author: Bread Financial8 plugin_author: Bread Pay 9 9 checkout_host_sandbox: https://checkout-sandbox.getbread.com 10 10 checkout_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 11 sdk_core_sandbox: https://connect-preview.breadpayments.com/sdk.js 14 12 sdk_core: https://connect.breadpayments.com/sdk.js 15 13 platform_domain_api_sandbox: https://api-preview.platform.breadpayments.com/api 16 14 platform_domain_api: https://api.platform.breadpayments.com/api 15 bread_host: https://api.getbread.com 16 bread_host_sandbox: https://api-sandbox.getbread.com 17 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 -
bread-finance/trunk/composer.json
r2984693 r3047587 10 10 "phpunit/phpunit": ">=8.5.23", 11 11 "yoast/phpunit-polyfills": "^1.0", 12 "rector/rector": " ^0.18.5"12 "rector/rector": "0.18.4" 13 13 }, 14 14 "autoload": {
Note: See TracChangeset
for help on using the changeset viewer.