From b46a29b1a7d9cbe802a7284ab9c1cff7fd2b01f0 Mon Sep 17 00:00:00 2001 From: Rupenieks <32895755+Rupenieks@users.noreply.github.com> Date: Tue, 30 Jun 2020 13:34:09 +0200 Subject: [PATCH 1/3] :construction: Resource descriptions --- .../credentials/PaddleApi.credentials.ts | 23 + .../nodes/Paddle/CouponDescription.ts | 447 ++++++++++++++++++ .../nodes/Paddle/GenericFunctions.ts | 41 ++ .../nodes/Paddle/OrderDescription.ts | 52 ++ .../nodes-base/nodes/Paddle/Paddle.node.ts | 92 ++++ .../nodes/Paddle/PaddleTrigger.node.ts | 164 +++++++ .../nodes/Paddle/PaymentDescription.ts | 197 ++++++++ .../nodes/Paddle/PlanDescription.ts | 52 ++ .../nodes/Paddle/ProductDescription.ts | 31 ++ .../nodes/Paddle/UserDescription.ts | 136 ++++++ packages/nodes-base/nodes/Paddle/paddle.png | Bin 0 -> 3076 bytes packages/nodes-base/package.json | 2 + 12 files changed, 1237 insertions(+) create mode 100644 packages/nodes-base/credentials/PaddleApi.credentials.ts create mode 100644 packages/nodes-base/nodes/Paddle/CouponDescription.ts create mode 100644 packages/nodes-base/nodes/Paddle/GenericFunctions.ts create mode 100644 packages/nodes-base/nodes/Paddle/OrderDescription.ts create mode 100644 packages/nodes-base/nodes/Paddle/Paddle.node.ts create mode 100644 packages/nodes-base/nodes/Paddle/PaddleTrigger.node.ts create mode 100644 packages/nodes-base/nodes/Paddle/PaymentDescription.ts create mode 100644 packages/nodes-base/nodes/Paddle/PlanDescription.ts create mode 100644 packages/nodes-base/nodes/Paddle/ProductDescription.ts create mode 100644 packages/nodes-base/nodes/Paddle/UserDescription.ts create mode 100644 packages/nodes-base/nodes/Paddle/paddle.png diff --git a/packages/nodes-base/credentials/PaddleApi.credentials.ts b/packages/nodes-base/credentials/PaddleApi.credentials.ts new file mode 100644 index 0000000000..143a24b3b8 --- /dev/null +++ b/packages/nodes-base/credentials/PaddleApi.credentials.ts @@ -0,0 +1,23 @@ +import { + ICredentialType, + NodePropertyTypes, +} from 'n8n-workflow'; + +export class PaddleApi implements ICredentialType { + name = 'paddleApi'; + displayName = 'Paddle API'; + properties = [ + { + displayName: 'Vendor Auth Code', + name: 'vendorAuthCode', + type: 'string' as NodePropertyTypes, + default: '', + }, + { + displayName: 'Vendor ID', + name: 'vendorId', + type: 'string' as NodePropertyTypes, + default: '', + }, + ]; +} diff --git a/packages/nodes-base/nodes/Paddle/CouponDescription.ts b/packages/nodes-base/nodes/Paddle/CouponDescription.ts new file mode 100644 index 0000000000..063ae2eda0 --- /dev/null +++ b/packages/nodes-base/nodes/Paddle/CouponDescription.ts @@ -0,0 +1,447 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const couponOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'coupon', + ], + }, + }, + options: [ + { + name: 'Create', + value: 'create', + description: 'Create a coupon.', + }, + { + name: 'Get All', + value: 'getAll', + description: 'Get all coupons.', + }, + { + name: 'Update', + value: 'update', + description: 'Update a coupon.', + }, + ], + default: 'create', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const couponFields = [ + +/* -------------------------------------------------------------------------- */ +/* coupon:create */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Coupon Type', + name: 'couponType', + type: 'options', + displayOptions: { + show: { + resource: [ + 'coupon', + ], + operation: [ + `create` + ] + }, + }, + default: '', + 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 ID(s)', + name: 'productIds', + type: 'string', + displayOptions: { + show: { + resource: [ + 'coupon', + ], + operation: [ + `create` + ], + couponType: [ + 'product', + ], + }, + }, + default: '', + description: 'Comma-separated list of product IDs. Required if coupon_type is product.', + required: true, + }, + { + displayName: 'Discount Type', + name: 'discountType', + type: 'options', + displayOptions: { + show: { + resource: [ + 'coupon', + ], + operation: [ + `create` + ], + }, + }, + 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: '', + description: 'Discount amount in currency.', + typeOptions: { + minValue: 0 + }, + displayOptions: { + show: { + resource: [ + 'coupon', + ], + operation: [ + `create` + ], + discountType: [ + 'flat', + ] + }, + }, + }, + { + displayName: 'Discount Amount %', + name: 'discountAmount', + type: 'number', + default: '', + description: 'Discount amount in percentage.', + typeOptions: { + minValue: 0, + maxValue: 100 + }, + displayOptions: { + show: { + resource: [ + 'coupon', + ], + operation: [ + `create` + ], + discountType: [ + 'percentage', + ] + }, + }, + }, + { + displayName: 'Currency', + name: 'currency', + type: 'options', + default: 'eur', + description: 'The currency must match the balance currency specified in your account.', + options: [ + { + name: 'EUR', + value: 'eur' + }, + { + name: 'GBP', + value: 'gbp' + }, + { + name: 'USD', + value: 'usd' + }, + ], + displayOptions: { + show: { + resource: [ + 'coupon', + ], + operation: [ + `create` + ], + discountType: [ + 'flat', + ] + }, + }, + }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + displayOptions: { + show: { + resource: [ + 'coupon', + ], + operation: [ + 'create', + ], + }, + }, + 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: '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: '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', + name: 'numberOfCoupons', + type: 'number', + default: 1, + description: 'Number of coupons to generate. 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.', + }, + ], + }, +/* -------------------------------------------------------------------------- */ +/* coupon:update */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Update by', + name: 'updateBy', + type: 'options', + displayOptions: { + show: { + resource: [ + 'coupon', + ], + operation: [ + `update` + ], + }, + }, + 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' + ] + }, + }, + default: '', + description: 'Identify the coupon to update', + }, + { + displayName: 'Group', + name: 'group', + type: 'string', + displayOptions: { + show: { + resource: [ + 'coupon', + ], + operation: [ + 'update' + ], + updateBy: [ + 'group' + ] + }, + }, + default: '', + description: 'The name of the group of coupons you want to update.', + }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + displayOptions: { + show: { + resource: [ + 'coupon', + ], + operation: [ + 'update', + ], + }, + }, + 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: 'Currency', + name: 'currency', + type: 'options', + default: 'eur', + description: 'The currency must match the balance currency specified in your account.', + options: [ + { + name: 'EUR', + value: 'eur' + }, + { + name: 'GBP', + value: 'gbp' + }, + { + name: 'USD', + value: 'usd' + }, + ], + }, + + { + displayName: 'Discount Amount', + name: 'discountAmount', + type: 'number', + default: '', + description: 'Discount amount.', + typeOptions: { + minValue: 0 + }, + }, + { + 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 ID(s)', + name: 'productIds', + type: 'string', + default: '', + description: 'Comma-separated list of product IDs. Required if coupon_type is product.', + }, + { + 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.', + }, + ], + }, + +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Paddle/GenericFunctions.ts b/packages/nodes-base/nodes/Paddle/GenericFunctions.ts new file mode 100644 index 0000000000..62f054414e --- /dev/null +++ b/packages/nodes-base/nodes/Paddle/GenericFunctions.ts @@ -0,0 +1,41 @@ +import { OptionsWithUri } from 'request'; + +import { + IExecuteFunctions, + IHookFunctions, + ILoadOptionsFunctions, + IExecuteSingleFunctions, + IWebhookFunctions, + BINARY_ENCODING +} from 'n8n-core'; + +import { + IDataObject, +} from 'n8n-workflow'; + +export async function paddleApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise { // tslint:disable-line:no-any + const credentials = this.getCredentials('paddleApi'); + + const options = { + method, + qs: query || {}, + uri: uri || `${env}/v1${endpoint}`, + body, + json: true + }; + + try { + return await this.helpers.request!(options); + } catch (error) { + + if (error.response.body) { + let errorMessage = error.response.body.message; + if (error.response.body.details) { + errorMessage += ` - Details: ${JSON.stringify(error.response.body.details)}`; + } + throw new Error(errorMessage); + } + + throw error; + } +} diff --git a/packages/nodes-base/nodes/Paddle/OrderDescription.ts b/packages/nodes-base/nodes/Paddle/OrderDescription.ts new file mode 100644 index 0000000000..367082a4b3 --- /dev/null +++ b/packages/nodes-base/nodes/Paddle/OrderDescription.ts @@ -0,0 +1,52 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const orderOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'order', + ], + }, + }, + options: [ + { + name: 'Get', + value: 'get', + description: 'Get an order', + } + ], + default: 'get', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const orderFields = [ + +/* -------------------------------------------------------------------------- */ +/* 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.', + }, +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Paddle/Paddle.node.ts b/packages/nodes-base/nodes/Paddle/Paddle.node.ts new file mode 100644 index 0000000000..b40102dec0 --- /dev/null +++ b/packages/nodes-base/nodes/Paddle/Paddle.node.ts @@ -0,0 +1,92 @@ +import { + IExecuteFunctions, +} from 'n8n-core'; + +import { + IDataObject, + ILoadOptionsFunctions, + INodeExecutionData, + INodePropertyOptions, + INodeType, + INodeTypeDescription, +} from 'n8n-workflow'; + +export class Paddle implements INodeType { + description: INodeTypeDescription = { + displayName: 'Paddle', + name: 'paddle', + icon: 'file:paddle.png', + group: ['output'], + version: 1, + subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', + description: 'Consume Paddle API', + defaults: { + name: 'Paddle', + color: '#45567c', + }, + inputs: ['main'], + outputs: ['main'], + credentials: [ + { + name: 'paddleApi', + required: true, + }, + ], + properties: [ + { + displayName: 'Resource', + name: 'resource', + type: 'options', + options: [ + { + name: 'Coupon', + value: 'coupon', + + }, + { + name: 'Payments', + value: 'payments', + }, + { + name: 'Plan', + value: 'plan', + }, + { + name: 'Product', + value: 'product', + }, + { + name: 'Order', + value: 'order', + }, + { + name: 'User', + value: 'user', + }, + ], + default: 'coupon', + description: 'Resource to consume.', + }, + + ], + }; + + async execute(this: IExecuteFunctions): Promise { + const items = this.getInputData(); + const returnData: IDataObject[] = []; + const length = items.length as unknown as number; + let responseData; + const qs: IDataObject = {}; + const resource = this.getNodeParameter('resource', 0) as string; + const operation = this.getNodeParameter('operation', 0) as string; + for (let i = 0; i < length; i++) { + + if (Array.isArray(responseData)) { + returnData.push.apply(returnData, responseData as IDataObject[]); + } else { + returnData.push(responseData as unknown as IDataObject); + } + } + return [this.helpers.returnJsonArray(returnData)]; + } +} diff --git a/packages/nodes-base/nodes/Paddle/PaddleTrigger.node.ts b/packages/nodes-base/nodes/Paddle/PaddleTrigger.node.ts new file mode 100644 index 0000000000..a2b5c6e484 --- /dev/null +++ b/packages/nodes-base/nodes/Paddle/PaddleTrigger.node.ts @@ -0,0 +1,164 @@ +import { + IHookFunctions, + IWebhookFunctions, + } from 'n8n-core'; + + import { + IDataObject, + INodeTypeDescription, + INodeType, + IWebhookResponseData, + ILoadOptionsFunctions, + INodePropertyOptions, + } from 'n8n-workflow'; + + 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 { + 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 payPalApiRequest.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 { + 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 payPalApiRequest.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 { + const webhookData = this.getWorkflowStaticData('node'); + if (webhookData.webhookId !== undefined) { + const endpoint = `/notifications/webhooks/${webhookData.webhookId}`; + try { + await payPalApiRequest.call(this, endpoint, 'DELETE', {}); + } catch (e) { + return false; + } + delete webhookData.webhookId; + } + return true; + }, + }, + }; + + async webhook(this: IWebhookFunctions): Promise { + 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 payPalApiRequest.call(this, endpoint, 'POST', body); + } catch (e) { + throw e; + } + if (webhook.verification_status !== 'SUCCESS') { + return {}; + } + } else { + return {}; + } + return { + workflowData: [ + this.helpers.returnJsonArray(req.body) + ], + }; + } + } diff --git a/packages/nodes-base/nodes/Paddle/PaymentDescription.ts b/packages/nodes-base/nodes/Paddle/PaymentDescription.ts new file mode 100644 index 0000000000..ef4faa55bc --- /dev/null +++ b/packages/nodes-base/nodes/Paddle/PaymentDescription.ts @@ -0,0 +1,197 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const paymentOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'payment', + ], + }, + }, + options: [ + { + name: 'Get All', + value: 'getAll', + description: 'Get all payments.', + }, + { + name: 'Reschedule', + value: 'reschedule', + description: 'Reschedule payment.', + } + ], + default: 'getAll', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const paymentFields = [ + +/* -------------------------------------------------------------------------- */ +/* payment:getAll */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Subscription ID', + name: 'subscriptionId', + type: 'number', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'getAll', + ], + }, + }, + description: 'A specific user subscription ID.', + }, + { + displayName: 'Plan', + name: 'planId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'getAll', + ], + }, + }, + description: 'Filter: The product/plan ID (single or comma-separated values).', + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + default: 1, + required: true, + typeOptions: { + minValue: 1, + maxValue: 200 + }, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'getAll', + ], + }, + }, + description: 'Number of subscription records to return per page.', + }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + displayOptions: { + show: { + operation: [ + 'getAll', + ], + resource: [ + 'user', + ], + }, + }, + default: {}, + options: [ + { + 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: 'Is Paid', + name: 'isPaid', + type: 'boolean', + default: false, + description: 'Payment is paid.', + }, + { + displayName: 'From', + name: 'from', + type: 'DateTime', + default: '', + description: 'Payments starting from date.', + }, + { + displayName: 'To', + name: 'to', + type: 'DateTime', + default: '', + description: 'Payments up until date.', + }, + { + displayName: 'One off charge', + name: 'isOneOffCharge', + type: 'boolean', + default: false, + description: 'Payment is paid.', + }, + ], + }, +/* -------------------------------------------------------------------------- */ +/* payment:reschedule */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Payment ID', + name: 'paymentId', + type: 'number', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'getAll', + ], + }, + }, + description: 'The upcoming subscription payment ID.', // Use loadoptions to select payment + }, + { + displayName: 'Date', + name: 'date', + type: 'DateTime', + default: '', + description: 'Date you want to move the payment to.', + }, +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Paddle/PlanDescription.ts b/packages/nodes-base/nodes/Paddle/PlanDescription.ts new file mode 100644 index 0000000000..9ddf82046e --- /dev/null +++ b/packages/nodes-base/nodes/Paddle/PlanDescription.ts @@ -0,0 +1,52 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const planOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'plan', + ], + }, + }, + options: [ + { + name: 'Get All', + value: 'getAll', + description: 'Get all plans.', + } + ], + default: 'getAll', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const planFields = [ + +/* -------------------------------------------------------------------------- */ +/* plan:getAll */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Plan ID', + name: 'planId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'plan', + ], + operation: [ + 'getAll', + ], + }, + }, + description: 'Filter: The subscription plan ID.', + }, +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Paddle/ProductDescription.ts b/packages/nodes-base/nodes/Paddle/ProductDescription.ts new file mode 100644 index 0000000000..b2565b6dd2 --- /dev/null +++ b/packages/nodes-base/nodes/Paddle/ProductDescription.ts @@ -0,0 +1,31 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const productOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'product', + ], + }, + }, + options: [ + { + name: 'Get All', + value: 'getAll', + description: 'Get all products.', + } + ], + default: 'getAll', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const productFields = [ + +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Paddle/UserDescription.ts b/packages/nodes-base/nodes/Paddle/UserDescription.ts new file mode 100644 index 0000000000..b970be875a --- /dev/null +++ b/packages/nodes-base/nodes/Paddle/UserDescription.ts @@ -0,0 +1,136 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const userOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'user', + ], + }, + }, + options: [ + { + name: 'Get All', + value: 'getAll', + description: 'Get all users', + } + ], + default: 'getAll', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const userFields = [ + +/* -------------------------------------------------------------------------- */ +/* user:getAll */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Subscription ID', + name: 'subscriptionId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'getAll', + ], + }, + }, + description: 'A specific user subscription ID.', + }, + { + displayName: 'Plan ID', + name: 'planId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'getAll', + ], + }, + }, + description: 'Filter: The subscription plan ID.', + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + default: 1, + required: true, + typeOptions: { + minValue: 1, + maxValue: 200 + }, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'getAll', + ], + }, + }, + description: 'Number of subscription records to return per page.', + }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + displayOptions: { + show: { + operation: [ + 'getAll', + ], + resource: [ + 'user', + ], + }, + }, + default: {}, + options: [ + { + 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' + }, + ] + }, + ], + }, +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Paddle/paddle.png b/packages/nodes-base/nodes/Paddle/paddle.png new file mode 100644 index 0000000000000000000000000000000000000000..80426ca92c3439e320c00be5eb12476c4957f7ab GIT binary patch literal 3076 zcmcImX;c$g77nW*q9CGx3o)P~kbQwf77>CVgf(guu&q=o5J^%Y6-feuqK%3S>YxpX z*eEEXqJoIpE^R<*pVEIt2Na~5xUbu|IiUgjx<#Y~-BlCsgL;*>1C^9L8 z3ns;bOaac@3+tg`p#&000bo@Uu@qscJaJ!mS?FGOOvGWoKos$wI3JxuERPe0^@ZgS zmQG;cK{Cx9>&7II88i}=;fke@$V?*1ok*tQNn{p@!J@liM}9cen_M7dMfmxT_(JbI zad8TTj720Wl}dt=N`U3DL^6|!a!`mA3LZt^5w%nSsPIz6VU)oSLO{7lrVznWtd0@j z!)q0uI8^Cy2ol*CtrQta6Phrh3Xl=W1d=YKQ6Pu&b*Mx#hDH?ZMAXZO-oGS9xM~?h zjDQe$tsI2diI7y`FzQSIj@ioA%EezI6@WxY3`tNJf(j##xst`f3K)rl|0a&H$79jR zSiW)yP{49742wq#6*kI(rJzw`otBHF0$7R6*C`q?fcyXj5kKqORu3zWlQ1xgVGAO)d7KTjMgiXajRSWJNFMt0)^ zcsj%c@gxC_j|WIX8lLLzEg>5 z1y2{aK`0T8iFc>c=y-r3gxo;}olX@(qimsa5&Gr;;y<(MR0&Wi_)QyMmT+?omH@-r}h(XiyVgsBfv2+{kI&I~92uPi)!i zSBFrR_(}E$|;-xlH(rd|DMIkT)V(ymB@S7-IIh39$A zk1{XsO%7{o+R>M`xX`=3!Sv^F$WSxh&N1Po-TaAXqmskaRTGU~q}H}xVQ&p)8GkNM z=`jzk-MC?j>%`Xd{hVT^2c^JJ1uSB970)|Rq`vLW#QnRljR9f zQ_~J<>gU-lqc-z5Mw*nxG(UT<-rG)FPb~`&p)*Cs#L%eu#$8n&_1OKh-}SX^KZ4Y}%YSCKo6F5ic1sMj_;6{{ zcQyRMqdvgE`JrsX18es(Eo=0}!o?=krZqhKd`?Rf=&(lWQv1o;IRoQTudFYs@anS= zKdDj7ef=~S)9ltZ2Wc%a0DAk(mmJaxaY@OHnrD=!mpp8(>bArZo{YEGZ%oZ?i+XT! z5$~g=Ua($_on}Vfo86!EuU0SE=C~5W+truz{lSd58@G4G9(QnY-*oH5s*31}hF-r$ zHzl_Bs`>z@TiaDwwkdJF%c|d8hKfTZkDN_0h|48j<}`e6&0PpT)l#)?Z9vjd;jfCPItX334aSpHPYttgMajg z80#9VQ%-f!S6Y%&_%i2+*+XTUmhbLq$hbAzJui9Hx{|iSsuHf!=h3xvo6zbdZG~#v zUbB|0srlGOUsQ+TQrXX?&8)#$HE`D~-YpYry{+TCY|0s;r-?tE`C;Qq+LOBGDot5J zZhDmLRno4207tzWo%MH1ZB^1cL>qAWhrE&rdX+r|RpFRu%Zl&fmOgH{0#9f6%GRYk zeZ490Ftf6(lrLvj0_v=vw07Lyks_V;=m+9U4iOXnqbV@RviAFqU(gU6lov1(C!zR=!`8FZStkNs-?;nG~# znH@&8Yk#->Si;*%vrudO=%BXdvbO6@+G_6Il2pZu&jz@=2a@);PNdkac3HA0F`P~3 z1>O2kAn&nIy{b+M2gpqX3)^d%TaE^=OVt#FBFAU!&DoJ%c%r@kjWV1a5wR+LZNdti z%QG(bSWIeT_dlM5DYktg73+68*QEqrJm;0}Jb!uH@kM1VH9*%zZQ8vUbfp zyUW^~_7jI@x6iBUTEe85U4Ah*P+xBwKh5xSk0Na4_7g+CXKqp{noXuduAv&2GcHHA zw`P}Ve#mPgM{C|usP$RlTk z7j-^=pJUKyIPZP(Vy%-QyQH}MUqwr);`+<(^G#F*zNECAnlSJ-;32eqct5-U@M-?(!&^QdR_#p7 znwjT-`1dh;F`eIU47HqC=t@sny?I}^b%toxblG!Zrjrq8a$a+cS5OC-dxxRdp@~ZF zjF)T3M}AU0on!wX*&pZbY)}j3Hog&S%THD|*q_@W&Z#WT3cS|yxGL)W!Hvo})(&P1 zJSJ6%(xBD0JaoyL@!)N0DYVSHc4%C= XufyuO^DY|czS9HQA$}(ot={+t`pL%m literal 0 HcmV?d00001 diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index c19d8e2349..c22657642e 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -104,6 +104,7 @@ "dist/credentials/OAuth1Api.credentials.js", "dist/credentials/OAuth2Api.credentials.js", "dist/credentials/OpenWeatherMapApi.credentials.js", + "dist/credentials/PaddleApi.credentials.js", "dist/credentials/PagerDutyApi.credentials.js", "dist/credentials/PagerDutyOAuth2Api.credentials.js", "dist/credentials/PayPalApi.credentials.js", @@ -246,6 +247,7 @@ "dist/nodes/NextCloud/NextCloud.node.js", "dist/nodes/NoOp.node.js", "dist/nodes/OpenWeatherMap.node.js", + "dist/nodes/Paddle/Paddle.node.js", "dist/nodes/PagerDuty/PagerDuty.node.js", "dist/nodes/PayPal/PayPal.node.js", "dist/nodes/PayPal/PayPalTrigger.node.js", From 4a968ee8ea14965908ec6e3c0859a75a112b260d Mon Sep 17 00:00:00 2001 From: Rupenieks <32895755+Rupenieks@users.noreply.github.com> Date: Tue, 30 Jun 2020 17:38:55 +0200 Subject: [PATCH 2/3] :construction: Node logic / Genericfunctions setup --- .../nodes/Paddle/CouponDescription.ts | 24 +- .../nodes/Paddle/GenericFunctions.ts | 24 +- .../nodes-base/nodes/Paddle/Paddle.node.ts | 226 +++++++++++++++++- .../nodes/Paddle/PaddleTrigger.node.ts | 9 +- .../nodes/Paddle/PaymentDescription.ts | 23 -- 5 files changed, 254 insertions(+), 52 deletions(-) diff --git a/packages/nodes-base/nodes/Paddle/CouponDescription.ts b/packages/nodes-base/nodes/Paddle/CouponDescription.ts index 063ae2eda0..553a0c0ffd 100644 --- a/packages/nodes-base/nodes/Paddle/CouponDescription.ts +++ b/packages/nodes-base/nodes/Paddle/CouponDescription.ts @@ -37,7 +37,6 @@ export const couponOperations = [ ] as INodeProperties[]; export const couponFields = [ - /* -------------------------------------------------------------------------- */ /* coupon:create */ /* -------------------------------------------------------------------------- */ @@ -55,7 +54,7 @@ export const couponFields = [ ] }, }, - default: '', + default: 'checkout', description: 'Either product (valid for specified products or subscription plans) or checkout (valid for any checkout).', options: [ { @@ -277,6 +276,26 @@ export const couponFields = [ ], }, /* -------------------------------------------------------------------------- */ +/* coupon:getAll */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Product ID', + name: 'productId', + type: 'number', + displayOptions: { + show: { + resource: [ + 'coupon', + ], + operation: [ + `getAll` + ] + }, + }, + default: '', + description: 'The specific product/subscription ID.', + }, +/* -------------------------------------------------------------------------- */ /* coupon:update */ /* -------------------------------------------------------------------------- */ { @@ -391,7 +410,6 @@ export const couponFields = [ }, ], }, - { displayName: 'Discount Amount', name: 'discountAmount', diff --git a/packages/nodes-base/nodes/Paddle/GenericFunctions.ts b/packages/nodes-base/nodes/Paddle/GenericFunctions.ts index 62f054414e..c56498935a 100644 --- a/packages/nodes-base/nodes/Paddle/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Paddle/GenericFunctions.ts @@ -16,26 +16,24 @@ import { export async function paddleApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise { // tslint:disable-line:no-any const credentials = this.getCredentials('paddleApi'); - const options = { + if (credentials === undefined) { + throw new Error('Could not retrieve credentials!'); + } + + const options : OptionsWithUri = { method, - qs: query || {}, - uri: uri || `${env}/v1${endpoint}`, + uri: `https://vendors.paddle.com/api${endpoint}` , body, json: true }; + body.vendor_id = credentials.vendorId; + body.vendor_auth_code = credentials.vendorAuthCode; + try { return await this.helpers.request!(options); } catch (error) { - - if (error.response.body) { - let errorMessage = error.response.body.message; - if (error.response.body.details) { - errorMessage += ` - Details: ${JSON.stringify(error.response.body.details)}`; - } - throw new Error(errorMessage); - } - - throw error; + console.log(error); + throw new Error(error); } } diff --git a/packages/nodes-base/nodes/Paddle/Paddle.node.ts b/packages/nodes-base/nodes/Paddle/Paddle.node.ts index b40102dec0..0a781e9bb4 100644 --- a/packages/nodes-base/nodes/Paddle/Paddle.node.ts +++ b/packages/nodes-base/nodes/Paddle/Paddle.node.ts @@ -1,15 +1,21 @@ -import { - IExecuteFunctions, -} from 'n8n-core'; - +import { IExecuteFunctions } from 'n8n-core'; import { IDataObject, - ILoadOptionsFunctions, + INodeExecutionData, - INodePropertyOptions, + INodeType, - INodeTypeDescription, + INodeTypeDescription } from 'n8n-workflow'; +import { couponFields, couponOperations } from './CouponDescription'; +import { paddleApiRequest } from './GenericFunctions'; +import { paymentFields, paymentOperations } from './PaymentDescription'; +import { planFields, planOperations } from './PlanDescription'; +import { productFields, productOperations } from './ProductDescription'; +import { userFields, userOperations } from './UserDescription'; + +import moment = require('moment'); +import { response } from 'express'; export class Paddle implements INodeType { description: INodeTypeDescription = { @@ -41,7 +47,6 @@ export class Paddle implements INodeType { { name: 'Coupon', value: 'coupon', - }, { name: 'Payments', @@ -68,6 +73,22 @@ export class Paddle implements INodeType { description: 'Resource to consume.', }, + // COUPON + couponFields, + couponOperations, + // PAYMENT + paymentFields, + paymentOperations, + // PLAN + planFields, + planOperations, + // PRODUCT + productFields, + productOperations, + // USER + userFields, + userOperations + ], }; @@ -76,10 +97,197 @@ export class Paddle implements INodeType { const returnData: IDataObject[] = []; const length = items.length as unknown as number; let responseData; - const qs: IDataObject = {}; + const body: IDataObject = {}; const resource = this.getNodeParameter('resource', 0) as string; const operation = this.getNodeParameter('operation', 0) as string; for (let i = 0; i < length; i++) { + if (resource === 'coupon') { + if (operation === 'create') { + const productIds = this.getNodeParameter('productIds', i) as string; + const discountType = this.getNodeParameter('discountType', i) as string; + const discountAmount = this.getNodeParameter('discountAmount', i) as number; + const currency = this.getNodeParameter('currency', i) as string; + + body.product_ids = productIds; + body.discount_type = discountType; + body.discount_amount = discountAmount; + body.currency = currency; + + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + + 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') as string; + } + if (additionalFields.group) { + body.group = additionalFields.group as string; + } + if (additionalFields.recurring) { + if (additionalFields.recurring === true) { + 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 = paddleApiRequest.call(this, endpoint, 'POST', body); + } + + if (operation === 'getAll') { + const productIds = this.getNodeParameter('productId', i) as string; + const endpoint = '/2.0/product/list_coupons'; + + body.product_ids = productIds as string; + + responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + } + + if (operation === 'update') { + 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) as IDataObject; + + 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') as string; + } + if (additionalFields.newGroup) { + body.new_group = additionalFields.newGroup as string; + } + if (additionalFields.recurring) { + if (additionalFields.recurring === true) { + body.recurring = 1; + } else { + body.recurring = 0; + } + } + if (additionalFields.productIds) { + body.product_ids = additionalFields.productIds as number; + } + if (additionalFields.discountAmount) { + body.discount_amount = additionalFields.discountAmount as number; + } + + const endpoint = '/2.1/product/update_coupon'; + + responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + } + } + if (resource === 'payment') { + if (operation === 'getAll') { + const subscriptionId = this.getNodeParameter('subscription', i) as string; + const planId = this.getNodeParameter('planId', i) as string; + + body.subscription_id = subscriptionId; + body.plan_id = planId; + + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + + if (additionalFields.state) { + body.state = additionalFields.state as string; + } + if (additionalFields.isPaid) { + if (additionalFields.isPaid === true) { + body.is_paid = 0; + } else { + body.is_paid = 1; + } + } + if (additionalFields.from) { + body.from = moment(additionalFields.from as Date).format('YYYY/MM/DD') as string; + } + if (additionalFields.to) { + body.to = moment(additionalFields.to as Date).format('YYYY/MM/DD') as string; + } + if (additionalFields.isOneOffCharge) { + body.is_one_off_charge = additionalFields.isOneOffCharge as boolean; + } + + const endpoint = '/2.0/subscription/payments'; + responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + } + 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 as Date).format('YYYY/MM/DD') as string; + + const endpoint = '/2.0/subscription/payments_reschedule'; + + responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + } + } + if (resource === 'plan') { + if (operation === 'getAll') { + const planId = this.getNodeParameter('planId', i) as string; + + body.plan = planId; + + const endpoint = '/2.0/subscription/plans'; + + responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + } + } + if (resource === 'product') { + if (operation === 'getAll') { + const endpoint = '/2.0/product/get_products'; + + responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + } + } + + if (resource === 'user') { + if (operation === 'getAll') { + const subscriptionId = this.getNodeParameter('subscriptionId', i) as string; + const planId = this.getNodeParameter('planId', i) as string; + const limit = this.getNodeParameter('limit', i) as number; + + body.subscription_id = subscriptionId; + body.plan_id = planId; + body.results_per_page = limit; + + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + + if (additionalFields.state) { + body.state = additionalFields.state as string; + } + + const endpoint = '/2.0/subscription/users'; + + responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + } + } if (Array.isArray(responseData)) { returnData.push.apply(returnData, responseData as IDataObject[]); diff --git a/packages/nodes-base/nodes/Paddle/PaddleTrigger.node.ts b/packages/nodes-base/nodes/Paddle/PaddleTrigger.node.ts index a2b5c6e484..f439a5beb6 100644 --- a/packages/nodes-base/nodes/Paddle/PaddleTrigger.node.ts +++ b/packages/nodes-base/nodes/Paddle/PaddleTrigger.node.ts @@ -11,6 +11,7 @@ import { ILoadOptionsFunctions, INodePropertyOptions, } from 'n8n-workflow'; +import { paddleApiRequest } from './GenericFunctions'; export class PaddleTrigger implements INodeType { description: INodeTypeDescription = { @@ -69,7 +70,7 @@ import { } const endpoint = `/notifications/webhooks/${webhookData.webhookId}`; try { - await payPalApiRequest.call(this, endpoint, 'GET'); + await paddleApiRequest.call(this, endpoint, 'GET'); } catch (err) { if (err.response && err.response.name === 'INVALID_RESOURCE_ID') { // Webhook does not exist @@ -93,7 +94,7 @@ import { }; const endpoint = '/notifications/webhooks'; try { - webhook = await payPalApiRequest.call(this, endpoint, 'POST', body); + webhook = await paddleApiRequest.call(this, endpoint, 'POST', body); } catch (e) { throw e; } @@ -111,7 +112,7 @@ import { if (webhookData.webhookId !== undefined) { const endpoint = `/notifications/webhooks/${webhookData.webhookId}`; try { - await payPalApiRequest.call(this, endpoint, 'DELETE', {}); + await paddleApiRequest.call(this, endpoint, 'DELETE', {}); } catch (e) { return false; } @@ -145,7 +146,7 @@ import { webhook_event: bodyData, }; try { - webhook = await payPalApiRequest.call(this, endpoint, 'POST', body); + webhook = await paddleApiRequest.call(this, endpoint, 'POST', body); } catch (e) { throw e; } diff --git a/packages/nodes-base/nodes/Paddle/PaymentDescription.ts b/packages/nodes-base/nodes/Paddle/PaymentDescription.ts index ef4faa55bc..77ff5ca432 100644 --- a/packages/nodes-base/nodes/Paddle/PaymentDescription.ts +++ b/packages/nodes-base/nodes/Paddle/PaymentDescription.ts @@ -32,7 +32,6 @@ export const paymentOperations = [ ] as INodeProperties[]; export const paymentFields = [ - /* -------------------------------------------------------------------------- */ /* payment:getAll */ /* -------------------------------------------------------------------------- */ @@ -72,28 +71,6 @@ export const paymentFields = [ }, description: 'Filter: The product/plan ID (single or comma-separated values).', }, - { - displayName: 'Limit', - name: 'limit', - type: 'number', - default: 1, - required: true, - typeOptions: { - minValue: 1, - maxValue: 200 - }, - displayOptions: { - show: { - resource: [ - 'user', - ], - operation: [ - 'getAll', - ], - }, - }, - description: 'Number of subscription records to return per page.', - }, { displayName: 'Additional Fields', name: 'additionalFields', From 0b46f5d63a8a0052ce733fa82a9186392b4fa557 Mon Sep 17 00:00:00 2001 From: Rupenieks <32895755+Rupenieks@users.noreply.github.com> Date: Thu, 2 Jul 2020 11:12:27 +0200 Subject: [PATCH 3/3] :construction: Tests / changes --- .../nodes/Paddle/CouponDescription.ts | 143 +++++++- .../nodes/Paddle/GenericFunctions.ts | 29 +- .../nodes-base/nodes/Paddle/Paddle.node.ts | 328 +++++++++++------- .../nodes/Paddle/PaymentDescription.ts | 130 ++++--- .../nodes/Paddle/PlanDescription.ts | 9 +- .../nodes/Paddle/UserDescription.ts | 96 +++-- 6 files changed, 514 insertions(+), 221 deletions(-) diff --git a/packages/nodes-base/nodes/Paddle/CouponDescription.ts b/packages/nodes-base/nodes/Paddle/CouponDescription.ts index 553a0c0ffd..64e87cf9a0 100644 --- a/packages/nodes-base/nodes/Paddle/CouponDescription.ts +++ b/packages/nodes-base/nodes/Paddle/CouponDescription.ts @@ -51,6 +51,9 @@ export const couponFields = [ ], operation: [ `create` + ], + jsonParameters: [ + false ] }, }, @@ -82,6 +85,9 @@ export const couponFields = [ couponType: [ 'product', ], + jsonParameters: [ + false + ] }, }, default: '', @@ -100,6 +106,9 @@ export const couponFields = [ operation: [ `create` ], + jsonParameters: [ + false + ] }, }, default: 'flat', @@ -122,7 +131,7 @@ export const couponFields = [ default: '', description: 'Discount amount in currency.', typeOptions: { - minValue: 0 + minValue: 1 }, displayOptions: { show: { @@ -134,6 +143,9 @@ export const couponFields = [ ], discountType: [ 'flat', + ], + jsonParameters: [ + false ] }, }, @@ -145,7 +157,7 @@ export const couponFields = [ default: '', description: 'Discount amount in percentage.', typeOptions: { - minValue: 0, + minValue: 1, maxValue: 100 }, displayOptions: { @@ -158,6 +170,9 @@ export const couponFields = [ ], discountType: [ 'percentage', + ], + jsonParameters: [ + false ] }, }, @@ -166,20 +181,20 @@ export const couponFields = [ displayName: 'Currency', name: 'currency', type: 'options', - default: 'eur', + default: 'EUR', description: 'The currency must match the balance currency specified in your account.', options: [ { name: 'EUR', - value: 'eur' + value: 'EUR' }, { name: 'GBP', - value: 'gbp' + value: 'GBP' }, { name: 'USD', - value: 'usd' + value: 'USD' }, ], displayOptions: { @@ -192,10 +207,53 @@ export const couponFields = [ ], discountType: [ 'flat', + ], + jsonParameters: [ + false ] }, }, }, + { + displayName: 'JSON Parameters', + name: 'jsonParameters', + type: 'boolean', + default: false, + description: '', + 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', @@ -209,6 +267,9 @@ export const couponFields = [ operation: [ 'create', ], + jsonParameters: [ + false + ] }, }, default: {}, @@ -237,7 +298,7 @@ export const couponFields = [ { displayName: 'Expires', name: 'expires', - type: 'DateTime', + type: 'dateTime', default: '', description: 'The coupon will expire on the date at 00:00:00 UTC.', }, @@ -310,6 +371,9 @@ export const couponFields = [ operation: [ `update` ], + jsonParameters: [ + false, + ], }, }, default: 'couponCode', @@ -339,7 +403,10 @@ export const couponFields = [ ], updateBy: [ 'couponCode' - ] + ], + jsonParameters: [ + false, + ], }, }, default: '', @@ -359,12 +426,55 @@ export const couponFields = [ ], 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, + description: '', + 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', @@ -378,6 +488,9 @@ export const couponFields = [ operation: [ 'update', ], + jsonParameters: [ + false + ] }, }, default: {}, @@ -393,20 +506,20 @@ export const couponFields = [ displayName: 'Currency', name: 'currency', type: 'options', - default: 'eur', + default: 'EUR', description: 'The currency must match the balance currency specified in your account.', options: [ { name: 'EUR', - value: 'eur' + value: 'EUR' }, { name: 'GBP', - value: 'gbp' + value: 'GBP' }, { name: 'USD', - value: 'usd' + value: 'USD' }, ], }, @@ -423,7 +536,7 @@ export const couponFields = [ { displayName: 'Expires', name: 'expires', - type: 'DateTime', + type: 'dateTime', default: '', description: 'The coupon will expire on the date at 00:00:00 UTC.', }, @@ -450,7 +563,7 @@ export const couponFields = [ name: 'productIds', type: 'string', default: '', - description: 'Comma-separated list of product IDs. Required if coupon_type is product.', + description: 'Comma-separated list of products e.g. 499531,1234,123546. If blank then remove associated products.', }, { displayName: 'Recurring', diff --git a/packages/nodes-base/nodes/Paddle/GenericFunctions.ts b/packages/nodes-base/nodes/Paddle/GenericFunctions.ts index c56498935a..8aa1318845 100644 --- a/packages/nodes-base/nodes/Paddle/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Paddle/GenericFunctions.ts @@ -22,18 +22,41 @@ export async function paddleApiRequest(this: IHookFunctions | IExecuteFunctions const options : OptionsWithUri = { method, + headers: { + 'content-type': 'application/json' + }, uri: `https://vendors.paddle.com/api${endpoint}` , body, json: true }; - body.vendor_id = credentials.vendorId; - body.vendor_auth_code = credentials.vendorAuthCode; + body['vendor_id'] = credentials.vendorId; + body['vendor_auth_code'] = credentials.vendorAuthCode; + + console.log(options.body); + console.log(options); try { - return await this.helpers.request!(options); + const response = await this.helpers.request!(options); + console.log(response); + + if (!response.success) { + throw new Error(`Code: ${response.error.code}. Message: ${response.error.message}`); + } + + return response.response; } catch (error) { console.log(error); throw new Error(error); } } + +export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any + let result; + try { + result = JSON.parse(json!); + } catch (exception) { + result = undefined; + } + return result; +} diff --git a/packages/nodes-base/nodes/Paddle/Paddle.node.ts b/packages/nodes-base/nodes/Paddle/Paddle.node.ts index 0a781e9bb4..e5478aa115 100644 --- a/packages/nodes-base/nodes/Paddle/Paddle.node.ts +++ b/packages/nodes-base/nodes/Paddle/Paddle.node.ts @@ -1,21 +1,20 @@ import { IExecuteFunctions } from 'n8n-core'; import { IDataObject, - INodeExecutionData, - INodeType, INodeTypeDescription } from 'n8n-workflow'; + import { couponFields, couponOperations } from './CouponDescription'; -import { paddleApiRequest } from './GenericFunctions'; -import { paymentFields, paymentOperations } from './PaymentDescription'; +import { paddleApiRequest, validateJSON } from './GenericFunctions'; +import { paymentsFields, paymentsOperations } from './PaymentDescription'; import { planFields, planOperations } from './PlanDescription'; import { productFields, productOperations } from './ProductDescription'; import { userFields, userOperations } from './UserDescription'; import moment = require('moment'); -import { response } from 'express'; +import { orderOperations, orderFields } from './OrderDescription'; export class Paddle implements INodeType { description: INodeTypeDescription = { @@ -72,23 +71,24 @@ export class Paddle implements INodeType { default: 'coupon', description: 'Resource to consume.', }, - // COUPON - couponFields, - couponOperations, + ...couponOperations, + ...couponFields, // PAYMENT - paymentFields, - paymentOperations, + ...paymentsOperations, + ...paymentsFields, // PLAN - planFields, - planOperations, + ...planOperations, + ...planFields, // PRODUCT - productFields, - productOperations, + ...productOperations, + ...productFields, + // ORDER + ...orderOperations, + ...orderFields, // USER - userFields, - userOperations - + ...userOperations, + ...userFields ], }; @@ -103,192 +103,274 @@ export class Paddle implements INodeType { for (let i = 0; i < length; i++) { if (resource === 'coupon') { if (operation === 'create') { - const productIds = this.getNodeParameter('productIds', i) as string; - const discountType = this.getNodeParameter('discountType', i) as string; - const discountAmount = this.getNodeParameter('discountAmount', i) as number; - const currency = this.getNodeParameter('currency', i) as string; + const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean; - body.product_ids = productIds; - body.discount_type = discountType; - body.discount_amount = discountAmount; - body.currency = currency; + if (jsonParameters) { + const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string; - const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + if (additionalFieldsJson !== '') { + if (validateJSON(additionalFieldsJson) !== undefined) { + Object.assign(body, JSON.parse(additionalFieldsJson)); + } else { + throw new Error('Additional fields must be a valid JSON'); + } + } - 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') as string; - } - if (additionalFields.group) { - body.group = additionalFields.group as string; - } - if (additionalFields.recurring) { - if (additionalFields.recurring === true) { + } 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; + const currency = this.getNodeParameter('currency', i) as string; + + if (couponType === 'product') { + body.product_ids = this.getNodeParameter('productIds', i) as string; + } + + body.coupon_type = couponType; + body.discount_type = discountType; + body.discount_amount = discountAmount; + body.currency = currency; + + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + + 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') as string; + } + 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; - } + 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'; + const endpoint = '/2.1/product/create_coupon'; - responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + responseData = await paddleApiRequest.call(this, endpoint, 'POST', body); + } } if (operation === 'getAll') { const productIds = this.getNodeParameter('productId', i) as string; const endpoint = '/2.0/product/list_coupons'; - body.product_ids = productIds as string; + body.product_id = productIds as string; - responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + responseData = await paddleApiRequest.call(this, endpoint, 'POST', body); } if (operation === 'update') { - const updateBy = this.getNodeParameter('updateBy', i) as string; - if (updateBy === 'group') { - body.group = this.getNodeParameter('group', i) as string; + const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean; + + 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 Error('Additional fields must be a valid JSON'); + } + } + } else { - body.coupon_code = this.getNodeParameter('couponCode', i) as string; - } + const updateBy = this.getNodeParameter('updateBy', i) as string; - const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + if (updateBy === 'group') { + body.group = this.getNodeParameter('group', i) as string; + } else { + body.coupon_code = this.getNodeParameter('couponCode', i) as string; + } - 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') as string; - } - if (additionalFields.newGroup) { - body.new_group = additionalFields.newGroup as string; - } - if (additionalFields.recurring) { - if (additionalFields.recurring === true) { + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + + 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') as string; + } + if (additionalFields.newGroup) { + body.new_group = additionalFields.newGroup as string; + } + if (additionalFields.recurring) { body.recurring = 1; } else { 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.productIds) { + body.product_ids = additionalFields.productIds as number; + } + if (additionalFields.discountAmount) { + body.discount_amount = additionalFields.discountAmount as number; + } } const endpoint = '/2.1/product/update_coupon'; - responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + responseData = await paddleApiRequest.call(this, endpoint, 'POST', body); } } if (resource === 'payment') { if (operation === 'getAll') { - const subscriptionId = this.getNodeParameter('subscription', i) as string; - const planId = this.getNodeParameter('planId', i) as string; + const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean; - body.subscription_id = subscriptionId; - body.plan_id = planId; + if (jsonParameters) { + const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string; - const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; - - if (additionalFields.state) { - body.state = additionalFields.state as string; - } - if (additionalFields.isPaid) { - if (additionalFields.isPaid === true) { - body.is_paid = 0; - } else { - body.is_paid = 1; + if (additionalFieldsJson !== '') { + if (validateJSON(additionalFieldsJson) !== undefined) { + Object.assign(body, JSON.parse(additionalFieldsJson)); + } else { + throw new Error('Additional fields must be a valid JSON'); + } + } + + } else { + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + + 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.recurring) { + body.recurring = 1; + } else { + body.recurring = 0; + } + if (additionalFields.from) { + body.from = moment(additionalFields.from as Date).format('YYYY-MM-DD') as string; + } + if (additionalFields.to) { + body.to = moment(additionalFields.to as Date).format('YYYY-MM-DD') as string; + } + if (additionalFields.isOneOffCharge) { + body.is_one_off_charge = additionalFields.isOneOffCharge as boolean; } - } - if (additionalFields.from) { - body.from = moment(additionalFields.from as Date).format('YYYY/MM/DD') as string; - } - if (additionalFields.to) { - body.to = moment(additionalFields.to as Date).format('YYYY/MM/DD') as string; - } - if (additionalFields.isOneOffCharge) { - body.is_one_off_charge = additionalFields.isOneOffCharge as boolean; } const endpoint = '/2.0/subscription/payments'; - responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + + responseData = await paddleApiRequest.call(this, endpoint, 'POST', body); } 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 as Date).format('YYYY/MM/DD') as string; + body.date = body.to = moment(date as Date).format('YYYY-MM-DD') as string; const endpoint = '/2.0/subscription/payments_reschedule'; - responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + responseData = await paddleApiRequest.call(this, endpoint, 'POST', body); } } if (resource === 'plan') { if (operation === 'getAll') { + const endpoint = '/2.0/subscription/plans'; + + responseData = await paddleApiRequest.call(this, endpoint, 'POST', body); + } + if (operation === 'get') { const planId = this.getNodeParameter('planId', i) as string; body.plan = planId; const endpoint = '/2.0/subscription/plans'; - responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + responseData = await paddleApiRequest.call(this, endpoint, 'POST', body); } } if (resource === 'product') { if (operation === 'getAll') { const endpoint = '/2.0/product/get_products'; - responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + responseData = await paddleApiRequest.call(this, endpoint, 'POST', body); } } + 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 subscriptionId = this.getNodeParameter('subscriptionId', i) as string; - const planId = this.getNodeParameter('planId', i) as string; - const limit = this.getNodeParameter('limit', i) as number; - body.subscription_id = subscriptionId; - body.plan_id = planId; - body.results_per_page = limit; + const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean; - const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + 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 Error('Additional fields must be a valid JSON'); + } + } + + } 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; + + 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; + } - if (additionalFields.state) { - body.state = additionalFields.state as string; } - const endpoint = '/2.0/subscription/users'; - responseData = paddleApiRequest.call(this, endpoint, 'POST', body); + responseData = await paddleApiRequest.call(this, endpoint, 'POST', body); } } + console.log(responseData); + if (Array.isArray(responseData)) { returnData.push.apply(returnData, responseData as IDataObject[]); } else { diff --git a/packages/nodes-base/nodes/Paddle/PaymentDescription.ts b/packages/nodes-base/nodes/Paddle/PaymentDescription.ts index 77ff5ca432..45d3553850 100644 --- a/packages/nodes-base/nodes/Paddle/PaymentDescription.ts +++ b/packages/nodes-base/nodes/Paddle/PaymentDescription.ts @@ -2,7 +2,7 @@ import { INodeProperties, } from 'n8n-workflow'; -export const paymentOperations = [ +export const paymentsOperations = [ { displayName: 'Operation', name: 'operation', @@ -10,7 +10,7 @@ export const paymentOperations = [ displayOptions: { show: { resource: [ - 'payment', + 'payments', ], }, }, @@ -31,45 +31,49 @@ export const paymentOperations = [ }, ] as INodeProperties[]; -export const paymentFields = [ +export const paymentsFields = [ /* -------------------------------------------------------------------------- */ -/* payment:getAll */ +/* payments:getAll */ /* -------------------------------------------------------------------------- */ { - displayName: 'Subscription ID', - name: 'subscriptionId', - type: 'number', - default: '', - required: true, + displayName: 'JSON Parameters', + name: 'jsonParameters', + type: 'boolean', + default: false, + description: '', displayOptions: { show: { resource: [ - 'user', + 'payments', ], operation: [ 'getAll', ], }, }, - description: 'A specific user subscription ID.', }, { - displayName: 'Plan', - name: 'planId', - type: 'string', + displayName: ' Additional Fields', + name: 'additionalFieldsJson', + type: 'json', + typeOptions: { + alwaysOpenEditWindow: true, + }, default: '', - required: true, displayOptions: { show: { resource: [ - 'user', + 'payments', ], operation: [ 'getAll', ], + jsonParameters: [ + true, + ], }, }, - description: 'Filter: The product/plan ID (single or comma-separated values).', + description: `Attributes in JSON form.`, }, { displayName: 'Additional Fields', @@ -78,16 +82,54 @@ export const paymentFields = [ placeholder: 'Add Field', displayOptions: { show: { + resource: [ + 'payments', + ], operation: [ 'getAll', ], - resource: [ - 'user', - ], + jsonParameters: [ + false + ] }, }, default: {}, options: [ + { + displayName: 'Date From', + name: 'from', + type: 'dateTime', + default: '', + description: 'payments starting from date.', + }, + { + displayName: 'Date To', + name: 'to', + type: 'dateTime', + default: '', + description: 'payments up until date.', + }, + { + displayName: 'Is Paid', + name: 'isPaid', + type: 'boolean', + default: false, + description: 'payment is paid.', + }, + { + displayName: 'Plan', + 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', @@ -113,62 +155,50 @@ export const paymentFields = [ }, ] }, - { - displayName: 'Is Paid', - name: 'isPaid', - type: 'boolean', - default: false, - description: 'Payment is paid.', - }, - { - displayName: 'From', - name: 'from', - type: 'DateTime', - default: '', - description: 'Payments starting from date.', - }, - { - displayName: 'To', - name: 'to', - type: 'DateTime', - default: '', - description: 'Payments up until date.', - }, { displayName: 'One off charge', name: 'isOneOffCharge', type: 'boolean', default: false, - description: 'Payment is paid.', }, ], }, /* -------------------------------------------------------------------------- */ -/* payment:reschedule */ +/* payments:reschedule */ /* -------------------------------------------------------------------------- */ { - displayName: 'Payment ID', - name: 'paymentId', + displayName: 'payments ID', + name: 'paymentsId', type: 'number', default: '', required: true, displayOptions: { show: { resource: [ - 'user', + 'payments', ], operation: [ - 'getAll', + 'reschedule', ], }, }, - description: 'The upcoming subscription payment ID.', // Use loadoptions to select payment + description: 'The upcoming subscription payments ID.', // Use loadoptions to select payments }, { displayName: 'Date', name: 'date', - type: 'DateTime', + type: 'dateTime', default: '', - description: 'Date you want to move the payment to.', + displayOptions: { + show: { + resource: [ + 'payments', + ], + operation: [ + 'reschedule', + ], + }, + }, + description: 'Date you want to move the payments to.', }, ] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Paddle/PlanDescription.ts b/packages/nodes-base/nodes/Paddle/PlanDescription.ts index 9ddf82046e..f6887ca64f 100644 --- a/packages/nodes-base/nodes/Paddle/PlanDescription.ts +++ b/packages/nodes-base/nodes/Paddle/PlanDescription.ts @@ -15,6 +15,11 @@ export const planOperations = [ }, }, options: [ + { + name: 'Get', + value: 'get', + description: 'Get a plan.', + }, { name: 'Get All', value: 'getAll', @@ -29,7 +34,7 @@ export const planOperations = [ export const planFields = [ /* -------------------------------------------------------------------------- */ -/* plan:getAll */ +/* plan:get */ /* -------------------------------------------------------------------------- */ { displayName: 'Plan ID', @@ -43,7 +48,7 @@ export const planFields = [ 'plan', ], operation: [ - 'getAll', + 'get', ], }, }, diff --git a/packages/nodes-base/nodes/Paddle/UserDescription.ts b/packages/nodes-base/nodes/Paddle/UserDescription.ts index b970be875a..d45cc2ddb1 100644 --- a/packages/nodes-base/nodes/Paddle/UserDescription.ts +++ b/packages/nodes-base/nodes/Paddle/UserDescription.ts @@ -27,16 +27,13 @@ export const userOperations = [ ] as INodeProperties[]; export const userFields = [ - /* -------------------------------------------------------------------------- */ /* user:getAll */ /* -------------------------------------------------------------------------- */ { - displayName: 'Subscription ID', - name: 'subscriptionId', - type: 'string', - default: '', - required: true, + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', displayOptions: { show: { resource: [ @@ -47,25 +44,8 @@ export const userFields = [ ], }, }, - description: 'A specific user subscription ID.', - }, - { - displayName: 'Plan ID', - name: 'planId', - type: 'string', - default: '', - required: true, - displayOptions: { - show: { - resource: [ - 'user', - ], - operation: [ - 'getAll', - ], - }, - }, - description: 'Filter: The subscription plan ID.', + default: false, + description: 'If all results should be returned or only up to a given limit.', }, { displayName: 'Limit', @@ -85,10 +65,53 @@ export const userFields = [ operation: [ 'getAll', ], + returnAll: [ + false + ] }, }, description: 'Number of subscription records to return per page.', }, + { + displayName: 'JSON Parameters', + name: 'jsonParameters', + type: 'boolean', + default: false, + description: '', + 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', @@ -96,16 +119,33 @@ export const userFields = [ placeholder: 'Add Field', displayOptions: { show: { - operation: [ - 'getAll', - ], 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',