Ensure saved card payment use default payment flow for free trial subscriptions

This commit is contained in:
Emili Castells Guasch 2024-07-24 17:00:58 +02:00
parent efbd36025d
commit 29e195e7f3
2 changed files with 21 additions and 1 deletions

View file

@ -216,7 +216,10 @@ const bootstrap = () => {
spinner spinner
); );
if ( typeof paypal.CardFields !== 'undefined' ) { if ( typeof paypal.CardFields !== 'undefined' ) {
if ( PayPalCommerceGateway.is_free_trial_cart ) { if (
PayPalCommerceGateway.is_free_trial_cart &&
PayPalCommerceGateway.user?.has_wc_card_payment_tokens !== true
) {
creditCardRenderer = new CardFieldsFreeTrialRenderer( creditCardRenderer = new CardFieldsFreeTrialRenderer(
PayPalCommerceGateway, PayPalCommerceGateway,
errorHandler, errorHandler,

View file

@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\Button\Assets;
use Exception; use Exception;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use WC_Order; use WC_Order;
use WC_Payment_Tokens;
use WC_Product; use WC_Product;
use WC_Product_Variation; use WC_Product_Variation;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentTokensEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentTokensEndpoint;
@ -1293,6 +1294,7 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
'funding_sources_without_redirect' => $this->funding_sources_without_redirect, 'funding_sources_without_redirect' => $this->funding_sources_without_redirect,
'user' => array( 'user' => array(
'is_logged' => is_user_logged_in(), 'is_logged' => is_user_logged_in(),
'has_wc_card_payment_tokens' => $this->user_has_wc_card_payment_tokens(get_current_user_id()),
), ),
'should_handle_shipping_in_paypal' => $this->should_handle_shipping_in_paypal && ! $this->is_checkout(), 'should_handle_shipping_in_paypal' => $this->should_handle_shipping_in_paypal && ! $this->is_checkout(),
'vaultingEnabled' => $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ), 'vaultingEnabled' => $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ),
@ -2132,4 +2134,19 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
return $location; return $location;
} }
} }
/**
* Whether the given user has WC card payment tokens.
*
* @param int $user_id
* @return bool
*/
private function user_has_wc_card_payment_tokens(int $user_id): bool {
$tokens = WC_Payment_Tokens::get_customer_tokens( $user_id, CreditCardGateway::ID );
if($tokens) {
return true;
}
return false;
}
} }