From 3674cc25e4a50a0fb0259a401803c76fe6a60ea8 Mon Sep 17 00:00:00 2001 From: Philipp Sonntag Date: Mon, 14 Oct 2024 18:02:35 +0200 Subject: [PATCH] feat(payments-plugin): Added env variable for PayPal base uri --- packages/payments-plugin/e2e/paypal-dev-server.ts | 12 +++++------- .../src/paypal/paypal-base.service.ts | 4 +--- 2 files changed, 6 insertions(+), 10 deletions(-) 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 {