Enable subscriptions plugin support, add settings for vaulting

This commit is contained in:
dinamiko 2021-02-15 13:54:42 +01:00
parent 25282da555
commit 6bfb8b2c2a
4 changed files with 73 additions and 14 deletions

View file

@ -89,7 +89,7 @@ document.addEventListener(
}
);
if (PayPalCommerceGateway.data_client_id.set_attribute) {
if (PayPalCommerceGateway.data_client_id.set_attribute || PayPalCommerceGateway.data_client_id.save_paypal_account) {
dataClientIdAttributeHandler(script, PayPalCommerceGateway.data_client_id);
return;
}

View file

@ -517,7 +517,7 @@ class SmartButton implements SmartButtonInterface {
return;
}
$save_card = $this->can_save_vault_token() ? sprintf(
$save_card = $this->can_save_credit_card() ? sprintf(
'<div>
<label for="ppcp-vault-%1$s">%2$s</label>
@ -536,12 +536,10 @@ class SmartButton implements SmartButtonInterface {
printf(
'<div id="%1$s" style="display:none;">
<button class="button alt">%6$s</button>
<button class="button alt">%3$s</button>
%2$s
</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__( 'Credit Card number', 'woocommerce-paypal-payments' ),
esc_html__( 'Expiration', 'woocommerce-paypal-payments' ),
esc_html__( 'CVV', 'woocommerce-paypal-payments' ),
//phpcs:ignore
$save_card,
esc_html( $label )
@ -565,6 +563,17 @@ class SmartButton implements SmartButtonInterface {
return is_user_logged_in();
}
private function can_save_credit_card() {
if ( ! $this->settings->has( 'client_id' ) || ! $this->settings->get( 'client_id' ) ) {
return false;
}
if ( ! $this->settings->has( 'dcc_save_card' ) || ! $this->settings->get( 'dcc_save_card' ) ) {
return false;
}
return is_user_logged_in();
}
/**
* Whether we need to initialize the script to enable tokenization for subscriptions or not.
*
@ -593,11 +602,12 @@ class SmartButton implements SmartButtonInterface {
$localize = array(
'script_attributes' => $this->attributes(),
'data_client_id' => array(
'set_attribute' => ( is_checkout() && $this->dcc_is_enabled() )
'set_attribute' => ( is_checkout() && $this->dcc_is_enabled() )
|| $this->can_save_vault_token(),
'endpoint' => home_url( \WC_AJAX::get_endpoint( DataClientIdEndpoint::ENDPOINT ) ),
'nonce' => wp_create_nonce( DataClientIdEndpoint::nonce() ),
'user' => get_current_user_id(),
'save_paypal_account' => $this->save_paypal_account(),
'endpoint' => home_url( \WC_AJAX::get_endpoint( DataClientIdEndpoint::ENDPOINT ) ),
'nonce' => wp_create_nonce( DataClientIdEndpoint::nonce() ),
'user' => get_current_user_id(),
),
'redirect' => wc_get_checkout_url(),
'context' => $this->context(),
@ -895,6 +905,13 @@ class SmartButton implements SmartButtonInterface {
return true;
}
private function save_paypal_account(): bool {
if ( ! $this->settings->has( 'save_paypal_account' ) || ! $this->settings->get( 'save_paypal_account' ) ) {
return false;
}
return true;
}
/**
* Determines the style for a given indicator in a given context.
*

View file

@ -479,6 +479,34 @@ return array(
),
'gateway' => 'dcc',
),
'dcc_vault_enabled' => array(
'title' => __( 'Vaulting For Credit Cards', 'woocommerce-paypal-payments' ),
'desc_tip' => true,
'description' => __( '', 'woocommerce-paypal-payments' ),
'label' => __( 'Enable Vaulting For Credit Cards', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'default' => false,
'gateway' => 'dcc',
'requirements' => array(
'dcc',
),
'screens' => array(
State::STATE_ONBOARDED,
),
),
'dcc_save_card' => array(
'title' => __( 'Save Credit Card', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'desc_tip' => true,
'label' => __( 'Allow Registered Buyers to Save Credit Card', 'woocommerce-paypal-payments' ),
'description' => __( 'Buyers that create an account on your store may save their Credit Card for faster checkout.', 'woocommerce-paypal-payments' ),
'default' => true,
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'dcc',
),
'description' => array(
'title' => __( 'Description', 'woocommerce-paypal-payments' ),
'type' => 'text',
@ -621,11 +649,24 @@ return array(
'gateway' => 'paypal',
),
'vault_enabled' => array(
'title' => __( 'Vaulting', 'woocommerce-paypal-payments' ),
'title' => __( 'Vaulting for PayPal Accounts', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'desc_tip' => true,
'label' => __( 'Enable vaulting', 'woocommerce-paypal-payments' ),
'description' => __( 'Enables you to store payment tokens for subscriptions.', 'woocommerce-paypal-payments' ),
'label' => __( 'Enable Vaulting for PayPal Accounts', 'woocommerce-paypal-payments' ),
'description' => __( '', 'woocommerce-paypal-payments' ),
'default' => true,
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'paypal',
),
'save_paypal_account' => array(
'title' => __( 'Save PayPal Account', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'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,
'screens' => array(
State::STATE_ONBOARDED,
@ -633,7 +674,6 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'logging_enabled' => array(
'title' => __( 'Logging', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',

View file

@ -28,6 +28,8 @@ define( 'PAYPAL_API_URL', 'https://api.paypal.com' );
define( 'PAYPAL_SANDBOX_API_URL', 'https://api.sandbox.paypal.com' );
define( 'PAYPAL_INTEGRATION_DATE', '2020-10-15' );
define( 'PPCP_FLAG_SUBSCRIPTION', true );
! defined( 'CONNECT_WOO_CLIENT_ID' ) && define( 'CONNECT_WOO_CLIENT_ID', 'AcCAsWta_JTL__OfpjspNyH7c1GGHH332fLwonA5CwX4Y10mhybRZmHLA0GdRbwKwjQIhpDQy0pluX_P' );
! defined( 'CONNECT_WOO_SANDBOX_CLIENT_ID' ) && define( 'CONNECT_WOO_SANDBOX_CLIENT_ID', 'AYmOHbt1VHg-OZ_oihPdzKEVbU3qg0qXonBcAztuzniQRaKE0w1Hr762cSFwd4n8wxOl-TCWohEa0XM_' );
! defined( 'CONNECT_WOO_MERCHANT_ID' ) && define( 'CONNECT_WOO_MERCHANT_ID', 'K8SKZ36LQBWXJ' );