mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
✨ Update operation selection on Chargebee-Node
This commit is contained in:
parent
ccac2597f0
commit
77d9ff08cf
|
@ -45,77 +45,56 @@ export class Chargebee implements INodeType {
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
displayName: 'Operation',
|
displayName: 'Resource',
|
||||||
name: 'operation',
|
name: 'resource',
|
||||||
default: 'listInvoices',
|
|
||||||
description: 'The operation to perform.',
|
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'Cancel Subscription',
|
name: 'Customer',
|
||||||
value: 'cancelSubscription',
|
value: 'customer',
|
||||||
description: 'Cancel a subscription',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Create Customer',
|
name: 'Invoice',
|
||||||
value: 'createCustomer',
|
value: 'invoice',
|
||||||
description: 'Create a customer',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Delete Subscription',
|
name: 'Subscription',
|
||||||
value: 'deleteSubscription',
|
value: 'subscription',
|
||||||
description: 'Deletes a subscription',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'List Invoices',
|
|
||||||
value: 'listInvoices',
|
|
||||||
description: 'Returns the invoices',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'PDF Invoice URL',
|
|
||||||
value: 'pdfInvoiceUrl',
|
|
||||||
description: 'Gets PDF invoice URL and adds it as property "pdfUrl"',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
default: 'invoice',
|
||||||
|
description: 'The resource to operate on.',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// cancelSubscription
|
// customer
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Subscription Id',
|
displayName: 'Operation',
|
||||||
name: 'subscriptionId',
|
name: 'operation',
|
||||||
description: 'The id of the subscription to cancel.',
|
type: 'options',
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
required: true,
|
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
resource: [
|
||||||
'cancelSubscription'
|
'customer',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'Schedule end of Term',
|
name: 'Create',
|
||||||
name: 'endOfTerm',
|
value: 'create',
|
||||||
type: 'boolean',
|
description: 'Create a customer',
|
||||||
default: false,
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
operation: [
|
|
||||||
'cancelSubscription'
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
],
|
||||||
description: 'If set it will not cancel it directly in will instead schedule the cancelation for the end of the term..',
|
default: 'create',
|
||||||
|
description: 'The operation to perform.',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// createCustomer
|
// customer:create
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Properties',
|
displayName: 'Properties',
|
||||||
|
@ -124,7 +103,10 @@ export class Chargebee implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'createCustomer'
|
'create'
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'customer',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -174,10 +156,6 @@ export class Chargebee implements INodeType {
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The company of the customer.',
|
description: 'The company of the customer.',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
displayName: 'Custom Properties',
|
displayName: 'Custom Properties',
|
||||||
name: 'customProperties',
|
name: 'customProperties',
|
||||||
|
@ -212,53 +190,43 @@ export class Chargebee implements INodeType {
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// deleteSubscription
|
// invoice
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Subscription Id',
|
displayName: 'Operation',
|
||||||
name: 'subscriptionId',
|
name: 'operation',
|
||||||
description: 'The id of the subscription to delete.',
|
default: 'listInvoices',
|
||||||
type: 'string',
|
description: 'The operation to perform.',
|
||||||
default: '',
|
type: 'options',
|
||||||
required: true,
|
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
resource: [
|
||||||
'deleteSubscription'
|
'invoice',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
options: [
|
||||||
|
{
|
||||||
|
name: 'List',
|
||||||
// ----------------------------------
|
value: 'list',
|
||||||
// pdfInvoiceUrl
|
description: 'Returns the invoices',
|
||||||
// ----------------------------------
|
|
||||||
{
|
|
||||||
displayName: 'Invoice Id',
|
|
||||||
name: 'invoiceId',
|
|
||||||
description: 'The id of the invoice to get.',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
required: true,
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
operation: [
|
|
||||||
'pdfInvoiceUrl'
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
|
name: 'PDF Invoice URL',
|
||||||
|
value: 'pdfUrl',
|
||||||
|
description: 'Gets PDF invoice URL and adds it as property "pdfUrl"',
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// listInvoices
|
// invoice:list
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Max results',
|
displayName: 'Max results',
|
||||||
|
@ -272,7 +240,10 @@ export class Chargebee implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'listInvoices'
|
'list'
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'invoice'
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -291,7 +262,10 @@ export class Chargebee implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'listInvoices'
|
'list'
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'invoice'
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -386,6 +360,122 @@ export class Chargebee implements INodeType {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// invoice:pdfUrl
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Invoice Id',
|
||||||
|
name: 'invoiceId',
|
||||||
|
description: 'The id of the invoice to get.',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'pdfUrl'
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'invoice'
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// subscription
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'subscription',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Cancel',
|
||||||
|
value: 'cancel',
|
||||||
|
description: 'Cancel a subscription',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Delete',
|
||||||
|
value: 'delete',
|
||||||
|
description: 'Delete a subscription',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'delete',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// subscription:cancel
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Subscription Id',
|
||||||
|
name: 'subscriptionId',
|
||||||
|
description: 'The id of the subscription to cancel.',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'cancel'
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'subscription',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Schedule end of Term',
|
||||||
|
name: 'endOfTerm',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'cancel'
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'subscription',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'If set it will not cancel it directly in will instead schedule the cancelation for the end of the term..',
|
||||||
|
},
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// subscription:delete
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Subscription Id',
|
||||||
|
name: 'subscriptionId',
|
||||||
|
description: 'The id of the subscription to delete.',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'delete'
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'subscription',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -412,68 +502,103 @@ export class Chargebee implements INodeType {
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
|
||||||
item = items[i];
|
item = items[i];
|
||||||
|
const resource = this.getNodeParameter('resource', i) as string;
|
||||||
const operation = this.getNodeParameter('operation', i) as string;
|
const operation = this.getNodeParameter('operation', i) as string;
|
||||||
|
|
||||||
let requestMethod = 'GET';
|
let requestMethod = 'GET';
|
||||||
let endpoint = '';
|
let endpoint = '';
|
||||||
body = {};
|
body = {};
|
||||||
qs = {};
|
qs = {};
|
||||||
|
if (resource === 'customer') {
|
||||||
|
if (operation === 'create') {
|
||||||
|
// ----------------------------------
|
||||||
|
// create
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
if (operation === 'cancelSubscription') {
|
requestMethod = 'POST';
|
||||||
requestMethod = 'POST';
|
|
||||||
|
|
||||||
const subscriptionId = this.getNodeParameter('subscriptionId', i, {}) as string;
|
const properties = this.getNodeParameter('properties', i, {}) as IDataObject;
|
||||||
body.end_of_term = this.getNodeParameter('endOfTerm', i, {}) as boolean;
|
|
||||||
|
|
||||||
endpoint = `subscriptions/${subscriptionId.trim()}/cancel`;
|
for (const key of Object.keys(properties)) {
|
||||||
} else if (operation === 'createCustomer') {
|
if (key === 'customProperties' && (properties.customProperties as IDataObject).property !== undefined) {
|
||||||
requestMethod = 'POST';
|
for (const customProperty of (properties.customProperties as IDataObject)!.property! as CustomProperty[]) {
|
||||||
|
qs[customProperty.name] = customProperty.value;
|
||||||
const properties = this.getNodeParameter('properties', i, {}) as IDataObject;
|
}
|
||||||
|
} else {
|
||||||
for (const key of Object.keys(properties)) {
|
qs[key] = properties[key];
|
||||||
if (key === 'customProperties' && (properties.customProperties as IDataObject).property !== undefined) {
|
|
||||||
for (const customProperty of (properties.customProperties as IDataObject)!.property! as CustomProperty[]) {
|
|
||||||
qs[customProperty.name] = customProperty.value;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
qs[key] = properties[key];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
endpoint = `customers`;
|
||||||
|
} else {
|
||||||
|
throw new Error(`The operation "${operation}" is not known!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint = `customers`;
|
} else if (resource === 'invoice') {
|
||||||
} else if (operation === 'deleteSubscription') {
|
if (operation === 'list') {
|
||||||
requestMethod = 'POST';
|
// ----------------------------------
|
||||||
|
// list
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
const subscriptionId = this.getNodeParameter('subscriptionId', i, {}) as string;
|
endpoint = 'invoices';
|
||||||
|
// TODO: Make also sorting configurable
|
||||||
|
qs['sort_by[desc]'] = 'date';
|
||||||
|
|
||||||
endpoint = `subscriptions/${subscriptionId.trim()}/delete`;
|
qs.limit = this.getNodeParameter('maxResults', i, {});
|
||||||
} else if (operation === 'listInvoices') {
|
|
||||||
endpoint = 'invoices';
|
|
||||||
// TODO: Make also sorting configurable
|
|
||||||
qs['sort_by[desc]'] = 'date';
|
|
||||||
|
|
||||||
qs.limit = this.getNodeParameter('maxResults', i, {});
|
const setFilters: FilterValues = this.getNodeParameter('filters', i, {}) as unknown as FilterValues;
|
||||||
|
|
||||||
const setFilters: FilterValues = this.getNodeParameter('filters', i, {}) as unknown as FilterValues;
|
let filter: FilterValue;
|
||||||
|
let value: NodeParameterValue;
|
||||||
|
|
||||||
let filter: FilterValue;
|
for (const filterProperty of Object.keys(setFilters)) {
|
||||||
let value: NodeParameterValue;
|
for (filter of setFilters[filterProperty]) {
|
||||||
|
value = filter.value;
|
||||||
for (const filterProperty of Object.keys(setFilters)) {
|
if (filterProperty === 'date') {
|
||||||
for (filter of setFilters[filterProperty]) {
|
value = Math.floor(new Date(value as string).getTime() / 1000);
|
||||||
value = filter.value;
|
}
|
||||||
if (filterProperty === 'date') {
|
qs[`${filterProperty}[${filter.operation}]`] = value;
|
||||||
value = Math.floor(new Date(value as string).getTime() / 1000);
|
|
||||||
}
|
}
|
||||||
qs[`${filterProperty}[${filter.operation}]`] = value;
|
|
||||||
}
|
}
|
||||||
|
} else if (operation === 'pdfUrl') {
|
||||||
|
// ----------------------------------
|
||||||
|
// pdfUrl
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
|
requestMethod = 'POST';
|
||||||
|
const invoiceId = this.getNodeParameter('invoiceId', i) as string;
|
||||||
|
endpoint = `invoices/${invoiceId.trim()}/pdf`;
|
||||||
|
} else {
|
||||||
|
throw new Error(`The operation "${operation}" is not known!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (operation === 'pdfInvoiceUrl') {
|
} else if (resource === 'subscription') {
|
||||||
requestMethod = 'POST';
|
if (operation === 'cancel') {
|
||||||
const invoiceId = this.getNodeParameter('invoiceId', i) as string;
|
// ----------------------------------
|
||||||
endpoint = `invoices/${invoiceId.trim()}/pdf`;
|
// cancel
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
|
requestMethod = 'POST';
|
||||||
|
|
||||||
|
const subscriptionId = this.getNodeParameter('subscriptionId', i, {}) as string;
|
||||||
|
body.end_of_term = this.getNodeParameter('endOfTerm', i, {}) as boolean;
|
||||||
|
|
||||||
|
endpoint = `subscriptions/${subscriptionId.trim()}/cancel`;
|
||||||
|
} else if (operation === 'delete') {
|
||||||
|
// ----------------------------------
|
||||||
|
// delete
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
|
requestMethod = 'POST';
|
||||||
|
|
||||||
|
const subscriptionId = this.getNodeParameter('subscriptionId', i, {}) as string;
|
||||||
|
|
||||||
|
endpoint = `subscriptions/${subscriptionId.trim()}/delete`;
|
||||||
|
} else {
|
||||||
|
throw new Error(`The operation "${operation}" is not known!`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error(`The resource "${resource}" is not known!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
|
@ -490,11 +615,11 @@ export class Chargebee implements INodeType {
|
||||||
|
|
||||||
const responseData = await requestPromise(options);
|
const responseData = await requestPromise(options);
|
||||||
|
|
||||||
if (operation === 'listInvoices') {
|
if (resource === 'invoice' && operation === 'list') {
|
||||||
responseData.list.forEach((data: IDataObject) => {
|
responseData.list.forEach((data: IDataObject) => {
|
||||||
returnData.push(data.invoice as IDataObject);
|
returnData.push(data.invoice as IDataObject);
|
||||||
});
|
});
|
||||||
} else if (operation === 'pdfInvoiceUrl') {
|
} else if (resource === 'invoice' && operation === 'pdfUrl') {
|
||||||
item.json.pdfUrl = responseData.download.download_url;
|
item.json.pdfUrl = responseData.download.download_url;
|
||||||
returnData.push(item.json);
|
returnData.push(item.json);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue