From 779da62845430a09ebd442fc33a0687951a3bfe9 Mon Sep 17 00:00:00 2001 From: MedAliMarz Date: Wed, 12 May 2021 20:50:53 +0200 Subject: [PATCH] :zap: Enable sandbox env in Paddle (#1777) * Enable sandbox env in Paddle * Change sandbox option displayName --- packages/nodes-base/credentials/PaddleApi.credentials.ts | 6 ++++++ packages/nodes-base/nodes/Paddle/GenericFunctions.ts | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/credentials/PaddleApi.credentials.ts b/packages/nodes-base/credentials/PaddleApi.credentials.ts index 76c0d5bfb3..5aba2bb032 100644 --- a/packages/nodes-base/credentials/PaddleApi.credentials.ts +++ b/packages/nodes-base/credentials/PaddleApi.credentials.ts @@ -20,5 +20,11 @@ export class PaddleApi implements ICredentialType { type: 'string' as NodePropertyTypes, default: '', }, + { + displayName: 'Use Sandbox environment API', + name: 'sandbox', + type: 'boolean' as NodePropertyTypes, + default: false, + }, ]; } diff --git a/packages/nodes-base/nodes/Paddle/GenericFunctions.ts b/packages/nodes-base/nodes/Paddle/GenericFunctions.ts index 0baed95f52..b169582b5e 100644 --- a/packages/nodes-base/nodes/Paddle/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Paddle/GenericFunctions.ts @@ -16,17 +16,21 @@ import { export async function paddleApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise { // tslint:disable-line:no-any const credentials = this.getCredentials('paddleApi'); + const productionUrl = 'https://vendors.paddle.com/api'; + const sandboxUrl = 'https://sandbox-vendors.paddle.com/api'; if (credentials === undefined) { throw new NodeOperationError(this.getNode(), 'Could not retrieve credentials!'); } + const isSandbox = credentials.sandbox; + const options: OptionsWithUri = { method, headers: { 'content-type': 'application/json', }, - uri: `https://vendors.paddle.com/api${endpoint}`, + uri: `${isSandbox === true ? sandboxUrl : productionUrl}${endpoint}`, body, json: true, };