Enable sandbox env in Paddle (#1777)

* Enable sandbox env in Paddle

* Change sandbox option displayName
This commit is contained in:
MedAliMarz 2021-05-12 20:50:53 +02:00 committed by GitHub
parent 6460ce3965
commit 779da62845
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -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,
},
];
}

View file

@ -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<any> { // 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,
};