From 6d215c83060c7a10885d80443a8410210c9847fa Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Fri, 8 Jul 2022 16:25:07 +0400 Subject: [PATCH 01/27] Create the setting to switch the behavior. --- modules/ppcp-wc-gateway/services.php | 203 +++++++++++++++------------ 1 file changed, 111 insertions(+), 92 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 63a5a4814..9dadd094e 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -314,7 +314,7 @@ return array( $module_url = $container->get( 'wcgateway.url' ); $fields = array( - 'ppcp_onboarading_header' => array( + 'ppcp_onboarading_header' => array( 'type' => 'ppcp-text', 'classes' => array( 'ppcp-onboarding-element' ), 'text' => ' @@ -347,7 +347,7 @@ return array( 'gateway' => 'paypal', ), - 'credentials_production_heading' => array( + 'credentials_production_heading' => array( 'heading' => __( 'API Credentials', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-heading', 'screens' => array( @@ -357,7 +357,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'credentials_sandbox_heading' => array( + 'credentials_sandbox_heading' => array( 'heading' => __( 'Sandbox API Credentials', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-heading', 'screens' => array( @@ -369,7 +369,7 @@ return array( 'description' => __( 'Your account is connected to sandbox, no real charging takes place. To accept live payments, turn off sandbox mode and connect your live PayPal account.', 'woocommerce-paypal-payments' ), ), - 'ppcp_onboarading_options' => array( + 'ppcp_onboarading_options' => array( 'type' => 'ppcp-text', 'classes' => array( 'ppcp-onboarding-element' ), 'text' => $onboarding_options_renderer->render( $is_shop_supports_dcc ), @@ -385,7 +385,7 @@ return array( // We need to have a button for each option (ppcp, express) // because currently the only documented way to use the PayPal onboarding JS library // is to have the buttons before loading the script. - 'ppcp_onboarding_production_ppcp' => array( + 'ppcp_onboarding_production_ppcp' => array( 'type' => 'ppcp_onboarding', 'classes' => array( 'ppcp-onboarding-element' ), 'screens' => array( @@ -397,7 +397,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'ppcp_onboarding_production_express' => array( + 'ppcp_onboarding_production_express' => array( 'type' => 'ppcp_onboarding', 'classes' => array( 'ppcp-onboarding-element' ), 'screens' => array( @@ -409,7 +409,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'ppcp_onboarding_sandbox_ppcp' => array( + 'ppcp_onboarding_sandbox_ppcp' => array( 'type' => 'ppcp_onboarding', 'classes' => array( 'ppcp-onboarding-element' ), 'screens' => array( @@ -422,7 +422,7 @@ return array( 'gateway' => 'paypal', 'description' => __( 'Prior to accepting live payments, you can test payments on your WooCommerce platform in a safe PayPal sandbox environment.', 'woocommerce-paypal-payments' ), ), - 'ppcp_onboarding_sandbox_express' => array( + 'ppcp_onboarding_sandbox_express' => array( 'type' => 'ppcp_onboarding', 'classes' => array( 'ppcp-onboarding-element' ), 'screens' => array( @@ -436,7 +436,7 @@ return array( 'description' => __( 'Prior to accepting live payments, you can test payments on your WooCommerce platform in a safe PayPal sandbox environment.', 'woocommerce-paypal-payments' ), ), - 'ppcp_disconnect_production' => array( + 'ppcp_disconnect_production' => array( 'title' => __( 'Disconnect from PayPal', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-text', 'text' => '', @@ -449,7 +449,7 @@ return array( 'gateway' => 'paypal', 'description' => __( 'Click to reset current credentials and use another account.', 'woocommerce-paypal-payments' ), ), - 'ppcp_disconnect_sandbox' => array( + 'ppcp_disconnect_sandbox' => array( 'title' => __( 'Disconnect from PayPal Sandbox', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-text', 'text' => '', @@ -462,7 +462,7 @@ return array( 'gateway' => 'paypal', 'description' => __( 'Click to reset current credentials and use another account.', 'woocommerce-paypal-payments' ), ), - 'toggle_manual_input' => array( + 'toggle_manual_input' => array( 'type' => 'ppcp-text', 'text' => '', 'classes' => array( 'ppcp-onboarding-element' ), @@ -473,7 +473,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'error_label' => array( + 'error_label' => array( 'type' => 'ppcp-text', 'text' => '', 'classes' => array( 'hide', 'ppcp-always-shown-element' ), @@ -484,7 +484,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'sandbox_on' => array( + 'sandbox_on' => array( 'title' => __( 'Sandbox', 'woocommerce-paypal-payments' ), 'classes' => array( 'ppcp-onboarding-element', 'ppcp-always-shown-element' ), 'type' => 'checkbox', @@ -497,7 +497,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'merchant_email_production' => array( + 'merchant_email_production' => array( 'title' => __( 'Live Email address', 'woocommerce-paypal-payments' ), 'classes' => array( State::STATE_ONBOARDED === $state->production_state() ? 'onboarded' : '', 'ppcp-always-shown-element' ), 'type' => 'text', @@ -512,7 +512,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'merchant_id_production' => array( + 'merchant_id_production' => array( 'title' => __( 'Live Merchant Id', 'woocommerce-paypal-payments' ), 'classes' => array( State::STATE_ONBOARDED === $state->production_state() ? 'onboarded' : '', 'ppcp-always-shown-element' ), 'type' => 'ppcp-text-input', @@ -526,7 +526,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'client_id_production' => array( + 'client_id_production' => array( 'title' => __( 'Live Client Id', 'woocommerce-paypal-payments' ), 'classes' => array( State::STATE_ONBOARDED === $state->production_state() ? 'onboarded' : '', 'ppcp-always-shown-element' ), 'type' => 'ppcp-text-input', @@ -540,7 +540,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'client_secret_production' => array( + 'client_secret_production' => array( 'title' => __( 'Live Secret Key', 'woocommerce-paypal-payments' ), 'classes' => array( State::STATE_ONBOARDED === $state->production_state() ? 'onboarded' : '', 'ppcp-always-shown-element' ), 'type' => 'ppcp-password', @@ -555,7 +555,7 @@ return array( 'gateway' => 'paypal', ), - 'merchant_email_sandbox' => array( + 'merchant_email_sandbox' => array( 'title' => __( 'Sandbox Email address', 'woocommerce-paypal-payments' ), 'classes' => array( State::STATE_ONBOARDED === $state->sandbox_state() ? 'onboarded' : '', 'ppcp-always-shown-element' ), 'type' => 'text', @@ -570,7 +570,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'merchant_id_sandbox' => array( + 'merchant_id_sandbox' => array( 'title' => __( 'Sandbox Merchant Id', 'woocommerce-paypal-payments' ), 'classes' => array( State::STATE_ONBOARDED === $state->sandbox_state() ? 'onboarded' : '', 'ppcp-always-shown-element' ), 'type' => 'ppcp-text-input', @@ -584,7 +584,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'client_id_sandbox' => array( + 'client_id_sandbox' => array( 'title' => __( 'Sandbox Client Id', 'woocommerce-paypal-payments' ), 'classes' => array( State::STATE_ONBOARDED === $state->sandbox_state() ? 'onboarded' : '', 'ppcp-always-shown-element' ), 'type' => 'ppcp-text-input', @@ -598,7 +598,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'client_secret_sandbox' => array( + 'client_secret_sandbox' => array( 'title' => __( 'Sandbox Secret Key', 'woocommerce-paypal-payments' ), 'classes' => array( State::STATE_ONBOARDED === $state->sandbox_state() ? 'onboarded' : '', 'ppcp-always-shown-element' ), 'type' => 'ppcp-password', @@ -613,7 +613,7 @@ return array( 'gateway' => 'paypal', ), - 'checkout_settings_heading' => array( + 'checkout_settings_heading' => array( 'heading' => __( 'PayPal Checkout Settings', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-heading', 'screens' => array( @@ -623,7 +623,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'title' => array( + 'title' => array( 'title' => __( 'Title', 'woocommerce-paypal-payments' ), 'type' => 'text', 'description' => __( @@ -639,7 +639,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' ), @@ -654,7 +654,7 @@ return array( State::STATE_ONBOARDED, ), ), - 'dcc_gateway_title' => array( + 'dcc_gateway_title' => array( 'title' => __( 'Title', 'woocommerce-paypal-payments' ), 'type' => 'text', 'description' => __( @@ -671,7 +671,7 @@ return array( ), 'gateway' => 'dcc', ), - 'description' => array( + 'description' => array( 'title' => __( 'Description', 'woocommerce-paypal-payments' ), 'type' => 'text', 'desc_tip' => true, @@ -690,7 +690,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'intent' => array( + 'intent' => array( 'title' => __( 'Intent', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -712,7 +712,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, @@ -729,7 +729,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'payee_preferred' => array( + 'payee_preferred' => array( 'title' => __( 'Instant Payments ', 'woocommerce-paypal-payments' ), 'type' => 'checkbox', 'default' => false, @@ -746,7 +746,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' ), @@ -762,7 +762,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'landing_page' => array( + 'landing_page' => array( 'title' => __( 'Landing Page', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -784,7 +784,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(), @@ -808,7 +808,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'vault_enabled' => array( + 'vault_enabled' => array( 'title' => __( 'Vaulting', 'woocommerce-paypal-payments' ), 'type' => 'checkbox', 'desc_tip' => true, @@ -822,7 +822,26 @@ return array( 'gateway' => array( 'paypal', 'dcc' ), 'input_class' => $container->get( 'wcgateway.helper.vaulting-scope' ) ? array() : array( 'ppcp-disabled-checkbox' ), ), - 'logging_enabled' => 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, + 'label' => __( 'Determines the capture behavior for subscriptions if saving the payment method failed. This setting only applies when the intent capture is configured.', 'woocommerce-paypal-payments' ), + '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' ), + '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' ), + ), + 'screens' => array( + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => array( 'paypal', 'dcc' ), + ), + 'logging_enabled' => array( 'title' => __( 'Logging', 'woocommerce-paypal-payments' ), 'type' => 'checkbox', 'desc_tip' => true, @@ -837,7 +856,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'prefix' => array( + 'prefix' => array( 'title' => __( 'Invoice prefix', 'woocommerce-paypal-payments' ), 'type' => 'text', 'desc_tip' => true, @@ -861,7 +880,7 @@ return array( ), // General button styles. - 'button_style_heading' => array( + 'button_style_heading' => array( 'heading' => __( 'Checkout', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-heading', 'screens' => array( @@ -872,7 +891,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' ), @@ -884,7 +903,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_layout' => array( + 'button_layout' => array( 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -906,7 +925,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_tagline' => array( + 'button_tagline' => array( 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), 'type' => 'checkbox', 'default' => true, @@ -923,7 +942,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_label' => array( + 'button_label' => array( 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -950,7 +969,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_color' => array( + 'button_color' => array( 'title' => __( 'Color', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -974,7 +993,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_shape' => array( + 'button_shape' => array( 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -996,7 +1015,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( @@ -1008,7 +1027,7 @@ return array( 'description' => str_replace( '', '', __( 'Displays Pay Later messaging for available offers. Restrictions apply. Click here to learn more. 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' ) ), @@ -1020,7 +1039,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(), @@ -1042,7 +1061,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(), @@ -1066,7 +1085,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(), @@ -1089,7 +1108,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(), @@ -1113,7 +1132,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(), @@ -1140,7 +1159,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(), @@ -1166,7 +1185,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( @@ -1177,7 +1196,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' ), @@ -1189,7 +1208,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(), @@ -1211,7 +1230,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' ), @@ -1228,7 +1247,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(), @@ -1255,7 +1274,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_product_color' => array( + 'button_product_color' => array( 'title' => __( 'Color', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -1279,7 +1298,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_product_shape' => array( + 'button_product_shape' => array( 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -1302,7 +1321,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( @@ -1314,7 +1333,7 @@ return array( 'description' => str_replace( '', '', __( 'Displays Pay Later messaging for available offers. Restrictions apply. Click here to learn more. 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' ) ), @@ -1326,7 +1345,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(), @@ -1348,7 +1367,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(), @@ -1372,7 +1391,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(), @@ -1395,7 +1414,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(), @@ -1419,7 +1438,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(), @@ -1446,7 +1465,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(), @@ -1472,7 +1491,7 @@ return array( ), // Cart settings. - 'button_cart_heading' => array( + 'button_cart_heading' => array( 'heading' => __( 'Cart', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-heading', 'screens' => array( @@ -1483,7 +1502,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' ), @@ -1495,7 +1514,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(), @@ -1517,7 +1536,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' ), @@ -1534,7 +1553,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(), @@ -1561,7 +1580,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_cart_color' => array( + 'button_cart_color' => array( 'title' => __( 'Color', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -1585,7 +1604,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_cart_shape' => array( + 'button_cart_shape' => array( 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -1608,7 +1627,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( @@ -1620,7 +1639,7 @@ return array( 'description' => str_replace( '', '', __( 'Displays Pay Later messaging for available offers. Restrictions apply. Click here to learn more. 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' ) ), @@ -1632,7 +1651,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(), @@ -1654,7 +1673,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(), @@ -1678,7 +1697,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(), @@ -1701,7 +1720,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(), @@ -1725,7 +1744,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(), @@ -1752,7 +1771,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(), @@ -1778,7 +1797,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( @@ -1789,7 +1808,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' ), @@ -1801,7 +1820,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(), @@ -1823,7 +1842,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' ), @@ -1840,7 +1859,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(), @@ -1867,7 +1886,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(), @@ -1891,7 +1910,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(), @@ -1913,7 +1932,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', @@ -1927,7 +1946,7 @@ return array( 'gateway' => 'paypal', ), - 'disable_cards' => array( + 'disable_cards' => array( 'title' => __( 'Disable specific credit cards', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-multiselect', 'class' => array(), @@ -1955,7 +1974,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(), @@ -1985,7 +2004,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( @@ -2013,7 +2032,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( From 9ca0054e7ce7da7e786ae5356c81c179e6af38c2 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Fri, 8 Jul 2022 16:25:35 +0400 Subject: [PATCH 02/27] Hide the setting when vaulting is disabled. --- modules/ppcp-onboarding/assets/js/settings.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/ppcp-onboarding/assets/js/settings.js b/modules/ppcp-onboarding/assets/js/settings.js index 993c48edb..92ee06bc7 100644 --- a/modules/ppcp-onboarding/assets/js/settings.js +++ b/modules/ppcp-onboarding/assets/js/settings.js @@ -311,6 +311,13 @@ document.addEventListener( ] ); + groupToggle( + '#ppcp-vault_enabled', + [ + '#field-subscription_behavior_when_vault_fails', + ] + ); + groupToggleSelect( '#ppcp-intent', From e27ad82e12b2ac97c8346de9d29348da16d09694 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 11 Jul 2022 15:56:48 +0400 Subject: [PATCH 03/27] Change the method of manual renewal saving --- .../ppcp-vaulting/src/PaymentTokenChecker.php | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-vaulting/src/PaymentTokenChecker.php b/modules/ppcp-vaulting/src/PaymentTokenChecker.php index 604c7cc37..87b39bd59 100644 --- a/modules/ppcp-vaulting/src/PaymentTokenChecker.php +++ b/modules/ppcp-vaulting/src/PaymentTokenChecker.php @@ -28,6 +28,8 @@ class PaymentTokenChecker { use FreeTrialHandlerTrait; + const VAULTING_FAILED_META_KEY = '_ppcp_vaulting_failed'; + /** * The payment token repository. * @@ -115,7 +117,11 @@ class PaymentTokenChecker { } $tokens = $this->payment_token_repository->all_for_user_id( $customer_id ); - if ( $tokens ) { + + $subscription_behavior_when_vault_fails_setting_name = 'subscription_behavior_when_vault_fails'; + $subscription_behavior_when_vault_fails = $this->settings->get( $subscription_behavior_when_vault_fails_setting_name ); + + if ( $tokens || $subscription_behavior_when_vault_fails === 'capture_auth' ) { try { if ( $this->is_free_trial_order( $wc_order ) ) { if ( CreditCardGateway::ID === $wc_order->get_payment_method() @@ -129,7 +135,26 @@ class PaymentTokenChecker { return; } + if ( ! $tokens ) { + update_post_meta( $wc_order->get_id(), self::VAULTING_FAILED_META_KEY, $subscription_behavior_when_vault_fails ); + } $this->capture_authorized_payment( $wc_order ); + + if ( ! $tokens && $subscription_behavior_when_vault_fails === 'capture_auth' ) { + $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 the payment method could not be saved at PayPal', 'woocommerce-paypal-payments' ); + $wc_order->add_order_note( $message ); + + } catch ( Exception $exception ) { + $this->logger->error( "Could not update payment method on subscription #{$subscription->get_id()} " . $exception->getMessage() ); + } + } + } } catch ( Exception $exception ) { $this->logger->error( $exception->getMessage() ); } @@ -141,12 +166,14 @@ class PaymentTokenChecker { try { $order = $this->order_repository->for_wc_order( $wc_order ); + update_post_meta( $wc_order->get_id(), self::VAULTING_FAILED_META_KEY, $subscription_behavior_when_vault_fails ); $this->authorized_payments_processor->void_authorizations( $order ); } catch ( RuntimeException $exception ) { $this->logger->warning( $exception->getMessage() ); } $this->update_failed_status( $wc_order ); + } /** @@ -169,7 +196,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 because the payment method could not be saved at PayPal. Contact PayPal MTS for guidance.', 'woocommerce-paypal-payments' ); $wc_order->update_status( 'failed', $error_message ); /** From 25ac06057f9c9021a2a6b0c3c6a7b3958c717fec Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 11 Jul 2022 15:58:38 +0400 Subject: [PATCH 04/27] Filter failed vaulting emails for subscription orders --- modules/ppcp-vaulting/src/VaultingModule.php | 100 +++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/modules/ppcp-vaulting/src/VaultingModule.php b/modules/ppcp-vaulting/src/VaultingModule.php index 99184f096..038a815f8 100644 --- a/modules/ppcp-vaulting/src/VaultingModule.php +++ b/modules/ppcp-vaulting/src/VaultingModule.php @@ -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( '

The subscription payment failed because the payment method could not be saved. Please try again with a different payment method.

' ); + } + + if ( $subscription_behavior_when_vault_fails === 'capture_auth' ) { + echo wp_kses_post( '

Subscription set to Manual Renewal because the payment method could not be saved. To enable automatic renewal payments, please try a different payment method.

' ); + } + } + } + ); + + 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(); + } + } + } + } + ); } /** From 887cb45787a2ddcb902ac5c77eef8871c77b21d0 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 16 Aug 2022 11:29:38 +0200 Subject: [PATCH 05/27] Make strings translatables --- modules/ppcp-vaulting/src/VaultingModule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-vaulting/src/VaultingModule.php b/modules/ppcp-vaulting/src/VaultingModule.php index 038a815f8..aa772ff2b 100644 --- a/modules/ppcp-vaulting/src/VaultingModule.php +++ b/modules/ppcp-vaulting/src/VaultingModule.php @@ -193,11 +193,11 @@ class VaultingModule implements ModuleInterface { $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( '

The subscription payment failed because the payment method could not be saved. Please try again with a different payment method.

' ); + echo wp_kses_post( '

' . __( 'The subscription payment failed because the payment method could not be saved. Please try again with a different payment method.', 'woocommerce-paypal-payments' ) . '

' ); } if ( $subscription_behavior_when_vault_fails === 'capture_auth' ) { - echo wp_kses_post( '

Subscription set to Manual Renewal because the payment method could not be saved. To enable automatic renewal payments, please try a different payment method.

' ); + echo wp_kses_post( '

' . __( 'Subscription set to Manual Renewal because the payment method could not be saved. To enable automatic renewal payments, please try a different payment method.', 'woocommerce-paypal-payments' ) . '

' ); } } } From 2e814c8d386e4808851d2c3ee073e5da3cd5327c Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 16 Aug 2022 12:29:20 +0200 Subject: [PATCH 06/27] Allow use description and description tip at the same time --- modules/ppcp-wc-gateway/services.php | 28 +++++++++---------- .../src/Settings/SettingsRenderer.php | 4 +++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 34f8d5a2d..81f259ce7 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -862,23 +862,23 @@ return array( 'input_class' => $container->get( 'wcgateway.helper.vaulting-scope' ) ? array() : array( 'ppcp-disabled-checkbox' ), ), '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, - 'label' => __( 'Determines the capture behavior for subscriptions if saving the payment method failed. This setting only applies when the intent capture is configured.', 'woocommerce-paypal-payments' ), - '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' ), - 'options' => 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 the capture behavior for subscriptions if saving the payment method failed. This setting only applies when the intent capture is configured.', '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' ), ), - 'screens' => array( + 'screens' => array( State::STATE_ONBOARDED, ), - 'requirements' => array(), - 'gateway' => array( 'paypal', 'dcc' ), + 'requirements' => array(), + 'gateway' => array( 'paypal', 'dcc' ), ), 'logging_enabled' => array( 'title' => __( 'Logging', 'woocommerce-paypal-payments' ), @@ -917,7 +917,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'card_billing_data_mode' => array( + 'card_billing_data_mode' => array( 'title' => __( 'Card billing data handling', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -937,7 +937,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, diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php b/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php index cfcce2a15..d18e3bb86 100644 --- a/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php +++ b/modules/ppcp-wc-gateway/src/Settings/SettingsRenderer.php @@ -433,6 +433,10 @@ $data_rows_html

+ + +

+ Date: Tue, 16 Aug 2022 15:04:18 +0200 Subject: [PATCH 07/27] Do not schedule check saved payment if subscription behavior when fail is capture auth --- .../ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php index 25902e227..1b57294d7 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php +++ b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php @@ -53,6 +53,13 @@ trait ProcessPaymentTrait { * @param int $customer_id The customer ID. */ protected function schedule_saved_payment_check( int $wc_order_id, int $customer_id ): void { + if ( + $this->config->has( 'subscription_behavior_when_vault_fails' ) + && $this->config->get( 'subscription_behavior_when_vault_fails' ) === 'capture_auth' + ) { + return; + } + as_schedule_single_action( time() + ( 1 * MINUTE_IN_SECONDS ), 'woocommerce_paypal_payments_check_saved_payment', From b1a49a9af15c6ea5c116b92d0fc5d4899eefee9e Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 16 Aug 2022 15:55:13 +0200 Subject: [PATCH 08/27] Do not delay scheduled action when subscription behavior is capture auth --- modules/ppcp-vaulting/src/PaymentTokenChecker.php | 4 ++-- modules/ppcp-vaulting/src/VaultingModule.php | 2 +- modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-vaulting/src/PaymentTokenChecker.php b/modules/ppcp-vaulting/src/PaymentTokenChecker.php index b6df7496a..c9035fda2 100644 --- a/modules/ppcp-vaulting/src/PaymentTokenChecker.php +++ b/modules/ppcp-vaulting/src/PaymentTokenChecker.php @@ -148,7 +148,7 @@ class PaymentTokenChecker { $subscription->set_requires_manual_renewal( true ); $subscription->save(); - $message = __( 'Subscription set to Manual Renewal because the payment method could not be saved at PayPal', 'woocommerce-paypal-payments' ); + $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 ) { @@ -197,7 +197,7 @@ class PaymentTokenChecker { * @param WC_Order $wc_order The WC order. */ private function update_failed_status( WC_Order $wc_order ): void { - $error_message = __( 'Subscription payment failed because the payment method could not be saved at PayPal. Contact PayPal MTS for guidance.', '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 ); /** diff --git a/modules/ppcp-vaulting/src/VaultingModule.php b/modules/ppcp-vaulting/src/VaultingModule.php index aa772ff2b..669e0b9ff 100644 --- a/modules/ppcp-vaulting/src/VaultingModule.php +++ b/modules/ppcp-vaulting/src/VaultingModule.php @@ -197,7 +197,7 @@ class VaultingModule implements ModuleInterface { } if ( $subscription_behavior_when_vault_fails === 'capture_auth' ) { - echo wp_kses_post( '

' . __( 'Subscription set to Manual Renewal because the payment method could not be saved. To enable automatic renewal payments, please try a different payment method.', 'woocommerce-paypal-payments' ) . '

' ); + echo wp_kses_post( '

' . __( 'The subscription has been activated but the payment method could not be saved. Please try again with a different payment method to allow automatic renewal payments.', 'woocommerce-paypal-payments' ) . '

' ); } } } diff --git a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php index 1b57294d7..da17f822b 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php +++ b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php @@ -53,15 +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' ) { - return; + $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, From ae11b15164eedc1276c714a587d058850dff4ad5 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 2 Sep 2022 12:59:53 +0200 Subject: [PATCH 09/27] Do not show subscription behavior setting if subscriptions plugin is not active --- .../assets/css/order-edit-page.css | 1 + .../assets/js/order-edit-page-style.js | 1 + .../assets/js/order-edit-page.js | 1 + modules/ppcp-vaulting/src/VaultingModule.php | 2 +- .../resources/js/gateway-settings.js | 4 +++ modules/ppcp-wc-gateway/services.php | 23 ++++++++++++-- .../src/Assets/SettingsPageAssets.php | 30 +++++++++++++++---- .../ppcp-wc-gateway/src/WCGatewayModule.php | 3 +- 8 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 modules/ppcp-order-tracking/assets/css/order-edit-page.css create mode 100644 modules/ppcp-order-tracking/assets/js/order-edit-page-style.js create mode 100644 modules/ppcp-order-tracking/assets/js/order-edit-page.js diff --git a/modules/ppcp-order-tracking/assets/css/order-edit-page.css b/modules/ppcp-order-tracking/assets/css/order-edit-page.css new file mode 100644 index 000000000..2d8631b4a --- /dev/null +++ b/modules/ppcp-order-tracking/assets/css/order-edit-page.css @@ -0,0 +1 @@ +#ppcp_order-tracking .tracking-info-message{padding-left:20px}#ppcp_order-tracking .error{color:red;font-weight:bold}#ppcp_order-tracking .success{color:green;font-weight:bold}#ppcp_order-tracking input,#ppcp_order-tracking select{width:100%} \ No newline at end of file diff --git a/modules/ppcp-order-tracking/assets/js/order-edit-page-style.js b/modules/ppcp-order-tracking/assets/js/order-edit-page-style.js new file mode 100644 index 000000000..19f5d8548 --- /dev/null +++ b/modules/ppcp-order-tracking/assets/js/order-edit-page-style.js @@ -0,0 +1 @@ +(()=>{"use strict";var __webpack_modules__={705:(__unused_webpack_module,__unused_webpack___webpack_exports__,__webpack_require__)=>{eval('/* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = (__webpack_require__.p + "css/order-edit-page.css");//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiNzA1LmpzIiwibWFwcGluZ3MiOiJBQUFBLHNFQUFlLHFCQUF1Qiw0QkFBNEIiLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9wcGNwLW9yZGVyLXRyYWNraW5nLy4vcmVzb3VyY2VzL2Nzcy9vcmRlci1lZGl0LXBhZ2Uuc2Nzcz83YTdmIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IF9fd2VicGFja19wdWJsaWNfcGF0aF9fICsgXCJjc3Mvb3JkZXItZWRpdC1wYWdlLmNzc1wiOyJdLCJuYW1lcyI6W10sInNvdXJjZVJvb3QiOiIifQ==\n//# sourceURL=webpack-internal:///705\n')}},__webpack_require__={};__webpack_require__.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),(()=>{var e;__webpack_require__.g.importScripts&&(e=__webpack_require__.g.location+"");var _=__webpack_require__.g.document;if(!e&&_&&(_.currentScript&&(e=_.currentScript.src),!e)){var r=_.getElementsByTagName("script");r.length&&(e=r[r.length-1].src)}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),__webpack_require__.p=e+"../"})();var __webpack_exports__={};__webpack_modules__[705](0,__webpack_exports__,__webpack_require__)})(); \ No newline at end of file diff --git a/modules/ppcp-order-tracking/assets/js/order-edit-page.js b/modules/ppcp-order-tracking/assets/js/order-edit-page.js new file mode 100644 index 000000000..c9d6e7c8c --- /dev/null +++ b/modules/ppcp-order-tracking/assets/js/order-edit-page.js @@ -0,0 +1 @@ +(()=>{"use strict";var __webpack_modules__={673:()=>{eval("\n;// CONCATENATED MODULE: ../ppcp-button/resources/js/modules/Helper/CheckoutMethodState.js\nconst PaymentMethods = {\n PAYPAL: 'ppcp-gateway',\n CARDS: 'ppcp-credit-card-gateway',\n OXXO: 'ppcp-oxxo-gateway',\n CARD_BUTTON: 'ppcp-card-button-gateway'\n};\nconst ORDER_BUTTON_SELECTOR = '#place_order';\nconst getCurrentPaymentMethod = () => {\n const el = document.querySelector('input[name=\"payment_method\"]:checked');\n\n if (!el) {\n return null;\n }\n\n return el.value;\n};\nconst isSavedCardSelected = () => {\n const savedCardList = document.querySelector('#saved-credit-card');\n return savedCardList && savedCardList.value !== '';\n};\n;// CONCATENATED MODULE: ./resources/js/order-edit-page.js\n\ndocument.addEventListener('DOMContentLoaded', () => {\n const config = PayPalCommerceGatewayOrderTrackingInfo;\n\n if (!typeof PayPalCommerceGatewayOrderTrackingInfo) {\n console.error('trackign cannot be set.');\n return;\n }\n\n const transactionId = document.querySelector('.ppcp-tracking-transaction_id');\n const trackingNumber = document.querySelector('.ppcp-tracking-tracking_number');\n const status = document.querySelector('.ppcp-tracking-status');\n const carrier = document.querySelector('.ppcp-tracking-carrier');\n const orderId = document.querySelector('.ppcp-order_id');\n const submitButton = document.querySelector('.submit_tracking_info');\n submitButton.addEventListener('click', function (event) {\n submitButton.setAttribute('disabled', 'disabled');\n fetch(config.ajax.tracking_info.endpoint, {\n method: 'POST',\n body: JSON.stringify({\n nonce: config.ajax.tracking_info.nonce,\n transaction_id: transactionId ? transactionId.value : null,\n tracking_number: trackingNumber ? trackingNumber.value : null,\n status: status ? status.value : null,\n carrier: carrier ? carrier.value : null,\n order_id: orderId ? orderId.value : null,\n action: submitButton ? submitButton.dataset.action : null\n })\n }).then(function (res) {\n return res.json();\n }).then(function (data) {\n if (!data.success) {\n console.error(data);\n throw Error(data.data.message);\n }\n\n jQuery(\"\" + data.data.message + \"\").insertAfter(submitButton);\n setTimeout(() => jQuery('.tracking-info-message').remove(), 3000);\n submitButton.dataset.action = 'update';\n submitButton.textContent = 'update';\n submitButton.removeAttribute('disabled');\n });\n });\n});//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiNjczLmpzIiwibWFwcGluZ3MiOiI7O0FBQU8sTUFBTUEsY0FBYyxHQUFHO0VBQzFCQyxNQUFNLEVBQUUsY0FEa0I7RUFFMUJDLEtBQUssRUFBRSwwQkFGbUI7RU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W5mby5lbmRwb2ludCwge1xuICAgICAgICAgICAgICAgIG1ldGhvZDogJ1BPU1QnLFxuICAgICAgICAgICAgICAgIGJvZHk6IEpTT04uc3RyaW5naWZ5KHtcbiAgICAgICAgICAgICAgICAgICAgbm9uY2U6IGNvbmZpZy5hamF4LnRyYWNraW5nX2luZm8ubm9uY2UsXG4gICAgICAgICAgICAgICAgICAgIHRyYW5zYWN0aW9uX2lkOiB0cmFuc2FjdGlvbklkID8gdHJhbnNhY3Rpb25JZC52YWx1ZSA6IG51bGwsXG4gICAgICAgICAgICAgICAgICAgIHRyYWNraW5nX251bWJlcjogdHJhY2tpbmdOdW1iZXIgPyB0cmFja2luZ051bWJlci52YWx1ZSA6IG51bGwsXG4gICAgICAgICAgICAgICAgICAgIHN0YXR1czogc3RhdHVzID8gc3RhdHVzLnZhbHVlIDogbnVsbCxcbiAgICAgICAgICAgICAgICAgICAgY2FycmllcjogY2FycmllciA/IGNhcnJpZXIudmFsdWUgOiBudWxsLFxuICAgICAgICAgICAgICAgICAgICBvcmRlcl9pZDogb3JkZXJJZCA/IG9yZGVySWQudmFsdWUgOiBudWxsLFxuICAgICAgICAgICAgICAgICAgICBhY3Rpb246IHN1Ym1pdEJ1dHRvbiA/IHN1Ym1pdEJ1dHRvbi5kYXRhc2V0LmFjdGlvbiA6IG51bGwsXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH0pLnRoZW4oZnVuY3Rpb24gKHJlcykge1xuICAgICAgICAgICAgICAgIHJldHVybiByZXMuanNvbigpO1xuICAgICAgICAgICAgfSkudGhlbihmdW5jdGlvbiAoZGF0YSkge1xuICAgICAgICAgICAgICAgIGlmICghZGF0YS5zdWNjZXNzKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoZGF0YSk7XG4gICAgICAgICAgICAgICAgICAgIHRocm93IEVycm9yKGRhdGEuZGF0YS5tZXNzYWdlKTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAg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V0Y2giLCJhamF4IiwidHJhY2tpbmdfaW5mbyIsImVuZHBvaW50IiwibWV0aG9kIiwiYm9keSIsIkpTT04iLCJzdHJpbmdpZnkiLCJub25jZSIsInRyYW5zYWN0aW9uX2lkIiwidHJhY2tpbmdfbnVtYmVyIiwib3JkZXJfaWQiLCJhY3Rpb24iLCJkYXRhc2V0IiwidGhlbiIsInJlcyIsImpzb24iLCJkYXRhIiwic3VjY2VzcyIsIkVycm9yIiwibWVzc2FnZSIsImpRdWVyeSIsImluc2VydEFmdGVyIiwic2V0VGltZW91dCIsInJlbW92ZSIsInRleHRDb250ZW50IiwicmVtb3ZlQXR0cmlidXRlIl0sInNvdXJjZVJvb3QiOiIifQ==\n//# sourceURL=webpack-internal:///673\n")}},__webpack_exports__={};__webpack_modules__[673]()})(); \ No newline at end of file diff --git a/modules/ppcp-vaulting/src/VaultingModule.php b/modules/ppcp-vaulting/src/VaultingModule.php index 669e0b9ff..a680d580c 100644 --- a/modules/ppcp-vaulting/src/VaultingModule.php +++ b/modules/ppcp-vaulting/src/VaultingModule.php @@ -197,7 +197,7 @@ class VaultingModule implements ModuleInterface { } if ( $subscription_behavior_when_vault_fails === 'capture_auth' ) { - echo wp_kses_post( '

' . __( 'The subscription has been activated but the payment method could not be saved. Please try again with a different payment method to allow automatic renewal payments.', 'woocommerce-paypal-payments' ) . '

' ); + echo wp_kses_post( '

' . __( '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' ) . '

' ); } } } diff --git a/modules/ppcp-wc-gateway/resources/js/gateway-settings.js b/modules/ppcp-wc-gateway/resources/js/gateway-settings.js index 8e8cfe21b..cf9ee45bd 100644 --- a/modules/ppcp-wc-gateway/resources/js/gateway-settings.js +++ b/modules/ppcp-wc-gateway/resources/js/gateway-settings.js @@ -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'; + } } ); diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 81f259ce7..4c8fa1a37 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -869,7 +869,7 @@ return array( '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 the capture behavior for subscriptions if saving the payment method failed. This setting only applies when the intent capture is configured.', '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' ), @@ -2368,7 +2368,11 @@ 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( + __( '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' ), + '', + '' + ); if ( ! $container->get( 'wcgateway.helper.vaulting-scope' ) ) { $vaulting_label .= sprintf( @@ -2383,7 +2387,20 @@ return array( } $vaulting_label .= '

'; - $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 tag. + __( 'This will disable all %1$sPay Later%2$s features and %3$sAlternative Payment Methods%4$s on your site.', 'woocommerce-paypal-payments' ), + '', + '', + '', + '' + ); $vaulting_label .= '

'; return $vaulting_label; diff --git a/modules/ppcp-wc-gateway/src/Assets/SettingsPageAssets.php b/modules/ppcp-wc-gateway/src/Assets/SettingsPageAssets.php index 7a61aee9d..5926580ff 100644 --- a/modules/ppcp-wc-gateway/src/Assets/SettingsPageAssets.php +++ b/modules/ppcp-wc-gateway/src/Assets/SettingsPageAssets.php @@ -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(), + ) + ); } } diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index b6a30b4d1..bc9c73f7c 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -148,7 +148,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(); } From 85ad00293730c08593608c9325e45aa41785c703 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 2 Sep 2022 14:09:51 +0200 Subject: [PATCH 10/27] Fix phpunit --- tests/PHPUnit/WcGateway/Assets/SettingsPagesAssetsTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/PHPUnit/WcGateway/Assets/SettingsPagesAssetsTest.php b/tests/PHPUnit/WcGateway/Assets/SettingsPagesAssetsTest.php index 1827e02cc..23f32d100 100644 --- a/tests/PHPUnit/WcGateway/Assets/SettingsPagesAssetsTest.php +++ b/tests/PHPUnit/WcGateway/Assets/SettingsPagesAssetsTest.php @@ -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); From 8f5d5bf92a2f7cd4e6395b27d317dff1995e6c56 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 5 Sep 2022 09:16:08 +0200 Subject: [PATCH 11/27] Fix phpcs --- modules/ppcp-wc-gateway/services.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 4c8fa1a37..0505cbad3 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -2369,6 +2369,7 @@ return array( 'button.helper.vaulting-label' => static function ( ContainerInterface $container ): string { $vaulting_label = sprintf( + // translators: %1$s and %2$s are the opening and closing of HTML 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' ), '', '' From 073a13e1bf3b73b449b84cb9d8c21319cd0c28ec Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Fri, 9 Sep 2022 16:24:04 +0400 Subject: [PATCH 12/27] Resubscribe the WebHooks after updating plugin with newer version. --- modules/ppcp-webhooks/src/WebhookModule.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/ppcp-webhooks/src/WebhookModule.php b/modules/ppcp-webhooks/src/WebhookModule.php index b3ec62838..06e12c0f1 100644 --- a/modules/ppcp-webhooks/src/WebhookModule.php +++ b/modules/ppcp-webhooks/src/WebhookModule.php @@ -144,6 +144,21 @@ class WebhookModule implements ModuleInterface { $logger->error( 'Failed to load webhooks list: ' . $exception->getMessage() ); } } + + add_action( + 'woocommerce_paypal_payments_gateway_migrate', + static function () use ( $container ) { + $registrar = $container->get( 'webhook.registrar' ); + assert( $registrar instanceof WebhookRegistrar ); + add_action( + 'init', + function () use ( $registrar ) { + $registrar->unregister(); + $registrar->register(); + } + ); + } + ); } /** From a50ec0719d4743e5e15ebef28ff7b132c78141cb Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 14 Sep 2022 15:08:40 +0200 Subject: [PATCH 13/27] Ignore order tracking assets --- modules/ppcp-order-tracking/.gitignore | 2 +- modules/ppcp-order-tracking/assets/css/order-edit-page.css | 1 - modules/ppcp-order-tracking/assets/js/order-edit-page-style.js | 1 - modules/ppcp-order-tracking/assets/js/order-edit-page.js | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 modules/ppcp-order-tracking/assets/css/order-edit-page.css delete mode 100644 modules/ppcp-order-tracking/assets/js/order-edit-page-style.js delete mode 100644 modules/ppcp-order-tracking/assets/js/order-edit-page.js diff --git a/modules/ppcp-order-tracking/.gitignore b/modules/ppcp-order-tracking/.gitignore index f69a89f4b..265c2208c 100644 --- a/modules/ppcp-order-tracking/.gitignore +++ b/modules/ppcp-order-tracking/.gitignore @@ -1,2 +1,2 @@ node_modules -/assets +assets diff --git a/modules/ppcp-order-tracking/assets/css/order-edit-page.css b/modules/ppcp-order-tracking/assets/css/order-edit-page.css deleted file mode 100644 index 2d8631b4a..000000000 --- a/modules/ppcp-order-tracking/assets/css/order-edit-page.css +++ /dev/null @@ -1 +0,0 @@ -#ppcp_order-tracking .tracking-info-message{padding-left:20px}#ppcp_order-tracking .error{color:red;font-weight:bold}#ppcp_order-tracking .success{color:green;font-weight:bold}#ppcp_order-tracking input,#ppcp_order-tracking select{width:100%} \ No newline at end of file diff --git a/modules/ppcp-order-tracking/assets/js/order-edit-page-style.js b/modules/ppcp-order-tracking/assets/js/order-edit-page-style.js deleted file mode 100644 index 19f5d8548..000000000 --- a/modules/ppcp-order-tracking/assets/js/order-edit-page-style.js +++ /dev/null @@ -1 +0,0 @@ -(()=>{"use strict";var __webpack_modules__={705:(__unused_webpack_module,__unused_webpack___webpack_exports__,__webpack_require__)=>{eval('/* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = (__webpack_require__.p + "css/order-edit-page.css");//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiNzA1LmpzIiwibWFwcGluZ3MiOiJBQUFBLHNFQUFlLHFCQUF1Qiw0QkFBNEIiLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9wcGNwLW9yZGVyLXRyYWNraW5nLy4vcmVzb3VyY2VzL2Nzcy9vcmRlci1lZGl0LXBhZ2Uuc2Nzcz83YTdmIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IF9fd2VicGFja19wdWJsaWNfcGF0aF9fICsgXCJjc3Mvb3JkZXItZWRpdC1wYWdlLmNzc1wiOyJdLCJuYW1lcyI6W10sInNvdXJjZVJvb3QiOiIifQ==\n//# sourceURL=webpack-internal:///705\n')}},__webpack_require__={};__webpack_require__.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),(()=>{var e;__webpack_require__.g.importScripts&&(e=__webpack_require__.g.location+"");var _=__webpack_require__.g.document;if(!e&&_&&(_.currentScript&&(e=_.currentScript.src),!e)){var r=_.getElementsByTagName("script");r.length&&(e=r[r.length-1].src)}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),__webpack_require__.p=e+"../"})();var __webpack_exports__={};__webpack_modules__[705](0,__webpack_exports__,__webpack_require__)})(); \ No newline at end of file diff --git a/modules/ppcp-order-tracking/assets/js/order-edit-page.js b/modules/ppcp-order-tracking/assets/js/order-edit-page.js deleted file mode 100644 index c9d6e7c8c..000000000 --- a/modules/ppcp-order-tracking/assets/js/order-edit-page.js +++ /dev/null @@ -1 +0,0 @@ -(()=>{"use strict";var __webpack_modules__={673:()=>{eval("\n;// CONCATENATED MODULE: ../ppcp-button/resources/js/modules/Helper/CheckoutMethodState.js\nconst PaymentMethods = {\n PAYPAL: 'ppcp-gateway',\n CARDS: 'ppcp-credit-card-gateway',\n OXXO: 'ppcp-oxxo-gateway',\n CARD_BUTTON: 'ppcp-card-button-gateway'\n};\nconst ORDER_BUTTON_SELECTOR = '#place_order';\nconst getCurrentPaymentMethod = () => {\n const el = document.querySelector('input[name=\"payment_method\"]:checked');\n\n if (!el) {\n return null;\n }\n\n return el.value;\n};\nconst isSavedCardSelected = () => {\n const savedCardList = document.querySelector('#saved-credit-card');\n return savedCardList && savedCardList.value !== '';\n};\n;// CONCATENATED MODULE: ./resources/js/order-edit-page.js\n\ndocument.addEventListener('DOMContentLoaded', () => {\n const config = PayPalCommerceGatewayOrderTrackingInfo;\n\n if (!typeof PayPalCommerceGatewayOrderTrackingInfo) {\n console.error('trackign cannot be set.');\n return;\n }\n\n const transactionId = document.querySelector('.ppcp-tracking-transaction_id');\n const trackingNumber = document.querySelector('.ppcp-tracking-tracking_number');\n const status = document.querySelector('.ppcp-tracking-status');\n const carrier = document.querySelector('.ppcp-tracking-carrier');\n const orderId = document.querySelector('.ppcp-order_id');\n const submitButton = document.querySelector('.submit_tracking_info');\n submitButton.addEventListener('click', function (event) {\n submitButton.setAttribute('disabled', 'disabled');\n fetch(config.ajax.tracking_info.endpoint, {\n method: 'POST',\n body: JSON.stringify({\n nonce: config.ajax.tracking_info.nonce,\n transaction_id: transactionId ? transactionId.value : null,\n tracking_number: trackingNumber ? trackingNumber.value : null,\n status: status ? status.value : null,\n carrier: carrier ? carrier.value : null,\n order_id: orderId ? orderId.value : null,\n action: submitButton ? submitButton.dataset.action : null\n })\n }).then(function (res) {\n return res.json();\n }).then(function (data) {\n if (!data.success) {\n console.error(data);\n throw Error(data.data.message);\n }\n\n jQuery(\"\" + data.data.message + \"\").insertAfter(submitButton);\n setTimeout(() => jQuery('.tracking-info-message').remove(), 3000);\n submitButton.dataset.action = 'update';\n submitButton.textContent = 'update';\n submitButton.removeAttribute('disabled');\n });\n });\n});//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiNjczLmpzIiwibWFwcGluZ3MiOiI7O0FBQU8sTUFBTUEsY0FBYyxHQUFHO0VBQzFCQyxNQUFNLEVBQUUsY0FEa0I7RUFFMUJDLEtBQUssRUFBRSwwQkFGbUI7RUFHMUJDLElBQUksRUFBRSxtQkFIb0I7RUFJMUJDLFdBQVcsRUFBRTtBQUphLENBQXZCO0FBT0EsTUFBTUMscUJBQXFCLEdBQUcsY0FBOUI7QUFFQSxNQUFNQyx1QkFBdUIsR0FBRyxNQUFNO0VBQ3pDLE1BQU1DL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WNraW5nX2luZm8ubm9uY2UsXG4gICAgICAgICAgICAgICAgICAgIHRyYW5zYWN0aW9uX2lkOiB0cmFuc2FjdGlvbklkID8gdHJhbnNhY3Rpb25JZC52YWx1ZSA6IG51bGwsXG4gICAgICAgICAgICAgICAgICAgIHRyYWNraW5nX251bWJlcjogdHJhY2tpbmdOdW1iZXIgPyB0cmFja2luZ051bWJlci52YWx1ZSA6IG51bGwsXG4gICAgICAgICAgICAgICAgICAgIHN0YXR1czogc3RhdHVzID8gc3RhdHVzLnZhbHVlIDogbnVsbCxcbiAgICAgICAgICAgICAgICAgICAgY2FycmllcjogY2FycmllciA/IGNhcnJpZXIudmFsdWUgOiBudWxsLFxuICAgICAgICAgICAgICAgICAgICBvcmRlcl9pZDogb3JkZXJJZCA/IG9yZGVySWQudmFsdWUgOiBudWxsLFxuICAgICAgICAgICAgICAgICAgICBhY3Rpb246IHN1Ym1pdEJ1dHRvbiA/IHN1Ym1pdEJ1dHRvbi5kYXRhc2V0LmFjdGlvbiA6IG51bGwsXG4gICAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH0pLnRoZW4oZnVuY3Rpb24gKHJlcykge1xuICAgICAgICAgICAgICAgIHJldHVybiByZXMuanNvbigpO1xuICAgICAgICAgICAgfSkudGhlbihmdW5jdGlvbiAoZGF0YSkge1xuICAgICAgICAgICAgICAgIGlmICghZGF0YS5zdWNjZXNzKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoZGF0YSk7XG4gICAgICAgICAgICAgICAgICAgIHRocm93IEVycm9yKGRhdGEuZGF0YS5tZXNzYWdlKTtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBqUXVlcnkoIFwiPHNwYW4gY2xhc3M9J3N1Y2Nlc3MgdHJhY2tpbmctaW5mby1tZXNzYWdlJz5cIiArIGRhdGEuZGF0YS5tZXNzYWdlICsgXCI8L3NwYW4+XCIgKS5pbnNlcnRBZnRlcihzdWJtaXRCd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WQiLCJhY3Rpb24iLCJkYXRhc2V0IiwidGhlbiIsInJlcyIsImpzb24iLCJkYXRhIiwic3VjY2VzcyIsIkVycm9yIiwibWVzc2FnZSIsImpRdWVyeSIsImluc2VydEFmdGVyIiwic2V0VGltZW91dCIsInJlbW92ZSIsInRleHRDb250ZW50IiwicmVtb3ZlQXR0cmlidXRlIl0sInNvdXJjZVJvb3QiOiIifQ==\n//# sourceURL=webpack-internal:///673\n")}},__webpack_exports__={};__webpack_modules__[673]()})(); \ No newline at end of file From 9858bbb354a05bfea627d77c5b3a3dd5410d97a9 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 15 Sep 2022 12:44:44 +0200 Subject: [PATCH 14/27] Revert some changes after merge conflic resolve --- modules/ppcp-wc-gateway/services.php | 41 ++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index c438574cf..c30c7d8e8 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -574,6 +574,25 @@ return array( 'gateway' => array( 'paypal', 'dcc' ), 'input_class' => $container->get( 'wcgateway.helper.vaulting-scope' ) ? array() : array( 'ppcp-disabled-checkbox' ), ), + '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' ), + ), + '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', @@ -2026,7 +2045,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 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' ), + '', + '' + ); if ( ! $container->get( 'wcgateway.helper.vaulting-scope' ) ) { $vaulting_label .= sprintf( @@ -2041,7 +2065,20 @@ return array( } $vaulting_label .= '

'; - $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 tag. + __( 'This will disable all %1$sPay Later%2$s features and %3$sAlternative Payment Methods%4$s on your site.', 'woocommerce-paypal-payments' ), + '', + '', + '', + '' + ); $vaulting_label .= '

'; return $vaulting_label; From 5df633037ac0aa5f13c6ec60576b264a4e0ef3d2 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 26 Sep 2022 12:48:20 +0200 Subject: [PATCH 15/27] Add capture auth ignore to subs fail handler --- .../ppcp-vaulting/src/PaymentTokenChecker.php | 109 +++++++------ modules/ppcp-wc-gateway/services.php | 147 +++++++++--------- 2 files changed, 134 insertions(+), 122 deletions(-) diff --git a/modules/ppcp-vaulting/src/PaymentTokenChecker.php b/modules/ppcp-vaulting/src/PaymentTokenChecker.php index c9035fda2..002fe96a8 100644 --- a/modules/ppcp-vaulting/src/PaymentTokenChecker.php +++ b/modules/ppcp-vaulting/src/PaymentTokenChecker.php @@ -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; @@ -117,64 +118,74 @@ class PaymentTokenChecker { return; } - $tokens = $this->payment_token_repository->all_for_user_id( $customer_id ); - - $subscription_behavior_when_vault_fails_setting_name = 'subscription_behavior_when_vault_fails'; - $subscription_behavior_when_vault_fails = $this->settings->get( $subscription_behavior_when_vault_fails_setting_name ); - - if ( $tokens || $subscription_behavior_when_vault_fails === 'capture_auth' ) { - 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; - } - - if ( ! $tokens ) { - update_post_meta( $wc_order->get_id(), self::VAULTING_FAILED_META_KEY, $subscription_behavior_when_vault_fails ); - } - $this->capture_authorized_payment( $wc_order ); - - if ( ! $tokens && $subscription_behavior_when_vault_fails === 'capture_auth' ) { - $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->error( "Could not update payment method on subscription #{$subscription->get_id()} " . $exception->getMessage() ); - } - } - } - } 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 ); - update_post_meta( $wc_order->get_id(), self::VAULTING_FAILED_META_KEY, $subscription_behavior_when_vault_fails ); - $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->error( "Payment for subscription parent order #{$order_id} was not saved on 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->error( "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; + } } /** diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 34275f2cf..6701afc0f 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -387,7 +387,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( @@ -397,7 +397,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'title' => array( + 'title' => array( 'title' => __( 'Title', 'woocommerce-paypal-payments' ), 'type' => 'text', 'description' => __( @@ -413,7 +413,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' ), @@ -428,7 +428,7 @@ return array( State::STATE_ONBOARDED, ), ), - 'dcc_gateway_title' => array( + 'dcc_gateway_title' => array( 'title' => __( 'Title', 'woocommerce-paypal-payments' ), 'type' => 'text', 'description' => __( @@ -445,7 +445,7 @@ return array( ), 'gateway' => 'dcc', ), - 'description' => array( + 'description' => array( 'title' => __( 'Description', 'woocommerce-paypal-payments' ), 'type' => 'text', 'desc_tip' => true, @@ -464,7 +464,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'intent' => array( + 'intent' => array( 'title' => __( 'Intent', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -486,7 +486,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, @@ -503,7 +503,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'payee_preferred' => array( + 'payee_preferred' => array( 'title' => __( 'Instant Payments ', 'woocommerce-paypal-payments' ), 'type' => 'checkbox', 'default' => false, @@ -520,7 +520,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' ), @@ -536,7 +536,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'landing_page' => array( + 'landing_page' => array( 'title' => __( 'Landing Page', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -558,7 +558,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(), @@ -582,7 +582,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'vault_enabled' => array( + 'vault_enabled' => array( 'title' => __( 'Vaulting', 'woocommerce-paypal-payments' ), 'type' => 'checkbox', 'desc_tip' => true, @@ -606,8 +606,9 @@ return array( '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' ), + '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, @@ -615,7 +616,7 @@ return array( 'requirements' => array(), 'gateway' => array( 'paypal', 'dcc' ), ), - 'card_billing_data_mode' => array( + 'card_billing_data_mode' => array( 'title' => __( 'Card billing data handling', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -635,7 +636,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, @@ -651,7 +652,7 @@ return array( ), // General button styles. - 'button_style_heading' => array( + 'button_style_heading' => array( 'heading' => __( 'Checkout', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-heading', 'screens' => array( @@ -662,7 +663,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' ), @@ -674,7 +675,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_layout' => array( + 'button_layout' => array( 'title' => __( 'Button Layout', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -696,7 +697,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_tagline' => array( + 'button_tagline' => array( 'title' => __( 'Tagline', 'woocommerce-paypal-payments' ), 'type' => 'checkbox', 'default' => true, @@ -713,7 +714,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_label' => array( + 'button_label' => array( 'title' => __( 'Button Label', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -740,7 +741,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_color' => array( + 'button_color' => array( 'title' => __( 'Color', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -764,7 +765,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_shape' => array( + 'button_shape' => array( 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -786,7 +787,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( @@ -798,7 +799,7 @@ return array( 'description' => str_replace( '', '', __( 'Displays Pay Later messaging for available offers. Restrictions apply. Click here to learn more. 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' ) ), @@ -810,7 +811,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(), @@ -832,7 +833,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(), @@ -856,7 +857,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(), @@ -879,7 +880,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(), @@ -903,7 +904,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(), @@ -930,7 +931,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(), @@ -956,7 +957,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( @@ -967,7 +968,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' ), @@ -979,7 +980,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(), @@ -1001,7 +1002,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' ), @@ -1018,7 +1019,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(), @@ -1045,7 +1046,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_product_color' => array( + 'button_product_color' => array( 'title' => __( 'Color', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -1069,7 +1070,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_product_shape' => array( + 'button_product_shape' => array( 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -1092,7 +1093,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( @@ -1104,7 +1105,7 @@ return array( 'description' => str_replace( '', '', __( 'Displays Pay Later messaging for available offers. Restrictions apply. Click here to learn more. 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' ) ), @@ -1116,7 +1117,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(), @@ -1138,7 +1139,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(), @@ -1162,7 +1163,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(), @@ -1185,7 +1186,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(), @@ -1209,7 +1210,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(), @@ -1236,7 +1237,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(), @@ -1262,7 +1263,7 @@ return array( ), // Cart settings. - 'button_cart_heading' => array( + 'button_cart_heading' => array( 'heading' => __( 'Cart', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-heading', 'screens' => array( @@ -1273,7 +1274,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' ), @@ -1285,7 +1286,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(), @@ -1307,7 +1308,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' ), @@ -1324,7 +1325,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(), @@ -1351,7 +1352,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_cart_color' => array( + 'button_cart_color' => array( 'title' => __( 'Color', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -1375,7 +1376,7 @@ return array( 'requirements' => array(), 'gateway' => 'paypal', ), - 'button_cart_shape' => array( + 'button_cart_shape' => array( 'title' => __( 'Shape', 'woocommerce-paypal-payments' ), 'type' => 'select', 'class' => array(), @@ -1398,7 +1399,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( @@ -1410,7 +1411,7 @@ return array( 'description' => str_replace( '', '', __( 'Displays Pay Later messaging for available offers. Restrictions apply. Click here to learn more. 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' ) ), @@ -1422,7 +1423,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(), @@ -1444,7 +1445,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(), @@ -1468,7 +1469,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(), @@ -1491,7 +1492,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(), @@ -1515,7 +1516,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(), @@ -1542,7 +1543,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(), @@ -1568,7 +1569,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( @@ -1579,7 +1580,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' ), @@ -1591,7 +1592,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(), @@ -1613,7 +1614,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' ), @@ -1630,7 +1631,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(), @@ -1657,7 +1658,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(), @@ -1681,7 +1682,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(), @@ -1703,7 +1704,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', @@ -1717,7 +1718,7 @@ return array( 'gateway' => 'paypal', ), - 'disable_cards' => array( + 'disable_cards' => array( 'title' => __( 'Disable specific credit cards', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-multiselect', 'class' => array(), @@ -1745,7 +1746,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(), @@ -1775,7 +1776,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( @@ -1803,7 +1804,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( From 7e59b29a1286404fc1d6bc44cf9f93058f75614f Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 26 Sep 2022 15:53:13 +0200 Subject: [PATCH 16/27] Update logging messages --- modules/ppcp-vaulting/src/PaymentTokenChecker.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-vaulting/src/PaymentTokenChecker.php b/modules/ppcp-vaulting/src/PaymentTokenChecker.php index 002fe96a8..e798ec139 100644 --- a/modules/ppcp-vaulting/src/PaymentTokenChecker.php +++ b/modules/ppcp-vaulting/src/PaymentTokenChecker.php @@ -151,7 +151,7 @@ class PaymentTokenChecker { case 'void_auth': $order = $this->order_repository->for_wc_order( $wc_order ); $this->authorized_payments_processor->void_authorizations( $order ); - $this->logger->error( "Payment for subscription parent order #{$order_id} was not saved on PayPal." ); + $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': @@ -172,7 +172,7 @@ class PaymentTokenChecker { $wc_order->add_order_note( $message ); } catch ( Exception $exception ) { - $this->logger->error( "Could not update payment method on subscription #{$subscription->get_id()} " . $exception->getMessage() ); + $this->logger->warning( "Could not update payment method on subscription #{$subscription->get_id()} " . $exception->getMessage() ); } } break; From f94211bf3f088ee0f998d0b0c7bc23e5628c601c Mon Sep 17 00:00:00 2001 From: Alex P Date: Tue, 27 Sep 2022 16:49:40 +0300 Subject: [PATCH 17/27] Do not try updating gateway enabled on the connection tab --- .../ppcp-wc-gateway/src/Settings/SettingsListener.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php index 936c30633..0b4ff2274 100644 --- a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php +++ b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php @@ -281,12 +281,15 @@ class SettingsListener { $credentials_change_status = null; // Cannot detect on Card Processing page. - if ( PayPalGateway::ID === $this->page_id || Settings::CONNECTION_TAB_ID === $this->page_id ) { - $settings['enabled'] = isset( $_POST['woocommerce_ppcp-gateway_enabled'] ) - && 1 === absint( $_POST['woocommerce_ppcp-gateway_enabled'] ); - + if ( Settings::CONNECTION_TAB_ID === $this->page_id ) { $credentials_change_status = $this->determine_credentials_change_status( $settings ); } + + if ( PayPalGateway::ID === $this->page_id ) { + $settings['enabled'] = isset( $_POST['woocommerce_ppcp-gateway_enabled'] ) + && 1 === absint( $_POST['woocommerce_ppcp-gateway_enabled'] ); + } + // phpcs:enable phpcs:disable WordPress.Security.NonceVerification.Missing // phpcs:enable phpcs:disable WordPress.Security.NonceVerification.Missing if ( $credentials_change_status ) { From 153fc09a09271175bdfcab9b9c87a397df4f3f82 Mon Sep 17 00:00:00 2001 From: Alex P Date: Wed, 28 Sep 2022 11:45:00 +0300 Subject: [PATCH 18/27] Handle virtual-only auto-capture the same as normal capture Do not duplicate code and make it call payment_complete to handle the statuses properly. --- modules/ppcp-subscription/src/RenewalHandler.php | 8 ++------ modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/modules/ppcp-subscription/src/RenewalHandler.php b/modules/ppcp-subscription/src/RenewalHandler.php index 771a57c9d..2b96b2f34 100644 --- a/modules/ppcp-subscription/src/RenewalHandler.php +++ b/modules/ppcp-subscription/src/RenewalHandler.php @@ -203,12 +203,8 @@ class RenewalHandler { $this->handle_new_order_status( $order, $wc_order ); - if ( $this->capture_authorized_downloads( $order ) && AuthorizedPaymentsProcessor::SUCCESSFUL === $this->authorized_payments_processor->process( $wc_order ) ) { - $wc_order->add_order_note( - __( 'Payment successfully captured.', 'woocommerce-paypal-payments' ) - ); - $wc_order->update_meta_data( AuthorizedPaymentsProcessor::CAPTURED_META_KEY, 'true' ); - $wc_order->update_status( 'completed' ); + if ( $this->capture_authorized_downloads( $order ) ) { + $this->authorized_payments_processor->capture_authorized_payment( $wc_order ); } } diff --git a/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php b/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php index a621e88b5..7b9b80c55 100644 --- a/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php +++ b/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php @@ -210,12 +210,8 @@ class OrderProcessor { $this->handle_new_order_status( $order, $wc_order ); - if ( $this->capture_authorized_downloads( $order ) && AuthorizedPaymentsProcessor::SUCCESSFUL === $this->authorized_payments_processor->process( $wc_order ) ) { - $wc_order->add_order_note( - __( 'Payment successfully captured.', 'woocommerce-paypal-payments' ) - ); - $wc_order->update_meta_data( AuthorizedPaymentsProcessor::CAPTURED_META_KEY, 'true' ); - $wc_order->update_status( 'completed' ); + if ( $this->capture_authorized_downloads( $order ) ) { + $this->authorized_payments_processor->capture_authorized_payment( $wc_order ); } $this->last_error = ''; return true; From 2355083f51c62b5a28d3e473cedd04b113adbb84 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 28 Sep 2022 14:17:19 +0200 Subject: [PATCH 19/27] Do not render dcc tab if not available --- modules/ppcp-wc-gateway/services.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 62590006a..f8508f43b 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -243,6 +243,12 @@ return array( } } + $dcc_product_status = $container->get( 'wcgateway.helper.dcc-product-status' ); + assert( $dcc_product_status instanceof DCCProductStatus ); + if ( ! $dcc_product_status->dcc_is_active() ) { + unset( $sections['ppcp-credit-card-gateway'] ); + } + return $sections; }, 'wcgateway.settings.status' => static function ( ContainerInterface $container ): SettingsStatus { From 92ae16f99bb9e339a06c5cc6ad16f7426b3ef8a6 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 29 Sep 2022 14:34:11 +0200 Subject: [PATCH 20/27] Add short expiration time when ddc applies for country --- modules/ppcp-wc-gateway/services.php | 7 ++++++- .../src/Helper/DCCProductStatus.php | 20 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index f8508f43b..331a7ec3d 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1929,7 +1929,12 @@ return array( $settings = $container->get( 'wcgateway.settings' ); $partner_endpoint = $container->get( 'api.endpoint.partners' ); - return new DCCProductStatus( $settings, $partner_endpoint, $container->get( 'dcc.status-cache' ) ); + return new DCCProductStatus( + $settings, + $partner_endpoint, + $container->get( 'dcc.status-cache' ), + $container->get( 'api.helpers.dccapplies' ) + ); }, 'button.helper.messages-disclaimers' => static function ( ContainerInterface $container ): MessagesDisclaimers { diff --git a/modules/ppcp-wc-gateway/src/Helper/DCCProductStatus.php b/modules/ppcp-wc-gateway/src/Helper/DCCProductStatus.php index bd55cfbff..3c60fea55 100644 --- a/modules/ppcp-wc-gateway/src/Helper/DCCProductStatus.php +++ b/modules/ppcp-wc-gateway/src/Helper/DCCProductStatus.php @@ -13,6 +13,7 @@ use Throwable; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusProduct; use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache; +use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; /** @@ -49,21 +50,31 @@ class DCCProductStatus { */ private $partners_endpoint; + /** + * The dcc applies helper. + * + * @var DccApplies + */ + protected $dcc_applies; + /** * DccProductStatus constructor. * * @param Settings $settings The Settings. * @param PartnersEndpoint $partners_endpoint The Partner Endpoint. * @param Cache $cache The cache. + * @param DccApplies $dcc_applies The dcc applies helper. */ public function __construct( Settings $settings, PartnersEndpoint $partners_endpoint, - Cache $cache + Cache $cache, + DccApplies $dcc_applies ) { $this->settings = $settings; $this->partners_endpoint = $partners_endpoint; $this->cache = $cache; + $this->dcc_applies = $dcc_applies; } /** @@ -113,7 +124,12 @@ class DCCProductStatus { return true; } } - $this->cache->set( self::DCC_STATUS_CACHE_KEY, false, 3 * MONTH_IN_SECONDS ); + + $expiration = 3 * MONTH_IN_SECONDS; + if ( $this->dcc_applies->for_country_currency() ) { + $expiration = 3 * HOUR_IN_SECONDS; + } + $this->cache->set( self::DCC_STATUS_CACHE_KEY, false, $expiration ); $this->current_status_cache = false; return false; From cccc879f61fe73f284dc2c46a3193701e8d1c1bc Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 29 Sep 2022 14:37:03 +0200 Subject: [PATCH 21/27] Fix psalm --- .psalm/stubs.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.psalm/stubs.php b/.psalm/stubs.php index 00ece2e4e..863e769e7 100644 --- a/.psalm/stubs.php +++ b/.psalm/stubs.php @@ -5,3 +5,6 @@ if (!defined('EP_PAGES')) { if (!defined('MONTH_IN_SECONDS')) { define('MONTH_IN_SECONDS', 30 * DAY_IN_SECONDS); } +if (!defined('HOUR_IN_SECONDS')) { + define('HOUR_IN_SECONDS', 60 * MINUTE_IN_SECONDS); +} From a01c209ad635823328d1694ea432917271d027da Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 30 Sep 2022 09:18:07 +0200 Subject: [PATCH 22/27] Do not include credit card section if it does not apply for country currency --- modules/ppcp-wc-gateway/services.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 331a7ec3d..aed95972a 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -245,7 +245,9 @@ return array( $dcc_product_status = $container->get( 'wcgateway.helper.dcc-product-status' ); assert( $dcc_product_status instanceof DCCProductStatus ); - if ( ! $dcc_product_status->dcc_is_active() ) { + $dcc_applies = $container->get( 'api.helpers.dccapplies' ); + assert( $dcc_applies instanceof DccApplies ); + if ( ! $dcc_product_status->dcc_is_active() || ! $dcc_applies->for_country_currency() ) { unset( $sections['ppcp-credit-card-gateway'] ); } From c3c3a7425868ad4e787f339971d29c54883d7649 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 30 Sep 2022 16:16:11 +0200 Subject: [PATCH 23/27] Bump 1.9.4 version --- changelog.txt | 11 +++++++++++ package.json | 2 +- readme.txt | 13 ++++++++++++- woocommerce-paypal-payments.php | 4 ++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/changelog.txt b/changelog.txt index b60c7a0c5..91cd6e901 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,16 @@ *** Changelog *** += 1.9.4 - TBD = +* Add - Create new connection tab #801 +* Add - Functionality to choose subscription failure behavior #728 +* Fix - Virtual-only orders always move order status to completed #868 +* Fix - PayPal order created twice when context is checkout #832 +* Enhancement - Handle unsupported browsers better #843 +* Enhancement - Combine the Webhooks Status page into a new Connection tab (891) #827 +* Enhancement - Hide PayPal Card Processing tab is not available in country or for merchant #870 +* Enhancement - Resubscribe webhooks on plugin upgrades #838 +* Enhancement - PUI-relevant webhook not subscribed to #842 + = 1.9.3 - 2022-08-31 = * Add - Tracking API #792 * Fix - Improve compatibility with Siteground Optimizer plugin #797 diff --git a/package.json b/package.json index b09a58a1f..dfb76a0cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "woocommerce-paypal-payments", - "version": "1.9.3", + "version": "1.9.4", "description": "WooCommerce PayPal Payments", "repository": "https://github.com/woocommerce/woocommerce-paypal-payments", "license": "GPL-2.0", diff --git a/readme.txt b/readme.txt index 2e2fbed94..6043fc08f 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: woocommerce, paypal, payments, ecommerce, e-commerce, store, sales, sell, Requires at least: 5.3 Tested up to: 6.0 Requires PHP: 7.1 -Stable tag: 1.9.3 +Stable tag: 1.9.4 License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -81,6 +81,17 @@ Follow the steps below to connect the plugin to your PayPal account: == Changelog == += 1.9.4 = +* Add - Create new connection tab #801 +* Add - Functionality to choose subscription failure behavior #728 +* Fix - Virtual-only orders always move order status to completed #868 +* Fix - PayPal order created twice when context is checkout #832 +* Enhancement - Handle unsupported browsers better #843 +* Enhancement - Combine the Webhooks Status page into a new Connection tab (891) #827 +* Enhancement - Hide PayPal Card Processing tab is not available in country or for merchant #870 +* Enhancement - Resubscribe webhooks on plugin upgrades #838 +* Enhancement - PUI-relevant webhook not subscribed to #842 + = 1.9.3 = * Add - Tracking API #792 * Fix - Improve compatibility with Siteground Optimizer plugin #797 diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php index f4ddc2404..96d2c7336 100644 --- a/woocommerce-paypal-payments.php +++ b/woocommerce-paypal-payments.php @@ -3,13 +3,13 @@ * Plugin Name: WooCommerce PayPal Payments * Plugin URI: https://woocommerce.com/products/woocommerce-paypal-payments/ * Description: PayPal's latest complete payments processing solution. Accept PayPal, Pay Later, credit/debit cards, alternative digital wallets local payment types and bank accounts. Turn on only PayPal options or process a full suite of payment methods. Enable global transaction with extensive currency and country coverage. - * Version: 1.9.3 + * Version: 1.9.4 * Author: WooCommerce * Author URI: https://woocommerce.com/ * License: GPL-2.0 * Requires PHP: 7.1 * WC requires at least: 3.9 - * WC tested up to: 6.8 + * WC tested up to: 6.9 * Text Domain: woocommerce-paypal-payments * * @package WooCommerce\PayPalCommerce From 112de1ab8ee46fedc208af8db8e75ae4d1d7b70e Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 30 Sep 2022 16:28:16 +0200 Subject: [PATCH 24/27] Fix typo --- changelog.txt | 2 +- readme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.txt b/changelog.txt index 91cd6e901..5f1515f4d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -7,7 +7,7 @@ * Fix - PayPal order created twice when context is checkout #832 * Enhancement - Handle unsupported browsers better #843 * Enhancement - Combine the Webhooks Status page into a new Connection tab (891) #827 -* Enhancement - Hide PayPal Card Processing tab is not available in country or for merchant #870 +* Enhancement - Hide PayPal Card Processing tab if not available in country or for merchant #870 * Enhancement - Resubscribe webhooks on plugin upgrades #838 * Enhancement - PUI-relevant webhook not subscribed to #842 diff --git a/readme.txt b/readme.txt index 6043fc08f..4884a61fe 100644 --- a/readme.txt +++ b/readme.txt @@ -88,7 +88,7 @@ Follow the steps below to connect the plugin to your PayPal account: * Fix - PayPal order created twice when context is checkout #832 * Enhancement - Handle unsupported browsers better #843 * Enhancement - Combine the Webhooks Status page into a new Connection tab (891) #827 -* Enhancement - Hide PayPal Card Processing tab is not available in country or for merchant #870 +* Enhancement - Hide PayPal Card Processing tab if not available in country or for merchant #870 * Enhancement - Resubscribe webhooks on plugin upgrades #838 * Enhancement - PUI-relevant webhook not subscribed to #842 From bd243cad8983babed53fe093dfa996a714ed100a Mon Sep 17 00:00:00 2001 From: Alex P Date: Mon, 3 Oct 2022 12:40:07 +0300 Subject: [PATCH 25/27] Remove WC logo during onboarding --- modules/ppcp-api-client/src/Repository/PartnerReferralsData.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php index d1ea64f64..a955dcf23 100644 --- a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php +++ b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php @@ -79,7 +79,6 @@ class PartnerReferralsData { 'ppcp_partner_referrals_data', array( 'partner_config_override' => array( - 'partner_logo_url' => 'https://connect.woocommerce.com/images/woocommerce_logo.png', /** * Returns the URL which will be opened at the end of onboarding. */ From d02137cb1ea78bc12efff4782da0618ca2ed6240 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 4 Oct 2022 09:47:58 +0200 Subject: [PATCH 26/27] Update changelog --- changelog.txt | 1 + readme.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/changelog.txt b/changelog.txt index 5f1515f4d..ddf414ea9 100644 --- a/changelog.txt +++ b/changelog.txt @@ -10,6 +10,7 @@ * Enhancement - Hide PayPal Card Processing tab if not available in country or for merchant #870 * Enhancement - Resubscribe webhooks on plugin upgrades #838 * Enhancement - PUI-relevant webhook not subscribed to #842 +* Enhancement - Remove WC logo during onboarding #881 = 1.9.3 - 2022-08-31 = * Add - Tracking API #792 diff --git a/readme.txt b/readme.txt index 4884a61fe..84132db07 100644 --- a/readme.txt +++ b/readme.txt @@ -91,6 +91,7 @@ Follow the steps below to connect the plugin to your PayPal account: * Enhancement - Hide PayPal Card Processing tab if not available in country or for merchant #870 * Enhancement - Resubscribe webhooks on plugin upgrades #838 * Enhancement - PUI-relevant webhook not subscribed to #842 +* Enhancement - Remove WC logo during onboarding #881 = 1.9.3 = * Add - Tracking API #792 From cd9065c57891d43cb13d839b29fedba83e62762a Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 5 Oct 2022 19:07:37 +0400 Subject: [PATCH 27/27] Add filters and hooks --- .../src/Endpoint/OrderTrackingEndpoint.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php b/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php index 33283f685..ebb406b18 100644 --- a/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php +++ b/modules/ppcp-order-tracking/src/Endpoint/OrderTrackingEndpoint.php @@ -117,14 +117,17 @@ class OrderTrackingEndpoint { $url = trailingslashit( $this->host ) . 'v1/shipping/trackers-batch'; $body = array( - 'trackers' => array( $data ), + 'trackers' => array( (array) apply_filters( 'woocommerce_paypal_payments_tracking_data_before_sending', $data, $order_id ) ), ); - $args = array( + $args = array( 'method' => 'POST', 'headers' => $this->request_headers(), 'body' => wp_json_encode( $body ), ); + + do_action( 'woocommerce_paypal_payments_before_tracking_is_added', $order_id, $data ); + $response = $this->request( $url, $args ); if ( is_wp_error( $response ) ) { @@ -169,6 +172,8 @@ class OrderTrackingEndpoint { } update_post_meta( $order_id, '_ppcp_paypal_tracking_number', $data['tracking_number'] ?? '' ); + + do_action( 'woocommerce_paypal_payments_after_tracking_is_added', $order_id, $response ); } /** @@ -243,9 +248,11 @@ class OrderTrackingEndpoint { $args = array( 'method' => 'PUT', 'headers' => $this->request_headers(), - 'body' => wp_json_encode( $data ), + 'body' => wp_json_encode( (array) apply_filters( 'woocommerce_paypal_payments_tracking_data_before_update', $data, $order_id ) ), ); + do_action( 'woocommerce_paypal_payments_before_tracking_is_updated', $order_id, $data ); + $response = $this->request( $url, $args ); if ( is_wp_error( $response ) ) { @@ -290,6 +297,8 @@ class OrderTrackingEndpoint { } update_post_meta( $order_id, '_ppcp_paypal_tracking_number', $data['tracking_number'] ?? '' ); + + do_action( 'woocommerce_paypal_payments_after_tracking_is_updated', $order_id, $response ); } /**