mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Add client-side vaulting for subscription renewals
This commit is contained in:
parent
e7f592efe3
commit
ed3a91f333
6 changed files with 53 additions and 21 deletions
|
@ -103,8 +103,9 @@ class CreditCardRenderer {
|
|||
});
|
||||
|
||||
if (formValid && this.cardValid) {
|
||||
const vault_card_setting_enabled = this.defaultConfig.vault_card_setting_enabled ? true : false;
|
||||
const vault = document.getElementById('ppcp-credit-card-vault') ?
|
||||
document.getElementById('ppcp-credit-card-vault').checked : false;
|
||||
document.getElementById('ppcp-credit-card-vault').checked : vault_card_setting_enabled;
|
||||
hostedFields.submit({
|
||||
contingencies: ['3D_SECURE'],
|
||||
vault: vault
|
||||
|
|
|
@ -554,7 +554,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
if ( ! $this->settings->has( 'client_id' ) || ! $this->settings->get( 'client_id' ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! $this->settings->has( 'vault_enabled' ) || ! $this->settings->get( 'vault_enabled' ) ) {
|
||||
if ( ! $this->vault_settings_enabled() ) {
|
||||
return false;
|
||||
}
|
||||
return is_user_logged_in();
|
||||
|
@ -623,6 +623,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
),
|
||||
),
|
||||
'enforce_vault' => $this->has_subscriptions(),
|
||||
'vault_card_setting_enabled' => $this->vault_card_setting_enabled(),
|
||||
'bn_codes' => $this->bn_codes(),
|
||||
'payer' => $this->payerData(),
|
||||
'button' => array(
|
||||
|
@ -940,4 +941,23 @@ class SmartButton implements SmartButtonInterface {
|
|||
}
|
||||
return (string) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException
|
||||
*/
|
||||
protected function vault_settings_enabled(): bool {
|
||||
if ( ! $this->settings->has( 'vault_enabled' ) && ! $this->settings->has( 'dcc_vault_enabled' )
|
||||
|| ! $this->settings->get( 'dcc_vault_enabled' ) && ! $this->settings->get( 'dcc_vault_enabled' ) ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function vault_card_setting_enabled(): bool {
|
||||
if ( ! $this->settings->get( 'dcc_vault_enabled' ) && ! $this->settings->get( 'dcc_vault_enabled' ) ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -654,7 +654,7 @@ return array(
|
|||
'desc_tip' => true,
|
||||
'label' => __( 'Enable Vaulting for PayPal Accounts', 'woocommerce-paypal-payments' ),
|
||||
'description' => __( '', 'woocommerce-paypal-payments' ),
|
||||
'default' => true,
|
||||
'default' => false,
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
|
@ -667,7 +667,7 @@ return array(
|
|||
'desc_tip' => true,
|
||||
'label' => __( 'Allow Registered Buyers to Save PayPal Account', 'woocommerce-paypal-payments' ),
|
||||
'description' => __( 'Buyers that create an account on your store may save their PayPal account for faster checkout. Note that you may not present Pay Later messages when using this feature.', 'woocommerce-paypal-payments' ),
|
||||
'default' => true,
|
||||
'default' => false,
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
|
|
|
@ -81,8 +81,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
if (
|
||||
defined( 'PPCP_FLAG_SUBSCRIPTION' )
|
||||
&& PPCP_FLAG_SUBSCRIPTION
|
||||
&& $this->config->has( 'vault_enabled' )
|
||||
&& $this->config->get( 'vault_enabled' )
|
||||
&& $this->vault_settings_enabled()
|
||||
) {
|
||||
$this->supports = array(
|
||||
'refunds',
|
||||
|
|
|
@ -119,8 +119,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
if (
|
||||
defined( 'PPCP_FLAG_SUBSCRIPTION' )
|
||||
&& PPCP_FLAG_SUBSCRIPTION
|
||||
&& $this->config->has( 'vault_enabled' )
|
||||
&& $this->config->get( 'vault_enabled' )
|
||||
&& $this->vault_settings_enabled()
|
||||
) {
|
||||
$this->supports = array(
|
||||
'refunds',
|
||||
|
|
|
@ -85,4 +85,17 @@ trait ProcessPaymentTrait {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException
|
||||
*/
|
||||
protected function vault_settings_enabled(): bool {
|
||||
if ( ! $this->config->has( 'vault_enabled' ) && ! $this->config->has( 'dcc_vault_enabled' )
|
||||
|| ! $this->config->get( 'dcc_vault_enabled' ) && ! $this->config->get( 'dcc_vault_enabled' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue