Skip to content

Commit

Permalink
Merge branch 'develop' into improve-pmme-placement-shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
frosso authored Dec 20, 2024
2 parents 26c55cf + 779ef47 commit 4bf0445
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 108 deletions.
4 changes: 4 additions & 0 deletions changelog/add-woopay-klaviyo-newsletter-support
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: add

Add WooPay Klaviyo newsletter integration.
5 changes: 5 additions & 0 deletions changelog/fix-198-mccy-fedex-conversion
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: Fix FedEx insurance rates with different currencies.


Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Use translatable strings on the fee breakdown tooltip of the payment settings screen.
4 changes: 4 additions & 0 deletions changelog/fix-ece-button-for-price-including-tax
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Show express checkout for products w/o shipping but where tax is included into price.
20 changes: 16 additions & 4 deletions client/utils/account-fees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const formatMethodFeesTooltip = (
return (
<div className={ 'wcpay-fees-tooltip' }>
<div>
<div>Base fee</div>
<div>{ __( 'Base fee', 'woocommerce-payments' ) }</div>
<div>
{ getFeeDescriptionString(
accountFees.base,
Expand All @@ -153,7 +153,12 @@ export const formatMethodFeesTooltip = (
</div>
{ hasFees( accountFees.additional ) ? (
<div>
<div>International payment method fee</div>
<div>
{ __(
'International payment method fee',
'woocommerce-payments'
) }
</div>
<div>
{ getFeeDescriptionString(
accountFees.additional,
Expand All @@ -166,14 +171,21 @@ export const formatMethodFeesTooltip = (
) }
{ hasFees( accountFees.fx ) ? (
<div>
<div>Currency conversion fee</div>
<div>
{ __(
'Currency conversion fee',
'woocommerce-payments'
) }
</div>
<div>{ getFeeDescriptionString( accountFees.fx ) }</div>
</div>
) : (
''
) }
<div>
<div>Total per transaction</div>
<div>
{ __( 'Total per transaction', 'woocommerce-payments' ) }
</div>
<div className={ 'wcpay-fees-tooltip__bold' }>
{ getFeeDescriptionString( total ) }
</div>
Expand Down
9 changes: 9 additions & 0 deletions includes/compat/blocks/class-blocks-data-extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ private function get_available_blocks() {
$blocks[] = new \Mailchimp_Woocommerce_Newsletter_Blocks_Integration();
}

if ( class_exists( '\WCK\Blocks\CheckoutIntegration' ) ) {
// phpcs:ignore
/**
* @psalm-suppress UndefinedClass
* @phpstan-ignore-next-line
*/
$blocks[] = new \WCK\Blocks\CheckoutIntegration();
}

return $blocks;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public function should_show_express_checkout_button() {
return true;
}

// Non-shipping product and billing is calculated based on shopper billing addres. Excludes Pay for Order page.
// Non-shipping product and tax is calculated based on shopper billing address. Excludes Pay for Order page.
if (
// If the product doesn't needs shipping.
(
Expand All @@ -426,8 +426,10 @@ public function should_show_express_checkout_button() {
( ( $this->is_cart() || $this->is_checkout() ) && ! WC()->cart->needs_shipping() )
)

// ...and billing is calculated based on billing address.
&& wc_tax_enabled() && 'billing' === get_option( 'woocommerce_tax_based_on' )
// ...and tax is calculated based on billing address.
&& wc_tax_enabled()
&& 'billing' === get_option( 'woocommerce_tax_based_on' )
&& 'yes' !== get_option( 'woocommerce_prices_include_tax' )
) {
return false;
}
Expand Down
45 changes: 35 additions & 10 deletions includes/multi-currency/Compatibility/WooCommerceFedEx.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@
namespace WCPay\MultiCurrency\Compatibility;

use WCPay\MultiCurrency\MultiCurrency;
use WCPay\MultiCurrency\Utils;

/**
* Class that controls Multi Currency Compatibility with WooCommerce FedEx Plugin.
*/
class WooCommerceFedEx extends BaseCompatibility {

/**
* Calls to look for in the backtrace when determining whether
* to return store currency or skip converting product prices.
*/
private const WC_SHIPPING_FEDEX_CALLS = [
'WC_Shipping_Fedex->set_settings',
'WC_Shipping_Fedex->per_item_shipping',
'WC_Shipping_Fedex->box_shipping',
'WC_Shipping_Fedex->get_fedex_api_request',
'WC_Shipping_Fedex->get_fedex_requests',
'WC_Shipping_Fedex->process_result',
];

/**
* Init the class.
*
Expand All @@ -23,10 +35,31 @@ class WooCommerceFedEx extends BaseCompatibility {
public function init() {
// Add needed actions and filters if FedEx is active.
if ( class_exists( 'WC_Shipping_Fedex_Init' ) ) {
add_filter( MultiCurrency::FILTER_PREFIX . 'should_convert_product_price', [ $this, 'should_convert_product_price' ] );
add_filter( MultiCurrency::FILTER_PREFIX . 'should_return_store_currency', [ $this, 'should_return_store_currency' ] );
}
}

/**
* Checks to see if the product's price should be converted.
*
* @param bool $return Whether to convert the product's price or not. Default is true.
*
* @return bool True if it should be converted.
*/
public function should_convert_product_price( bool $return ): bool {
// If it's already false, return it.
if ( ! $return ) {
return $return;
}

if ( $this->utils->is_call_in_backtrace( self::WC_SHIPPING_FEDEX_CALLS ) ) {
return false;
}

return $return;
}

/**
* Determine whether to return the store currency or not.
*
Expand All @@ -40,15 +73,7 @@ public function should_return_store_currency( bool $return ): bool {
return $return;
}

$calls = [
'WC_Shipping_Fedex->set_settings',
'WC_Shipping_Fedex->per_item_shipping',
'WC_Shipping_Fedex->box_shipping',
'WC_Shipping_Fedex->get_fedex_api_request',
'WC_Shipping_Fedex->get_fedex_requests',
'WC_Shipping_Fedex->process_result',
];
if ( $this->utils->is_call_in_backtrace( $calls ) ) {
if ( $this->utils->is_call_in_backtrace( self::WC_SHIPPING_FEDEX_CALLS ) ) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php
/**
* Class WC_Payments_Express_Checkout_Button_Handler_Test
*
* @package WooCommerce\Payments\Tests
*/

use PHPUnit\Framework\MockObject\MockObject;

/**
* WC_Payments_Express_Checkout_Button_Handler unit tests.
*/
class WC_Payments_Express_Checkout_Button_Handler_Test extends WCPAY_UnitTestCase {
/**
* System under test.
*
* @var WC_Payments_Express_Checkout_Button_Handler
*/
private $system_under_test;

/**
* Mock WC_Payments_Account.
*
* @var WC_Payments_Account|MockObject
*/
private $mock_wcpay_account;

/**
* Mock WC_Payment_Gateway_WCPay.
*
* @var WC_Payment_Gateway_WCPay|MockObject
*/
private $mock_wcpay_gateway;

/**
* Mock Express Checkout Button Helper.
*
* @var WC_Payments_Express_Checkout_Button_Helper|MockObject
*/
private $mock_ece_button_helper;

/**
* Mock Express Checkout Ajax Handler.
*
* @var WC_Payments_Express_Checkout_Ajax_Handler|MockObject
*/
private $mock_express_checkout_ajax_handler;



/**
* Shipping zone.
*
* @var WC_Shipping_Zone
*/
private $zone;

/**
* Flat rate shipping method ID.
*
* @var int
*/
private $flat_rate_id;

/**
* Local pickup shipping method ID.
*
* @var int
*/
private $local_pickup_id;

/**
* Pre-test setup
*/
public function set_up() {
parent::set_up();

WC()->shipping()->unregister_shipping_methods();

$this->mock_wcpay_account = $this->createMock( WC_Payments_Account::class );
$this->mock_wcpay_gateway = $this->createMock( WC_Payment_Gateway_WCPay::class );
$this->mock_ece_button_helper = $this->createMock( WC_Payments_Express_Checkout_Button_Helper::class );
$this->mock_express_checkout_ajax_handler = $this->createMock( WC_Payments_Express_Checkout_Ajax_Handler::class );

$this->system_under_test = new WC_Payments_Express_Checkout_Button_Handler(
$this->mock_wcpay_account,
$this->mock_wcpay_gateway,
$this->mock_ece_button_helper,
$this->mock_express_checkout_ajax_handler
);

// Set up shipping zones and methods.
$this->zone = new WC_Shipping_Zone();
$this->zone->set_zone_name( 'Worldwide' );
$this->zone->set_zone_order( 1 );
$this->zone->save();

$flat_rate = $this->zone->add_shipping_method( 'flat_rate' );
$this->flat_rate_id = $flat_rate;

$local_pickup = $this->zone->add_shipping_method( 'local_pickup' );
$this->local_pickup_id = $local_pickup;
}

public function tear_down() {
parent::tear_down();

// Clean up shipping zones and methods.
$this->zone->delete();
}

public function test_filter_cart_needs_shipping_address_regular_products() {
$this->assertEquals(
true,
$this->system_under_test->filter_cart_needs_shipping_address( true ),
'Should not modify shipping address requirement for regular products'
);
}


public function test_filter_cart_needs_shipping_address_subscription_products() {
WC_Subscriptions_Cart::set_cart_contains_subscription( true );
$this->mock_ece_button_helper->method( 'is_checkout' )->willReturn( true );

$this->zone->delete_shipping_method( $this->flat_rate_id );
$this->zone->delete_shipping_method( $this->local_pickup_id );

$this->assertFalse(
$this->system_under_test->filter_cart_needs_shipping_address( true ),
'Should not require shipping address for subscription without shipping methods'
);

remove_filter( 'woocommerce_shipping_method_count', '__return_zero' );
WC_Subscriptions_Cart::set_cart_contains_subscription( false );
}
}
Loading

0 comments on commit 4bf0445

Please sign in to comment.