Skip to content

Commit

Permalink
Merge branch 'develop' into fix/6782-support-phone-dev-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jessy-p authored Dec 16, 2023
2 parents 37ee776 + cc42940 commit f623948
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 24 deletions.
5 changes: 5 additions & 0 deletions changelog/dev-fix-e2e-tests-on-wc-7-7
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: Fix e2e tests on WC 7.7.


4 changes: 4 additions & 0 deletions changelog/fix-apple-pay-including-tax
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fixed Apple Pay Double Tax Calculation Issue
30 changes: 15 additions & 15 deletions includes/class-wc-payments-payment-request-button-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ public function get_button_height() {
*/
public function get_product_price( $product ) {
// If prices should include tax, using tax inclusive price.
if ( ! $this->prices_exclude_tax() ) {
if ( $this->cart_prices_include_tax() ) {
$base_price = wc_get_price_including_tax( $product );
} else {
$base_price = $product->get_price();
$base_price = wc_get_price_excluding_tax( $product );
}

// Add subscription sign-up fees to product price.
Expand Down Expand Up @@ -292,7 +292,7 @@ public function get_product_data() {
];

$total_tax = 0;
foreach ( $this->get_taxes( $product, $price ) as $tax ) {
foreach ( $this->get_taxes_like_cart( $product, $price ) as $tax ) {
$total_tax += $tax;

$items[] = [
Expand Down Expand Up @@ -1094,7 +1094,7 @@ public function ajax_get_selected_product_data() {
];

$total_tax = 0;
foreach ( $this->get_taxes( $product, $price ) as $tax ) {
foreach ( $this->get_taxes_like_cart( $product, $price ) as $tax ) {
$total_tax += $tax;

$items[] = [
Expand Down Expand Up @@ -1511,13 +1511,13 @@ protected function calculate_shipping( $address = [] ) {
}

/**
* Whether tax should be displayed on seperate line.
* returns true if tax is enabled & display of tax in checkout is set to exclusive.
* Whether tax should be displayed on separate line in cart.
* returns true if tax is disabled or display of tax in checkout is set to inclusive.
*
* @return boolean
*/
private function prices_exclude_tax() {
return wc_tax_enabled() && 'incl' !== get_option( 'woocommerce_tax_display_cart' );
private function cart_prices_include_tax() {
return ! wc_tax_enabled() || 'incl' === get_option( 'woocommerce_tax_display_cart' );
}

/**
Expand Down Expand Up @@ -1549,7 +1549,7 @@ protected function build_shipping_methods( $shipping_methods ) {
*
* @param boolean $itemized_display_items Indicates whether to show subtotals or itemized views.
*/
protected function build_display_items( $itemized_display_items = false ) {
public function build_display_items( $itemized_display_items = false ) {
if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
define( 'WOOCOMMERCE_CART', true );
}
Expand All @@ -1568,7 +1568,7 @@ protected function build_display_items( $itemized_display_items = false ) {

$product_name = $cart_item['data']->get_name();

$item_tax = $this->prices_exclude_tax() ? 0 : ( $cart_item['line_subtotal_tax'] ?? 0 );
$item_tax = $this->cart_prices_include_tax() ? ( $cart_item['line_subtotal_tax'] ?? 0 ) : 0;

$item = [
'label' => $product_name . $quantity_label,
Expand All @@ -1595,15 +1595,15 @@ protected function build_display_items( $itemized_display_items = false ) {
$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
$order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( '' );

if ( $this->prices_exclude_tax() ) {
if ( ! $this->cart_prices_include_tax() ) {
$items[] = [
'label' => esc_html( __( 'Tax', 'woocommerce-payments' ) ),
'amount' => WC_Payments_Utils::prepare_amount( $tax, $currency ),
];
}

if ( WC()->cart->needs_shipping() ) {
$shipping_tax = $this->prices_exclude_tax() ? 0 : WC()->cart->shipping_tax_total;
$shipping_tax = $this->cart_prices_include_tax() ? WC()->cart->shipping_tax_total : 0;
$items[] = [
'label' => esc_html( __( 'Shipping', 'woocommerce-payments' ) ),
'amount' => WC_Payments_Utils::prepare_amount( $shipping + $shipping_tax, $currency ),
Expand Down Expand Up @@ -1708,14 +1708,14 @@ public function get_login_confirmation_settings() {
}

/**
* Calculates taxes, based on a product and a particular price.
* Calculates taxes as displayed on cart, based on a product and a particular price.
*
* @param WC_Product $product The product, for retrieval of tax classes.
* @param float $price The price, which to calculate taxes for.
* @return array An array of final taxes.
*/
private function get_taxes( $product, $price ) {
if ( ! wc_tax_enabled() || ! $this->prices_exclude_tax() ) {
private function get_taxes_like_cart( $product, $price ) {
if ( ! wc_tax_enabled() || $this->cart_prices_include_tax() ) {
// Only proceed when taxes are enabled, but not included.
return [];
}
Expand Down
14 changes: 7 additions & 7 deletions includes/class-wc-payments-woopay-button-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ protected function build_display_items( $itemized_display_items = false ) {

$product_name = $cart_item['data']->get_name();

$item_tax = $this->prices_exclude_tax() ? 0 : ( $cart_item['line_subtotal_tax'] ?? 0 );
$item_tax = $this->cart_prices_include_tax() ? ( $cart_item['line_subtotal_tax'] ?? 0 ) : 0;

$item = [
'label' => $product_name . $quantity_label,
Expand All @@ -336,15 +336,15 @@ protected function build_display_items( $itemized_display_items = false ) {
$items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts;
$order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( '' );

if ( $this->prices_exclude_tax() ) {
if ( ! $this->cart_prices_include_tax() ) {
$items[] = [
'label' => esc_html( __( 'Tax', 'woocommerce-payments' ) ),
'amount' => WC_Payments_Utils::prepare_amount( $tax, $currency ),
];
}

if ( WC()->cart->needs_shipping() ) {
$shipping_tax = $this->prices_exclude_tax() ? 0 : WC()->cart->shipping_tax_total;
$shipping_tax = $this->cart_prices_include_tax() ? WC()->cart->shipping_tax_total : 0;
$items[] = [
'label' => esc_html( __( 'Shipping', 'woocommerce-payments' ) ),
'amount' => WC_Payments_Utils::prepare_amount( $shipping + $shipping_tax, $currency ),
Expand Down Expand Up @@ -383,13 +383,13 @@ protected function build_display_items( $itemized_display_items = false ) {
}

/**
* Whether tax should be displayed on seperate line.
* returns true if tax is enabled & display of tax in checkout is set to exclusive.
* Whether tax should be displayed on separate line in cart.
* returns true if tax is disabled or display of tax in checkout is set to inclusive.
*
* @return boolean
*/
private function prices_exclude_tax() {
return wc_tax_enabled() && 'incl' !== get_option( 'woocommerce_tax_display_cart' );
private function cart_prices_include_tax() {
return ! wc_tax_enabled() || 'incl' === get_option( 'woocommerce_tax_display_cart' );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe( 'Shopper Multi-Currency widget', () => {
await setupTest();
await page.waitForSelector( '.widget select[name=currency]', {
visible: true,
timeout: 5000,
} );
await page.select( '.widget select[name=currency]', 'EUR' );
await expect( page.url() ).toContain(
Expand All @@ -105,6 +106,7 @@ describe( 'Shopper Multi-Currency widget', () => {
);
// Change it back to USD for the other tests.
await page.select( '.widget select[name=currency]', 'USD' );
await page.reload( { waitUntil: 'networkidle0' } );
} );
}
);
Expand Down Expand Up @@ -178,5 +180,6 @@ describe( 'Shopper Multi-Currency widget', () => {
'.widget select[name=currency]'
);
expect( currencySwitcher ).toBeNull();
await merchant.logout();
} );
} );
8 changes: 6 additions & 2 deletions tests/e2e/utils/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,11 @@ export const merchantWCP = {
searchInput.type( 'switcher', { delay: 20 } );

await page.waitForSelector(
'button.components-button[role="option"]'
'button.components-button[role="option"]',
{
visible: true,
timeout: 5000,
}
);
await page.click( 'button.components-button[role="option"]' );
await page.waitFor( 2000 );
Expand All @@ -699,7 +703,7 @@ export const merchantWCP = {
await merchant.openNewOrder();
await page.click( 'button.add-line-item' );
await page.click( 'button.add-order-item' );
await page.click( 'select.wc-product-search' );
await page.click( 'select[name="item_id"]' );
await page.type(
'.select2-search--dropdown > input',
config.get( 'products.simple.name' ),
Expand Down
Loading

0 comments on commit f623948

Please sign in to comment.