mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 22:54:05 -08:00
🚧 Tests / changes
This commit is contained in:
parent
4a968ee8ea
commit
0b46f5d63a
|
@ -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',
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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[];
|
||||
|
|
|
@ -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',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue