Merge pull request #729 from woocommerce/PCP-688-add-functionality-to-choose-subscription-failure-behavior

Functionality to choose subscription failure behavior
This commit is contained in:
Emili Castells 2022-09-30 15:57:31 +02:00 committed by GitHub
commit e638d91687
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 329 additions and 109 deletions

View file

@ -311,6 +311,13 @@ document.addEventListener(
]
);
groupToggle(
'#ppcp-vault_enabled',
[
'#field-subscription_behavior_when_vault_fails',
]
);
groupToggleSelect(
'#ppcp-intent',

View file

@ -1,2 +1,2 @@
node_modules
/assets
assets

View file

@ -16,6 +16,7 @@ use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Repository\OrderRepository;
use WooCommerce\PayPalCommerce\Subscription\FreeTrialHandlerTrait;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
@ -29,6 +30,8 @@ class PaymentTokenChecker {
use FreeTrialHandlerTrait;
const VAULTING_FAILED_META_KEY = '_ppcp_vaulting_failed';
/**
* The payment token repository.
*
@ -115,39 +118,74 @@ class PaymentTokenChecker {
return;
}
$tokens = $this->payment_token_repository->all_for_user_id( $customer_id );
if ( $tokens ) {
try {
if ( $this->is_free_trial_order( $wc_order ) ) {
if ( in_array( $wc_order->get_payment_method(), array( CreditCardGateway::ID, CardButtonGateway::ID ), true )
|| ( PayPalGateway::ID === $wc_order->get_payment_method() && 'card' === $wc_order->get_meta( PayPalGateway::ORDER_PAYMENT_SOURCE_META_KEY ) )
) {
$order = $this->order_repository->for_wc_order( $wc_order );
$this->authorized_payments_processor->void_authorizations( $order );
$wc_order->payment_complete();
}
return;
}
$this->capture_authorized_payment( $wc_order );
} catch ( Exception $exception ) {
$this->logger->error( $exception->getMessage() );
if ( $this->is_free_trial_order( $wc_order ) ) {
if ( in_array( $wc_order->get_payment_method(), array( CreditCardGateway::ID, CardButtonGateway::ID ), true )
|| ( PayPalGateway::ID === $wc_order->get_payment_method() && 'card' === $wc_order->get_meta( PayPalGateway::ORDER_PAYMENT_SOURCE_META_KEY ) )
) {
$order = $this->order_repository->for_wc_order( $wc_order );
$this->authorized_payments_processor->void_authorizations( $order );
$wc_order->payment_complete();
}
return;
}
$this->logger->error( "Payment for subscription parent order #{$order_id} was not saved on PayPal." );
$tokens = $this->payment_token_repository->all_for_user_id( $customer_id );
if ( $tokens ) {
try {
$this->capture_authorized_payment( $wc_order );
} catch ( Exception $exception ) {
$this->logger->warning( $exception->getMessage() );
}
try {
$order = $this->order_repository->for_wc_order( $wc_order );
$this->authorized_payments_processor->void_authorizations( $order );
} catch ( RuntimeException $exception ) {
$this->logger->warning( $exception->getMessage() );
return;
}
$this->update_failed_status( $wc_order );
try {
$subscription_behavior_when_fails = $this->settings->get( 'subscription_behavior_when_vault_fails' );
} catch ( NotFoundException $exception ) {
return;
}
switch ( $subscription_behavior_when_fails ) {
case 'void_auth':
$order = $this->order_repository->for_wc_order( $wc_order );
$this->authorized_payments_processor->void_authorizations( $order );
$this->logger->warning( "Payment for subscription parent order #{$order_id} was not saved at PayPal." );
$this->update_failed_status( $wc_order );
break;
case 'capture_auth':
try {
$this->capture_authorized_payment( $wc_order );
} catch ( Exception $exception ) {
$this->logger->warning( $exception->getMessage() );
return;
}
$subscriptions = function_exists( 'wcs_get_subscriptions_for_order' ) ? wcs_get_subscriptions_for_order( $wc_order ) : array();
foreach ( $subscriptions as $subscription ) {
try {
$subscription->set_requires_manual_renewal( true );
$subscription->save();
$message = __( 'Subscription set to Manual Renewal because payment method was not saved at PayPal.', 'woocommerce-paypal-payments' );
$wc_order->add_order_note( $message );
} catch ( Exception $exception ) {
$this->logger->warning( "Could not update payment method on subscription #{$subscription->get_id()} " . $exception->getMessage() );
}
}
break;
case 'capture_auth_ignore':
try {
$this->capture_authorized_payment( $wc_order );
} catch ( Exception $exception ) {
$this->logger->warning( $exception->getMessage() );
return;
}
break;
}
}
/**
@ -170,7 +208,7 @@ class PaymentTokenChecker {
* @param WC_Order $wc_order The WC order.
*/
private function update_failed_status( WC_Order $wc_order ): void {
$error_message = __( 'Could not process order because it was not possible to save the payment on PayPal.', 'woocommerce-paypal-payments' );
$error_message = __( 'Subscription payment failed. Payment method was not saved at PayPal.', 'woocommerce-paypal-payments' );
$wc_order->update_status( 'failed', $error_message );
/**

View file

@ -13,7 +13,12 @@ use Dhii\Container\ServiceProvider;
use Dhii\Modular\Module\ModuleInterface;
use Interop\Container\ServiceProviderInterface;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use WC_Order;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\Vaulting\Endpoint\DeletePaymentTokenEndpoint;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
/**
* Class StatusReportModule
@ -35,6 +40,7 @@ class VaultingModule implements ModuleInterface {
* {@inheritDoc}
*
* @param ContainerInterface $container A services container instance.
* @throws NotFoundException When service could not be found.
*/
public function run( ContainerInterface $container ): void {
@ -144,6 +150,100 @@ class VaultingModule implements ModuleInterface {
10,
3
);
$this->filterFailedVaultingEmailsForSubscriptionOrders( $container );
}
/**
* Filters the emails when vaulting is failed for subscription orders.
*
* @param ContainerInterface $container A services container instance.
* @throws NotFoundException When service could not be found.
*/
protected function filterFailedVaultingEmailsForSubscriptionOrders( ContainerInterface $container ):void {
add_action(
'woocommerce_email_before_order_table',
function( WC_Order $order ) use ( $container ) {
/**
* The SubscriptionHelper.
*
* @var SubscriptionHelper $subscription_helper
*/
$subscription_helper = $container->get( 'subscription.helper' );
/**
* The logger.
*
* @var LoggerInterface $logger
*/
$logger = $container->get( 'woocommerce.logger.woocommerce' );
/**
* The Gateway settings.
*
* @var Settings $settings
*/
$settings = $container->get( 'wcgateway.settings' );
$vault_failed = get_post_meta( $order->get_id(), PaymentTokenChecker::VAULTING_FAILED_META_KEY );
if ( $subscription_helper->has_subscription( $order->get_id() ) && ! empty( $vault_failed ) ) {
$subscription_behavior_when_vault_fails_setting_name = 'subscription_behavior_when_vault_fails';
$subscription_behavior_when_vault_fails = $settings->get( $subscription_behavior_when_vault_fails_setting_name );
$logger->info( "Adding vaulting failure info to email for order #{$order->get_id()}." );
if ( $subscription_behavior_when_vault_fails === 'void_auth' ) {
echo wp_kses_post( '<p>' . __( 'The subscription payment failed because the payment method could not be saved. Please try again with a different payment method.', 'woocommerce-paypal-payments' ) . '</p>' );
}
if ( $subscription_behavior_when_vault_fails === 'capture_auth' ) {
echo wp_kses_post( '<p>' . __( 'The subscription has been activated, but the payment method could not be saved. Please contact the merchant to save a payment method for automatic subscription renewal payments.', 'woocommerce-paypal-payments' ) . '</p>' );
}
}
}
);
add_action(
'woocommerce_email_after_order_table',
function( WC_Order $order ) use ( $container ) {
/**
* The SubscriptionHelper.
*
* @var SubscriptionHelper $subscription_helper
*/
$subscription_helper = $container->get( 'subscription.helper' );
/**
* The logger.
*
* @var LoggerInterface $logger
*/
$logger = $container->get( 'woocommerce.logger.woocommerce' );
/**
* The Gateway settings.
*
* @var Settings $settings
*/
$settings = $container->get( 'wcgateway.settings' );
$vault_failed = get_post_meta( $order->get_id(), PaymentTokenChecker::VAULTING_FAILED_META_KEY );
if ( $subscription_helper->has_subscription( $order->get_id() ) && ! empty( $vault_failed ) ) {
$subscription_behavior_when_vault_fails_setting_name = 'subscription_behavior_when_vault_fails';
$subscription_behavior_when_vault_fails = $settings->get( $subscription_behavior_when_vault_fails_setting_name );
$logger->info( "Changing subscription auto-renewal status for order #{$order->get_id()}." );
if ( $subscription_behavior_when_vault_fails === 'capture_auth' ) {
$subscriptions = function_exists( 'wcs_get_subscriptions_for_order' ) ? wcs_get_subscriptions_for_order( $order->get_id() ) : array();
foreach ( $subscriptions as $subscription ) {
$subscription->set_requires_manual_renewal( true );
$subscription->save();
}
}
}
}
);
}
/**

View file

@ -69,5 +69,9 @@
togglePayLater()
vaultingCheckboxes.forEach(node => node.addEventListener('change', togglePayLater));
if(PayPalCommerceGatewaySettings.is_subscriptions_plugin_active !== '1') {
document.getElementById('field-subscription_behavior_when_vault_fails').style.display = 'none';
}
}
);

View file

@ -402,7 +402,7 @@ return array(
assert( $onboarding_options_renderer instanceof OnboardingOptionsRenderer );
$fields = array(
'checkout_settings_heading' => array(
'checkout_settings_heading' => array(
'heading' => __( 'PayPal Checkout Settings', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
'screens' => array(
@ -412,7 +412,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'title' => array(
'title' => array(
'title' => __( 'Title', 'woocommerce-paypal-payments' ),
'type' => 'text',
'description' => __(
@ -428,7 +428,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'dcc_enabled' => array(
'dcc_enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
'desc_tip' => true,
'description' => __( 'Once enabled, the Credit Card option will show up in the checkout.', 'woocommerce-paypal-payments' ),
@ -443,7 +443,7 @@ return array(
State::STATE_ONBOARDED,
),
),
'dcc_gateway_title' => array(
'dcc_gateway_title' => array(
'title' => __( 'Title', 'woocommerce-paypal-payments' ),
'type' => 'text',
'description' => __(
@ -460,7 +460,7 @@ return array(
),
'gateway' => 'dcc',
),
'description' => array(
'description' => array(
'title' => __( 'Description', 'woocommerce-paypal-payments' ),
'type' => 'text',
'desc_tip' => true,
@ -479,7 +479,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'intent' => array(
'intent' => array(
'title' => __( 'Intent', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -501,7 +501,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'capture_for_virtual_only' => array(
'capture_for_virtual_only' => array(
'title' => __( 'Capture Virtual-Only Orders ', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'default' => false,
@ -518,7 +518,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'payee_preferred' => array(
'payee_preferred' => array(
'title' => __( 'Instant Payments ', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'default' => false,
@ -535,7 +535,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'brand_name' => array(
'brand_name' => array(
'title' => __( 'Brand Name', 'woocommerce-paypal-payments' ),
'type' => 'text',
'default' => get_bloginfo( 'name' ),
@ -551,7 +551,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'landing_page' => array(
'landing_page' => array(
'title' => __( 'Landing Page', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -573,7 +573,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'disable_funding' => array(
'disable_funding' => array(
'title' => __( 'Hide Funding Source(s)', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-multiselect',
'class' => array(),
@ -597,7 +597,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'vault_enabled' => array(
'vault_enabled' => array(
'title' => __( 'Vaulting', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'desc_tip' => true,
@ -611,7 +611,27 @@ return array(
'gateway' => array( 'paypal', 'dcc' ),
'input_class' => $container->get( 'wcgateway.helper.vaulting-scope' ) ? array() : array( 'ppcp-disabled-checkbox' ),
),
'card_billing_data_mode' => array(
'subscription_behavior_when_vault_fails' => array(
'title' => __( 'Subscription capture behavior if Vault fails', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => 'void_auth',
'desc_tip' => true,
'description' => __( 'By default, subscription payments are captured only when saving the payment method was successful. Without a saved payment method, automatic renewal payments are not possible.', 'woocommerce-paypal-payments' ),
'description_with_tip' => __( 'Determines whether authorized payments for subscription orders are captured or voided if there is no saved payment method. This only applies when the intent Capture is used for the subscription order.', 'woocommerce-paypal-payments' ),
'options' => array(
'void_auth' => __( 'Void authorization & fail the order/subscription', 'woocommerce-paypal-payments' ),
'capture_auth' => __( 'Capture authorized payment & set subscription to Manual Renewal', 'woocommerce-paypal-payments' ),
'capture_auth_ignore' => __( 'Capture authorized payment & disregard missing payment method', 'woocommerce-paypal-payments' ),
),
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => array( 'paypal', 'dcc' ),
),
'card_billing_data_mode' => array(
'title' => __( 'Card billing data handling', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -631,7 +651,7 @@ return array(
'requirements' => array(),
'gateway' => array( 'paypal', CardButtonGateway::ID ),
),
'allow_card_button_gateway' => array(
'allow_card_button_gateway' => array(
'title' => __( 'Separate Card Button from PayPal gateway', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'desc_tip' => true,
@ -647,7 +667,7 @@ return array(
),
// General button styles.
'button_style_heading' => array(
'button_style_heading' => array(
'heading' => __( 'Checkout', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
'screens' => array(
@ -658,7 +678,7 @@ return array(
'gateway' => 'paypal',
'description' => __( 'Customize the appearance of PayPal Checkout on the checkout page.', 'woocommerce-paypal-payments' ),
),
'button_enabled' => array(
'button_enabled' => array(
'title' => __( 'Enable buttons on Checkout', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => __( 'Enable on Checkout', 'woocommerce-paypal-payments' ),
@ -670,7 +690,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_layout' => array(
'button_layout' => array(
'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -692,7 +712,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_tagline' => array(
'button_tagline' => array(
'title' => __( 'Tagline', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'default' => true,
@ -709,7 +729,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_label' => array(
'button_label' => array(
'title' => __( 'Button Label', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -736,7 +756,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_color' => array(
'button_color' => array(
'title' => __( 'Color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -760,7 +780,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_shape' => array(
'button_shape' => array(
'title' => __( 'Shape', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -782,7 +802,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'message_heading' => array(
'message_heading' => array(
'heading' => __( 'Pay Later on Checkout', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
'screens' => array(
@ -794,7 +814,7 @@ return array(
'description' => str_replace( '<a>', '<a href="' . $messages_disclaimers->link_for_country() . '" target="_blank">', __( 'Displays Pay Later messaging for available offers. Restrictions apply. <a>Click here to learn more</a>. Pay Later button will show for eligible buyers and PayPal determines eligibility.', 'woocommerce-paypal-payments' ) ),
'class' => array( 'ppcp-subheading' ),
),
'message_enabled' => array(
'message_enabled' => array(
'title' => __( 'Enable message on Checkout', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => sprintf( $container->get( 'wcgateway.settings.fields.pay-later-label' ), __( 'Enable on Checkout', 'woocommerce-paypal-payments' ) ),
@ -806,7 +826,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_layout' => array(
'message_layout' => array(
'title' => __( 'Pay Later Messaging layout', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -828,7 +848,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_logo' => array(
'message_logo' => array(
'title' => __( 'Pay Later Messaging logo', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -852,7 +872,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_position' => array(
'message_position' => array(
'title' => __( 'Pay Later Messaging logo position', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -875,7 +895,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_color' => array(
'message_color' => array(
'title' => __( 'Pay Later Messaging text color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -899,7 +919,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_flex_color' => array(
'message_flex_color' => array(
'title' => __( 'Pay Later Messaging color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -926,7 +946,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_flex_ratio' => array(
'message_flex_ratio' => array(
'title' => __( 'Pay Later Messaging ratio', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -952,7 +972,7 @@ return array(
),
// Single product page.
'button_product_heading' => array(
'button_product_heading' => array(
'heading' => __( 'Single Product Page', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
'screens' => array(
@ -963,7 +983,7 @@ return array(
'gateway' => 'paypal',
'description' => __( 'Customize the appearance of PayPal Checkout on the single product page.', 'woocommerce-paypal-payments' ),
),
'button_product_enabled' => array(
'button_product_enabled' => array(
'title' => __( 'Enable buttons on Single Product', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => __( 'Enable on Single Product', 'woocommerce-paypal-payments' ),
@ -975,7 +995,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_product_layout' => array(
'button_product_layout' => array(
'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -997,7 +1017,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_product_tagline' => array(
'button_product_tagline' => array(
'title' => __( 'Tagline', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ),
@ -1014,7 +1034,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_product_label' => array(
'button_product_label' => array(
'title' => __( 'Button Label', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1041,7 +1061,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_product_color' => array(
'button_product_color' => array(
'title' => __( 'Color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1065,7 +1085,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_product_shape' => array(
'button_product_shape' => array(
'title' => __( 'Shape', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1088,7 +1108,7 @@ return array(
'gateway' => 'paypal',
),
'message_product_heading' => array(
'message_product_heading' => array(
'heading' => __( 'Pay Later on Single Product Page', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
'screens' => array(
@ -1100,7 +1120,7 @@ return array(
'description' => str_replace( '<a>', '<a href="' . $messages_disclaimers->link_for_country() . '" target="_blank">', __( 'Displays Pay Later messaging for available offers. Restrictions apply. <a>Click here to learn more</a>. Pay Later button will show for eligible buyers and PayPal determines eligibility.', 'woocommerce-paypal-payments' ) ),
'class' => array( 'ppcp-subheading' ),
),
'message_product_enabled' => array(
'message_product_enabled' => array(
'title' => __( 'Enable message on Single Product', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => sprintf( $container->get( 'wcgateway.settings.fields.pay-later-label' ), __( 'Enable on Single Product', 'woocommerce-paypal-payments' ) ),
@ -1112,7 +1132,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_product_layout' => array(
'message_product_layout' => array(
'title' => __( 'Pay Later Messaging layout', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1134,7 +1154,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_product_logo' => array(
'message_product_logo' => array(
'title' => __( 'Pay Later Messaging logo', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1158,7 +1178,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_product_position' => array(
'message_product_position' => array(
'title' => __( 'Pay Later Messaging logo position', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1181,7 +1201,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_product_color' => array(
'message_product_color' => array(
'title' => __( 'Pay Later Messaging text color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1205,7 +1225,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_product_flex_color' => array(
'message_product_flex_color' => array(
'title' => __( 'Pay Later Messaging color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1232,7 +1252,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_product_flex_ratio' => array(
'message_product_flex_ratio' => array(
'title' => __( 'Pay Later Messaging ratio', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1258,7 +1278,7 @@ return array(
),
// Cart settings.
'button_cart_heading' => array(
'button_cart_heading' => array(
'heading' => __( 'Cart', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
'screens' => array(
@ -1269,7 +1289,7 @@ return array(
'gateway' => 'paypal',
'description' => __( 'Customize the appearance of PayPal Checkout on the cart page.', 'woocommerce-paypal-payments' ),
),
'button_cart_enabled' => array(
'button_cart_enabled' => array(
'title' => __( 'Buttons on Cart', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => __( 'Enable on Cart', 'woocommerce-paypal-payments' ),
@ -1281,7 +1301,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_cart_layout' => array(
'button_cart_layout' => array(
'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1303,7 +1323,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_cart_tagline' => array(
'button_cart_tagline' => array(
'title' => __( 'Tagline', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ),
@ -1320,7 +1340,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_cart_label' => array(
'button_cart_label' => array(
'title' => __( 'Button Label', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1347,7 +1367,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_cart_color' => array(
'button_cart_color' => array(
'title' => __( 'Color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1371,7 +1391,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_cart_shape' => array(
'button_cart_shape' => array(
'title' => __( 'Shape', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1394,7 +1414,7 @@ return array(
'gateway' => 'paypal',
),
'message_cart_heading' => array(
'message_cart_heading' => array(
'heading' => __( 'Pay Later on Cart', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
'screens' => array(
@ -1406,7 +1426,7 @@ return array(
'description' => str_replace( '<a>', '<a href="' . $messages_disclaimers->link_for_country() . '" target="_blank">', __( 'Displays Pay Later messaging for available offers. Restrictions apply. <a>Click here to learn more</a>. Pay Later button will show for eligible buyers and PayPal determines eligibility.', 'woocommerce-paypal-payments' ) ),
'class' => array( 'ppcp-subheading' ),
),
'message_cart_enabled' => array(
'message_cart_enabled' => array(
'title' => __( 'Enable message on Cart', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => sprintf( $container->get( 'wcgateway.settings.fields.pay-later-label' ), __( 'Enable on Cart', 'woocommerce-paypal-payments' ) ),
@ -1418,7 +1438,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_cart_layout' => array(
'message_cart_layout' => array(
'title' => __( 'Pay Later Messaging layout', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1440,7 +1460,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_cart_logo' => array(
'message_cart_logo' => array(
'title' => __( 'Pay Later Messaging logo', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1464,7 +1484,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_cart_position' => array(
'message_cart_position' => array(
'title' => __( 'Pay Later Messaging logo position', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1487,7 +1507,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_cart_color' => array(
'message_cart_color' => array(
'title' => __( 'Pay Later Messaging text color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1511,7 +1531,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_cart_flex_color' => array(
'message_cart_flex_color' => array(
'title' => __( 'Pay Later Messaging color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1538,7 +1558,7 @@ return array(
'requirements' => array( 'messages' ),
'gateway' => 'paypal',
),
'message_cart_flex_ratio' => array(
'message_cart_flex_ratio' => array(
'title' => __( 'Pay Later Messaging ratio', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1564,7 +1584,7 @@ return array(
),
// Mini cart settings.
'button_mini-cart_heading' => array(
'button_mini-cart_heading' => array(
'heading' => __( 'Mini Cart', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
'screens' => array(
@ -1575,7 +1595,7 @@ return array(
'gateway' => 'paypal',
'description' => __( 'Customize the appearance of PayPal Checkout on the Mini Cart.', 'woocommerce-paypal-payments' ),
),
'button_mini-cart_enabled' => array(
'button_mini-cart_enabled' => array(
'title' => __( 'Buttons on Mini Cart', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => __( 'Enable on Mini Cart', 'woocommerce-paypal-payments' ),
@ -1587,7 +1607,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_mini-cart_layout' => array(
'button_mini-cart_layout' => array(
'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1609,7 +1629,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_mini-cart_tagline' => array(
'button_mini-cart_tagline' => array(
'title' => __( 'Tagline', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => __( 'Enable tagline', 'woocommerce-paypal-payments' ),
@ -1626,7 +1646,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_mini-cart_label' => array(
'button_mini-cart_label' => array(
'title' => __( 'Button Label', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1653,7 +1673,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_mini-cart_color' => array(
'button_mini-cart_color' => array(
'title' => __( 'Color', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1677,7 +1697,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_mini-cart_shape' => array(
'button_mini-cart_shape' => array(
'title' => __( 'Shape', 'woocommerce-paypal-payments' ),
'type' => 'select',
'class' => array(),
@ -1699,7 +1719,7 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_mini-cart_height' => array(
'button_mini-cart_height' => array(
'title' => __( 'Button Height', 'woocommerce-paypal-payments' ),
'type' => 'number',
'default' => '35',
@ -1713,7 +1733,7 @@ return array(
'gateway' => 'paypal',
),
'disable_cards' => array(
'disable_cards' => array(
'title' => __( 'Disable specific credit cards', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-multiselect',
'class' => array(),
@ -1741,7 +1761,7 @@ return array(
),
'gateway' => 'dcc',
),
'card_icons' => array(
'card_icons' => array(
'title' => __( 'Show logo of the following credit cards', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-multiselect',
'class' => array(),
@ -1771,7 +1791,7 @@ return array(
),
'gateway' => 'dcc',
),
'3d_secure_heading' => array(
'3d_secure_heading' => array(
'heading' => __( '3D Secure', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
'description' => wp_kses_post(
@ -1799,7 +1819,7 @@ return array(
),
'gateway' => 'dcc',
),
'3d_secure_contingency' => array(
'3d_secure_contingency' => array(
'title' => __( 'Contingency for 3D Secure', 'woocommerce-paypal-payments' ),
'type' => 'select',
'description' => sprintf(
@ -2069,7 +2089,12 @@ return array(
},
'button.helper.vaulting-label' => static function ( ContainerInterface $container ): string {
$vaulting_label = __( 'Enable saved cards and subscription features on your store.', 'woocommerce-paypal-payments' );
$vaulting_label = sprintf(
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
__( 'Enable saved cards, PayPal accounts, and subscription features on your store. Payment methods are saved in the secure %1$sPayPal Vault%2$s.', 'woocommerce-paypal-payments' ),
'<a href="https://woocommerce.com/document/woocommerce-paypal-payments/#vaulting-saving-a-payment-method" target="_blank">',
'</a>'
);
if ( ! $container->get( 'wcgateway.helper.vaulting-scope' ) ) {
$vaulting_label .= sprintf(
@ -2084,7 +2109,20 @@ return array(
}
$vaulting_label .= '<p class="description">';
$vaulting_label .= __( 'This will disable all Pay Later messaging on your site.', 'woocommerce-paypal-payments' );
$vaulting_label .= sprintf(
// translators: %1$s, %2$s, %3$s and %4$s are the opening and closing of HTML <a> tag.
__( 'This will disable all %1$sPay Later%2$s features and %3$sAlternative Payment Methods%4$s on your site.', 'woocommerce-paypal-payments' ),
'<a
href="https://woocommerce.com/document/woocommerce-paypal-payments/#pay-later"
target="_blank"
>',
'</a>',
'<a
href="https://woocommerce.com/document/woocommerce-paypal-payments/#alternative-payment-methods"
target="_blank"
>',
'</a>'
);
$vaulting_label .= '</p>';
return $vaulting_label;

View file

@ -9,7 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
/**
* Class SettingsPageAssets
@ -30,15 +30,24 @@ class SettingsPageAssets {
*/
private $version;
/**
* The subscription helper.
*
* @var SubscriptionHelper
*/
protected $subscription_helper;
/**
* Assets constructor.
*
* @param string $module_url The url of this module.
* @param string $version The assets version.
* @param string $module_url The url of this module.
* @param string $version The assets version.
* @param SubscriptionHelper $subscription_helper The subscription helper.
*/
public function __construct( string $module_url, string $version ) {
$this->module_url = $module_url;
$this->version = $version;
public function __construct( string $module_url, string $version, SubscriptionHelper $subscription_helper ) {
$this->module_url = $module_url;
$this->version = $version;
$this->subscription_helper = $subscription_helper;
}
/**
@ -96,5 +105,14 @@ class SettingsPageAssets {
$this->version,
true
);
// Intent is configured with Authorize and Capture Virtual-Only Orders is not set.
wp_localize_script(
'ppcp-gateway-settings',
'PayPalCommerceGatewaySettings',
array(
'is_subscriptions_plugin_active' => $this->subscription_helper->plugin_is_active(),
)
);
}
}

View file

@ -53,8 +53,16 @@ trait ProcessPaymentTrait {
* @param int $customer_id The customer ID.
*/
protected function schedule_saved_payment_check( int $wc_order_id, int $customer_id ): void {
$timestamp = 1 * MINUTE_IN_SECONDS;
if (
$this->config->has( 'subscription_behavior_when_vault_fails' )
&& $this->config->get( 'subscription_behavior_when_vault_fails' ) === 'capture_auth'
) {
$timestamp = 0;
}
as_schedule_single_action(
time() + ( 1 * MINUTE_IN_SECONDS ),
time() + $timestamp,
'woocommerce_paypal_payments_check_saved_payment',
array(
'order_id' => $wc_order_id,

View file

@ -443,6 +443,10 @@ $data_rows_html
<?php if ( $description ) : ?>
<p class="<?php echo 'ppcp-heading' === $config['type'] ? '' : 'description'; ?>"><?php echo wp_kses_post( $description ); ?></p>
<?php endif; ?>
<?php if ( isset( $config['description_with_tip'] ) && $config['description_with_tip'] ) : ?>
<p class="<?php echo 'description'; ?>"><?php echo wp_kses_post( $config['description_with_tip'] ); ?></p>
<?php endif; ?>
</td>
</tr>
<?php

View file

@ -155,7 +155,8 @@ class WCGatewayModule implements ModuleInterface {
if ( $c->has( 'wcgateway.url' ) ) {
$assets = new SettingsPageAssets(
$c->get( 'wcgateway.url' ),
$c->get( 'ppcp.asset-version' )
$c->get( 'ppcp.asset-version' ),
$c->get( 'subscription.helper' )
);
$assets->register_assets();
}

View file

@ -3,6 +3,7 @@
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\TestCase;
use function Brain\Monkey\Functions\when;
use Mockery;
@ -13,8 +14,9 @@ class SettingsPagesAssetsTest extends TestCase
{
$moduleUrl = 'http://example.com/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-wc-gateway';
$modulePath = '/var/www/html/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-wc-gateway';
$subscriptionsHelper = Mockery::mock(SubscriptionHelper::class);
$testee = new SettingsPageAssets($moduleUrl, $modulePath);
$testee = new SettingsPageAssets($moduleUrl, $modulePath, $subscriptionsHelper);
when('is_admin')
->justReturn(true);