diff --git a/packages/payments-plugin/e2e/paypal-dev-server.ts b/packages/payments-plugin/e2e/paypal-dev-server.ts index bd01db2cd5..586436fa2a 100644 --- a/packages/payments-plugin/e2e/paypal-dev-server.ts +++ b/packages/payments-plugin/e2e/paypal-dev-server.ts @@ -19,20 +19,18 @@ import { PayPalSdkPlugin } from './paypal-sdk.plugin'; /** * This should only be used to locally test the PayPal payment plugin * Make sure you have `PAYPAL_CLIENT_ID=xxxx`, `PAYPAL_CLIENT_SECRET=xxxx` - * and `PAYPAL_MERCHANT_ID=xxxx` in your .env file + * , `PAYPAL_MERCHANT_ID=xxxx` and `PAYPAL_API_URL=xxx` in your .env file */ /* eslint-disable @typescript-eslint/no-floating-promises */ async function runPayPalDevServer() { // eslint-disable-next-line @typescript-eslint/no-var-requires require('dotenv').config(); - const { PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PAYPAL_MERCHANT_ID } = process.env; - if (!PAYPAL_CLIENT_ID || !PAYPAL_CLIENT_SECRET || !PAYPAL_MERCHANT_ID) { + const { PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PAYPAL_MERCHANT_ID, PAYPAL_API_URL } = process.env; + if (!PAYPAL_CLIENT_ID || !PAYPAL_CLIENT_SECRET || !PAYPAL_MERCHANT_ID || !PAYPAL_API_URL) { throw new Error('Please provide PayPal credentials in the .env file'); } - const apiUrl = 'https://api-m.sandbox.paypal.com'; - registerInitializer('sqljs', new SqljsInitializer(path.join(__dirname, '__data__'))); const config = mergeConfig(testConfig, { plugins: [ @@ -43,10 +41,10 @@ async function runPayPalDevServer() { port: 5001, }), PayPalPlugin.init({ - apiUrl, + apiUrl: PAYPAL_API_URL, }), PayPalSdkPlugin.init({ - apiUrl, + apiUrl: PAYPAL_API_URL, clientId: PAYPAL_CLIENT_ID, }), ], diff --git a/packages/payments-plugin/src/paypal/paypal-base.service.ts b/packages/payments-plugin/src/paypal/paypal-base.service.ts index 99188c471f..642bf578bd 100644 --- a/packages/payments-plugin/src/paypal/paypal-base.service.ts +++ b/packages/payments-plugin/src/paypal/paypal-base.service.ts @@ -30,9 +30,7 @@ export abstract class PayPalBaseService { protected async getPaymentMethod(ctx: RequestContext): Promise { const allPaymentMethods = await this.paymentMethodService.findAll(ctx); - const paymentMethod = allPaymentMethods.items.find(item => item.handler?.code === handlerCode); - - return paymentMethod; + return allPaymentMethods.items.find(item => item.handler?.code === handlerCode); } protected async authenticate(ctx: RequestContext): Promise {