From db7749cb7257be5d7a2e713657bfacccfb4e1235 Mon Sep 17 00:00:00 2001 From: RT3 Date: Tue, 1 Feb 2022 09:52:06 -0600 Subject: [PATCH 01/18] Update 3D Secure Change the 3D SECURE contingency to SCA_ALWAYS --- modules/ppcp-wc-gateway/services.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 57fb1d73d..db6422f7e 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1914,12 +1914,12 @@ return array( ), 'class' => array(), 'input_class' => array( 'wc-enhanced-select' ), - 'default' => $container->get( 'api.shop.is-psd2-country' ) ? '3D_SECURE' : 'NO_3D_SECURE', + 'default' => $container->get( 'api.shop.is-psd2-country' ) ? 'SCA_ALWAYS' : 'NO_3D_SECURE', 'desc_tip' => true, 'options' => array( 'NO_3D_SECURE' => __( 'No 3D Secure (transaction will be denied if 3D Secure is required)', 'woocommerce-paypal-payments' ), 'SCA_WHEN_REQUIRED' => __( '3D Secure when required', 'woocommerce-paypal-payments' ), - '3D_SECURE' => __( 'Always trigger 3D Secure', 'woocommerce-paypal-payments' ), + 'SCA_ALWAYS' => __( 'Always trigger 3D Secure', 'woocommerce-paypal-payments' ), ), 'screens' => array( State::STATE_ONBOARDED, From bb24635e2074aeb5b02dd15200deaae42eb3f6e3 Mon Sep 17 00:00:00 2001 From: RT3 Date: Tue, 1 Feb 2022 10:05:26 -0600 Subject: [PATCH 02/18] Change default to SCA_WHEN_REQUIRED --- modules/ppcp-wc-gateway/services.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index db6422f7e..6ab80957f 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1914,7 +1914,7 @@ return array( ), 'class' => array(), 'input_class' => array( 'wc-enhanced-select' ), - 'default' => $container->get( 'api.shop.is-psd2-country' ) ? 'SCA_ALWAYS' : 'NO_3D_SECURE', + 'default' => $container->get( 'api.shop.is-psd2-country' ) ? 'SCA_WHEN_REQUIRED' : 'NO_3D_SECURE', 'desc_tip' => true, 'options' => array( 'NO_3D_SECURE' => __( 'No 3D Secure (transaction will be denied if 3D Secure is required)', 'woocommerce-paypal-payments' ), From 3b0a057b317d479f5dbf84acab6a560a6ac3d424 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 3 Feb 2022 12:05:55 +0100 Subject: [PATCH 03/18] Ensure 3ds contingency uses `SCA_ALWAYS` instead of `3D_SECURE` --- .../ppcp-button/src/Assets/SmartButton.php | 4 ++++ .../src/Settings/SettingsListener.php | 20 ++++++++++++++++++- .../ppcp-wc-gateway/src/WCGatewayModule.php | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index 667560dbc..7b39454b3 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -627,6 +627,10 @@ class SmartButton implements SmartButtonInterface { if ( $this->settings->has( '3d_secure_contingency' ) ) { $value = $this->settings->get( '3d_secure_contingency' ); if ( $value ) { + if ( '3D_SECURE' === $value ) { + $value = 'SCA_ALWAYS'; + } + return $value; } } diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php index b3db8d3a6..c55109541 100644 --- a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php +++ b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php @@ -14,9 +14,9 @@ use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer; use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache; use WooCommerce\PayPalCommerce\Onboarding\State; -use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; use WooCommerce\PayPalCommerce\Webhooks\WebhookRegistrar; +use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException; /** * Class SettingsListener @@ -208,6 +208,24 @@ class SettingsListener { exit; } + /** + * Ensure 3DS contingency use `SCA_ALWAYS` instead of `3D_SECURE`. + * + * @throws NotFoundException When a setting was not found. + */ + public function listen_for_3d_secure_contingency() { + if ( ! $this->is_valid_site_request() || $this->settings->get( '3d_secure_contingency' ) !== '3D_SECURE' ) { + return; + } + + $this->settings->set( '3d_secure_contingency', 'SCA_ALWAYS' ); + $this->settings->persist(); + + $redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' ); + wp_safe_redirect( $redirect_url, 302 ); + exit; + } + /** * Listens to the request. * diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index 5de6680d6..f3c7d9aee 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -183,6 +183,7 @@ class WCGatewayModule implements ModuleInterface { */ $listener->listen_for_merchant_id(); $listener->listen_for_vaulting_enabled(); + $listener->listen_for_3d_secure_contingency(); } ); From d12a9d3547e58ece7ff88346ed19c94a7e3cb4cf Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 3 Feb 2022 12:11:22 +0100 Subject: [PATCH 04/18] Fix psalm --- modules/ppcp-wc-gateway/src/Settings/SettingsListener.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php index c55109541..6da931c9a 100644 --- a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php +++ b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php @@ -211,9 +211,10 @@ class SettingsListener { /** * Ensure 3DS contingency use `SCA_ALWAYS` instead of `3D_SECURE`. * + * @return void * @throws NotFoundException When a setting was not found. */ - public function listen_for_3d_secure_contingency() { + public function listen_for_3d_secure_contingency(): void { if ( ! $this->is_valid_site_request() || $this->settings->get( '3d_secure_contingency' ) !== '3D_SECURE' ) { return; } From 632113a7814c6736fca450ba1cba24a611e8bcc0 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Thu, 3 Feb 2022 16:54:34 +0400 Subject: [PATCH 05/18] Change the onboarding message --- modules/ppcp-wc-gateway/src/Notice/ConnectAdminNotice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/src/Notice/ConnectAdminNotice.php b/modules/ppcp-wc-gateway/src/Notice/ConnectAdminNotice.php index 0f0ee59eb..25b880d74 100644 --- a/modules/ppcp-wc-gateway/src/Notice/ConnectAdminNotice.php +++ b/modules/ppcp-wc-gateway/src/Notice/ConnectAdminNotice.php @@ -57,7 +57,7 @@ class ConnectAdminNotice { $message = sprintf( /* translators: %1$s the gateway name. */ __( - 'PayPal Checkout is almost ready. To get started, connect your account.', + 'PayPal Payments is almost ready. To get started, connect your account.', 'woocommerce-paypal-payments' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' ) From 53b017ae313199e52057dece055835f14b722431 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 3 Feb 2022 16:23:23 +0100 Subject: [PATCH 06/18] Move ensure 3ds contingency logic to `woocommerce_paypal_payments_gateway_migrate` action --- .../src/Settings/SettingsListener.php | 19 ------------------- .../ppcp-wc-gateway/src/WCGatewayModule.php | 12 +++++++++++- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php index 6da931c9a..ba2f4b08c 100644 --- a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php +++ b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php @@ -208,25 +208,6 @@ class SettingsListener { exit; } - /** - * Ensure 3DS contingency use `SCA_ALWAYS` instead of `3D_SECURE`. - * - * @return void - * @throws NotFoundException When a setting was not found. - */ - public function listen_for_3d_secure_contingency(): void { - if ( ! $this->is_valid_site_request() || $this->settings->get( '3d_secure_contingency' ) !== '3D_SECURE' ) { - return; - } - - $this->settings->set( '3d_secure_contingency', 'SCA_ALWAYS' ); - $this->settings->persist(); - - $redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' ); - wp_safe_redirect( $redirect_url, 302 ); - exit; - } - /** * Listens to the request. * diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index f3c7d9aee..0d68d86f4 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -132,6 +132,17 @@ class WCGatewayModule implements ModuleInterface { $endpoint->handle_request(); } ); + + add_action( + 'woocommerce_paypal_payments_gateway_migrate', + static function () use ( $c ) { + $settings = $c->get( 'wcgateway.settings' ); + if ( $settings->get( '3d_secure_contingency' ) === '3D_SECURE' ) { + $settings->set( '3d_secure_contingency', 'SCA_ALWAYS' ); + $settings->persist(); + } + } + ); } /** @@ -183,7 +194,6 @@ class WCGatewayModule implements ModuleInterface { */ $listener->listen_for_merchant_id(); $listener->listen_for_vaulting_enabled(); - $listener->listen_for_3d_secure_contingency(); } ); From eb514dd0fe17cdc8f77a834668bb2c6ddb025644 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 3 Feb 2022 16:26:22 +0100 Subject: [PATCH 07/18] Not needed, option value is already updated after plugin upgrade --- modules/ppcp-button/src/Assets/SmartButton.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index 7b39454b3..667560dbc 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -627,10 +627,6 @@ class SmartButton implements SmartButtonInterface { if ( $this->settings->has( '3d_secure_contingency' ) ) { $value = $this->settings->get( '3d_secure_contingency' ); if ( $value ) { - if ( '3D_SECURE' === $value ) { - $value = 'SCA_ALWAYS'; - } - return $value; } } From f16045f34329b0fa33497b7bbff7b03b9d2d1103 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 3 Feb 2022 16:30:37 +0100 Subject: [PATCH 08/18] Assert settings instance --- modules/ppcp-wc-gateway/src/WCGatewayModule.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index 0d68d86f4..a9184bf5c 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -137,6 +137,8 @@ class WCGatewayModule implements ModuleInterface { 'woocommerce_paypal_payments_gateway_migrate', static function () use ( $c ) { $settings = $c->get( 'wcgateway.settings' ); + assert( $settings instanceof Settings ); + if ( $settings->get( '3d_secure_contingency' ) === '3D_SECURE' ) { $settings->set( '3d_secure_contingency', 'SCA_ALWAYS' ); $settings->persist(); From 7b132f9d92e54df72860045210383c9672250a7e Mon Sep 17 00:00:00 2001 From: dinamiko Date: Fri, 4 Feb 2022 17:11:40 +0100 Subject: [PATCH 09/18] Get payer info from checkout form (WIP) --- .../src/Factory/PayerFactory.php | 20 +++++++++++++++++++ .../src/Endpoint/CreateOrderEndpoint.php | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/modules/ppcp-api-client/src/Factory/PayerFactory.php b/modules/ppcp-api-client/src/Factory/PayerFactory.php index fedeaa5a1..c0e10de61 100644 --- a/modules/ppcp-api-client/src/Factory/PayerFactory.php +++ b/modules/ppcp-api-client/src/Factory/PayerFactory.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\ApiClient\Factory; +use WooCommerce\PayPalCommerce\ApiClient\Entity\Address; use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer; use WooCommerce\PayPalCommerce\ApiClient\Entity\PayerName; use WooCommerce\PayPalCommerce\ApiClient\Entity\PayerTaxInfo; @@ -147,4 +148,23 @@ class PayerFactory { $tax_info ); } + + public function from_checkout_form(array $data) { + + $first_name = $data['billing_first_name'] ?? ''; + $last_name = $data['billing_last_name'] ?? ''; + $billing_email = $data['billing_email'] ?? ''; + $billing_country = $data['billing_country'] ?? ''; + $billing_address_1 = $data['billing_address_1'] ?? ''; + + return new Payer( + new PayerName($first_name, $last_name), + $billing_email, + '', + new Address( + $billing_country, + $billing_address_1 + ) + ); + } } diff --git a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php index 4a7f63348..a7d62fae3 100644 --- a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php +++ b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php @@ -12,8 +12,10 @@ namespace WooCommerce\PayPalCommerce\Button\Endpoint; use Exception; use Psr\Log\LoggerInterface; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint; +use WooCommerce\PayPalCommerce\ApiClient\Entity\Address; use WooCommerce\PayPalCommerce\ApiClient\Entity\Order; use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer; +use WooCommerce\PayPalCommerce\ApiClient\Entity\PayerName; use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentMethod; use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit; use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException; @@ -337,6 +339,12 @@ class CreateOrderEndpoint implements EndpointInterface { $payer = $this->payer_factory->from_paypal_response( json_decode( wp_json_encode( $data['payer'] ) ) ); } + + if(!$payer && isset($data['form'])) { + parse_str($data['form'], $output); + return $this->payer_factory->from_checkout_form($output); + } + return $payer; } From 849b02e44f895848358369266a9d0e4863c6e8f9 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 7 Feb 2022 11:07:06 +0100 Subject: [PATCH 10/18] Caught `NotFoundException` in case it does not exist --- modules/ppcp-wc-gateway/src/WCGatewayModule.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index a9184bf5c..ee8746ca5 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -21,6 +21,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Assets\SettingsPageAssets; use WooCommerce\PayPalCommerce\WcGateway\Checkout\CheckoutPayPalAddressPreset; use WooCommerce\PayPalCommerce\WcGateway\Checkout\DisableGateways; use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint; +use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice; @@ -139,9 +140,13 @@ class WCGatewayModule implements ModuleInterface { $settings = $c->get( 'wcgateway.settings' ); assert( $settings instanceof Settings ); - if ( $settings->get( '3d_secure_contingency' ) === '3D_SECURE' ) { - $settings->set( '3d_secure_contingency', 'SCA_ALWAYS' ); - $settings->persist(); + try { + if ( $settings->get( '3d_secure_contingency' ) === '3D_SECURE' ) { + $settings->set( '3d_secure_contingency', 'SCA_ALWAYS' ); + $settings->persist(); + } + } catch ( NotFoundException $exception ) { + return; } } ); From 033269ae50a16b9627b79bc3256f697906d8be46 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 7 Feb 2022 11:18:59 +0100 Subject: [PATCH 11/18] Update readme and changelog --- changelog.txt | 2 +- readme.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/changelog.txt b/changelog.txt index 2314e02d4..d6448106d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,7 +1,7 @@ *** Changelog *** = 1.6.5 - 2022-01-31 = -* Fix - Allow guest users to purchase subscription products #422 +* Fix - Allow guest users to purchase subscription products from checkout page #422 * Fix - Transaction ID missing for renewal order #424 * Fix - Save your credit card checkbox should be removed in pay for order for subscriptions #420 * Fix - Null currency error when the Aelia currency switcher plugin is active #426 diff --git a/readme.txt b/readme.txt index f01ee26dd..b607564d9 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: woocommerce, automattic Tags: woocommerce, paypal, payments, ecommerce, e-commerce, store, sales, sell, shop, shopping, cart, checkout Requires at least: 5.3 -Tested up to: 5.8 +Tested up to: 5.9 Requires PHP: 7.1 Stable tag: 1.6.5 License: GPLv2 @@ -82,7 +82,7 @@ Follow the steps below to connect the plugin to your PayPal account: == Changelog == = 1.6.5 = -* Fix - Allow guest users to purchase subscription products #422 +* Fix - Allow guest users to purchase subscription products from checkout page #422 * Fix - Transaction ID missing for renewal order #424 * Fix - Save your credit card checkbox should be removed in pay for order for subscriptions #420 * Fix - Null currency error when the Aelia currency switcher plugin is active #426 From ac9c0c982c58351ccaa4f3c338d9176c9261cdbf Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 7 Feb 2022 12:50:24 +0100 Subject: [PATCH 12/18] Add transaction id to order note when refund is received through webhook --- .../src/Handler/PaymentCaptureRefunded.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php b/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php index bc56dd935..f2a5ae632 100644 --- a/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php +++ b/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php @@ -150,6 +150,17 @@ class PaymentCaptureRefunded implements RequestHandler { 'order' => $wc_order, ) ); + + if ( isset( $request['resource']['id'] ) ) { + $wc_order->add_order_note( + sprintf( + /* translators: %s is the PayPal transaction ID */ + __( 'PayPal transaction ID: %s', 'woocommerce-paypal-payments' ), + $request['resource']['id'] + ) + ); + } + $response['success'] = true; return rest_ensure_response( $response ); } From 2c37b7c6021108f4312618ad5b43e36a8938c310 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 7 Feb 2022 12:57:35 +0100 Subject: [PATCH 13/18] Fix psalm error --- modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php b/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php index f2a5ae632..d271f7ac8 100644 --- a/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php +++ b/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php @@ -156,7 +156,7 @@ class PaymentCaptureRefunded implements RequestHandler { sprintf( /* translators: %s is the PayPal transaction ID */ __( 'PayPal transaction ID: %s', 'woocommerce-paypal-payments' ), - $request['resource']['id'] + $request['resource']['id'] ?? '' ) ); } From da37cbb2e55404b1be5c97b568d7853055915c9b Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 7 Feb 2022 14:26:24 +0100 Subject: [PATCH 14/18] Fix psalm error --- modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php b/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php index d271f7ac8..6a59a61ef 100644 --- a/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php +++ b/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php @@ -151,12 +151,12 @@ class PaymentCaptureRefunded implements RequestHandler { ) ); - if ( isset( $request['resource']['id'] ) ) { + if ( is_array( $request['resource'] ) && isset( $request['resource']['id'] ) ) { $wc_order->add_order_note( sprintf( /* translators: %s is the PayPal transaction ID */ __( 'PayPal transaction ID: %s', 'woocommerce-paypal-payments' ), - $request['resource']['id'] ?? '' + $request['resource']['id'] ) ); } From a0fc703efa5c7955d067c671125a57a4ffb52496 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 7 Feb 2022 17:51:03 +0400 Subject: [PATCH 15/18] Improve Disable Funding setting label and desc --- modules/ppcp-wc-gateway/services.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 6ab80957f..1442531a2 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -671,15 +671,20 @@ return array( 'gateway' => 'paypal', ), 'disable_funding' => array( - 'title' => __( 'Disable funding sources', 'woocommerce-paypal-payments' ), + 'title' => __( 'Hide Funding Source(s)', 'woocommerce-paypal-payments' ), 'type' => 'ppcp-multiselect', 'class' => array(), 'input_class' => array( 'wc-enhanced-select' ), 'default' => array(), - 'desc_tip' => true, - 'description' => __( - 'By default all possible funding sources will be shown. You can disable some sources, if you wish.', - 'woocommerce-paypal-payments' + 'desc_tip' => false, + 'description' => sprintf( + // translators: %1$s and %2$s are the opening and closing of HTML tag. + __( 'By default, all possible funding sources will be shown. This setting can disable funding sources such as Credit Cards, Pay Later, Venmo, or other %1$sAlternative Payment Methods%2$s.', 'woocommerce-paypal-payments' ), + '', + '' ), 'options' => array( 'card' => _x( 'Credit or debit cards', 'Name of payment method', 'woocommerce-paypal-payments' ), @@ -1919,7 +1924,7 @@ return array( 'options' => array( 'NO_3D_SECURE' => __( 'No 3D Secure (transaction will be denied if 3D Secure is required)', 'woocommerce-paypal-payments' ), 'SCA_WHEN_REQUIRED' => __( '3D Secure when required', 'woocommerce-paypal-payments' ), - 'SCA_ALWAYS' => __( 'Always trigger 3D Secure', 'woocommerce-paypal-payments' ), + 'SCA_ALWAYS' => __( 'Always trigger 3D Secure', 'woocommerce-paypal-payments' ), ), 'screens' => array( State::STATE_ONBOARDED, From e3ac3ccc160f47b2f0d175292e814ab910077b3c Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 7 Feb 2022 15:07:08 +0100 Subject: [PATCH 16/18] Set WC order transaction id, it also adds order note --- .../src/Handler/PaymentCaptureRefunded.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php b/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php index 6a59a61ef..ed85bc040 100644 --- a/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php +++ b/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php @@ -10,13 +10,14 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\Webhooks\Handler; use Psr\Log\LoggerInterface; +use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait; /** * Class PaymentCaptureRefunded */ class PaymentCaptureRefunded implements RequestHandler { - use PrefixTrait; + use PrefixTrait, TransactionIdHandlingTrait; /** * The logger. @@ -152,13 +153,7 @@ class PaymentCaptureRefunded implements RequestHandler { ); if ( is_array( $request['resource'] ) && isset( $request['resource']['id'] ) ) { - $wc_order->add_order_note( - sprintf( - /* translators: %s is the PayPal transaction ID */ - __( 'PayPal transaction ID: %s', 'woocommerce-paypal-payments' ), - $request['resource']['id'] - ) - ); + $this->update_transaction_id( $request['resource']['id'], $wc_order, $this->logger ); } $response['success'] = true; From 0947031c3f3bba39644b10f0d455c86f037d2423 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 7 Feb 2022 16:25:29 +0100 Subject: [PATCH 17/18] Ensure email exist otherwise do not return payer object --- .../src/Factory/PayerFactory.php | 47 +++++++++++++++---- .../src/Endpoint/CreateOrderEndpoint.php | 9 ++-- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/modules/ppcp-api-client/src/Factory/PayerFactory.php b/modules/ppcp-api-client/src/Factory/PayerFactory.php index c0e10de61..788b6e280 100644 --- a/modules/ppcp-api-client/src/Factory/PayerFactory.php +++ b/modules/ppcp-api-client/src/Factory/PayerFactory.php @@ -149,22 +149,51 @@ class PayerFactory { ); } - public function from_checkout_form(array $data) { + /** + * Returns a Payer object based off the given checkout form fields. + * + * @param array $form_fields The checkout form fields. + * @return Payer + */ + public function from_checkout_form( array $form_fields ): Payer { - $first_name = $data['billing_first_name'] ?? ''; - $last_name = $data['billing_last_name'] ?? ''; - $billing_email = $data['billing_email'] ?? ''; - $billing_country = $data['billing_country'] ?? ''; - $billing_address_1 = $data['billing_address_1'] ?? ''; + $first_name = $form_fields['billing_first_name'] ?? ''; + $last_name = $form_fields['billing_last_name'] ?? ''; + $billing_email = $form_fields['billing_email'] ?? ''; + $billing_country = $form_fields['billing_country'] ?? ''; + $billing_address_1 = $form_fields['billing_address_1'] ?? ''; + $billing_address_2 = $form_fields['billing_address_2'] ?? ''; + $admin_area_1 = $form_fields['billing_state'] ?? ''; + $admin_area_2 = $form_fields['billing_city'] ?? ''; + $billing_postcode = $form_fields['billing_postcode'] ?? ''; + + $phone = null; + if ( isset( $form_fields['billing_phone'] ) && '' !== $form_fields['billing_phone'] ) { + // make sure the phone number contains only numbers and is max 14. chars long. + $national_number = $form_fields['billing_phone']; + $national_number = preg_replace( '/[^0-9]/', '', $national_number ); + $national_number = substr( $national_number, 0, 14 ); + + $phone = new PhoneWithType( + 'HOME', + new Phone( $national_number ) + ); + } return new Payer( - new PayerName($first_name, $last_name), + new PayerName( $first_name, $last_name ), $billing_email, '', new Address( $billing_country, - $billing_address_1 - ) + $billing_address_1, + $billing_address_2, + $admin_area_1, + $admin_area_2, + $billing_postcode + ), + null, + $phone ); } } diff --git a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php index a7d62fae3..ec6b55c7a 100644 --- a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php +++ b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php @@ -340,9 +340,12 @@ class CreateOrderEndpoint implements EndpointInterface { $payer = $this->payer_factory->from_paypal_response( json_decode( wp_json_encode( $data['payer'] ) ) ); } - if(!$payer && isset($data['form'])) { - parse_str($data['form'], $output); - return $this->payer_factory->from_checkout_form($output); + if ( ! $payer && isset( $data['form'] ) ) { + parse_str( $data['form'], $form_fields ); + + if ( isset( $form_fields['billing_email'] ) && '' !== $form_fields['billing_email'] ) { + return $this->payer_factory->from_checkout_form( $form_fields ); + } } return $payer; From 4b43e05d59efd2f9c7d9d15a4314d5541cf758b8 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 7 Feb 2022 16:49:18 +0100 Subject: [PATCH 18/18] Fix psalm error --- .../ppcp-api-client/src/Factory/PayerFactory.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-api-client/src/Factory/PayerFactory.php b/modules/ppcp-api-client/src/Factory/PayerFactory.php index 788b6e280..70d33dee3 100644 --- a/modules/ppcp-api-client/src/Factory/PayerFactory.php +++ b/modules/ppcp-api-client/src/Factory/PayerFactory.php @@ -172,12 +172,15 @@ class PayerFactory { // make sure the phone number contains only numbers and is max 14. chars long. $national_number = $form_fields['billing_phone']; $national_number = preg_replace( '/[^0-9]/', '', $national_number ); - $national_number = substr( $national_number, 0, 14 ); - $phone = new PhoneWithType( - 'HOME', - new Phone( $national_number ) - ); + if ( null !== $national_number ) { + $national_number = substr( $national_number, 0, 14 ); + + $phone = new PhoneWithType( + 'HOME', + new Phone( $national_number ) + ); + } } return new Payer(