2020-06-30 04:34:09 -07:00
|
|
|
import { OptionsWithUri } from 'request';
|
|
|
|
|
|
|
|
import {
|
|
|
|
IExecuteFunctions,
|
|
|
|
IHookFunctions,
|
|
|
|
ILoadOptionsFunctions,
|
|
|
|
IExecuteSingleFunctions,
|
|
|
|
IWebhookFunctions,
|
|
|
|
BINARY_ENCODING
|
|
|
|
} from 'n8n-core';
|
|
|
|
|
|
|
|
import {
|
|
|
|
IDataObject,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
2020-06-30 08:38:55 -07:00
|
|
|
if (credentials === undefined) {
|
|
|
|
throw new Error('Could not retrieve credentials!');
|
|
|
|
}
|
|
|
|
|
|
|
|
const options : OptionsWithUri = {
|
2020-06-30 04:34:09 -07:00
|
|
|
method,
|
2020-06-30 08:38:55 -07:00
|
|
|
uri: `https://vendors.paddle.com/api${endpoint}` ,
|
2020-06-30 04:34:09 -07:00
|
|
|
body,
|
|
|
|
json: true
|
|
|
|
};
|
|
|
|
|
2020-06-30 08:38:55 -07:00
|
|
|
body.vendor_id = credentials.vendorId;
|
|
|
|
body.vendor_auth_code = credentials.vendorAuthCode;
|
|
|
|
|
2020-06-30 04:34:09 -07:00
|
|
|
try {
|
|
|
|
return await this.helpers.request!(options);
|
|
|
|
} catch (error) {
|
2020-06-30 08:38:55 -07:00
|
|
|
console.log(error);
|
|
|
|
throw new Error(error);
|
2020-06-30 04:34:09 -07:00
|
|
|
}
|
|
|
|
}
|