From 1f39afc6e6cbf45eb479fd635932196a77b0b3b8 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 18 Jan 2021 17:04:09 +0100 Subject: [PATCH 1/8] Introduce pay in 3 for UK --- .../src/Helper/class-messagesapply.php | 1 + modules/ppcp-wc-gateway/services.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/modules/ppcp-button/src/Helper/class-messagesapply.php b/modules/ppcp-button/src/Helper/class-messagesapply.php index ccfdbbced..7f37fba86 100644 --- a/modules/ppcp-button/src/Helper/class-messagesapply.php +++ b/modules/ppcp-button/src/Helper/class-messagesapply.php @@ -22,6 +22,7 @@ class MessagesApply { */ private $countries = array( 'US', + 'GB', ); /** diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 1aba3f682..bb8c82d02 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1785,6 +1785,24 @@ return array( unset( $fields['disable_funding']['options']['card'] ); } + /** + * Enable Pay in 3 for UK. + */ + if ( 'GB' === $country ) { + $fields['message_heading'] = [ + 'heading' => __( 'Pay Later Messaging on Checkout', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + 'description' => __( 'Display pay later messaging on your site for offers like Pay in 3, which lets customers pay with 3 interest-free monthly payments. We’ll show messages on your site to promote this feature for you. You may not promote pay later offers with any other content, marketing, or materials.', 'woocommerce-paypal-payments' ), + 'class' => array( 'ppcp-subheading' ), + ]; + } + $dcc_applies = $container->get( 'api.helpers.dccapplies' ); /** * Depending on your store location, some credit cards can't be used. From 3ab4d0ece4477894588ff55cda986f8c2e783907 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 18 Jan 2021 17:23:53 +0100 Subject: [PATCH 2/8] Update title and description for single product and cart page --- modules/ppcp-wc-gateway/services.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index bb8c82d02..0b8edeb09 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1801,6 +1801,30 @@ return array( 'description' => __( 'Display pay later messaging on your site for offers like Pay in 3, which lets customers pay with 3 interest-free monthly payments. We’ll show messages on your site to promote this feature for you. You may not promote pay later offers with any other content, marketing, or materials.', 'woocommerce-paypal-payments' ), 'class' => array( 'ppcp-subheading' ), ]; + $fields['message_product_heading'] = [ + 'heading' => __( 'Pay Later Messaging on Single Product Page', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + 'description' => __( 'Display pay later messaging on your site for offers like Pay in 3, which lets customers pay with 3 interest-free monthly payments. We’ll show messages on your site to promote this feature for you. You may not promote pay later offers with any other content, marketing, or materials.', 'woocommerce-paypal-payments' ), + 'class' => array( 'ppcp-subheading' ), + ]; + $fields['message_cart_heading'] = [ + 'heading' => __( 'Pay Later Messaging on Cart', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + 'description' => __( 'Display pay later messaging on your site for offers like Pay in 3, which lets customers pay with 3 interest-free monthly payments. We’ll show messages on your site to promote this feature for you. You may not promote pay later offers with any other content, marketing, or materials.', 'woocommerce-paypal-payments' ), + 'class' => array( 'ppcp-subheading' ), + ]; } $dcc_applies = $container->get( 'api.helpers.dccapplies' ); From 1d17335a99059c5e76ae893ed7c45446ab5ae0bd Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 20 Jan 2021 09:48:47 +0100 Subject: [PATCH 3/8] Fix phpcs errors --- modules/ppcp-wc-gateway/services.php | 82 ++++++++++++++-------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 0b8edeb09..87209ccd2 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1785,47 +1785,47 @@ return array( unset( $fields['disable_funding']['options']['card'] ); } - /** - * Enable Pay in 3 for UK. - */ - if ( 'GB' === $country ) { - $fields['message_heading'] = [ - 'heading' => __( 'Pay Later Messaging on Checkout', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-heading', - 'screens' => array( - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ), - 'requirements' => array( 'messages' ), - 'gateway' => 'paypal', - 'description' => __( 'Display pay later messaging on your site for offers like Pay in 3, which lets customers pay with 3 interest-free monthly payments. We’ll show messages on your site to promote this feature for you. You may not promote pay later offers with any other content, marketing, or materials.', 'woocommerce-paypal-payments' ), - 'class' => array( 'ppcp-subheading' ), - ]; - $fields['message_product_heading'] = [ - 'heading' => __( 'Pay Later Messaging on Single Product Page', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-heading', - 'screens' => array( - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ), - 'requirements' => array( 'messages' ), - 'gateway' => 'paypal', - 'description' => __( 'Display pay later messaging on your site for offers like Pay in 3, which lets customers pay with 3 interest-free monthly payments. We’ll show messages on your site to promote this feature for you. You may not promote pay later offers with any other content, marketing, or materials.', 'woocommerce-paypal-payments' ), - 'class' => array( 'ppcp-subheading' ), - ]; - $fields['message_cart_heading'] = [ - 'heading' => __( 'Pay Later Messaging on Cart', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-heading', - 'screens' => array( - State::STATE_PROGRESSIVE, - State::STATE_ONBOARDED, - ), - 'requirements' => array( 'messages' ), - 'gateway' => 'paypal', - 'description' => __( 'Display pay later messaging on your site for offers like Pay in 3, which lets customers pay with 3 interest-free monthly payments. We’ll show messages on your site to promote this feature for you. You may not promote pay later offers with any other content, marketing, or materials.', 'woocommerce-paypal-payments' ), - 'class' => array( 'ppcp-subheading' ), - ]; - } + /** + * Enable Pay in 3 for UK. + */ + if ( 'GB' === $country ) { + $fields['message_heading'] = array( + 'heading' => __( 'Pay Later Messaging on Checkout', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + 'description' => __( 'Display pay later messaging on your site for offers like Pay in 3, which lets customers pay with 3 interest-free monthly payments. We’ll show messages on your site to promote this feature for you. You may not promote pay later offers with any other content, marketing, or materials.', 'woocommerce-paypal-payments' ), + 'class' => array( 'ppcp-subheading' ), + ); + $fields['message_product_heading'] = array( + 'heading' => __( 'Pay Later Messaging on Single Product Page', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + 'description' => __( 'Display pay later messaging on your site for offers like Pay in 3, which lets customers pay with 3 interest-free monthly payments. We’ll show messages on your site to promote this feature for you. You may not promote pay later offers with any other content, marketing, or materials.', 'woocommerce-paypal-payments' ), + 'class' => array( 'ppcp-subheading' ), + ); + $fields['message_cart_heading'] = array( + 'heading' => __( 'Pay Later Messaging on Cart', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( + State::STATE_PROGRESSIVE, + State::STATE_ONBOARDED, + ), + 'requirements' => array( 'messages' ), + 'gateway' => 'paypal', + 'description' => __( 'Display pay later messaging on your site for offers like Pay in 3, which lets customers pay with 3 interest-free monthly payments. We’ll show messages on your site to promote this feature for you. You may not promote pay later offers with any other content, marketing, or materials.', 'woocommerce-paypal-payments' ), + 'class' => array( 'ppcp-subheading' ), + ); + } $dcc_applies = $container->get( 'api.helpers.dccapplies' ); /** From cec2fa045981aa761676031defd1c14ebd208003 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Thu, 21 Jan 2021 08:31:37 +0100 Subject: [PATCH 4/8] fix OrderEndpointTest --- tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php b/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php index 975185f14..cbfba53b6 100644 --- a/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php +++ b/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php @@ -6,10 +6,12 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint; use Hamcrest\Matchers; use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer; use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext; +use Woocommerce\PayPalCommerce\ApiClient\Entity\Capture; use WooCommerce\PayPalCommerce\ApiClient\Entity\Order; use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus; use WooCommerce\PayPalCommerce\ApiClient\Entity\PatchCollection; use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer; +use WooCommerce\PayPalCommerce\ApiClient\Entity\Payments; use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit; use WooCommerce\PayPalCommerce\ApiClient\Entity\Token; use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; @@ -238,6 +240,13 @@ class OrderEndpointTest extends TestCase ); expect('is_wp_error')->with($rawResponse)->andReturn(false); expect('wp_remote_retrieve_response_code')->with($rawResponse)->andReturn(201); + $purchaseUnit = Mockery::mock(PurchaseUnit::class); + $payment = Mockery::mock(Payments::class); + $capture = Mockery::mock(Capture::class); + $expectedOrder->shouldReceive('purchase_units')->once()->andReturn(['0'=>$purchaseUnit]); + $purchaseUnit->shouldReceive('payments')->once()->andReturn($payment); + $payment->shouldReceive('captures')->once()->andReturn(['0'=>$capture]); + $capture->shouldReceive('status')->once()->andReturn(''); $result = $testee->capture($orderToCapture); $this->assertEquals($expectedOrder, $result); From bb07e45e24a998f257be089ea0f65e20fde1987a Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Thu, 21 Jan 2021 08:36:30 +0100 Subject: [PATCH 5/8] fix PayerTest --- tests/PHPUnit/ApiClient/Entity/PayerTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/PHPUnit/ApiClient/Entity/PayerTest.php b/tests/PHPUnit/ApiClient/Entity/PayerTest.php index 95c62c7d0..b3ef019cb 100644 --- a/tests/PHPUnit/ApiClient/Entity/PayerTest.php +++ b/tests/PHPUnit/ApiClient/Entity/PayerTest.php @@ -16,6 +16,9 @@ class PayerTest extends TestCase $address ->expects('to_array') ->andReturn(['address']); + $address + ->expects('country_code') + ->andReturn('UK'); $phone = Mockery::mock(PhoneWithType::class); $phone ->expects('to_array') From 48a3f6d3f22ae36bc5752c4af00d2ce606ca486f Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Thu, 21 Jan 2021 08:38:41 +0100 Subject: [PATCH 6/8] fix PayerTest all the others --- tests/PHPUnit/ApiClient/Entity/PayerTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/PHPUnit/ApiClient/Entity/PayerTest.php b/tests/PHPUnit/ApiClient/Entity/PayerTest.php index b3ef019cb..43bfa8fb7 100644 --- a/tests/PHPUnit/ApiClient/Entity/PayerTest.php +++ b/tests/PHPUnit/ApiClient/Entity/PayerTest.php @@ -68,6 +68,9 @@ class PayerTest extends TestCase $address ->expects('to_array') ->andReturn(['address']); + $address + ->expects('country_code') + ->andReturn('UK'); $phone = Mockery::mock(PhoneWithType::class); $phone ->expects('to_array') @@ -105,6 +108,9 @@ class PayerTest extends TestCase $address ->expects('to_array') ->andReturn(['address']); + $address + ->expects('country_code') + ->andReturn('UK'); $phone = null; $taxInfo = Mockery::mock(PayerTaxInfo::class); $taxInfo @@ -139,6 +145,9 @@ class PayerTest extends TestCase $address ->expects('to_array') ->andReturn(['address']); + $address + ->expects('country_code') + ->andReturn('UK'); $phone = Mockery::mock(PhoneWithType::class); $phone ->expects('to_array') @@ -173,6 +182,9 @@ class PayerTest extends TestCase $address ->expects('to_array') ->andReturn(['address']); + $address + ->expects('country_code') + ->andReturn('UK'); $phone = Mockery::mock(PhoneWithType::class); $phone ->expects('to_array') From 0761f892694ed6083f70e60c253c227b14fbc405 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Thu, 21 Jan 2021 08:49:44 +0100 Subject: [PATCH 7/8] fix ItemFactoryTests --- .../ApiClient/Factory/ItemFactoryTest.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php b/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php index c7a185641..bd9e0596a 100644 --- a/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php +++ b/tests/PHPUnit/ApiClient/Factory/ItemFactoryTest.php @@ -48,7 +48,9 @@ class ItemFactoryTest extends TestCase expect('wc_get_price_excluding_tax') ->with($product) ->andReturn(1); - + expect('wp_strip_all_tags') + ->with('description') + ->andReturn('description'); $result = $testee->from_wc_cart($cart); $this->assertCount(1, $result); @@ -102,6 +104,9 @@ class ItemFactoryTest extends TestCase expect('wc_get_price_excluding_tax') ->with($product) ->andReturn(1); + expect('wp_strip_all_tags') + ->with('description') + ->andReturn('description'); $result = $testee->from_wc_cart($cart); @@ -126,6 +131,9 @@ class ItemFactoryTest extends TestCase $product ->expects('is_virtual') ->andReturn(false); + expect('wp_strip_all_tags') + ->with('description') + ->andReturn('description'); $item = Mockery::mock(\WC_Order_Item_Product::class); $item @@ -183,6 +191,9 @@ class ItemFactoryTest extends TestCase $product ->expects('is_virtual') ->andReturn(true); + expect('wp_strip_all_tags') + ->with('description') + ->andReturn('description'); $item = Mockery::mock(\WC_Order_Item_Product::class); $item @@ -235,6 +246,9 @@ class ItemFactoryTest extends TestCase $product ->expects('is_virtual') ->andReturn(true); + expect('wp_strip_all_tags') + ->with($description) + ->andReturn(mb_substr( $description, 0, 127 )); $item = Mockery::mock(\WC_Order_Item_Product::class); $item From 09fdd98369c8a764e2929df2e39b2f17dc543843 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Thu, 21 Jan 2021 11:11:23 +0100 Subject: [PATCH 8/8] Replace `PayPal Credit` to `Pay Later` in payment settings page --- modules/ppcp-wc-gateway/services.php | 10 +++++----- .../src/Gateway/class-paypalgateway.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 1aba3f682..a8230744a 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -541,7 +541,7 @@ return array( 'default' => false, 'desc_tip' => true, 'description' => __( - 'If you enable this setting, PayPal will be instructed not to allow the buyer to use funding sources that take additional time to complete (for example, eChecks). Instead, the buyer will be required to use an instant funding source, such as an instant transfer, a credit/debit card, or PayPal Credit.', + 'If you enable this setting, PayPal will be instructed not to allow the buyer to use funding sources that take additional time to complete (for example, eChecks). Instead, the buyer will be required to use an instant funding source, such as an instant transfer, a credit/debit card, or Pay Later.', 'woocommerce-paypal-payments' ), 'label' => __( 'Require Instant Payment', 'woocommerce-paypal-payments' ), @@ -603,7 +603,7 @@ return array( ), 'options' => array( 'card' => _x( 'Credit or debit cards', 'Name of payment method', 'woocommerce-paypal-payments' ), - 'credit' => _x( 'PayPal Credit', 'Name of payment method', 'woocommerce-paypal-payments' ), + 'credit' => _x( 'Pay Later', 'Name of payment method', 'woocommerce-paypal-payments' ), 'sepa' => _x( 'SEPA-Lastschrift', 'Name of payment method', 'woocommerce-paypal-payments' ), 'bancontact' => _x( 'Bancontact', 'Name of payment method', 'woocommerce-paypal-payments' ), 'eps' => _x( 'eps', 'Name of payment method', 'woocommerce-paypal-payments' ), @@ -804,7 +804,7 @@ return array( ), 'requirements' => array( 'messages' ), 'gateway' => 'paypal', - 'description' => str_replace( '', '', __( 'Customize the appearance of PayPal Credit messages on checkout to promote special financing offers, which help increase sales.', 'woocommerce-paypal-payments' ) ), + 'description' => str_replace( '', '', __( 'Customize the appearance of Pay Later messages on checkout to promote special financing offers, which help increase sales.', 'woocommerce-paypal-payments' ) ), 'class' => array( 'ppcp-subheading' ), ), 'message_enabled' => array( @@ -1107,7 +1107,7 @@ return array( ), 'requirements' => array( 'messages' ), 'gateway' => 'paypal', - 'description' => str_replace( '', '', __( 'Customize the appearance of PayPal Credit messages on product pages to promote special financing offers, which help increase sales.', 'woocommerce-paypal-payments' ) ), + 'description' => str_replace( '', '', __( 'Customize the appearance of Pay Later messages on product pages to promote special financing offers, which help increase sales.', 'woocommerce-paypal-payments' ) ), 'class' => array( 'ppcp-subheading' ), ), 'message_product_enabled' => array( @@ -1410,7 +1410,7 @@ return array( ), 'requirements' => array( 'messages' ), 'gateway' => 'paypal', - 'description' => str_replace( '', '', __( 'Customize the appearance of PayPal Credit messages on your cart page to promote special financing offers, which help increase sales.', 'woocommerce-paypal-payments' ) ), + 'description' => str_replace( '', '', __( 'Customize the appearance of Pay Later messages on your cart page to promote special financing offers, which help increase sales.', 'woocommerce-paypal-payments' ) ), 'class' => array( 'ppcp-subheading' ), ), 'message_cart_enabled' => array( diff --git a/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php b/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php index b7bc31a66..e9c9ccace 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php @@ -290,7 +290,7 @@ class PayPalGateway extends \WC_Payment_Gateway { } return __( - 'Accept PayPal, PayPal Credit and alternative payment types.', + 'Accept PayPal, Pay Later and alternative payment types.', 'woocommerce-paypal-payments' ); }