first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,758 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const couponOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a coupon',
|
||||
action: 'Create a coupon',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many coupons',
|
||||
action: 'Get many coupons',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a coupon',
|
||||
action: 'Update a coupon',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
];
|
||||
|
||||
export const couponFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* coupon:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Coupon Type',
|
||||
name: 'couponType',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['create'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
default: 'checkout',
|
||||
description:
|
||||
'Either product (valid for specified products or subscription plans) or checkout (valid for any checkout)',
|
||||
options: [
|
||||
{
|
||||
name: 'Checkout',
|
||||
value: 'checkout',
|
||||
},
|
||||
{
|
||||
name: 'Product',
|
||||
value: 'product',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Product Names or IDs',
|
||||
name: 'productIds',
|
||||
type: 'multiOptions',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getProducts',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['create'],
|
||||
couponType: ['product'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
default: [],
|
||||
description:
|
||||
'Comma-separated list of product IDs. Required if coupon_type is product. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Discount Type',
|
||||
name: 'discountType',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['create'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
default: 'flat',
|
||||
description: 'Either flat or percentage',
|
||||
options: [
|
||||
{
|
||||
name: 'Flat',
|
||||
value: 'flat',
|
||||
},
|
||||
{
|
||||
name: 'Percentage',
|
||||
value: 'percentage',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Discount Amount Currency',
|
||||
name: 'discountAmount',
|
||||
type: 'number',
|
||||
default: 1,
|
||||
description: 'Discount amount in currency',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['create'],
|
||||
discountType: ['flat'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Discount Amount %',
|
||||
name: 'discountAmount',
|
||||
type: 'number',
|
||||
default: 1,
|
||||
description: 'Discount amount in percentage',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 100,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['create'],
|
||||
discountType: ['percentage'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Currency',
|
||||
name: 'currency',
|
||||
type: 'options',
|
||||
default: 'EUR',
|
||||
description: 'The currency must match the balance currency specified in your account',
|
||||
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',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['create'],
|
||||
discountType: ['flat'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFieldsJson',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['create'],
|
||||
jsonParameters: [true],
|
||||
},
|
||||
},
|
||||
description: 'Attributes in JSON form',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['create'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Allowed Uses',
|
||||
name: 'allowedUses',
|
||||
type: 'number',
|
||||
default: 1,
|
||||
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: 'Coupon Code',
|
||||
name: 'couponCode',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Will be randomly generated if not specified',
|
||||
},
|
||||
{
|
||||
displayName: 'Coupon Prefix',
|
||||
name: 'couponPrefix',
|
||||
type: 'string',
|
||||
default: '',
|
||||
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',
|
||||
name: 'expires',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
description: 'The coupon will expire on the date at 00:00:00 UTC',
|
||||
},
|
||||
{
|
||||
displayName: 'Group',
|
||||
name: 'group',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 50,
|
||||
},
|
||||
default: '',
|
||||
description: 'The name of the coupon group this coupon should be assigned to',
|
||||
},
|
||||
{
|
||||
displayName: 'Number of Coupons',
|
||||
name: 'numberOfCoupons',
|
||||
type: 'number',
|
||||
default: 1,
|
||||
description: 'Number of coupons to generate. Not valid if coupon_code is specified.',
|
||||
},
|
||||
{
|
||||
displayName: 'Recurring',
|
||||
name: 'recurring',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
|
||||
description:
|
||||
'If the coupon is used on subscription products, this indicates whether the discount should apply to recurring payments after the initial purchase',
|
||||
},
|
||||
],
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* coupon:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Product ID',
|
||||
name: 'productId',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
required: true,
|
||||
description: 'The specific product/subscription ID',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['coupon'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results 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: 'Max number of results to return',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* coupon:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Update By',
|
||||
name: 'updateBy',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['update'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
default: 'couponCode',
|
||||
description: 'Either flat or percentage',
|
||||
options: [
|
||||
{
|
||||
name: 'Coupon Code',
|
||||
value: 'couponCode',
|
||||
},
|
||||
{
|
||||
name: 'Group',
|
||||
value: 'group',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Coupon Code',
|
||||
name: 'couponCode',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['update'],
|
||||
updateBy: ['couponCode'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Identify the coupon to update',
|
||||
},
|
||||
{
|
||||
displayName: 'Group',
|
||||
name: 'group',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['update'],
|
||||
updateBy: ['group'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The name of the group of coupons you want to update',
|
||||
},
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFieldsJson',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['update'],
|
||||
jsonParameters: [true],
|
||||
},
|
||||
},
|
||||
description: 'Attributes in JSON form',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['coupon'],
|
||||
operation: ['update'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Allowed Uses',
|
||||
name: 'allowedUses',
|
||||
type: 'number',
|
||||
default: 1,
|
||||
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',
|
||||
name: 'discount',
|
||||
type: 'fixedCollection',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Discount Properties',
|
||||
name: 'discountProperties',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Currency',
|
||||
name: 'currency',
|
||||
type: 'options',
|
||||
default: 'EUR',
|
||||
description:
|
||||
'The currency must match the balance currency specified in your account',
|
||||
displayOptions: {
|
||||
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: 'Expires',
|
||||
name: 'expires',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
description: 'The coupon will expire on the date at 00:00:00 UTC',
|
||||
},
|
||||
{
|
||||
displayName: 'New Coupon Code',
|
||||
name: 'newCouponCode',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'New code to rename the coupon to',
|
||||
},
|
||||
{
|
||||
displayName: 'New Group Name',
|
||||
name: 'newGroup',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 50,
|
||||
},
|
||||
default: '',
|
||||
description: 'New group name to move coupon to',
|
||||
},
|
||||
{
|
||||
displayName: 'Product IDs',
|
||||
name: 'productIds',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'Comma-separated list of products e.g. 499531,1234,123546. If blank then remove associated products.',
|
||||
},
|
||||
{
|
||||
displayName: 'Recurring',
|
||||
name: 'recurring',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
|
||||
description:
|
||||
'If the coupon is used on subscription products, this indicates whether the discount should apply to recurring payments after the initial purchase',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,89 @@
|
||||
import type {
|
||||
JsonObject,
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IWebhookFunctions,
|
||||
IDataObject,
|
||||
IHttpRequestMethods,
|
||||
IRequestOptions,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
export async function paddleApiRequest(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
|
||||
endpoint: string,
|
||||
method: IHttpRequestMethods,
|
||||
|
||||
body: any = {},
|
||||
_query?: IDataObject,
|
||||
_uri?: string,
|
||||
): Promise<any> {
|
||||
const credentials = await this.getCredentials('paddleApi');
|
||||
const productionUrl = 'https://vendors.paddle.com/api';
|
||||
const sandboxUrl = 'https://sandbox-vendors.paddle.com/api';
|
||||
|
||||
const isSandbox = credentials.sandbox;
|
||||
|
||||
const options: IRequestOptions = {
|
||||
method,
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
uri: `${isSandbox === true ? sandboxUrl : productionUrl}${endpoint}`,
|
||||
body,
|
||||
json: true,
|
||||
};
|
||||
|
||||
body.vendor_id = credentials.vendorId;
|
||||
body.vendor_auth_code = credentials.vendorAuthCode;
|
||||
try {
|
||||
const response = await this.helpers.request(options);
|
||||
|
||||
if (!response.success) {
|
||||
throw new NodeApiError(this.getNode(), response as JsonObject);
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
export async function paddleApiRequestAllItems(
|
||||
this: IHookFunctions | IExecuteFunctions,
|
||||
propertyName: string,
|
||||
endpoint: string,
|
||||
method: IHttpRequestMethods,
|
||||
|
||||
body: any = {},
|
||||
query: IDataObject = {},
|
||||
): Promise<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] as IDataObject[]);
|
||||
body.page++;
|
||||
} while (
|
||||
responseData[propertyName].length !== 0 &&
|
||||
responseData[propertyName].length === body.results_per_page
|
||||
);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export function validateJSON(json: string | undefined): any {
|
||||
let result;
|
||||
try {
|
||||
result = JSON.parse(json!);
|
||||
} catch (exception) {
|
||||
result = undefined;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const orderOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['order'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get an order',
|
||||
action: 'Get an order',
|
||||
},
|
||||
],
|
||||
default: 'get',
|
||||
},
|
||||
];
|
||||
|
||||
export const orderFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* order:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Checkout ID',
|
||||
name: 'checkoutId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['order'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
description: 'The identifier of the buyer’s checkout',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.paddle",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Sales"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/paddle/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.paddle/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,538 @@
|
||||
import moment from 'moment-timezone';
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
INodeExecutionData,
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError, NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { couponFields, couponOperations } from './CouponDescription';
|
||||
import { paddleApiRequest, 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';
|
||||
|
||||
export class Paddle implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Paddle',
|
||||
name: 'paddle',
|
||||
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
||||
icon: 'file:paddle.png',
|
||||
group: ['output'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume Paddle API',
|
||||
defaults: {
|
||||
name: 'Paddle',
|
||||
},
|
||||
usableAsTool: true,
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'paddleApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Coupon',
|
||||
value: 'coupon',
|
||||
},
|
||||
{
|
||||
name: 'Payment',
|
||||
value: 'payment',
|
||||
},
|
||||
{
|
||||
name: 'Plan',
|
||||
value: 'plan',
|
||||
},
|
||||
{
|
||||
name: 'Product',
|
||||
value: 'product',
|
||||
},
|
||||
// {
|
||||
// name: 'Order',
|
||||
// value: 'order',
|
||||
// },
|
||||
{
|
||||
name: 'User',
|
||||
value: 'user',
|
||||
},
|
||||
],
|
||||
default: 'coupon',
|
||||
},
|
||||
// COUPON
|
||||
...couponOperations,
|
||||
...couponFields,
|
||||
// PAYMENT
|
||||
...paymentOperations,
|
||||
...paymentFields,
|
||||
// PLAN
|
||||
...planOperations,
|
||||
...planFields,
|
||||
// PRODUCT
|
||||
...productOperations,
|
||||
...productFields,
|
||||
// ORDER
|
||||
// ...orderOperations,
|
||||
// ...orderFields,
|
||||
// USER
|
||||
...userOperations,
|
||||
...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 new NodeApiError(this.getNode(), paymentResponse as JsonObject, {
|
||||
message: '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 new NodeOperationError(this.getNode(), '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[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
const length = items.length;
|
||||
let responseData;
|
||||
const body: IDataObject = {};
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
for (let i = 0; i < length; i++) {
|
||||
try {
|
||||
if (resource === 'coupon') {
|
||||
if (operation === 'create') {
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i);
|
||||
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter(
|
||||
'additionalFieldsJson',
|
||||
i,
|
||||
) as string;
|
||||
|
||||
if (additionalFieldsJson !== '') {
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
} else {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Additional fields must be a valid JSON',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const discountType = this.getNodeParameter('discountType', i) as string;
|
||||
const couponType = this.getNodeParameter('couponType', i) as string;
|
||||
const discountAmount = this.getNodeParameter('discountAmount', i) as number;
|
||||
|
||||
if (couponType === 'product') {
|
||||
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.discount_type = discountType;
|
||||
body.discount_amount = discountAmount;
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
if (additionalFields.allowedUses) {
|
||||
body.allowed_uses = additionalFields.allowedUses as number;
|
||||
}
|
||||
if (additionalFields.couponCode) {
|
||||
body.coupon_code = additionalFields.couponCode as string;
|
||||
}
|
||||
if (additionalFields.couponPrefix) {
|
||||
body.coupon_prefix = additionalFields.couponPrefix as string;
|
||||
}
|
||||
if (additionalFields.expires) {
|
||||
body.expires = moment(additionalFields.expires as Date).format('YYYY-MM-DD');
|
||||
}
|
||||
if (additionalFields.group) {
|
||||
body.group = additionalFields.group as string;
|
||||
}
|
||||
if (additionalFields.recurring) {
|
||||
body.recurring = 1;
|
||||
} else {
|
||||
body.recurring = 0;
|
||||
}
|
||||
if (additionalFields.numberOfCoupons) {
|
||||
body.num_coupons = additionalFields.numberOfCoupons as number;
|
||||
}
|
||||
if (additionalFields.description) {
|
||||
body.description = additionalFields.description as string;
|
||||
}
|
||||
|
||||
const endpoint = '/2.1/product/create_coupon';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
responseData = responseData.response.coupon_codes.map((coupon: string) => ({
|
||||
coupon,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
if (operation === 'getAll') {
|
||||
const productId = this.getNodeParameter('productId', i) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
const endpoint = '/2.0/product/list_coupons';
|
||||
|
||||
body.product_id = productId;
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
|
||||
if (returnAll) {
|
||||
responseData = responseData.response;
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
responseData = responseData.response.splice(0, limit);
|
||||
}
|
||||
}
|
||||
|
||||
if (operation === 'update') {
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i);
|
||||
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter(
|
||||
'additionalFieldsJson',
|
||||
i,
|
||||
) as string;
|
||||
|
||||
if (additionalFieldsJson !== '') {
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
} else {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Additional fields must be a valid JSON',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const updateBy = this.getNodeParameter('updateBy', i) as string;
|
||||
|
||||
if (updateBy === 'group') {
|
||||
body.group = this.getNodeParameter('group', i) as string;
|
||||
} else {
|
||||
body.coupon_code = this.getNodeParameter('couponCode', i) as string;
|
||||
}
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
if (additionalFields.allowedUses) {
|
||||
body.allowed_uses = additionalFields.allowedUses as number;
|
||||
}
|
||||
if (additionalFields.currency) {
|
||||
body.currency = additionalFields.currency as string;
|
||||
}
|
||||
if (additionalFields.newCouponCode) {
|
||||
body.new_coupon_code = additionalFields.newCouponCode as string;
|
||||
}
|
||||
if (additionalFields.expires) {
|
||||
body.expires = moment(additionalFields.expires as Date).format('YYYY-MM-DD');
|
||||
}
|
||||
if (additionalFields.newGroup) {
|
||||
body.new_group = additionalFields.newGroup as string;
|
||||
}
|
||||
if (additionalFields.recurring === true) {
|
||||
body.recurring = 1;
|
||||
} else if (additionalFields.recurring === false) {
|
||||
body.recurring = 0;
|
||||
}
|
||||
if (additionalFields.productIds) {
|
||||
body.product_ids = additionalFields.productIds as number;
|
||||
}
|
||||
if (additionalFields.discountAmount) {
|
||||
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';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
responseData = responseData.response;
|
||||
}
|
||||
}
|
||||
if (resource === 'payment') {
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i);
|
||||
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter(
|
||||
'additionalFieldsJson',
|
||||
i,
|
||||
) as string;
|
||||
|
||||
if (additionalFieldsJson !== '') {
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
} else {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Additional fields must be a valid JSON',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
if (additionalFields.subscriptionId) {
|
||||
body.subscription_id = additionalFields.subscriptionId as number;
|
||||
}
|
||||
if (additionalFields.plan) {
|
||||
body.plan = additionalFields.plan as string;
|
||||
}
|
||||
if (additionalFields.state) {
|
||||
body.state = additionalFields.state as string;
|
||||
}
|
||||
if (additionalFields.isPaid) {
|
||||
body.is_paid = 1;
|
||||
} else {
|
||||
body.is_paid = 0;
|
||||
}
|
||||
if (additionalFields.from) {
|
||||
body.from = moment(additionalFields.from as Date).format('YYYY-MM-DD');
|
||||
}
|
||||
if (additionalFields.to) {
|
||||
body.to = moment(additionalFields.to as Date).format('YYYY-MM-DD');
|
||||
}
|
||||
if (additionalFields.isOneOffCharge) {
|
||||
body.is_one_off_charge = additionalFields.isOneOffCharge as boolean;
|
||||
}
|
||||
}
|
||||
const endpoint = '/2.0/subscription/payments';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
|
||||
if (returnAll) {
|
||||
responseData = responseData.response;
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
responseData = responseData.response.splice(0, limit);
|
||||
}
|
||||
}
|
||||
if (operation === 'reschedule') {
|
||||
const paymentId = this.getNodeParameter('paymentId', i) as number;
|
||||
const date = this.getNodeParameter('date', i) as Date;
|
||||
|
||||
body.payment_id = paymentId;
|
||||
body.date = body.to = moment(date).format('YYYY-MM-DD');
|
||||
|
||||
const endpoint = '/2.0/subscription/payments_reschedule';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
}
|
||||
}
|
||||
if (resource === 'plan') {
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
const endpoint = '/2.0/subscription/plans';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
|
||||
if (returnAll) {
|
||||
responseData = responseData.response;
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
responseData = responseData.response.splice(0, limit);
|
||||
}
|
||||
}
|
||||
if (operation === 'get') {
|
||||
const planId = this.getNodeParameter('planId', i) as string;
|
||||
|
||||
body.plan = planId;
|
||||
|
||||
const endpoint = '/2.0/subscription/plans';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
responseData = responseData.response;
|
||||
}
|
||||
}
|
||||
if (resource === 'product') {
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
const endpoint = '/2.0/product/get_products';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
|
||||
if (returnAll) {
|
||||
responseData = responseData.response.products;
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
responseData = responseData.response.products.splice(0, limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resource === 'order') {
|
||||
if (operation === 'get') {
|
||||
const endpoint = '/1.0/order';
|
||||
const checkoutId = this.getNodeParameter('checkoutId', i) as string;
|
||||
|
||||
body.checkout_id = checkoutId;
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'GET', body);
|
||||
}
|
||||
}
|
||||
if (resource === 'user') {
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i);
|
||||
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter(
|
||||
'additionalFieldsJson',
|
||||
i,
|
||||
) as string;
|
||||
|
||||
if (additionalFieldsJson !== '') {
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
} else {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Additional fields must be a valid JSON',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
if (additionalFields.state) {
|
||||
body.state = additionalFields.state as string;
|
||||
}
|
||||
if (additionalFields.planId) {
|
||||
body.plan_id = additionalFields.planId as string;
|
||||
}
|
||||
if (additionalFields.subscriptionId) {
|
||||
body.subscription_id = additionalFields.subscriptionId as string;
|
||||
}
|
||||
}
|
||||
|
||||
const endpoint = '/2.0/subscription/users';
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await paddleApiRequestAllItems.call(
|
||||
this,
|
||||
'response',
|
||||
endpoint,
|
||||
'POST',
|
||||
body,
|
||||
);
|
||||
} else {
|
||||
body.results_per_page = this.getNodeParameter('limit', i);
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
responseData = responseData.response;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
const executionErrorData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray({ error: error.message }),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
returnData.push(...executionErrorData);
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
}
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const paymentOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payment'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many payments',
|
||||
action: 'Get many payments',
|
||||
},
|
||||
{
|
||||
name: 'Reschedule',
|
||||
value: 'reschedule',
|
||||
description: 'Reschedule payment',
|
||||
action: 'Reschedule a payment',
|
||||
},
|
||||
],
|
||||
default: 'getAll',
|
||||
},
|
||||
];
|
||||
|
||||
export const paymentFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* payment:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['payment'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results 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: 'Max number of results to return',
|
||||
},
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payment'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFieldsJson',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payment'],
|
||||
operation: ['getAll'],
|
||||
jsonParameters: [true],
|
||||
},
|
||||
},
|
||||
description: 'Attributes in JSON form',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payment'],
|
||||
operation: ['getAll'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Date From',
|
||||
name: 'from',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
description: 'Payment starting from date',
|
||||
},
|
||||
{
|
||||
displayName: 'Date To',
|
||||
name: 'to',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
description: 'Payment up until date',
|
||||
},
|
||||
{
|
||||
displayName: 'Is Paid',
|
||||
name: 'isPaid',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether payment is paid',
|
||||
},
|
||||
{
|
||||
displayName: 'Plan ID',
|
||||
name: 'plan',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Filter: The product/plan ID (single or comma-separated values)',
|
||||
},
|
||||
{
|
||||
displayName: 'Subscription ID',
|
||||
name: 'subscriptionId',
|
||||
type: 'number',
|
||||
default: '',
|
||||
description: 'A specific user subscription ID',
|
||||
},
|
||||
{
|
||||
displayName: 'State',
|
||||
name: 'state',
|
||||
type: 'options',
|
||||
default: 'active',
|
||||
description:
|
||||
'Filter: The user subscription status. Returns all active, past_due, trialing and paused subscription plans if not specified.',
|
||||
options: [
|
||||
{
|
||||
name: 'Active',
|
||||
value: 'active',
|
||||
},
|
||||
{
|
||||
name: 'Past Due',
|
||||
value: 'past_due',
|
||||
},
|
||||
{
|
||||
name: 'Paused',
|
||||
value: 'paused',
|
||||
},
|
||||
{
|
||||
name: 'Trialing',
|
||||
value: 'trialing',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'One Off Charge',
|
||||
name: 'isOneOffCharge',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* payment:reschedule */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Payment Name or ID',
|
||||
name: 'paymentId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getPayments',
|
||||
},
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payment'],
|
||||
operation: ['reschedule'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'The upcoming subscription payment ID. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Date',
|
||||
name: 'date',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['payment'],
|
||||
operation: ['reschedule'],
|
||||
},
|
||||
},
|
||||
description: 'Date you want to move the payment to',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,81 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const planOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['plan'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a plan',
|
||||
action: 'Get a plan',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many plans',
|
||||
action: 'Get many plans',
|
||||
},
|
||||
],
|
||||
default: 'get',
|
||||
},
|
||||
];
|
||||
|
||||
export const planFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* plan:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Plan ID',
|
||||
name: 'planId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['plan'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
description: 'Filter: The subscription plan ID',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['plan'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results 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: 'Max number of results to return',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,58 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const productOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['product'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many products',
|
||||
action: 'Get many products',
|
||||
},
|
||||
],
|
||||
default: 'getAll',
|
||||
},
|
||||
];
|
||||
|
||||
export const productFields: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['product'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results 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: 'Max number of results to return',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,147 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const userOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['user'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many users',
|
||||
action: 'Get many users',
|
||||
},
|
||||
],
|
||||
default: 'getAll',
|
||||
},
|
||||
];
|
||||
|
||||
export const userFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* user:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['user'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
default: 100,
|
||||
required: true,
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 200,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['user'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['user'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFieldsJson',
|
||||
type: 'json',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['user'],
|
||||
operation: ['getAll'],
|
||||
jsonParameters: [true],
|
||||
},
|
||||
},
|
||||
description: 'Attributes in JSON form',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['user'],
|
||||
operation: ['getAll'],
|
||||
jsonParameters: [false],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Plan ID',
|
||||
name: 'planId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Filter: The subscription plan ID',
|
||||
},
|
||||
{
|
||||
displayName: 'Subscription ID',
|
||||
name: 'subscriptionId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'A specific user subscription ID',
|
||||
},
|
||||
{
|
||||
displayName: 'State',
|
||||
name: 'state',
|
||||
type: 'options',
|
||||
default: 'active',
|
||||
description:
|
||||
'Filter: The user subscription status. Returns all active, past_due, trialing and paused subscription plans if not specified.',
|
||||
options: [
|
||||
{
|
||||
name: 'Active',
|
||||
value: 'active',
|
||||
},
|
||||
{
|
||||
name: 'Past Due',
|
||||
value: 'past_due',
|
||||
},
|
||||
{
|
||||
name: 'Paused',
|
||||
value: 'paused',
|
||||
},
|
||||
{
|
||||
name: 'Trialing',
|
||||
value: 'trialing',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 849 B |
Reference in New Issue
Block a user