Skip to content

Commit

Permalink
feat(payments-plugin): Added env variable for PayPal base uri
Browse files Browse the repository at this point in the history
  • Loading branch information
sonntag-philipp committed Oct 14, 2024
1 parent fdaec8d commit 3674cc2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
12 changes: 5 additions & 7 deletions packages/payments-plugin/e2e/paypal-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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,
}),
],
Expand Down
4 changes: 1 addition & 3 deletions packages/payments-plugin/src/paypal/paypal-base.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ export abstract class PayPalBaseService {

protected async getPaymentMethod(ctx: RequestContext): Promise<PaymentMethod | undefined> {
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<PayPalAuthorizationResponse> {
Expand Down

0 comments on commit 3674cc2

Please sign in to comment.