Changeset 2941041
- Timestamp:
- 07/20/2023 11:27:09 PM (3 years ago)
- Location:
- bread-finance/trunk
- Files:
-
- 15 added
- 10 edited
-
README.md (modified) (1 diff)
-
assets/js/v2/main.js (modified) (3 diffs)
-
bin (added)
-
bin/install-wp-tests.sh (added)
-
bin/phpunit.sh (added)
-
bin/run-tests.bash (added)
-
bread-finance.php (modified) (2 diffs)
-
classes/class-bread-finance-ajax.php (modified) (10 diffs)
-
classes/class-bread-finance-button.php (modified) (2 diffs)
-
classes/class-bread-finance-form-fields.php (modified) (1 diff)
-
classes/class-bread-finance-gateway.php (modified) (12 diffs)
-
classes/class-bread-finance-options-checkout.php (modified) (4 diffs)
-
classes/class-bread-finance-utilities.php (modified) (5 diffs)
-
composer.json (modified) (2 diffs)
-
package.json (added)
-
phpunit.xml.dist (added)
-
tests (added)
-
tests/phpunit (added)
-
tests/phpunit/bootstrap.php (added)
-
tests/phpunit/test-bread-finance-ajax.php (added)
-
tests/phpunit/test-bread-finance-gateway.php (added)
-
tests/phpunit/test-bread-finance-options-checkout.php (added)
-
tests/phpunit/test-bread-finance-utilities.php (added)
-
tests/phpunit/test-bread-finance.php (added)
-
tests/phpunit/wc-helpers.php (added)
Legend:
- Unmodified
- Added
- Removed
-
bread-finance/trunk/README.md
r2916822 r2941041 72 72 73 73 == 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 74 81 = 3.3.4 75 * Current release76 82 * Bread Admin carts support 77 83 -
bread-finance/trunk/assets/js/v2/main.js
r2907371 r2941041 828 828 bread_sdk.setup({ 829 829 integrationKey: breadController.local.integration_key, 830 containerID: "bread-checkout-embedded", 830 831 buyer: { 831 832 givenName: opts.billingContact.firstName, … … 908 909 } 909 910 }]; 911 bread_sdk.setEmbedded(opts.setEmbedded) 910 912 bread_sdk.__internal__.setAutoRender(false); 911 913 bread_sdk.registerPlacements(data); 912 914 bread_sdk.setInitMode('manual'); 913 915 bread_sdk.init(); 916 if (opts.setEmbedded) { 917 this.scroll_to_embedded_checkout(); 918 } 914 919 }; 915 920 … … 1007 1012 }; 1008 1013 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 1009 1023 1010 1024 })(jQuery); -
bread-finance/trunk/bread-finance.php
r2916822 r2941041 6 6 * Author: Bread Pay 7 7 * Author URI: https://payments.breadfinancial.com/ 8 * Version: 3.3. 48 * Version: 3.3.5 9 9 * Text Domain: bread-finance 10 10 * Domain Path: /i18n/languages/ … … 22 22 23 23 //Require minimums and constants 24 define('WC_BREAD_FINANCE_VERSION', '3.3. 4');24 define('WC_BREAD_FINANCE_VERSION', '3.3.5'); 25 25 define('WC_BREAD_FINANCE_MIN_PHP_VER', '5.6.0'); 26 26 define('WC_BREAD_FINANCE_MIN_WC_VER', '3.4.0'); -
bread-finance/trunk/classes/class-bread-finance-ajax.php
r2897614 r2941041 195 195 $bread_version = $bread_finance_gateway->load_bread_env(); 196 196 197 $bread_checkout_options = Bread_Finance_Options_Checkout::instance(); 198 197 199 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); 199 201 } else { 200 202 self::bread_complete_checkout_classic($bread_finance_plugin, $bread_finance_gateway); … … 204 206 205 207 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; 208 210 if (!$bread_finance_plugin->get_bread_gateway()->enabled) { 209 211 return; … … 356 358 357 359 /* Validate calculated totals */ 358 $validateTotalsResponse = $bread_finance_utilities->validateCalculatedTotals($order, $transaction );360 $validateTotalsResponse = $bread_finance_utilities->validateCalculatedTotals($order, $transaction, $bread_finance_plugin); 359 361 if (is_wp_error($validateTotalsResponse)) { 360 362 $message = esc_html__("ALERT: Transaction amount does not equal order total.", $bread_finance_plugin->get_text_domain()); … … 418 420 } 419 421 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; 423 425 if (!$bread_finance_plugin->get_bread_gateway()->enabled) { 424 426 return; … … 446 448 447 449 //Get the list of cart items 448 $bread_finance_checkout_options = Bread_Finance_Options_Checkout::instance();449 450 $checkout_options = $bread_finance_checkout_options->get_options(); 450 451 … … 559 560 $message = esc_html__("Error: " . $coupon_response->get_error_message(), $bread_finance_plugin->get_text_domain()); 560 561 $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())); 562 563 } 563 564 } … … 576 577 $bread_finance_gateway->add_order_note($order, $transaction); 577 578 /* Validate calculated totals */ 578 $validateTotalsResponse = $bread_finance_utilities->validateCalculatedTotals($order, $transaction );579 $validateTotalsResponse = $bread_finance_utilities->validateCalculatedTotals($order, $transaction, $bread_finance_plugin); 579 580 if (is_wp_error($validateTotalsResponse)) { 580 581 $message = esc_html__("ALERT: Transaction amount does not equal order total.", $bread_finance_plugin->get_text_domain()); 581 582 $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())); 583 584 } 584 585 /* Authorize Bread transaction */ … … 592 593 $bread_finance_gateway->log_Bread_issue("error", "[AjaxHandlers] Transaction failed to authorize.", $errorInfo); 593 594 594 wp_send_json_error(array(595 $bread_finance_utilities->json_error(array( 595 596 'message' => __("Transaction FAILED to authorize.", $bread_finance_plugin->get_text_domain()), 596 597 'response' => $errorDescription, … … 617 618 } 618 619 619 wp_send_json_success(array(620 $bread_finance_utilities->json_success(array( 620 621 'transaction' => $order->get_meta_data('bread_tx_status'), 621 622 'order_id' => $order->get_id(), … … 623 624 )); 624 625 } else { 625 wp_send_json_error(array(626 $bread_finance_utilities->json_error(array( 626 627 'message' => __('Transaction has already been recorded to order #', $bread_finance_plugin->get_text_domain()) . $transaction['merchantOrderId'] 627 628 )); 628 629 } 629 630 } else { 630 wp_send_json_error(array(631 $bread_finance_utilities->json_error(array( 631 632 'message' => $transaction['description'] 632 633 )); -
bread-finance/trunk/classes/class-bread-finance-button.php
r2853897 r2941041 129 129 //Checkout page 130 130 $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; 131 132 if($bread_version === 'bread_2' && $this->bread_finance_utilities->getPageType() === 'checkout') { 132 133 add_action( 'woocommerce_after_checkout_form', function() { 133 134 print('<div id="bread_checkout_placeholder"></div>'); 134 }, 10 ); 135 print($this->render_embedded_container()); 136 }); 135 137 } 136 138 } … … 237 239 } 238 240 241 public function render_embedded_container() { 242 return '<div id="bread-checkout-embedded"</div>'; 243 } 244 239 245 } 240 246 -
bread-finance/trunk/classes/class-bread-finance-form-fields.php
r2916822 r2941041 62 62 'title' => esc_html__('Send Error Information to Bread', $text_domain), 63 63 '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), 64 70 'type' => 'checkbox', 65 71 'default' => 'no', -
bread-finance/trunk/classes/class-bread-finance-gateway.php
r2916822 r2941041 74 74 */ 75 75 public $bread_finance_api = false; 76 77 public $bread_finance_plugin = false; 76 78 77 79 /** … … 202 204 plugins_url('assets/js/v2/main.js', WC_BREAD_FINANCE_MAIN_FILE), 203 205 array('bread-sdk', 'mwp'), 204 WC_BREAD_FINANCE_VERSION,206 $this->is_production() ? WC_BREAD_FINANCE_VERSION: null, 205 207 true 206 208 ); … … 213 215 'gateway_token' => self::WC_BREAD_GATEWAY_ID, 214 216 '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')) 216 219 ); 217 220 … … 565 568 $this->bread_finance_utilities = Bread_Finance_Utilities::instance(); 566 569 } 567 568 570 571 if (!$this->bread_finance_plugin) { 572 $this->bread_finance_plugin = Bread_Finance_Plugin::instance(); 573 } 574 569 575 $this->log( 570 576 __FUNCTION__, … … 572 578 ); 573 579 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(); 575 582 576 583 $txToken = $_REQUEST['bread_tx_token']; … … 591 598 592 599 // 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); 594 601 $this->log( 595 602 __FUNCTION__, … … 738 745 $this->bread_finance_utilities = Bread_Finance_Utilities::instance(); 739 746 } 747 748 if (!$this->bread_finance_plugin) { 749 $this->bread_finance_plugin = Bread_Finance_Plugin::instance(); 750 } 751 740 752 $this->log( 741 753 __FUNCTION__, … … 767 779 "Order Total: " . $order->get_total() . " .. Trx Total: " . $transaction['adjustedTotal'] 768 780 ); 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); 770 782 $this->log( 771 783 __FUNCTION__, … … 1145 1157 public function create_cart_opts($order) { 1146 1158 $orderRef = strval($order->get_id()); 1147 $enableHealthcareMode = ( $this->get_option('healthcare_mode') === 'yes' ) ? true : false;1159 $enableHealthcareMode = $this->is_healthcare_mode(); 1148 1160 1149 1161 $opts = array( … … 1444 1456 public function is_healthcare_mode() { 1445 1457 $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'; 1447 1460 } 1448 1461 … … 1561 1574 </tr> 1562 1575 <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> 1564 1577 <td> 1565 1578 <?php … … 1802 1815 public function process_bread_cart_order() { 1803 1816 ob_start(); 1817 $this->bread_finance_plugin = Bread_Finance_Plugin::instance(); 1804 1818 $this->bread_finance_utilities = Bread_Finance_Utilities::instance(); 1805 1819 if (!$this->enabled) { -
bread-finance/trunk/classes/class-bread-finance-options-checkout.php
r2916822 r2941041 37 37 $gateway = $this->bread_finance_plugin->get_bread_gateway(); 38 38 $bread_version = $gateway->get_configuration_setting('env_bread_api'); 39 $source = isset($_REQUEST['source']) ? $_REQUEST['source'] : ''; 39 40 if($bread_version === 'bread_2') { 40 41 $options = array( 41 42 '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 43 45 ); 44 46 … … 49 51 //Get Discounts 50 52 $discountResponse = $this->getDiscounts(); 51 $discountTotal = $this->bread_finance_utilities->getDiscountTotal($discountResponse["discounts"] ? :array());53 $discountTotal = $this->bread_finance_utilities->getDiscountTotal($discountResponse["discounts"] ?? array()); 52 54 53 55 /* … … 67 69 68 70 //Get items 71 69 72 $options['items'] = $this->getItems(); 70 73 … … 92 95 'asLowAs' => $this->bread_finance_utilities->toBool($gateway->get_configuration_setting('button_as_low_as_checkout')), 93 96 'actAsLabel' => false, 94 'buttonLocation' => $ _REQUEST['source'],97 'buttonLocation' => $source, 95 98 'showInWindow' => $gateway->default_show_in_window(), 96 99 'disableEditShipping' => true, -
bread-finance/trunk/classes/class-bread-finance-utilities.php
r2907371 r2941041 80 80 * @since 3.3.0 81 81 */ 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 } 89 106 } 90 107 … … 154 171 } 155 172 156 public function validateCalculatedTotals($order, $transaction) { 157 $bread_finance_plugin = Bread_Finance_Plugin::instance(); 173 public function validateCalculatedTotals($order, $transaction, $bread_finance_plugin) { 158 174 $bread_api_version = $bread_finance_plugin->get_bread_gateway()->load_bread_env(); 159 175 if($bread_api_version === 'bread_2') { … … 162 178 $message = esc_html__("Transaction amount does not equal order total.", $bread_finance_plugin->get_text_domain()); 163 179 $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()); 165 182 } 166 183 … … 178 195 $message = esc_html__("Transaction amount does not equal order total.", $bread_finance_plugin->get_text_domain()); 179 196 $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()); 181 198 } 182 199 … … 189 206 } 190 207 } 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); 191 222 } 192 223 -
bread-finance/trunk/composer.json
r2726687 r2941041 1 2 1 { 3 2 "name": "bread/woocommercegateway", … … 5 4 "type": "project", 6 5 "require": { 7 "sentry/sdk": "2.0" 6 "sentry/sdk": "2.0", 7 "http-interop/http-factory-guzzle": "^1.2" 8 8 }, 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 } 14 26 }
Note: See TracChangeset
for help on using the changeset viewer.