mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
⚡ Add full continue-on-fail support to all nodes (#1996)
* Update Compression node * Update Crypto node * Update DateTime node * Update EditImage node * Update EmailSend node * Update ExecuteWorkflow node * Update FTP node * Update Function node * Update FunctionItem node * Update ExecuteCommand node * Update OpenWeatherMap node * Update ReadBinaryFile node * Update ReadPdf node * Update RssFeedRead node & add URL validation * Update SpreadsheetFile node * Update Switch node * Update WriteBinaryFile node * Update Xml node * Update ActiveCampaign node * Update Airtable node * Update ApiTemplateIo node * Update Asana node * Update AwsLambda node * Update AwsSns node * Update AwsComprehend node * Update AwsRekognition node * Update AwsS3 node * Fix Error item * Update AwsSes node * Update AwsSqs node * Update Amqp node * Update Bitly node * Update Box node * Update Brandfetch node * Update CircleCi node * Update Clearbit node * Update ClickUp node * Update Cockpit node * Update CoinGecko node * Update Contentful node * Update ConvertKit node * Update Cortex node * Update CustomerIo node * Update DeepL node * Update Demio node * Update Disqus node * Update Drift node * Update Dropbox node * Update GetResponse node * Refactor & Update Ghost node * Update Github node * Update Gitlab node * Update GoogleAnalytics node * Update GoogleBooks node * Update GoogleCalendar node * Update GoogleDrive node * Update Gmail node * Update GoogleSheets node * Update GoogleSlides node * Update GoogleTasks node * Update Gotify node * Update GraphQL node * Update HackerNews node * Update Harvest node * Update HtmlExtract node * Update Hubspot node * Update Hunter node * Update Intercom node * Update Kafka node * Refactor & update Line node * Update LinkedIn node * Update Mailchimp node * Update Mandrill node * Update Matrix node * Update Mautic node * Update Medium node * Update MessageBird node * Update Mindee node * Update Mocean node * Update MondayCom node * Update MicrosoftExcel node * Update MicrosoftOneDrive node * Update MicrosoftOutlook node * Update Affinity node * Update Chargebee node * Update Discourse node * Update Freshdesk node * Update YouTube node * Update InvoiceNinja node * Update MailerLite node * Update Mailgun node * Update Mailjet node * Update Mattermost node * Update Nasa node * Update NextCloud node * Update OpenThesaurus node * Update Orbit node * Update PagerDuty node * Update PayPal node * Update Peekalink node * Update Phantombuster node * Update PostHog node * Update ProfitWell node * Refactor & Update Pushbullet node * Update QuickBooks node * Update Raindrop node * Update Reddit node * Update Rocketchat node * Update S3 node * Update Salesforce node * Update SendGrid node * Update SentryIo node * Update Shopify node * Update Signl4 node * Update Slack node * Update Spontit node * Update Spotify node * Update Storyblok node * Refactor & Update Strapi node * Refactor & Update Strava node * Update Taiga node * Refactor & update Tapfiliate node * Update Telegram node * Update TheHive node * Update Todoist node * Update TravisCi node * Update Trello node * Update Twilio node * Update Twist node * Update Twitter node * Update Uplead node * Update UProc node * Update Vero node * Update Webflow node * Update Wekan node * Update Wordpress node * Update Xero node * Update Yourls node * Update Zendesk node * Update ZohoCrm node * Refactor & Update Zoom node * Update Zulip node * Update Clockify node * Update MongoDb node * Update MySql node * Update MicrosoftTeams node * Update Stackby node * Refactor Discourse node * Support corner-case in Github node update * Support corner-case in Gitlab node update * Refactor & Update GoogleContacts node * Refactor Mindee node * Update Coda node * Lint fixes * Update Beeminder node * Update Google Firebase RealtimeDatabase node * Update HelpScout node * Update Mailcheck node * Update Paddle node * Update Pipedrive node * Update Pushover node * Update Segment node * Refactor & Update Vonage node * Added new conditions to warnings on execute batch cmd * Added keep only properties flag * Fixed code for keep only props * Added dependencies for image editing Co-authored-by: dali <servfrdali@yahoo.fr>
This commit is contained in:
@@ -191,323 +191,330 @@ export class Paddle implements INodeType {
|
||||
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 jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
try {
|
||||
if (resource === 'coupon') {
|
||||
if (operation === 'create') {
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
|
||||
if (additionalFieldsJson !== '') {
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
} else {
|
||||
throw new NodeOperationError(this.getNode(), 'Additional fields must be a valid JSON');
|
||||
if (additionalFieldsJson !== '') {
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
} else {
|
||||
throw new NodeOperationError(this.getNode(), 'Additional fields must be a valid JSON');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
const discountType = this.getNodeParameter('discountType', i) as string;
|
||||
const couponType = this.getNodeParameter('couponType', i) as string;
|
||||
const discountAmount = this.getNodeParameter('discountAmount', i) as number;
|
||||
|
||||
if (couponType === 'product') {
|
||||
body.product_ids = this.getNodeParameter('productIds', i) as string;
|
||||
}
|
||||
|
||||
if (discountType === 'flat') {
|
||||
body.currency = this.getNodeParameter('currency', i) as string;
|
||||
}
|
||||
|
||||
body.coupon_type = couponType;
|
||||
body.discount_type = discountType;
|
||||
body.discount_amount = discountAmount;
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) 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;
|
||||
}
|
||||
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 endpoint = '/2.1/product/create_coupon';
|
||||
if (couponType === 'product') {
|
||||
body.product_ids = this.getNodeParameter('productIds', i) as string;
|
||||
}
|
||||
|
||||
if (discountType === 'flat') {
|
||||
body.currency = this.getNodeParameter('currency', i) as string;
|
||||
}
|
||||
|
||||
body.coupon_type = couponType;
|
||||
body.discount_type = discountType;
|
||||
body.discount_amount = discountAmount;
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) 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;
|
||||
}
|
||||
|
||||
const endpoint = '/2.1/product/create_coupon';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
responseData = responseData.response.coupon_codes.map((coupon : string) => ({coupon}));
|
||||
}
|
||||
}
|
||||
|
||||
if (operation === 'getAll') {
|
||||
const productId = this.getNodeParameter('productId', i) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const endpoint = '/2.0/product/list_coupons';
|
||||
|
||||
body.product_id = productId as string;
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
responseData = responseData.response.coupon_codes.map((coupon : string) => ({coupon}));
|
||||
}
|
||||
}
|
||||
|
||||
if (operation === 'getAll') {
|
||||
const productId = this.getNodeParameter('productId', i) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const endpoint = '/2.0/product/list_coupons';
|
||||
|
||||
body.product_id = productId as string;
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
|
||||
if (returnAll) {
|
||||
responseData = responseData.response;
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = responseData.response.splice(0, limit);
|
||||
}
|
||||
}
|
||||
|
||||
if (operation === 'update') {
|
||||
|
||||
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 NodeOperationError(this.getNode(), 'Additional fields must be a valid JSON');
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
const updateBy = this.getNodeParameter('updateBy', i) as string;
|
||||
|
||||
if (updateBy === 'group') {
|
||||
body.group = this.getNodeParameter('group', i) as string;
|
||||
if (returnAll) {
|
||||
responseData = responseData.response;
|
||||
} 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 === true) {
|
||||
body.recurring = 1;
|
||||
} else if (additionalFields.recurring === false) {
|
||||
body.recurring = 0;
|
||||
}
|
||||
if (additionalFields.productIds) {
|
||||
body.product_ids = additionalFields.productIds as number;
|
||||
}
|
||||
if (additionalFields.discountAmount) {
|
||||
body.discount_amount = additionalFields.discountAmount as number;
|
||||
}
|
||||
if (additionalFields.discount) {
|
||||
//@ts-ignore
|
||||
if (additionalFields.discount.discountProperties.discountType === 'percentage') {
|
||||
// @ts-ignore
|
||||
body.discount_amount = additionalFields.discount.discountProperties.discountAmount as number;
|
||||
} else {
|
||||
//@ts-ignore
|
||||
body.currency = additionalFields.discount.discountProperties.currency as string;
|
||||
//@ts-ignore
|
||||
body.discount_amount = additionalFields.discount.discountProperties.discountAmount as number;
|
||||
}
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = responseData.response.splice(0, limit);
|
||||
}
|
||||
}
|
||||
|
||||
const endpoint = '/2.1/product/update_coupon';
|
||||
if (operation === 'update') {
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
responseData = responseData.response;
|
||||
}
|
||||
}
|
||||
if (resource === 'payment') {
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
|
||||
if (additionalFieldsJson !== '') {
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
} else {
|
||||
throw new NodeOperationError(this.getNode(), 'Additional fields must be a valid JSON');
|
||||
if (additionalFieldsJson !== '') {
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
} else {
|
||||
throw new NodeOperationError(this.getNode(), 'Additional fields must be a valid JSON');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} 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.isPaid) {
|
||||
body.is_paid = 1;
|
||||
} else {
|
||||
body.is_paid = 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;
|
||||
}
|
||||
}
|
||||
const endpoint = '/2.0/subscription/payments';
|
||||
const updateBy = this.getNodeParameter('updateBy', i) as string;
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
|
||||
if (returnAll) {
|
||||
responseData = responseData.response;
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = responseData.response.splice(0, limit);
|
||||
}
|
||||
}
|
||||
if (operation === 'reschedule') {
|
||||
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 = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
}
|
||||
}
|
||||
if (resource === 'plan') {
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const endpoint = '/2.0/subscription/plans';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
|
||||
if (returnAll) {
|
||||
responseData = responseData.response;
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = responseData.response.splice(0, limit);
|
||||
}
|
||||
}
|
||||
if (operation === 'get') {
|
||||
const planId = this.getNodeParameter('planId', i) as string;
|
||||
|
||||
body.plan = planId;
|
||||
|
||||
const endpoint = '/2.0/subscription/plans';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
responseData = responseData.response;
|
||||
}
|
||||
}
|
||||
if (resource === 'product') {
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const endpoint = '/2.0/product/get_products';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
|
||||
if (returnAll) {
|
||||
responseData = responseData.response.products;
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = responseData.response.products.splice(0, limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resource === 'order') {
|
||||
if (operation === 'get') {
|
||||
const endpoint = '/1.0/order';
|
||||
const checkoutId = this.getNodeParameter('checkoutId', i) as string;
|
||||
|
||||
body.checkout_id = checkoutId;
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'GET', body);
|
||||
}
|
||||
}
|
||||
if (resource === 'user') {
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
|
||||
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));
|
||||
if (updateBy === 'group') {
|
||||
body.group = this.getNodeParameter('group', i) as string;
|
||||
} else {
|
||||
throw new NodeOperationError(this.getNode(), 'Additional fields must be a valid JSON');
|
||||
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 === true) {
|
||||
body.recurring = 1;
|
||||
} else if (additionalFields.recurring === false) {
|
||||
body.recurring = 0;
|
||||
}
|
||||
if (additionalFields.productIds) {
|
||||
body.product_ids = additionalFields.productIds as number;
|
||||
}
|
||||
if (additionalFields.discountAmount) {
|
||||
body.discount_amount = additionalFields.discountAmount as number;
|
||||
}
|
||||
if (additionalFields.discount) {
|
||||
//@ts-ignore
|
||||
if (additionalFields.discount.discountProperties.discountType === 'percentage') {
|
||||
// @ts-ignore
|
||||
body.discount_amount = additionalFields.discount.discountProperties.discountAmount as number;
|
||||
} else {
|
||||
//@ts-ignore
|
||||
body.currency = additionalFields.discount.discountProperties.currency as string;
|
||||
//@ts-ignore
|
||||
body.discount_amount = additionalFields.discount.discountProperties.discountAmount as number;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
const endpoint = '/2.1/product/update_coupon';
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
const endpoint = '/2.0/subscription/users';
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await paddleApiRequestAllItems.call(this, 'response', endpoint, 'POST', body);
|
||||
} else {
|
||||
body.results_per_page = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
responseData = responseData.response;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resource === 'payment') {
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
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 NodeOperationError(this.getNode(), '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.isPaid) {
|
||||
body.is_paid = 1;
|
||||
} else {
|
||||
body.is_paid = 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;
|
||||
}
|
||||
}
|
||||
const endpoint = '/2.0/subscription/payments';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
|
||||
if (returnAll) {
|
||||
responseData = responseData.response;
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = responseData.response.splice(0, limit);
|
||||
}
|
||||
}
|
||||
if (operation === 'reschedule') {
|
||||
const paymentId = this.getNodeParameter('paymentId', i) as number;
|
||||
const date = this.getNodeParameter('date', i) as Date;
|
||||
|
||||
body.payment_id = paymentId;
|
||||
body.date = body.to = moment(date as Date).format('YYYY-MM-DD') as string;
|
||||
|
||||
const endpoint = '/2.0/subscription/payments_reschedule';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
}
|
||||
}
|
||||
if (resource === 'plan') {
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const endpoint = '/2.0/subscription/plans';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
|
||||
if (returnAll) {
|
||||
responseData = responseData.response;
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = responseData.response.splice(0, limit);
|
||||
}
|
||||
}
|
||||
if (operation === 'get') {
|
||||
const planId = this.getNodeParameter('planId', i) as string;
|
||||
|
||||
body.plan = planId;
|
||||
|
||||
const endpoint = '/2.0/subscription/plans';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
responseData = responseData.response;
|
||||
}
|
||||
}
|
||||
if (resource === 'product') {
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const endpoint = '/2.0/product/get_products';
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
|
||||
if (returnAll) {
|
||||
responseData = responseData.response.products;
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = responseData.response.products.splice(0, limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resource === 'order') {
|
||||
if (operation === 'get') {
|
||||
const endpoint = '/1.0/order';
|
||||
const checkoutId = this.getNodeParameter('checkoutId', i) as string;
|
||||
|
||||
body.checkout_id = checkoutId;
|
||||
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'GET', body);
|
||||
}
|
||||
}
|
||||
if (resource === 'user') {
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
|
||||
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 NodeOperationError(this.getNode(), 'Additional fields must be a valid JSON');
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
const endpoint = '/2.0/subscription/users';
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await paddleApiRequestAllItems.call(this, 'response', endpoint, 'POST', body);
|
||||
} else {
|
||||
body.results_per_page = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await paddleApiRequest.call(this, endpoint, 'POST', body);
|
||||
responseData = responseData.response;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user