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();
|
||||
|
@ -597,8 +597,8 @@ class SmartButton implements SmartButtonInterface {
|
|||
|
||||
$this->request_data->enqueue_nonce_fix();
|
||||
$localize = array(
|
||||
'script_attributes' => $this->attributes(),
|
||||
'data_client_id' => array(
|
||||
'script_attributes' => $this->attributes(),
|
||||
'data_client_id' => array(
|
||||
'set_attribute' => ( is_checkout() && $this->dcc_is_enabled() )
|
||||
|| $this->can_save_vault_token(),
|
||||
'save_paypal_account' => $this->save_paypal_account(),
|
||||
|
@ -606,9 +606,9 @@ class SmartButton implements SmartButtonInterface {
|
|||
'nonce' => wp_create_nonce( DataClientIdEndpoint::nonce() ),
|
||||
'user' => get_current_user_id(),
|
||||
),
|
||||
'redirect' => wc_get_checkout_url(),
|
||||
'context' => $this->context(),
|
||||
'ajax' => array(
|
||||
'redirect' => wc_get_checkout_url(),
|
||||
'context' => $this->context(),
|
||||
'ajax' => array(
|
||||
'change_cart' => array(
|
||||
'endpoint' => home_url( \WC_AJAX::get_endpoint( ChangeCartEndpoint::ENDPOINT ) ),
|
||||
'nonce' => wp_create_nonce( ChangeCartEndpoint::nonce() ),
|
||||
|
@ -622,10 +622,11 @@ class SmartButton implements SmartButtonInterface {
|
|||
'nonce' => wp_create_nonce( ApproveOrderEndpoint::nonce() ),
|
||||
),
|
||||
),
|
||||
'enforce_vault' => $this->has_subscriptions(),
|
||||
'bn_codes' => $this->bn_codes(),
|
||||
'payer' => $this->payerData(),
|
||||
'button' => array(
|
||||
'enforce_vault' => $this->has_subscriptions(),
|
||||
'vault_card_setting_enabled' => $this->vault_card_setting_enabled(),
|
||||
'bn_codes' => $this->bn_codes(),
|
||||
'payer' => $this->payerData(),
|
||||
'button' => array(
|
||||
'wrapper' => '#ppc-button',
|
||||
'mini_cart_wrapper' => '#ppc-button-minicart',
|
||||
'cancel_wrapper' => '#ppcp-cancel',
|
||||
|
@ -645,7 +646,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
'tagline' => $this->style_for_context( 'tagline', $this->context() ),
|
||||
),
|
||||
),
|
||||
'hosted_fields' => array(
|
||||
'hosted_fields' => array(
|
||||
'wrapper' => '#ppcp-hosted-fields',
|
||||
'mini_cart_wrapper' => '#ppcp-hosted-fields-mini-cart',
|
||||
'labels' => array(
|
||||
|
@ -663,8 +664,8 @@ class SmartButton implements SmartButtonInterface {
|
|||
),
|
||||
'valid_cards' => $this->dcc_applies->valid_cards(),
|
||||
),
|
||||
'messages' => $this->message_values(),
|
||||
'labels' => array(
|
||||
'messages' => $this->message_values(),
|
||||
'labels' => array(
|
||||
'error' => array(
|
||||
'generic' => __(
|
||||
'Something went wrong. Please try again or choose another payment source.',
|
||||
|
@ -672,7 +673,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
),
|
||||
),
|
||||
),
|
||||
'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0,
|
||||
'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0,
|
||||
);
|
||||
|
||||
if ( $this->style_for_context( 'layout', 'mini-cart' ) !== 'horizontal' ) {
|
||||
|
@ -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