mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Merge branch 'save-changes-warning' of https://github.com/n8n-io/n8n into save-changes-warning
This commit is contained in:
commit
ebc7e76968
|
@ -37,9 +37,9 @@ export const couponOperations = [
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
||||||
export const couponFields = [
|
export const couponFields = [
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* coupon:create */
|
/* coupon:create */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'Coupon Type',
|
displayName: 'Coupon Type',
|
||||||
name: 'couponType',
|
name: 'couponType',
|
||||||
|
@ -71,12 +71,9 @@ export const couponFields = [
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Product IDs',
|
displayName: 'Product ID(s)',
|
||||||
name: 'productIds',
|
name: 'productIds',
|
||||||
type: 'multiOptions',
|
type: 'string',
|
||||||
typeOptions: {
|
|
||||||
loadOptionsMethod: 'getProducts',
|
|
||||||
},
|
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
|
@ -187,38 +184,6 @@ export const couponFields = [
|
||||||
default: 'EUR',
|
default: 'EUR',
|
||||||
description: 'The currency must match the balance currency specified in your account.',
|
description: 'The currency must match the balance currency specified in your account.',
|
||||||
options: [
|
options: [
|
||||||
{
|
|
||||||
name: 'ARS',
|
|
||||||
value: 'ARS'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'AUD',
|
|
||||||
value: 'AUD'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'BRL',
|
|
||||||
value: 'BRL'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'CAD',
|
|
||||||
value: 'CAD'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'CHF',
|
|
||||||
value: 'CHF'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'CNY',
|
|
||||||
value: 'CNY'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'CZK',
|
|
||||||
value: 'CZK'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'DKK',
|
|
||||||
value: 'DKK'
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'EUR',
|
name: 'EUR',
|
||||||
value: 'EUR'
|
value: 'EUR'
|
||||||
|
@ -227,70 +192,10 @@ export const couponFields = [
|
||||||
name: 'GBP',
|
name: 'GBP',
|
||||||
value: 'GBP'
|
value: 'GBP'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'HKD',
|
|
||||||
value: 'HKD'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'HUF',
|
|
||||||
value: 'HUF'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'INR',
|
|
||||||
value: 'INR'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'JPY',
|
|
||||||
value: 'JPY'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'KRW',
|
|
||||||
value: 'KRW'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'MXN',
|
|
||||||
value: 'MXN'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'NOK',
|
|
||||||
value: 'NOK'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'NZD',
|
|
||||||
value: 'NZD'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'PLN',
|
|
||||||
value: 'PLN'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'RUB',
|
|
||||||
value: 'RUB'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'SEK',
|
|
||||||
value: 'SEK'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'SGD',
|
|
||||||
value: 'SGD'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'THB',
|
|
||||||
value: 'THB'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'TWD',
|
|
||||||
value: 'TWD'
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'USD',
|
name: 'USD',
|
||||||
value: 'USD'
|
value: 'USD'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'ZAR',
|
|
||||||
value: 'ZAR'
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
|
@ -390,13 +295,6 @@ export const couponFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Prefix for generated codes. Not valid if coupon_code is specified.',
|
description: 'Prefix for generated codes. Not valid if coupon_code is specified.',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
displayName: 'Description',
|
|
||||||
name: 'description',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
description: 'Description of the coupon. This will be displayed in the Seller Dashboard.',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'Expires',
|
displayName: 'Expires',
|
||||||
name: 'expires',
|
name: 'expires',
|
||||||
|
@ -415,6 +313,13 @@ export const couponFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The name of the coupon group this coupon should be assigned to.',
|
description: 'The name of the coupon group this coupon should be assigned to.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Recurring',
|
||||||
|
name: 'recurring',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'If the coupon is used on subscription products, this indicates whether the discount should apply to recurring payments after the initial purchase.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Number of Coupons',
|
displayName: 'Number of Coupons',
|
||||||
name: 'numberOfCoupons',
|
name: 'numberOfCoupons',
|
||||||
|
@ -423,21 +328,21 @@ export const couponFields = [
|
||||||
description: 'Number of coupons to generate. Not valid if coupon_code is specified.',
|
description: 'Number of coupons to generate. Not valid if coupon_code is specified.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Recurring',
|
displayName: 'Description',
|
||||||
name: 'recurring',
|
name: 'description',
|
||||||
type: 'boolean',
|
type: 'string',
|
||||||
default: false,
|
default: '',
|
||||||
description: 'If the coupon is used on subscription products, this indicates whether the discount should apply to recurring payments after the initial purchase.',
|
description: 'Description of the coupon. This will be displayed in the Seller Dashboard.',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* coupon:getAll */
|
/* coupon:getAll */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'Product ID',
|
displayName: 'Product ID',
|
||||||
name: 'productId',
|
name: 'productId',
|
||||||
type: 'string',
|
type: 'number',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
|
@ -449,53 +354,11 @@ export const couponFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
required: true,
|
|
||||||
description: 'The specific product/subscription ID.',
|
description: 'The specific product/subscription ID.',
|
||||||
},
|
},
|
||||||
{
|
/* -------------------------------------------------------------------------- */
|
||||||
displayName: 'Return All',
|
/* coupon:update */
|
||||||
name: 'returnAll',
|
/* -------------------------------------------------------------------------- */
|
||||||
type: 'boolean',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
operation: [
|
|
||||||
'getAll',
|
|
||||||
],
|
|
||||||
resource: [
|
|
||||||
'coupon',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
default: false,
|
|
||||||
description: 'If all results should be returned or only up to a given limit.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Limit',
|
|
||||||
name: 'limit',
|
|
||||||
type: 'number',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
operation: [
|
|
||||||
'getAll',
|
|
||||||
],
|
|
||||||
resource: [
|
|
||||||
'coupon',
|
|
||||||
],
|
|
||||||
returnAll: [
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
typeOptions: {
|
|
||||||
minValue: 1,
|
|
||||||
maxValue: 500,
|
|
||||||
},
|
|
||||||
default: 100,
|
|
||||||
description: 'How many results to return.',
|
|
||||||
},
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* coupon:update */
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
{
|
{
|
||||||
displayName: 'Update by',
|
displayName: 'Update by',
|
||||||
name: 'updateBy',
|
name: 'updateBy',
|
||||||
|
@ -590,7 +453,7 @@ export const couponFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Additional Fields',
|
displayName: ' Additional Fields',
|
||||||
name: 'additionalFieldsJson',
|
name: 'additionalFieldsJson',
|
||||||
type: 'json',
|
type: 'json',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
|
@ -640,191 +503,36 @@ export const couponFields = [
|
||||||
description: 'Number of times a coupon can be used in a checkout. This will be set to 999,999 by default, if not specified.',
|
description: 'Number of times a coupon can be used in a checkout. This will be set to 999,999 by default, if not specified.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Discount',
|
displayName: 'Currency',
|
||||||
name: 'discount',
|
name: 'currency',
|
||||||
type: 'fixedCollection',
|
type: 'options',
|
||||||
default: 'discountProperties',
|
default: 'EUR',
|
||||||
|
description: 'The currency must match the balance currency specified in your account.',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'Discount Properties',
|
name: 'EUR',
|
||||||
name: 'discountProperties',
|
value: 'EUR'
|
||||||
values: [
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Currency',
|
name: 'GBP',
|
||||||
name: 'currency',
|
value: 'GBP'
|
||||||
type: 'options',
|
},
|
||||||
default: 'EUR',
|
{
|
||||||
description: 'The currency must match the balance currency specified in your account.',
|
name: 'USD',
|
||||||
displayOptions: {
|
value: 'USD'
|
||||||
show: {
|
|
||||||
discountType: [
|
|
||||||
'flat',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
name: 'ARS',
|
|
||||||
value: 'ARS'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'AUD',
|
|
||||||
value: 'AUD'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'BRL',
|
|
||||||
value: 'BRL'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'CAD',
|
|
||||||
value: 'CAD'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'CHF',
|
|
||||||
value: 'CHF'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'CNY',
|
|
||||||
value: 'CNY'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'CZK',
|
|
||||||
value: 'CZK'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'DKK',
|
|
||||||
value: 'DKK'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'EUR',
|
|
||||||
value: 'EUR'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'GBP',
|
|
||||||
value: 'GBP'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'HKD',
|
|
||||||
value: 'HKD'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'HUF',
|
|
||||||
value: 'HUF'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'INR',
|
|
||||||
value: 'INR'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'JPY',
|
|
||||||
value: 'JPY'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'KRW',
|
|
||||||
value: 'KRW'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'MXN',
|
|
||||||
value: 'MXN'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'NOK',
|
|
||||||
value: 'NOK'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'NZD',
|
|
||||||
value: 'NZD'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'PLN',
|
|
||||||
value: 'PLN'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'RUB',
|
|
||||||
value: 'RUB'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'SEK',
|
|
||||||
value: 'SEK'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'SGD',
|
|
||||||
value: 'SGD'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'THB',
|
|
||||||
value: 'THB'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'TWD',
|
|
||||||
value: 'TWD'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'USD',
|
|
||||||
value: 'USD'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'ZAR',
|
|
||||||
value: 'ZAR'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Discount Amount Currency',
|
|
||||||
name: 'discountAmount',
|
|
||||||
type: 'number',
|
|
||||||
default: '',
|
|
||||||
description: 'Discount amount.',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
discountType: [
|
|
||||||
'flat',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
typeOptions: {
|
|
||||||
minValue: 0
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Discount Amount Percentage',
|
|
||||||
name: 'discountAmount',
|
|
||||||
type: 'number',
|
|
||||||
default: '',
|
|
||||||
description: 'Discount amount.',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
discountType: [
|
|
||||||
'percentage',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
typeOptions: {
|
|
||||||
minValue: 0,
|
|
||||||
maxValue: 100
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Discount Type',
|
|
||||||
name: 'discountType',
|
|
||||||
type: 'options',
|
|
||||||
default: 'flat',
|
|
||||||
description: 'Either flat or percentage.',
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
name: 'Flat',
|
|
||||||
value: 'flat'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Percentage',
|
|
||||||
value: 'percentage'
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Discount Amount',
|
||||||
|
name: 'discountAmount',
|
||||||
|
type: 'number',
|
||||||
|
default: '',
|
||||||
|
description: 'Discount amount.',
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 0
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Expires',
|
displayName: 'Expires',
|
||||||
name: 'expires',
|
name: 'expires',
|
||||||
|
@ -851,7 +559,7 @@ export const couponFields = [
|
||||||
description: 'New group name to move coupon to.',
|
description: 'New group name to move coupon to.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Product IDs',
|
displayName: 'Product ID(s)',
|
||||||
name: 'productIds',
|
name: 'productIds',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import {
|
import { OptionsWithUri } from 'request';
|
||||||
OptionsWithUri,
|
|
||||||
} from 'request';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
|
@ -8,6 +6,7 @@ import {
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
IExecuteSingleFunctions,
|
IExecuteSingleFunctions,
|
||||||
IWebhookFunctions,
|
IWebhookFunctions,
|
||||||
|
BINARY_ENCODING
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -21,50 +20,37 @@ export async function paddleApiRequest(this: IHookFunctions | IExecuteFunctions
|
||||||
throw new Error('Could not retrieve credentials!');
|
throw new Error('Could not retrieve credentials!');
|
||||||
}
|
}
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
const options : OptionsWithUri = {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
'content-type': 'application/json'
|
'content-type': 'application/json'
|
||||||
},
|
},
|
||||||
uri: `https://vendors.paddle.com/api${endpoint}`,
|
uri: `https://vendors.paddle.com/api${endpoint}` ,
|
||||||
body,
|
body,
|
||||||
json: true
|
json: true
|
||||||
};
|
};
|
||||||
|
|
||||||
body['vendor_id'] = credentials.vendorId;
|
body['vendor_id'] = credentials.vendorId;
|
||||||
body['vendor_auth_code'] = credentials.vendorAuthCode;
|
body['vendor_auth_code'] = credentials.vendorAuthCode;
|
||||||
|
|
||||||
|
console.log(options.body);
|
||||||
|
console.log(options);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.helpers.request!(options);
|
const response = await this.helpers.request!(options);
|
||||||
|
console.log(response);
|
||||||
|
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
throw new Error(`Code: ${response.error.code}. Message: ${response.error.message}`);
|
throw new Error(`Code: ${response.error.code}. Message: ${response.error.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response.response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`ERROR: Code: ${error.code}. Message: ${error.message}`);
|
console.log(error);
|
||||||
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function paddleApiRequestAllItems(this: IHookFunctions | IExecuteFunctions, propertyName: string, endpoint: string, method: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
|
||||||
|
|
||||||
const returnData: IDataObject[] = [];
|
|
||||||
|
|
||||||
let responseData;
|
|
||||||
|
|
||||||
body.results_per_page = 200;
|
|
||||||
body.page = 1;
|
|
||||||
|
|
||||||
do {
|
|
||||||
responseData = await paddleApiRequest.call(this, endpoint, method, body, query);
|
|
||||||
returnData.push.apply(returnData, responseData[propertyName]);
|
|
||||||
} while (
|
|
||||||
responseData[propertyName].length !== 0
|
|
||||||
);
|
|
||||||
|
|
||||||
return returnData;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
||||||
let result;
|
let result;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -28,9 +28,9 @@ export const orderOperations = [
|
||||||
|
|
||||||
export const orderFields = [
|
export const orderFields = [
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* order:get */
|
/* order:get */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'Checkout ID',
|
displayName: 'Checkout ID',
|
||||||
name: 'checkoutId',
|
name: 'checkoutId',
|
||||||
|
|
|
@ -1,53 +1,20 @@
|
||||||
import {
|
import { IExecuteFunctions } from 'n8n-core';
|
||||||
IExecuteFunctions
|
|
||||||
} from 'n8n-core';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
ILoadOptionsFunctions,
|
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodePropertyOptions,
|
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import {
|
import { couponFields, couponOperations } from './CouponDescription';
|
||||||
couponFields,
|
import { paddleApiRequest, validateJSON } from './GenericFunctions';
|
||||||
couponOperations,
|
import { paymentsFields, paymentsOperations } from './PaymentDescription';
|
||||||
} from './CouponDescription';
|
import { planFields, planOperations } from './PlanDescription';
|
||||||
|
import { productFields, productOperations } from './ProductDescription';
|
||||||
|
import { userFields, userOperations } from './UserDescription';
|
||||||
|
|
||||||
import {
|
import moment = require('moment');
|
||||||
paddleApiRequest,
|
import { orderOperations, orderFields } from './OrderDescription';
|
||||||
paddleApiRequestAllItems,
|
|
||||||
validateJSON
|
|
||||||
} from './GenericFunctions';
|
|
||||||
|
|
||||||
import {
|
|
||||||
paymentFields,
|
|
||||||
paymentOperations,
|
|
||||||
} from './PaymentDescription';
|
|
||||||
|
|
||||||
import {
|
|
||||||
planFields,
|
|
||||||
planOperations,
|
|
||||||
} from './PlanDescription';
|
|
||||||
|
|
||||||
import {
|
|
||||||
productFields,
|
|
||||||
productOperations,
|
|
||||||
} from './ProductDescription';
|
|
||||||
|
|
||||||
import {
|
|
||||||
userFields,
|
|
||||||
userOperations,
|
|
||||||
} from './UserDescription';
|
|
||||||
|
|
||||||
// import {
|
|
||||||
// orderOperations,
|
|
||||||
// orderFields,
|
|
||||||
// } from './OrderDescription';
|
|
||||||
|
|
||||||
import * as moment from 'moment';
|
|
||||||
|
|
||||||
export class Paddle implements INodeType {
|
export class Paddle implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -81,8 +48,8 @@ export class Paddle implements INodeType {
|
||||||
value: 'coupon',
|
value: 'coupon',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Payment',
|
name: 'Payments',
|
||||||
value: 'payment',
|
value: 'payments',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Plan',
|
name: 'Plan',
|
||||||
|
@ -92,10 +59,10 @@ export class Paddle implements INodeType {
|
||||||
name: 'Product',
|
name: 'Product',
|
||||||
value: 'product',
|
value: 'product',
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// name: 'Order',
|
name: 'Order',
|
||||||
// value: 'order',
|
value: 'order',
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
name: 'User',
|
name: 'User',
|
||||||
value: 'user',
|
value: 'user',
|
||||||
|
@ -108,8 +75,8 @@ export class Paddle implements INodeType {
|
||||||
...couponOperations,
|
...couponOperations,
|
||||||
...couponFields,
|
...couponFields,
|
||||||
// PAYMENT
|
// PAYMENT
|
||||||
...paymentOperations,
|
...paymentsOperations,
|
||||||
...paymentFields,
|
...paymentsFields,
|
||||||
// PLAN
|
// PLAN
|
||||||
...planOperations,
|
...planOperations,
|
||||||
...planFields,
|
...planFields,
|
||||||
|
@ -117,69 +84,14 @@ export class Paddle implements INodeType {
|
||||||
...productOperations,
|
...productOperations,
|
||||||
...productFields,
|
...productFields,
|
||||||
// ORDER
|
// ORDER
|
||||||
// ...orderOperations,
|
...orderOperations,
|
||||||
// ...orderFields,
|
...orderFields,
|
||||||
// USER
|
// USER
|
||||||
...userOperations,
|
...userOperations,
|
||||||
...userFields
|
...userFields
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
methods = {
|
|
||||||
loadOptions: {
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* PAYMENT */
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
// Get all payment so they can be selected in payment rescheduling
|
|
||||||
async getPayments(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
||||||
const returnData: INodePropertyOptions[] = [];
|
|
||||||
const endpoint = '/2.0/subscription/payments';
|
|
||||||
const paymentResponse = await paddleApiRequest.call(this, endpoint, 'POST', {});
|
|
||||||
|
|
||||||
// Alert user if there's no payments present to be loaded into payments property
|
|
||||||
if (paymentResponse.response === undefined || paymentResponse.response.length === 0) {
|
|
||||||
throw Error('No payments on account.');
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const payment of paymentResponse.response) {
|
|
||||||
const id = payment.id;
|
|
||||||
returnData.push({
|
|
||||||
name: id,
|
|
||||||
value: id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return returnData;
|
|
||||||
},
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
/* PRODUCTS */
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
// Get all Products so they can be selected in coupon creation when assigning products
|
|
||||||
async getProducts(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
||||||
const returnData: INodePropertyOptions[] = [];
|
|
||||||
const endpoint = '/2.0/product/get_products';
|
|
||||||
const products = await paddleApiRequest.call(this, endpoint, 'POST', {});
|
|
||||||
|
|
||||||
// Alert user if there's no products present to be loaded into payments property
|
|
||||||
if (products.length === 0) {
|
|
||||||
throw Error('No products on account.');
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const product of products) {
|
|
||||||
const name = product.name;
|
|
||||||
const id = product.id;
|
|
||||||
returnData.push({
|
|
||||||
name,
|
|
||||||
value: id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return returnData;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
|
@ -205,21 +117,20 @@ export class Paddle implements INodeType {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
const discountType = this.getNodeParameter('discountType', i) as string;
|
const discountType = this.getNodeParameter('discountType', i) as string;
|
||||||
const couponType = this.getNodeParameter('couponType', i) as string;
|
const couponType = this.getNodeParameter('couponType', i) as string;
|
||||||
const discountAmount = this.getNodeParameter('discountAmount', i) as number;
|
const discountAmount = this.getNodeParameter('discountAmount', i) as number;
|
||||||
|
const currency = this.getNodeParameter('currency', i) as string;
|
||||||
|
|
||||||
if (couponType === 'product') {
|
if (couponType === 'product') {
|
||||||
body.product_ids = (this.getNodeParameter('productIds', i) as string[]).join();
|
body.product_ids = this.getNodeParameter('productIds', i) as string;
|
||||||
}
|
|
||||||
|
|
||||||
if (discountType === 'flat') {
|
|
||||||
body.currency = this.getNodeParameter('currency', i) as string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body.coupon_type = couponType;
|
body.coupon_type = couponType;
|
||||||
body.discount_type = discountType;
|
body.discount_type = discountType;
|
||||||
body.discount_amount = discountAmount;
|
body.discount_amount = discountAmount;
|
||||||
|
body.currency = currency;
|
||||||
|
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
|
||||||
|
@ -253,25 +164,16 @@ export class Paddle implements INodeType {
|
||||||
const endpoint = '/2.1/product/create_coupon';
|
const endpoint = '/2.1/product/create_coupon';
|
||||||
|
|
||||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||||
responseData = responseData.response.coupon_codes;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (operation === 'getAll') {
|
if (operation === 'getAll') {
|
||||||
const productId = this.getNodeParameter('productId', i) as string;
|
const productIds = this.getNodeParameter('productId', i) as string;
|
||||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
|
||||||
const endpoint = '/2.0/product/list_coupons';
|
const endpoint = '/2.0/product/list_coupons';
|
||||||
|
|
||||||
body.product_id = productId as string;
|
body.product_id = productIds as string;
|
||||||
|
|
||||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||||
|
|
||||||
if (returnAll) {
|
|
||||||
responseData = responseData.response;
|
|
||||||
} else {
|
|
||||||
const limit = this.getNodeParameter('limit', i) as number;
|
|
||||||
responseData = responseData.response.splice(0, limit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (operation === 'update') {
|
if (operation === 'update') {
|
||||||
|
@ -315,9 +217,9 @@ export class Paddle implements INodeType {
|
||||||
if (additionalFields.newGroup) {
|
if (additionalFields.newGroup) {
|
||||||
body.new_group = additionalFields.newGroup as string;
|
body.new_group = additionalFields.newGroup as string;
|
||||||
}
|
}
|
||||||
if (additionalFields.recurring === true) {
|
if (additionalFields.recurring) {
|
||||||
body.recurring = 1;
|
body.recurring = 1;
|
||||||
} else if (additionalFields.recurring === false) {
|
} else {
|
||||||
body.recurring = 0;
|
body.recurring = 0;
|
||||||
}
|
}
|
||||||
if (additionalFields.productIds) {
|
if (additionalFields.productIds) {
|
||||||
|
@ -326,29 +228,15 @@ export class Paddle implements INodeType {
|
||||||
if (additionalFields.discountAmount) {
|
if (additionalFields.discountAmount) {
|
||||||
body.discount_amount = additionalFields.discountAmount as number;
|
body.discount_amount = additionalFields.discountAmount as number;
|
||||||
}
|
}
|
||||||
if (additionalFields.discount) {
|
|
||||||
//@ts-ignore
|
|
||||||
if (additionalFields.discount.discountProperties.discountType === 'percentage') {
|
|
||||||
// @ts-ignore
|
|
||||||
body.discount_amount = additionalFields.discount.discountProperties.discountAmount as number;
|
|
||||||
} else {
|
|
||||||
//@ts-ignore
|
|
||||||
body.currency = additionalFields.discount.discountProperties.currency as string;
|
|
||||||
//@ts-ignore
|
|
||||||
body.discount_amount = additionalFields.discount.discountProperties.discountAmount as number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const endpoint = '/2.1/product/update_coupon';
|
const endpoint = '/2.1/product/update_coupon';
|
||||||
|
|
||||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||||
responseData = responseData.response;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (resource === 'payment') {
|
if (resource === 'payment') {
|
||||||
if (operation === 'getAll') {
|
if (operation === 'getAll') {
|
||||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
|
||||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||||
|
|
||||||
if (jsonParameters) {
|
if (jsonParameters) {
|
||||||
|
@ -374,10 +262,10 @@ export class Paddle implements INodeType {
|
||||||
if (additionalFields.state) {
|
if (additionalFields.state) {
|
||||||
body.state = additionalFields.state as string;
|
body.state = additionalFields.state as string;
|
||||||
}
|
}
|
||||||
if (additionalFields.isPaid) {
|
if (additionalFields.recurring) {
|
||||||
body.is_paid = 1;
|
body.recurring = 1;
|
||||||
} else {
|
} else {
|
||||||
body.is_paid = 0;
|
body.recurring = 0;
|
||||||
}
|
}
|
||||||
if (additionalFields.from) {
|
if (additionalFields.from) {
|
||||||
body.from = moment(additionalFields.from as Date).format('YYYY-MM-DD') as string;
|
body.from = moment(additionalFields.from as Date).format('YYYY-MM-DD') as string;
|
||||||
|
@ -389,16 +277,10 @@ export class Paddle implements INodeType {
|
||||||
body.is_one_off_charge = additionalFields.isOneOffCharge as boolean;
|
body.is_one_off_charge = additionalFields.isOneOffCharge as boolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const endpoint = '/2.0/subscription/payments';
|
const endpoint = '/2.0/subscription/payments';
|
||||||
|
|
||||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||||
|
|
||||||
if (returnAll) {
|
|
||||||
responseData = responseData.response;
|
|
||||||
} else {
|
|
||||||
const limit = this.getNodeParameter('limit', i) as number;
|
|
||||||
responseData = responseData.response.splice(0, limit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (operation === 'reschedule') {
|
if (operation === 'reschedule') {
|
||||||
const paymentId = this.getNodeParameter('paymentId', i) as number;
|
const paymentId = this.getNodeParameter('paymentId', i) as number;
|
||||||
|
@ -414,17 +296,9 @@ export class Paddle implements INodeType {
|
||||||
}
|
}
|
||||||
if (resource === 'plan') {
|
if (resource === 'plan') {
|
||||||
if (operation === 'getAll') {
|
if (operation === 'getAll') {
|
||||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
|
||||||
const endpoint = '/2.0/subscription/plans';
|
const endpoint = '/2.0/subscription/plans';
|
||||||
|
|
||||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||||
|
|
||||||
if (returnAll) {
|
|
||||||
responseData = responseData.response;
|
|
||||||
} else {
|
|
||||||
const limit = this.getNodeParameter('limit', i) as number;
|
|
||||||
responseData = responseData.response.splice(0, limit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (operation === 'get') {
|
if (operation === 'get') {
|
||||||
const planId = this.getNodeParameter('planId', i) as string;
|
const planId = this.getNodeParameter('planId', i) as string;
|
||||||
|
@ -434,22 +308,13 @@ export class Paddle implements INodeType {
|
||||||
const endpoint = '/2.0/subscription/plans';
|
const endpoint = '/2.0/subscription/plans';
|
||||||
|
|
||||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||||
responseData = responseData.response;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (resource === 'product') {
|
if (resource === 'product') {
|
||||||
if (operation === 'getAll') {
|
if (operation === 'getAll') {
|
||||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
|
||||||
const endpoint = '/2.0/product/get_products';
|
const endpoint = '/2.0/product/get_products';
|
||||||
|
|
||||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||||
|
|
||||||
if (returnAll) {
|
|
||||||
responseData = responseData.response.products;
|
|
||||||
} else {
|
|
||||||
const limit = this.getNodeParameter('limit', i) as number;
|
|
||||||
responseData = responseData.response.products.splice(0, limit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (resource === 'order') {
|
if (resource === 'order') {
|
||||||
|
@ -464,7 +329,6 @@ export class Paddle implements INodeType {
|
||||||
}
|
}
|
||||||
if (resource === 'user') {
|
if (resource === 'user') {
|
||||||
if (operation === 'getAll') {
|
if (operation === 'getAll') {
|
||||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
|
||||||
|
|
||||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||||
|
|
||||||
|
@ -480,6 +344,11 @@ export class Paddle implements INodeType {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
|
||||||
|
if (!returnAll) {
|
||||||
|
body.results_per_page = this.getNodeParameter('limit', i) as number;
|
||||||
|
}
|
||||||
|
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
|
||||||
|
@ -492,20 +361,16 @@ export class Paddle implements INodeType {
|
||||||
if (additionalFields.subscriptionId) {
|
if (additionalFields.subscriptionId) {
|
||||||
body.subscription_id = additionalFields.subscriptionId as string;
|
body.subscription_id = additionalFields.subscriptionId as string;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
const endpoint = '/2.0/subscription/users';
|
const endpoint = '/2.0/subscription/users';
|
||||||
|
|
||||||
if (returnAll) {
|
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||||
responseData = await paddleApiRequestAllItems.call(this, 'response', endpoint, 'POST', body);
|
|
||||||
} else {
|
|
||||||
body.results_per_page = this.getNodeParameter('limit', i) as number;
|
|
||||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
|
||||||
responseData = responseData.response;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(responseData);
|
||||||
|
|
||||||
if (Array.isArray(responseData)) {
|
if (Array.isArray(responseData)) {
|
||||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||||
} else {
|
} else {
|
||||||
|
|
165
packages/nodes-base/nodes/Paddle/PaddleTrigger.node.ts
Normal file
165
packages/nodes-base/nodes/Paddle/PaddleTrigger.node.ts
Normal file
|
@ -0,0 +1,165 @@
|
||||||
|
import {
|
||||||
|
IHookFunctions,
|
||||||
|
IWebhookFunctions,
|
||||||
|
} from 'n8n-core';
|
||||||
|
|
||||||
|
import {
|
||||||
|
IDataObject,
|
||||||
|
INodeTypeDescription,
|
||||||
|
INodeType,
|
||||||
|
IWebhookResponseData,
|
||||||
|
ILoadOptionsFunctions,
|
||||||
|
INodePropertyOptions,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
import { paddleApiRequest } from './GenericFunctions';
|
||||||
|
|
||||||
|
export class PaddleTrigger implements INodeType {
|
||||||
|
description: INodeTypeDescription = {
|
||||||
|
displayName: 'Paddle Trigger',
|
||||||
|
name: 'paddleTrigger',
|
||||||
|
icon: 'file:paddle.png',
|
||||||
|
group: ['trigger'],
|
||||||
|
version: 1,
|
||||||
|
description: 'Handle Paddle events via webhooks',
|
||||||
|
defaults: {
|
||||||
|
name: 'Paddle Trigger',
|
||||||
|
color: '#32325d',
|
||||||
|
},
|
||||||
|
inputs: [],
|
||||||
|
outputs: ['main'],
|
||||||
|
credentials: [
|
||||||
|
{
|
||||||
|
name: 'paddleApi',
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
webhooks: [
|
||||||
|
{
|
||||||
|
name: 'default',
|
||||||
|
httpMethod: 'POST',
|
||||||
|
reponseMode: 'onReceived',
|
||||||
|
path: 'webhook',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
properties: [
|
||||||
|
{
|
||||||
|
displayName: 'Events',
|
||||||
|
name: 'events',
|
||||||
|
type: 'multiOptions',
|
||||||
|
required: true,
|
||||||
|
default: [],
|
||||||
|
description: 'The event to listen to.',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getEvents'
|
||||||
|
},
|
||||||
|
options: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// @ts-ignore (because of request)
|
||||||
|
webhookMethods = {
|
||||||
|
default: {
|
||||||
|
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||||
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
|
if (webhookData.webhookId === undefined) {
|
||||||
|
// No webhook id is set so no webhook can exist
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const endpoint = `/notifications/webhooks/${webhookData.webhookId}`;
|
||||||
|
try {
|
||||||
|
await paddleApiRequest.call(this, endpoint, 'GET');
|
||||||
|
} catch (err) {
|
||||||
|
if (err.response && err.response.name === 'INVALID_RESOURCE_ID') {
|
||||||
|
// Webhook does not exist
|
||||||
|
delete webhookData.webhookId;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
throw new Error(`Paddle Error: ${err}`);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
async create(this: IHookFunctions): Promise<boolean> {
|
||||||
|
let webhook;
|
||||||
|
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||||
|
const events = this.getNodeParameter('events', []) as string[];
|
||||||
|
const body = {
|
||||||
|
url: webhookUrl,
|
||||||
|
event_types: events.map(event => {
|
||||||
|
return { name: event };
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
const endpoint = '/notifications/webhooks';
|
||||||
|
try {
|
||||||
|
webhook = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (webhook.id === undefined) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
|
webhookData.webhookId = webhook.id as string;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
async delete(this: IHookFunctions): Promise<boolean> {
|
||||||
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
|
if (webhookData.webhookId !== undefined) {
|
||||||
|
const endpoint = `/notifications/webhooks/${webhookData.webhookId}`;
|
||||||
|
try {
|
||||||
|
await paddleApiRequest.call(this, endpoint, 'DELETE', {});
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
delete webhookData.webhookId;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||||
|
let webhook;
|
||||||
|
const webhookData = this.getWorkflowStaticData('node') as IDataObject;
|
||||||
|
const bodyData = this.getBodyData() as IDataObject;
|
||||||
|
const req = this.getRequestObject();
|
||||||
|
const headerData = this.getHeaderData() as IDataObject;
|
||||||
|
const endpoint = '/notifications/verify-webhook-signature';
|
||||||
|
|
||||||
|
if (headerData['PAYPAL-AUTH-ALGO'] !== undefined
|
||||||
|
&& headerData['PAYPAL-CERT-URL'] !== undefined
|
||||||
|
&& headerData['PAYPAL-TRANSMISSION-ID'] !== undefined
|
||||||
|
&& headerData['PAYPAL-TRANSMISSION-SIG'] !== undefined
|
||||||
|
&& headerData['PAYPAL-TRANSMISSION-TIME'] !== undefined) {
|
||||||
|
const body = {
|
||||||
|
auth_algo: headerData['PAYPAL-AUTH-ALGO'],
|
||||||
|
cert_url: headerData['PAYPAL-CERT-URL'],
|
||||||
|
transmission_id: headerData['PAYPAL-TRANSMISSION-ID'],
|
||||||
|
transmission_sig: headerData['PAYPAL-TRANSMISSION-SIG'],
|
||||||
|
transmission_time: headerData['PAYPAL-TRANSMISSION-TIME'],
|
||||||
|
webhook_id: webhookData.webhookId,
|
||||||
|
webhook_event: bodyData,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
webhook = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
if (webhook.verification_status !== 'SUCCESS') {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
workflowData: [
|
||||||
|
this.helpers.returnJsonArray(req.body)
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,7 @@ import {
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export const paymentOperations = [
|
export const paymentsOperations = [
|
||||||
{
|
{
|
||||||
displayName: 'Operation',
|
displayName: 'Operation',
|
||||||
name: 'operation',
|
name: 'operation',
|
||||||
|
@ -10,7 +10,7 @@ export const paymentOperations = [
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'payment',
|
'payments',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -18,7 +18,7 @@ export const paymentOperations = [
|
||||||
{
|
{
|
||||||
name: 'Get All',
|
name: 'Get All',
|
||||||
value: 'getAll',
|
value: 'getAll',
|
||||||
description: 'Get all payment.',
|
description: 'Get all payments.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Reschedule',
|
name: 'Reschedule',
|
||||||
|
@ -31,51 +31,10 @@ export const paymentOperations = [
|
||||||
},
|
},
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
||||||
export const paymentFields = [
|
export const paymentsFields = [
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* payment:getAll */
|
/* payments:getAll */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
|
||||||
displayName: 'Return All',
|
|
||||||
name: 'returnAll',
|
|
||||||
type: 'boolean',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
operation: [
|
|
||||||
'getAll',
|
|
||||||
],
|
|
||||||
resource: [
|
|
||||||
'payment',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
default: false,
|
|
||||||
description: 'If all results should be returned or only up to a given limit.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Limit',
|
|
||||||
name: 'limit',
|
|
||||||
type: 'number',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
operation: [
|
|
||||||
'getAll',
|
|
||||||
],
|
|
||||||
resource: [
|
|
||||||
'payment',
|
|
||||||
],
|
|
||||||
returnAll: [
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
typeOptions: {
|
|
||||||
minValue: 1,
|
|
||||||
maxValue: 500,
|
|
||||||
},
|
|
||||||
default: 100,
|
|
||||||
description: 'How many results to return.',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'JSON Parameters',
|
displayName: 'JSON Parameters',
|
||||||
name: 'jsonParameters',
|
name: 'jsonParameters',
|
||||||
|
@ -85,7 +44,7 @@ export const paymentFields = [
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'payment',
|
'payments',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'getAll',
|
'getAll',
|
||||||
|
@ -94,7 +53,7 @@ export const paymentFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Additional Fields',
|
displayName: ' Additional Fields',
|
||||||
name: 'additionalFieldsJson',
|
name: 'additionalFieldsJson',
|
||||||
type: 'json',
|
type: 'json',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
|
@ -104,7 +63,7 @@ export const paymentFields = [
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'payment',
|
'payments',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'getAll',
|
'getAll',
|
||||||
|
@ -124,7 +83,7 @@ export const paymentFields = [
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'payment',
|
'payments',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'getAll',
|
'getAll',
|
||||||
|
@ -141,14 +100,14 @@ export const paymentFields = [
|
||||||
name: 'from',
|
name: 'from',
|
||||||
type: 'dateTime',
|
type: 'dateTime',
|
||||||
default: '',
|
default: '',
|
||||||
description: 'payment starting from date.',
|
description: 'payments starting from date.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Date To',
|
displayName: 'Date To',
|
||||||
name: 'to',
|
name: 'to',
|
||||||
type: 'dateTime',
|
type: 'dateTime',
|
||||||
default: '',
|
default: '',
|
||||||
description: 'payment up until date.',
|
description: 'payments up until date.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Is Paid',
|
displayName: 'Is Paid',
|
||||||
|
@ -158,7 +117,7 @@ export const paymentFields = [
|
||||||
description: 'payment is paid.',
|
description: 'payment is paid.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Plan ID',
|
displayName: 'Plan',
|
||||||
name: 'plan',
|
name: 'plan',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -204,29 +163,26 @@ export const paymentFields = [
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* payment:reschedule */
|
/* payments:reschedule */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'Payment ID',
|
displayName: 'payments ID',
|
||||||
name: 'paymentId',
|
name: 'paymentsId',
|
||||||
type: 'options',
|
type: 'number',
|
||||||
typeOptions: {
|
|
||||||
loadOptionsMethod: 'getpayment',
|
|
||||||
},
|
|
||||||
default: '',
|
default: '',
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'payment',
|
'payments',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'reschedule',
|
'reschedule',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'The upcoming subscription payment ID.',
|
description: 'The upcoming subscription payments ID.', // Use loadoptions to select payments
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Date',
|
displayName: 'Date',
|
||||||
|
@ -236,13 +192,13 @@ export const paymentFields = [
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'payment',
|
'payments',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'reschedule',
|
'reschedule',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'Date you want to move the payment to.',
|
description: 'Date you want to move the payments to.',
|
||||||
},
|
},
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
|
@ -26,16 +26,16 @@ export const planOperations = [
|
||||||
description: 'Get all plans.',
|
description: 'Get all plans.',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
default: 'get',
|
default: 'getAll',
|
||||||
description: 'The operation to perform.',
|
description: 'The operation to perform.',
|
||||||
},
|
},
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
||||||
export const planFields = [
|
export const planFields = [
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* plan:get */
|
/* plan:get */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'Plan ID',
|
displayName: 'Plan ID',
|
||||||
name: 'planId',
|
name: 'planId',
|
||||||
|
@ -54,45 +54,4 @@ export const planFields = [
|
||||||
},
|
},
|
||||||
description: 'Filter: The subscription plan ID.',
|
description: 'Filter: The subscription plan ID.',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
displayName: 'Return All',
|
|
||||||
name: 'returnAll',
|
|
||||||
type: 'boolean',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
operation: [
|
|
||||||
'getAll',
|
|
||||||
],
|
|
||||||
resource: [
|
|
||||||
'plan',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
default: false,
|
|
||||||
description: 'If all results should be returned or only up to a given limit.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Limit',
|
|
||||||
name: 'limit',
|
|
||||||
type: 'number',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
operation: [
|
|
||||||
'getAll',
|
|
||||||
],
|
|
||||||
resource: [
|
|
||||||
'plan',
|
|
||||||
],
|
|
||||||
returnAll: [
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
typeOptions: {
|
|
||||||
minValue: 1,
|
|
||||||
maxValue: 500,
|
|
||||||
},
|
|
||||||
default: 100,
|
|
||||||
description: 'How many results to return.',
|
|
||||||
},
|
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
|
@ -27,45 +27,4 @@ export const productOperations = [
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
||||||
export const productFields = [
|
export const productFields = [
|
||||||
{
|
|
||||||
displayName: 'Return All',
|
|
||||||
name: 'returnAll',
|
|
||||||
type: 'boolean',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
operation: [
|
|
||||||
'getAll',
|
|
||||||
],
|
|
||||||
resource: [
|
|
||||||
'product',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
default: false,
|
|
||||||
description: 'If all results should be returned or only up to a given limit.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Limit',
|
|
||||||
name: 'limit',
|
|
||||||
type: 'number',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
operation: [
|
|
||||||
'getAll',
|
|
||||||
],
|
|
||||||
resource: [
|
|
||||||
'product',
|
|
||||||
],
|
|
||||||
returnAll: [
|
|
||||||
false,
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
typeOptions: {
|
|
||||||
minValue: 1,
|
|
||||||
maxValue: 500,
|
|
||||||
},
|
|
||||||
default: 100,
|
|
||||||
description: 'How many results to return.',
|
|
||||||
},
|
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
|
@ -27,9 +27,9 @@ export const userOperations = [
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
||||||
export const userFields = [
|
export const userFields = [
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* user:getAll */
|
/* user:getAll */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'Return All',
|
displayName: 'Return All',
|
||||||
name: 'returnAll',
|
name: 'returnAll',
|
||||||
|
@ -51,7 +51,7 @@ export const userFields = [
|
||||||
displayName: 'Limit',
|
displayName: 'Limit',
|
||||||
name: 'limit',
|
name: 'limit',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
default: 100,
|
default: 1,
|
||||||
required: true,
|
required: true,
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
minValue: 1,
|
minValue: 1,
|
||||||
|
@ -90,7 +90,7 @@ export const userFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Additional Fields',
|
displayName: ' Additional Fields',
|
||||||
name: 'additionalFieldsJson',
|
name: 'additionalFieldsJson',
|
||||||
type: 'json',
|
type: 'json',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
|
|
Loading…
Reference in a new issue