From 6979747caf12261b7af8ea420a5ff391cfb447e3 Mon Sep 17 00:00:00 2001 From: Alex P Date: Fri, 29 Sep 2023 17:20:47 +0300 Subject: [PATCH 1/2] Use api-m PayPal API URLs Switched to the new API endpoints. Seems to work fine, the same as before. --- tests/PHPUnit/ModularTestCase.php | 4 ++-- .../tests/subscriptions-api.spec.js | 22 +++++++++---------- woocommerce-paypal-payments.php | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/PHPUnit/ModularTestCase.php b/tests/PHPUnit/ModularTestCase.php index a77f359e2..61583c4e1 100644 --- a/tests/PHPUnit/ModularTestCase.php +++ b/tests/PHPUnit/ModularTestCase.php @@ -40,8 +40,8 @@ class ModularTestCase extends TestCase $wpdb->posts = ''; $wpdb->postmeta = ''; - !defined('PAYPAL_API_URL') && define('PAYPAL_API_URL', 'https://api.paypal.com'); - !defined('PAYPAL_SANDBOX_API_URL') && define('PAYPAL_SANDBOX_API_URL', 'https://api.sandbox.paypal.com'); + !defined('PAYPAL_API_URL') && define('PAYPAL_API_URL', 'https://api-m.paypal.com'); + !defined('PAYPAL_SANDBOX_API_URL') && define('PAYPAL_SANDBOX_API_URL', 'https://api-m.sandbox.paypal.com'); !defined('PAYPAL_INTEGRATION_DATE') && define('PAYPAL_INTEGRATION_DATE', '2020-10-15'); !defined('PPCP_FLAG_SUBSCRIPTION') && define('PPCP_FLAG_SUBSCRIPTION', true); diff --git a/tests/Playwright/tests/subscriptions-api.spec.js b/tests/Playwright/tests/subscriptions-api.spec.js index d575ed8f7..0c0098059 100644 --- a/tests/Playwright/tests/subscriptions-api.spec.js +++ b/tests/Playwright/tests/subscriptions-api.spec.js @@ -57,7 +57,7 @@ test.describe.serial('Subscriptions Merchant', () => { const message = await page.locator('.notice-success'); await expect(message).toContainText('Product published.'); - const products = await request.get('https://api.sandbox.paypal.com/v1/catalogs/products?page_size=100&page=1&total_required=true', { + const products = await request.get('https://api-m.sandbox.paypal.com/v1/catalogs/products?page_size=100&page=1&total_required=true', { headers: { 'Authorization': AUTHORIZATION, 'Content-Type': 'application/json' @@ -73,7 +73,7 @@ test.describe.serial('Subscriptions Merchant', () => { product_id = product.id; - const plans = await request.get(`https://api.sandbox.paypal.com/v1/billing/plans?product_id=${product_id}&page_size=10&page=1&total_required=true`, { + const plans = await request.get(`https://api-m.sandbox.paypal.com/v1/billing/plans?product_id=${product_id}&page_size=10&page=1&total_required=true`, { headers: { 'Authorization': AUTHORIZATION, 'Content-Type': 'application/json' @@ -107,7 +107,7 @@ test.describe.serial('Subscriptions Merchant', () => { const message = await page.locator('.notice-success'); await expect(message).toContainText('Product updated.'); - const products = await request.get('https://api.sandbox.paypal.com/v1/catalogs/products?page_size=100&page=1&total_required=true', { + const products = await request.get('https://api-m.sandbox.paypal.com/v1/catalogs/products?page_size=100&page=1&total_required=true', { headers: { 'Authorization': AUTHORIZATION, 'Content-Type': 'application/json' @@ -121,7 +121,7 @@ test.describe.serial('Subscriptions Merchant', () => { }); await expect(product.id).toBeTruthy; - const plan = await request.get(`https://api.sandbox.paypal.com/v1/billing/plans/${plan_id}`, { + const plan = await request.get(`https://api-m.sandbox.paypal.com/v1/billing/plans/${plan_id}`, { headers: { 'Authorization': AUTHORIZATION, 'Content-Type': 'application/json' @@ -156,7 +156,7 @@ test('Create new free trial subscription product', async ({page, request}) => { const message = await page.locator('.notice-success'); await expect(message).toContainText('Product published.'); - const products = await request.get('https://api.sandbox.paypal.com/v1/catalogs/products?page_size=100&page=1&total_required=true', { + const products = await request.get('https://api-m.sandbox.paypal.com/v1/catalogs/products?page_size=100&page=1&total_required=true', { headers: { 'Authorization': AUTHORIZATION, 'Content-Type': 'application/json' @@ -170,7 +170,7 @@ test('Create new free trial subscription product', async ({page, request}) => { }); await expect(product.id).toBeTruthy; - const plans = await request.get(`https://api.sandbox.paypal.com/v1/billing/plans?product_id=${product.id}&page_size=10&page=1&total_required=true`, { + const plans = await request.get(`https://api-m.sandbox.paypal.com/v1/billing/plans?product_id=${product.id}&page_size=10&page=1&total_required=true`, { headers: { 'Authorization': AUTHORIZATION, 'Content-Type': 'application/json' @@ -184,7 +184,7 @@ test('Create new free trial subscription product', async ({page, request}) => { }); await expect(plan.id).toBeTruthy; - const planDetail = await request.get(`https://api.sandbox.paypal.com/v1/billing/plans/${plan.id}`, { + const planDetail = await request.get(`https://api-m.sandbox.paypal.com/v1/billing/plans/${plan.id}`, { headers: { 'Authorization': AUTHORIZATION, 'Content-Type': 'application/json' @@ -253,7 +253,7 @@ test.describe('Subscriber my account actions', () => { await page.locator('text=View').first().click(); const subscriptionId = await page.locator('#ppcp-subscription-id').textContent(); - let subscription = await request.get(`https://api.sandbox.paypal.com/v1/billing/subscriptions/${subscriptionId}`, { + let subscription = await request.get(`https://api-m.sandbox.paypal.com/v1/billing/subscriptions/${subscriptionId}`, { headers: { 'Authorization': AUTHORIZATION, 'Content-Type': 'application/json' @@ -267,7 +267,7 @@ test.describe('Subscriber my account actions', () => { const title = page.locator('.woocommerce-message'); await expect(title).toHaveText('Your subscription has been cancelled.'); - subscription = await request.get(`https://api.sandbox.paypal.com/v1/billing/subscriptions/${subscriptionId}`, { + subscription = await request.get(`https://api-m.sandbox.paypal.com/v1/billing/subscriptions/${subscriptionId}`, { headers: { 'Authorization': AUTHORIZATION, 'Content-Type': 'application/json' @@ -285,7 +285,7 @@ test.describe('Subscriber my account actions', () => { await page.locator('text=View').first().click(); const subscriptionId = await page.locator('#ppcp-subscription-id').textContent(); - let subscription = await request.get(`https://api.sandbox.paypal.com/v1/billing/subscriptions/${subscriptionId}`, { + let subscription = await request.get(`https://api-m.sandbox.paypal.com/v1/billing/subscriptions/${subscriptionId}`, { headers: { 'Authorization': AUTHORIZATION, 'Content-Type': 'application/json' @@ -299,7 +299,7 @@ test.describe('Subscriber my account actions', () => { const title = page.locator('.woocommerce-message'); await expect(title).toHaveText('Your subscription has been cancelled.'); - subscription = await request.get(`https://api.sandbox.paypal.com/v1/billing/subscriptions/${subscriptionId}`, { + subscription = await request.get(`https://api-m.sandbox.paypal.com/v1/billing/subscriptions/${subscriptionId}`, { headers: { 'Authorization': AUTHORIZATION, 'Content-Type': 'application/json' diff --git a/woocommerce-paypal-payments.php b/woocommerce-paypal-payments.php index 81dad2f90..dd438323f 100644 --- a/woocommerce-paypal-payments.php +++ b/woocommerce-paypal-payments.php @@ -21,8 +21,8 @@ namespace WooCommerce\PayPalCommerce; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; -define( 'PAYPAL_API_URL', 'https://api.paypal.com' ); -define( 'PAYPAL_SANDBOX_API_URL', 'https://api.sandbox.paypal.com' ); +define( 'PAYPAL_API_URL', 'https://api-m.paypal.com' ); +define( 'PAYPAL_SANDBOX_API_URL', 'https://api-m.sandbox.paypal.com' ); define( 'PAYPAL_INTEGRATION_DATE', '2023-09-26' ); ! defined( 'CONNECT_WOO_CLIENT_ID' ) && define( 'CONNECT_WOO_CLIENT_ID', 'AcCAsWta_JTL__OfpjspNyH7c1GGHH332fLwonA5CwX4Y10mhybRZmHLA0GdRbwKwjQIhpDQy0pluX_P' ); From ccb874b0b946cec38ac50a925da23cbaca7ef90e Mon Sep 17 00:00:00 2001 From: Alex P Date: Fri, 6 Oct 2023 18:04:36 +0300 Subject: [PATCH 2/2] Make Settings singleton --- modules/ppcp-wc-gateway/services.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 8a825b0b1..bc5dbf3a2 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -200,10 +200,12 @@ return array( return $ppcp_tab ? $ppcp_tab : $section; }, - 'wcgateway.settings' => static function ( ContainerInterface $container ): Settings { - $default_button_locations = $container->get( 'wcgateway.button.default-locations' ); - return new Settings( $default_button_locations ); - }, + 'wcgateway.settings' => SingletonDecorator::make( + static function ( ContainerInterface $container ): Settings { + $default_button_locations = $container->get( 'wcgateway.button.default-locations' ); + return new Settings( $default_button_locations ); + } + ), 'wcgateway.notice.connect' => static function ( ContainerInterface $container ): ConnectAdminNotice { $state = $container->get( 'onboarding.state' ); $settings = $container->get( 'wcgateway.settings' );