Merge pull request #2054 from woocommerce/PCP-2523-woo-payments-multi-currency-not-working-on-block-cart-checkout-pages

WooPayments multi-currency not working on Block Cart & Checkout pages (2523)
This commit is contained in:
Emili Castells 2024-02-29 11:54:10 +01:00 committed by GitHub
commit d0b0895a81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 18 deletions

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Blocks;
use WooCommerce\PayPalCommerce\Blocks\Endpoint\UpdateShippingEndpoint;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
return array(
'blocks.url' => static function ( ContainerInterface $container ): string {
@ -28,7 +29,9 @@ return array(
return new PayPalPaymentMethod(
$container->get( 'blocks.url' ),
$container->get( 'ppcp.asset-version' ),
$container->get( 'button.smart-button' ),
function () use ( $container ): SmartButtonInterface {
return $container->get( 'button.smart-button' );
},
$container->get( 'wcgateway.settings' ),
$container->get( 'wcgateway.settings.status' ),
$container->get( 'wcgateway.paypal-gateway' ),

View file

@ -41,7 +41,7 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
/**
* The smart button script loading handler.
*
* @var SmartButtonInterface
* @var SmartButtonInterface|callable
*/
private $smart_button;
@ -125,25 +125,25 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
/**
* Assets constructor.
*
* @param string $module_url The url of this module.
* @param string $version The assets version.
* @param SmartButtonInterface $smart_button The smart button script loading handler.
* @param Settings $plugin_settings The settings.
* @param SettingsStatus $settings_status The Settings status helper.
* @param PayPalGateway $gateway The WC gateway.
* @param bool $final_review_enabled Whether the final review is enabled.
* @param CancelView $cancellation_view The cancellation view.
* @param SessionHandler $session_handler The Session handler.
* @param bool $add_place_order_method Whether to create a non-express method with the standard "Place order" button.
* @param bool $use_place_order Whether to use the standard "Place order" button instead of PayPal buttons.
* @param string $place_order_button_text The text for the standard "Place order" button.
* @param string $place_order_button_description The text for additional "Place order" description.
* @param array $all_funding_sources All existing funding sources for PayPal buttons.
* @param string $module_url The url of this module.
* @param string $version The assets version.
* @param SmartButtonInterface|callable $smart_button The smart button script loading handler.
* @param Settings $plugin_settings The settings.
* @param SettingsStatus $settings_status The Settings status helper.
* @param PayPalGateway $gateway The WC gateway.
* @param bool $final_review_enabled Whether the final review is enabled.
* @param CancelView $cancellation_view The cancellation view.
* @param SessionHandler $session_handler The Session handler.
* @param bool $add_place_order_method Whether to create a non-express method with the standard "Place order" button.
* @param bool $use_place_order Whether to use the standard "Place order" button instead of PayPal buttons.
* @param string $place_order_button_text The text for the standard "Place order" button.
* @param string $place_order_button_description The text for additional "Place order" description.
* @param array $all_funding_sources All existing funding sources for PayPal buttons.
*/
public function __construct(
string $module_url,
string $version,
SmartButtonInterface $smart_button,
$smart_button,
Settings $plugin_settings,
SettingsStatus $settings_status,
PayPalGateway $gateway,
@ -209,7 +209,7 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
* {@inheritDoc}
*/
public function get_payment_method_data() {
$script_data = $this->smart_button->script_data();
$script_data = $this->smart_button()->script_data();
if ( isset( $script_data['continuation'] ) ) {
$url = add_query_arg( array( CancelController::NONCE => wp_create_nonce( CancelController::NONCE ) ), wc_get_checkout_url() );
@ -267,4 +267,21 @@ class PayPalPaymentMethod extends AbstractPaymentMethodType {
$screen = get_current_screen();
return $screen && $screen->is_block_editor();
}
/**
* The smart button.
*
* @return SmartButtonInterface
*/
private function smart_button(): SmartButtonInterface {
if ( $this->smart_button instanceof SmartButtonInterface ) {
return $this->smart_button;
}
if ( is_callable( $this->smart_button ) ) {
$this->smart_button = ( $this->smart_button )();
}
return $this->smart_button;
}
}