🔀 Merge branch 'trunk'

Resolve merge conflict due to new JS code format
This commit is contained in:
Philipp Stracker 2024-07-15 11:16:47 +02:00
commit 1eca3b09d7
No known key found for this signature in database
181 changed files with 25000 additions and 12119 deletions

View file

@ -32,6 +32,7 @@ use WooCommerce\PayPalCommerce\Button\Endpoint\SimulateCartEndpoint;
use WooCommerce\PayPalCommerce\Button\Endpoint\StartPayPalVaultingEndpoint;
use WooCommerce\PayPalCommerce\Button\Endpoint\ValidateCheckoutEndpoint;
use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
use WooCommerce\PayPalCommerce\Button\Helper\DisabledFundingSources;
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\PayLaterBlock\PayLaterBlockModule;
@ -225,6 +226,13 @@ class SmartButton implements SmartButtonInterface {
*/
private $should_handle_shipping_in_paypal;
/**
* List of funding sources to be disabled.
*
* @var DisabledFundingSources
*/
private $disabled_funding_sources;
/**
* SmartButton constructor.
*
@ -251,6 +259,7 @@ class SmartButton implements SmartButtonInterface {
* @param PaymentTokensEndpoint $payment_tokens_endpoint Payment tokens endpoint.
* @param LoggerInterface $logger The logger.
* @param bool $should_handle_shipping_in_paypal Whether the shipping should be handled in PayPal.
* @param DisabledFundingSources $disabled_funding_sources List of funding sources to be disabled.
*/
public function __construct(
string $module_url,
@ -275,7 +284,8 @@ class SmartButton implements SmartButtonInterface {
bool $vault_v3_enabled,
PaymentTokensEndpoint $payment_tokens_endpoint,
LoggerInterface $logger,
bool $should_handle_shipping_in_paypal
bool $should_handle_shipping_in_paypal,
DisabledFundingSources $disabled_funding_sources
) {
$this->module_url = $module_url;
@ -301,6 +311,7 @@ class SmartButton implements SmartButtonInterface {
$this->logger = $logger;
$this->payment_tokens_endpoint = $payment_tokens_endpoint;
$this->should_handle_shipping_in_paypal = $should_handle_shipping_in_paypal;
$this->disabled_funding_sources = $disabled_funding_sources;
}
/**
@ -971,7 +982,6 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
*/
public function dcc_renderer() {
$id = 'ppcp-hosted-fields';
if ( ! $this->can_render_dcc() ) {
return;
}
@ -984,12 +994,11 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
// phpcs:enable WordPress.WP.I18n.TextDomainMismatch
printf(
'<div id="%1$s" style="display:none;">
<button type="submit" class="button alt ppcp-dcc-order-button" style="display: none;">%2$s</button>
'<div id="ppcp-hosted-fields" style="display:none;">
<button id="place_order" type="submit" class="button alt ppcp-dcc-order-button wp-element-button" style="display: none;">%1$s</button>
</div>
<div id="payments-sdk__contingency-lightbox"></div>
<style id="ppcp-hide-dcc">.payment_method_ppcp-credit-card-gateway {display:none;}</style>',
esc_attr( $id ),
esc_html( $label )
);
}
@ -1402,54 +1411,18 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
}
}
$disable_funding = $this->settings->has( 'disable_funding' )
? $this->settings->get( 'disable_funding' )
: array();
if ( ! is_checkout() ) {
$disable_funding[] = 'card';
}
$is_dcc_enabled = $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' );
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
$is_separate_card_enabled = isset( $available_gateways[ CardButtonGateway::ID ] );
if ( is_checkout() && ( $is_dcc_enabled || $is_separate_card_enabled ) ) {
$key = array_search( 'card', $disable_funding, true );
if ( false !== $key ) {
unset( $disable_funding[ $key ] );
}
}
if ( in_array( $context, array( 'checkout-block', 'cart-block' ), true ) ) {
$disable_funding = array_merge(
$disable_funding,
array_diff(
array_keys( $this->all_funding_sources ),
array( 'venmo', 'paylater', 'paypal', 'card' )
)
);
}
if ( $this->is_free_trial_cart() ) {
$all_sources = array_keys( $this->all_funding_sources );
if ( $is_dcc_enabled || $is_separate_card_enabled ) {
$all_sources = array_diff( $all_sources, array( 'card' ) );
}
$disable_funding = $all_sources;
}
$disabled_funding_sources = $this->disabled_funding_sources->sources( $context );
$enable_funding = array( 'venmo' );
if ( $this->is_pay_later_button_enabled_for_location( $context ) ) {
$enable_funding[] = 'paylater';
} else {
$disable_funding[] = 'paylater';
$disabled_funding_sources[] = 'paylater';
}
$disable_funding = array_filter(
$disable_funding,
$disabled_funding_sources = array_filter(
$disabled_funding_sources,
/**
* Make sure paypal is not sent in disable funding.
*
@ -1462,8 +1435,8 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
}
);
if ( count( $disable_funding ) > 0 ) {
$params['disable-funding'] = implode( ',', array_unique( $disable_funding ) );
if ( count( $disabled_funding_sources ) > 0 ) {
$params['disable-funding'] = implode( ',', array_unique( $disabled_funding_sources ) );
}
if ( $this->is_free_trial_cart() ) {

View file

@ -137,6 +137,10 @@ trait ContextTrait {
case $this->is_block_editor():
$context = 'block-editor';
break;
case $this->is_paypal_continuation():
$context = 'continuation';
break;
}
return apply_filters( 'woocommerce_paypal_payments_context', $context );

View file

@ -0,0 +1,109 @@
<?php
/**
* Creates the list of disabled funding sources.
*
* @package WooCommerce\PayPalCommerce\Button\Helper
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Button\Helper;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcSubscriptions\FreeTrialHandlerTrait;
/**
* Class DisabledFundingSources
*/
class DisabledFundingSources {
use FreeTrialHandlerTrait;
/**
* The settings.
*
* @var Settings
*/
private $settings;
/**
* All existing funding sources.
*
* @var array
*/
private $all_funding_sources;
/**
* DisabledFundingSources constructor.
*
* @param Settings $settings The settings.
* @param array $all_funding_sources All existing funding sources.
*/
public function __construct( Settings $settings, array $all_funding_sources ) {
$this->settings = $settings;
$this->all_funding_sources = $all_funding_sources;
}
/**
* Returns the list of funding sources to be disabled.
*
* @param string $context The context.
* @return array|int[]|mixed|string[]
* @throws NotFoundException When the setting is not found.
*/
public function sources( string $context ) {
$disable_funding = $this->settings->has( 'disable_funding' )
? $this->settings->get( 'disable_funding' )
: array();
$is_dcc_enabled = $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' );
if (
! is_checkout()
|| ( $is_dcc_enabled && in_array( $context, array( 'checkout-block', 'cart-block' ), true ) )
) {
$disable_funding[] = 'card';
}
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
$is_separate_card_enabled = isset( $available_gateways[ CardButtonGateway::ID ] );
if (
(
is_checkout()
&& ! in_array( $context, array( 'checkout-block', 'cart-block' ), true )
)
&& (
$is_dcc_enabled
|| $is_separate_card_enabled
)
) {
$key = array_search( 'card', $disable_funding, true );
if ( false !== $key ) {
unset( $disable_funding[ $key ] );
}
}
if ( in_array( $context, array( 'checkout-block', 'cart-block' ), true ) ) {
$disable_funding = array_merge(
$disable_funding,
array_diff(
array_keys( $this->all_funding_sources ),
array( 'venmo', 'paylater', 'paypal', 'card' )
)
);
}
if ( $this->is_free_trial_cart() ) {
$all_sources = array_keys( $this->all_funding_sources );
if ( $is_dcc_enabled || $is_separate_card_enabled ) {
$all_sources = array_diff( $all_sources, array( 'card' ) );
}
$disable_funding = $all_sources;
}
return $disable_funding;
}
}