From 9a70095e44f148492524de1d1a257dba873e55ce Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Tue, 10 Dec 2024 02:10:03 -0300 Subject: [PATCH 01/12] Create Customer action --- .../create-customer/create-customer.mjs | 68 +++++++++++++++++++ components/chargebee/chargebee.app.mjs | 3 + components/chargebee/package.json | 4 +- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 components/chargebee/actions/create-customer/create-customer.mjs diff --git a/components/chargebee/actions/create-customer/create-customer.mjs b/components/chargebee/actions/create-customer/create-customer.mjs new file mode 100644 index 0000000000000..96aada0e7ec07 --- /dev/null +++ b/components/chargebee/actions/create-customer/create-customer.mjs @@ -0,0 +1,68 @@ +import chargebee from "../../chargebee.app.mjs"; + +export default { + key: "chargebee-create-customer", + name: "Create Customer", + description: "Create a customer in Chargebee. [See the documentation](https://apidocs.chargebee.com/docs/api/customers?lang=node-v3#create_a_customer)", + version: "0.0.1", + type: "action", + props: { + chargebee, + id: { + type: "string", + label: "ID", + description: "ID for the new customer. If not given, this will be auto-generated.", + optional: true, + }, + firstName: { + type: "string", + label: "First Name", + description: "First name of the customer.", + optional: true, + }, + lastName: { + type: "string", + label: "Last Name", + description: "Last name of the customer.", + optional: true, + }, + email: { + type: "string", + label: "Email", + description: "Email of the customer.", + optional: true, + }, + phone: { + type: "string", + label: "Phone", + description: "Phone number of the customer.", + optional: true, + }, + company: { + type: "string", + label: "Company", + description: "Company name of the customer.", + optional: true, + }, + additionalFields: { + type: "object", + label: "Additional Fields", + description: "Additional fields and values to set for the customer. [See the documentation](https://apidocs.chargebee.com/docs/api/customers?lang=curl#create_a_customer) for all available fields.", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.chargebee.createCustomer(Object.fromEntries(Object.entries({ + id: this.id, + first_name: this.firstName, + last_name: this.lastName, + email: this.email, + phone: this.phone, + company: this.company, + ...this.additionalFields, + }).filter(([_, v]) => v !== undefined))); + + $.export("$summary", `Successfully created customer (ID: ${response?.customer?.id})`); + return response; + }, +}; diff --git a/components/chargebee/chargebee.app.mjs b/components/chargebee/chargebee.app.mjs index df798cf319d40..cdf54418181c8 100644 --- a/components/chargebee/chargebee.app.mjs +++ b/components/chargebee/chargebee.app.mjs @@ -29,5 +29,8 @@ export default { getEvents(args = {}) { return this.instance().event.list(args).request(); }, + createCustomer(args = {}) { + return this.instance().customer.create(args).request(); + } }, }; diff --git a/components/chargebee/package.json b/components/chargebee/package.json index a67b8c2e839e9..9be2c6cbb6ccc 100644 --- a/components/chargebee/package.json +++ b/components/chargebee/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/chargebee", - "version": "0.0.2", + "version": "0.1.0", "description": "Pipedream Chargebee Components", "main": "chargebee.app.mjs", "keywords": [ @@ -11,7 +11,7 @@ "author": "Pipedream (https://pipedream.com/)", "license": "MIT", "dependencies": { - "@pipedream/platform": "^1.4.1", + "@pipedream/platform": "^3.0.3", "chargebee": "^2.22.3" }, "publishConfig": { From 141c90f89b79703f3bbc9a8c83c181025623c97f Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Tue, 10 Dec 2024 15:57:58 -0300 Subject: [PATCH 02/12] Create Subscription action --- .../create-subscription.mjs | 54 +++++++++++++++++++ components/chargebee/chargebee.app.mjs | 19 ++++++- components/chargebee/common/utils.mjs | 3 ++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 components/chargebee/actions/create-subscription/create-subscription.mjs create mode 100644 components/chargebee/common/utils.mjs diff --git a/components/chargebee/actions/create-subscription/create-subscription.mjs b/components/chargebee/actions/create-subscription/create-subscription.mjs new file mode 100644 index 0000000000000..e167287d45c62 --- /dev/null +++ b/components/chargebee/actions/create-subscription/create-subscription.mjs @@ -0,0 +1,54 @@ +import chargebee from "../../chargebee.app.mjs"; +import { clearObject } from "../../common/utils.mjs"; + +export default { + key: "chargebee-create-subscription", + name: "Create Subscription", + description: "Create a new subscription for an existing customer. [See the documentation](https://apidocs.chargebee.com/docs/api/subscriptions?lang=curl#create_subscription_for_items)", + version: "0.0.1", + type: "action", + props: { + chargebee, + customerId: { + propDefinition: [ + chargebee, + "customerId", + ] + }, + id: { + type: "string", + label: "ID", + description: "A unique and immutable identifier for the subscription. If not provided, it is autogenerated.", + optional: true, + }, + netTermDays: { + type: "integer", + label: "Net Term Days", + description: "Defines [Net D](https://www.chargebee.com/docs/net_d.html?_gl=1*1w075xz*_gcl_au*MTU4NzU2NDYzOC4xNzMzODA0OTYw) for the subscription. Net D is the number of days within which any invoice raised for the subscription must be paid.", + optional: true, + }, + startDate: { + type: "string", + label: "Start Date", + description: "The date/time at which the subscription is to start, e.g. `2024-08-15T09:30:00Z`. If not provided, the subscription starts immediately.", + optional: true, + }, + additionalFields: { + type: "object", + label: "Additional Fields", + description: "Additional fields and values to set for the subscription. [See the documentation](https://apidocs.chargebee.com/docs/api/subscriptions?lang=curl#create_subscription_for_items) for all available fields.", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.chargebee.createCustomer(this.customerId, clearObject({ + id: this.id, + net_term_days: this.netTermDays, + start_date: this.startDate && (Date.parse(this.startDate) / 1000), + ...this.additionalFields, + })); + + $.export("$summary", `Successfully created subscription (ID: ${response?.subscription?.id})`); + return response; + }, +}; diff --git a/components/chargebee/chargebee.app.mjs b/components/chargebee/chargebee.app.mjs index cdf54418181c8..be916b8df4c1b 100644 --- a/components/chargebee/chargebee.app.mjs +++ b/components/chargebee/chargebee.app.mjs @@ -3,6 +3,20 @@ import chargebee from "chargebee"; export default { type: "app", app: "chargebee", + propDefinitions: { + customerId: { + type: "string", + label: "Customer ID", + description: "The ID of the customer to create the subscription for.", + async options() { + const customers = await this.getCustomers(); + return customers.list.map((customer) => ({ + label: `${customer.first_name ?? ''} ${customer.last_name ?? ''} (${customer.email ?? customer.id})`, + value: customer.id, + })); + } + } + }, methods: { instance() { chargebee.configure({ @@ -31,6 +45,9 @@ export default { }, createCustomer(args = {}) { return this.instance().customer.create(args).request(); - } + }, + createSubscription(customerId, args = {}) { + return this.instance().subscription.create_for_customer(customerId, args).request(); + }, }, }; diff --git a/components/chargebee/common/utils.mjs b/components/chargebee/common/utils.mjs new file mode 100644 index 0000000000000..4ee6c88bd0c42 --- /dev/null +++ b/components/chargebee/common/utils.mjs @@ -0,0 +1,3 @@ +export function clearObject(obj) { + return Object.fromEntries(Object.entries(obj).filter(([_, v]) => v !== undefined)); +} From e04c3ec4ff9704a035a82b158326c9ce16f29a8b Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Tue, 10 Dec 2024 16:27:23 -0300 Subject: [PATCH 03/12] ESLint and pnpm-lock --- .../chargebee/actions/create-customer/create-customer.mjs | 5 ++++- .../actions/create-subscription/create-subscription.mjs | 2 +- components/chargebee/chargebee.app.mjs | 6 +++--- components/chargebee/common/utils.mjs | 5 ++++- pnpm-lock.yaml | 4 ++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/components/chargebee/actions/create-customer/create-customer.mjs b/components/chargebee/actions/create-customer/create-customer.mjs index 96aada0e7ec07..cb9881f3b6bd4 100644 --- a/components/chargebee/actions/create-customer/create-customer.mjs +++ b/components/chargebee/actions/create-customer/create-customer.mjs @@ -60,7 +60,10 @@ export default { phone: this.phone, company: this.company, ...this.additionalFields, - }).filter(([_, v]) => v !== undefined))); + }).filter(([ + _, + v, + ]) => v !== undefined))); $.export("$summary", `Successfully created customer (ID: ${response?.customer?.id})`); return response; diff --git a/components/chargebee/actions/create-subscription/create-subscription.mjs b/components/chargebee/actions/create-subscription/create-subscription.mjs index e167287d45c62..7cef70d84d84c 100644 --- a/components/chargebee/actions/create-subscription/create-subscription.mjs +++ b/components/chargebee/actions/create-subscription/create-subscription.mjs @@ -13,7 +13,7 @@ export default { propDefinition: [ chargebee, "customerId", - ] + ], }, id: { type: "string", diff --git a/components/chargebee/chargebee.app.mjs b/components/chargebee/chargebee.app.mjs index be916b8df4c1b..2d1d51bda20b5 100644 --- a/components/chargebee/chargebee.app.mjs +++ b/components/chargebee/chargebee.app.mjs @@ -11,11 +11,11 @@ export default { async options() { const customers = await this.getCustomers(); return customers.list.map((customer) => ({ - label: `${customer.first_name ?? ''} ${customer.last_name ?? ''} (${customer.email ?? customer.id})`, + label: `${customer.first_name ?? ""} ${customer.last_name ?? ""} (${customer.email ?? customer.id})`, value: customer.id, })); - } - } + }, + }, }, methods: { instance() { diff --git a/components/chargebee/common/utils.mjs b/components/chargebee/common/utils.mjs index 4ee6c88bd0c42..6f97480341d95 100644 --- a/components/chargebee/common/utils.mjs +++ b/components/chargebee/common/utils.mjs @@ -1,3 +1,6 @@ export function clearObject(obj) { - return Object.fromEntries(Object.entries(obj).filter(([_, v]) => v !== undefined)); + return Object.fromEntries(Object.entries(obj).filter(([ + _, + v, + ]) => v !== undefined)); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e6a591a2dffae..b9e4a8bf388c6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1621,8 +1621,8 @@ importers: components/chargebee: dependencies: '@pipedream/platform': - specifier: ^1.4.1 - version: 1.6.6 + specifier: ^3.0.3 + version: 3.0.3 chargebee: specifier: ^2.22.3 version: 2.44.0 From 9eb95420aebf379f197a0afc2e39a99dba914de3 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Tue, 10 Dec 2024 16:32:18 -0300 Subject: [PATCH 04/12] Source version bumps --- .../customer-card-expired-instant.mjs | 2 +- .../customer-changed-instant/customer-changed-instant.mjs | 2 +- .../new-customer-created-instant.mjs | 2 +- components/chargebee/sources/new-event/new-event.mjs | 2 +- .../new-invoice-created-instant/new-invoice-created-instant.mjs | 2 +- .../new-invoice-updated-instant/new-invoice-updated-instant.mjs | 2 +- .../new-payment-source-added-instant.mjs | 2 +- .../sources/payment-failed-instant/payment-failed-instant.mjs | 2 +- .../payment-refunded-instant/payment-refunded-instant.mjs | 2 +- .../payment-source-updated-instant.mjs | 2 +- .../payment-succeeded-instant/payment-succeeded-instant.mjs | 2 +- .../subscription-activated-instant.mjs | 2 +- .../subscription-cancellation-scheduled-instant.mjs | 2 +- .../subscription-cancelled-instant.mjs | 2 +- .../subscription-changed-instant.mjs | 2 +- .../subscription-created-instant.mjs | 2 +- .../subscription-paused-instant/subscription-paused-instant.mjs | 2 +- .../subscription-reactivated-instant.mjs | 2 +- .../subscription-renewed-instant.mjs | 2 +- .../subscription-resumed-instant.mjs | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/components/chargebee/sources/customer-card-expired-instant/customer-card-expired-instant.mjs b/components/chargebee/sources/customer-card-expired-instant/customer-card-expired-instant.mjs index 3a74d3b10d86d..28ca224f21b94 100644 --- a/components/chargebee/sources/customer-card-expired-instant/customer-card-expired-instant.mjs +++ b/components/chargebee/sources/customer-card-expired-instant/customer-card-expired-instant.mjs @@ -8,7 +8,7 @@ export default { name: "Customer Card Expired (Instant)", description: "Emit new event when a customer card has expired. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#card_expired). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/customer-changed-instant/customer-changed-instant.mjs b/components/chargebee/sources/customer-changed-instant/customer-changed-instant.mjs index ef6fcffe01b22..b591ff2b858ac 100644 --- a/components/chargebee/sources/customer-changed-instant/customer-changed-instant.mjs +++ b/components/chargebee/sources/customer-changed-instant/customer-changed-instant.mjs @@ -8,7 +8,7 @@ export default { name: "Customer Changed (Instant)", description: "Emit new event when a customer is changed. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#customer_changed). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/new-customer-created-instant/new-customer-created-instant.mjs b/components/chargebee/sources/new-customer-created-instant/new-customer-created-instant.mjs index 215c024ce5172..50af5d9f75a08 100644 --- a/components/chargebee/sources/new-customer-created-instant/new-customer-created-instant.mjs +++ b/components/chargebee/sources/new-customer-created-instant/new-customer-created-instant.mjs @@ -8,7 +8,7 @@ export default { name: "New Customer Created (Instant)", description: "Emit new event when a new customer is created. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#customer_created). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/new-event/new-event.mjs b/components/chargebee/sources/new-event/new-event.mjs index 7dca499f23b2b..0079e25251cca 100644 --- a/components/chargebee/sources/new-event/new-event.mjs +++ b/components/chargebee/sources/new-event/new-event.mjs @@ -8,7 +8,7 @@ export default { name: "New Event", description: "Emit new event when the selected event is triggered. [See the Documentation](https://apidocs.chargebee.com/docs/api/events). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.1", + version: "0.0.2", dedupe: "unique", props: { ...common.props, diff --git a/components/chargebee/sources/new-invoice-created-instant/new-invoice-created-instant.mjs b/components/chargebee/sources/new-invoice-created-instant/new-invoice-created-instant.mjs index 3a92be609fff1..23baf9e2c8682 100644 --- a/components/chargebee/sources/new-invoice-created-instant/new-invoice-created-instant.mjs +++ b/components/chargebee/sources/new-invoice-created-instant/new-invoice-created-instant.mjs @@ -8,7 +8,7 @@ export default { name: "New Invoice Created (Instant)", description: "Emit new event when a new invoice is created. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#invoice_generated). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/new-invoice-updated-instant/new-invoice-updated-instant.mjs b/components/chargebee/sources/new-invoice-updated-instant/new-invoice-updated-instant.mjs index 33f8c2787c53e..8ec3706f1d92f 100644 --- a/components/chargebee/sources/new-invoice-updated-instant/new-invoice-updated-instant.mjs +++ b/components/chargebee/sources/new-invoice-updated-instant/new-invoice-updated-instant.mjs @@ -8,7 +8,7 @@ export default { name: "New Invoice Updated (Instant)", description: "Emit new event when a new invoice is updated. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#invoice_updated). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.1", + version: "0.0.2", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/new-payment-source-added-instant/new-payment-source-added-instant.mjs b/components/chargebee/sources/new-payment-source-added-instant/new-payment-source-added-instant.mjs index afb7c3bcee224..354559d9f5544 100644 --- a/components/chargebee/sources/new-payment-source-added-instant/new-payment-source-added-instant.mjs +++ b/components/chargebee/sources/new-payment-source-added-instant/new-payment-source-added-instant.mjs @@ -8,7 +8,7 @@ export default { name: "New Payment Source Added (Instant)", description: "Emit new event when a new payment source is added. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#payment_source_added). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/payment-failed-instant/payment-failed-instant.mjs b/components/chargebee/sources/payment-failed-instant/payment-failed-instant.mjs index 0e985226d49a8..37009f7c4cdb4 100644 --- a/components/chargebee/sources/payment-failed-instant/payment-failed-instant.mjs +++ b/components/chargebee/sources/payment-failed-instant/payment-failed-instant.mjs @@ -8,7 +8,7 @@ export default { name: "Payment Failed (Instant)", description: "Emit new event when a payment is failed. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#payment_failed). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/payment-refunded-instant/payment-refunded-instant.mjs b/components/chargebee/sources/payment-refunded-instant/payment-refunded-instant.mjs index 467bc8fd00c7f..c44e9fb54cf6e 100644 --- a/components/chargebee/sources/payment-refunded-instant/payment-refunded-instant.mjs +++ b/components/chargebee/sources/payment-refunded-instant/payment-refunded-instant.mjs @@ -8,7 +8,7 @@ export default { name: "New Payment Refunded (Instant)", description: "Emit new event when a payment is refunded. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#payment_refunded). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.1", + version: "0.0.2", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/payment-source-updated-instant/payment-source-updated-instant.mjs b/components/chargebee/sources/payment-source-updated-instant/payment-source-updated-instant.mjs index 8c88970b904fb..5d44d8e4b66b3 100644 --- a/components/chargebee/sources/payment-source-updated-instant/payment-source-updated-instant.mjs +++ b/components/chargebee/sources/payment-source-updated-instant/payment-source-updated-instant.mjs @@ -8,7 +8,7 @@ export default { name: "Payment Source Updated (Instant)", description: "Emit new event when a payment source is updated. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#payment_source_updated). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/payment-succeeded-instant/payment-succeeded-instant.mjs b/components/chargebee/sources/payment-succeeded-instant/payment-succeeded-instant.mjs index da7134771dcc9..7dee368aadebe 100644 --- a/components/chargebee/sources/payment-succeeded-instant/payment-succeeded-instant.mjs +++ b/components/chargebee/sources/payment-succeeded-instant/payment-succeeded-instant.mjs @@ -8,7 +8,7 @@ export default { name: "Payment Succeeded (Instant)", description: "Emit new event when a payment is successful. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#payment_succeeded). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/subscription-activated-instant/subscription-activated-instant.mjs b/components/chargebee/sources/subscription-activated-instant/subscription-activated-instant.mjs index 131b6681065ff..401e4c181f8df 100644 --- a/components/chargebee/sources/subscription-activated-instant/subscription-activated-instant.mjs +++ b/components/chargebee/sources/subscription-activated-instant/subscription-activated-instant.mjs @@ -8,7 +8,7 @@ export default { name: "New Subscription Activated (Instant)", description: "Emit new event when a subscription is activated. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#subscription_activated). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.1", + version: "0.0.2", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/subscription-cancellation-scheduled-instant/subscription-cancellation-scheduled-instant.mjs b/components/chargebee/sources/subscription-cancellation-scheduled-instant/subscription-cancellation-scheduled-instant.mjs index 2707cbb587b43..c739e94554126 100644 --- a/components/chargebee/sources/subscription-cancellation-scheduled-instant/subscription-cancellation-scheduled-instant.mjs +++ b/components/chargebee/sources/subscription-cancellation-scheduled-instant/subscription-cancellation-scheduled-instant.mjs @@ -7,7 +7,7 @@ export default { name: "Subscription Cancellation Scheduled (Instant)", description: "Emit new event when a subscription cancellation is scheduled. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#subscription_cancellation_scheduled). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/subscription-cancelled-instant/subscription-cancelled-instant.mjs b/components/chargebee/sources/subscription-cancelled-instant/subscription-cancelled-instant.mjs index 6443b6f498694..18159b7a8b441 100644 --- a/components/chargebee/sources/subscription-cancelled-instant/subscription-cancelled-instant.mjs +++ b/components/chargebee/sources/subscription-cancelled-instant/subscription-cancelled-instant.mjs @@ -8,7 +8,7 @@ export default { name: "Subscription Cancelled (Instant)", description: "Emit new event when a subscription is cancelled. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#subscription_cancelled). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/subscription-changed-instant/subscription-changed-instant.mjs b/components/chargebee/sources/subscription-changed-instant/subscription-changed-instant.mjs index 3e9aa3505a7a4..72f0074abee32 100644 --- a/components/chargebee/sources/subscription-changed-instant/subscription-changed-instant.mjs +++ b/components/chargebee/sources/subscription-changed-instant/subscription-changed-instant.mjs @@ -8,7 +8,7 @@ export default { name: "Subscription Changed (Instant)", description: "Emit new event when a subscription is changed. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#subscription_changed). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/subscription-created-instant/subscription-created-instant.mjs b/components/chargebee/sources/subscription-created-instant/subscription-created-instant.mjs index acb82218a0a5a..26f98b7c726f9 100644 --- a/components/chargebee/sources/subscription-created-instant/subscription-created-instant.mjs +++ b/components/chargebee/sources/subscription-created-instant/subscription-created-instant.mjs @@ -8,7 +8,7 @@ export default { name: "New Subscription Created (Instant)", description: "Emit new event when a new subscription is created. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#subscription_created). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/subscription-paused-instant/subscription-paused-instant.mjs b/components/chargebee/sources/subscription-paused-instant/subscription-paused-instant.mjs index 0a31e1e25ad5a..83e28f1d55468 100644 --- a/components/chargebee/sources/subscription-paused-instant/subscription-paused-instant.mjs +++ b/components/chargebee/sources/subscription-paused-instant/subscription-paused-instant.mjs @@ -8,7 +8,7 @@ export default { name: "Subscription Paused (Instant)", description: "Emit new event when a subscription is paused. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#subscription_paused). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/subscription-reactivated-instant/subscription-reactivated-instant.mjs b/components/chargebee/sources/subscription-reactivated-instant/subscription-reactivated-instant.mjs index e123be272e3ec..d502af20efc80 100644 --- a/components/chargebee/sources/subscription-reactivated-instant/subscription-reactivated-instant.mjs +++ b/components/chargebee/sources/subscription-reactivated-instant/subscription-reactivated-instant.mjs @@ -8,7 +8,7 @@ export default { name: "Subscription Reactivated (Instant)", description: "Emit new event when a subscription is reactivated. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#subscription_reactivated). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/subscription-renewed-instant/subscription-renewed-instant.mjs b/components/chargebee/sources/subscription-renewed-instant/subscription-renewed-instant.mjs index e3ad3cfe3601f..16d6e9289b646 100644 --- a/components/chargebee/sources/subscription-renewed-instant/subscription-renewed-instant.mjs +++ b/components/chargebee/sources/subscription-renewed-instant/subscription-renewed-instant.mjs @@ -8,7 +8,7 @@ export default { name: "New Subscription Renewed (Instant)", description: "Emit new event when a subscription is renewed. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#subscription_renewed). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.1", + version: "0.0.2", dedupe: "unique", methods: { ...common.methods, diff --git a/components/chargebee/sources/subscription-resumed-instant/subscription-resumed-instant.mjs b/components/chargebee/sources/subscription-resumed-instant/subscription-resumed-instant.mjs index ec0e7391e776c..c442a040d1bb6 100644 --- a/components/chargebee/sources/subscription-resumed-instant/subscription-resumed-instant.mjs +++ b/components/chargebee/sources/subscription-resumed-instant/subscription-resumed-instant.mjs @@ -7,7 +7,7 @@ export default { name: "Subscription Resumed (Instant)", description: "Emit new event when a subscription is resumed. [See the Documentation](https://apidocs.chargebee.com/docs/api/events#subscription_resumed). Please make sure once you deploy this source, you copy/paste the webhook URL to create it in your [Chargebee Webhook settings](https://www.chargebee.com/docs/2.0/webhook_settings.html#configure-webhooks).", type: "source", - version: "0.0.2", + version: "0.0.3", dedupe: "unique", methods: { ...common.methods, From f87ab920de699d5cb45bacf01bca17f5678cb406 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Tue, 10 Dec 2024 16:34:03 -0300 Subject: [PATCH 05/12] ESLint fixes --- .../chargebee/actions/create-customer/create-customer.mjs | 8 +++----- components/chargebee/common/utils.mjs | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/components/chargebee/actions/create-customer/create-customer.mjs b/components/chargebee/actions/create-customer/create-customer.mjs index cb9881f3b6bd4..e2ad5a4196cad 100644 --- a/components/chargebee/actions/create-customer/create-customer.mjs +++ b/components/chargebee/actions/create-customer/create-customer.mjs @@ -1,4 +1,5 @@ import chargebee from "../../chargebee.app.mjs"; +import { clearObject } from "../../common/utils.mjs"; export default { key: "chargebee-create-customer", @@ -52,7 +53,7 @@ export default { }, }, async run({ $ }) { - const response = await this.chargebee.createCustomer(Object.fromEntries(Object.entries({ + const response = await this.chargebee.createCustomer(clearObject({ id: this.id, first_name: this.firstName, last_name: this.lastName, @@ -60,10 +61,7 @@ export default { phone: this.phone, company: this.company, ...this.additionalFields, - }).filter(([ - _, - v, - ]) => v !== undefined))); + })); $.export("$summary", `Successfully created customer (ID: ${response?.customer?.id})`); return response; diff --git a/components/chargebee/common/utils.mjs b/components/chargebee/common/utils.mjs index 6f97480341d95..5756f20689d80 100644 --- a/components/chargebee/common/utils.mjs +++ b/components/chargebee/common/utils.mjs @@ -1,6 +1,6 @@ export function clearObject(obj) { return Object.fromEntries(Object.entries(obj).filter(([ - _, + , v, ]) => v !== undefined)); } From e1fae4909bdd47490ed2e9299aea17fe60946c79 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Wed, 11 Dec 2024 01:47:34 -0300 Subject: [PATCH 06/12] Create Subscription adjustments --- .../create-subscription.mjs | 31 +++++++++++++- components/chargebee/chargebee.app.mjs | 40 +++++++++++++------ components/chargebee/package.json | 2 +- 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/components/chargebee/actions/create-subscription/create-subscription.mjs b/components/chargebee/actions/create-subscription/create-subscription.mjs index 7cef70d84d84c..20f9f4b255079 100644 --- a/components/chargebee/actions/create-subscription/create-subscription.mjs +++ b/components/chargebee/actions/create-subscription/create-subscription.mjs @@ -15,6 +15,22 @@ export default { "customerId", ], }, + itemPriceId: { + propDefinition: [ + chargebee, + "itemPriceId" + ], + }, + unitPrice: { + type: "integer", + label: "Unit Price", + description: "The unit price of the plan item.", + }, + quantity: { + type: "integer", + label: "Quantity", + description: "The quantity of the plan item.", + }, id: { type: "string", label: "ID", @@ -41,14 +57,27 @@ export default { }, }, async run({ $ }) { - const response = await this.chargebee.createCustomer(this.customerId, clearObject({ + try { + const response = await this.chargebee.createSubscription(this.customerId, clearObject({ id: this.id, net_term_days: this.netTermDays, start_date: this.startDate && (Date.parse(this.startDate) / 1000), + subscription_items: [ + { + item_price_id: this.itemPriceId, + item_type: "plan", + unit_price: this.unitPrice, + quantity: this.quantity, + } + ], ...this.additionalFields, })); $.export("$summary", `Successfully created subscription (ID: ${response?.subscription?.id})`); return response; + } catch (error) { + $.export("debug", error); + throw new Error("Error creating subscription. Check the debug export for more information.") + } }, }; diff --git a/components/chargebee/chargebee.app.mjs b/components/chargebee/chargebee.app.mjs index 2d1d51bda20b5..2fccc880da7fd 100644 --- a/components/chargebee/chargebee.app.mjs +++ b/components/chargebee/chargebee.app.mjs @@ -1,4 +1,4 @@ -import chargebee from "chargebee"; +import Chargebee from "chargebee"; export default { type: "app", @@ -10,44 +10,58 @@ export default { description: "The ID of the customer to create the subscription for.", async options() { const customers = await this.getCustomers(); - return customers.list.map((customer) => ({ + return customers.list.map(({ customer }) => ({ label: `${customer.first_name ?? ""} ${customer.last_name ?? ""} (${customer.email ?? customer.id})`, value: customer.id, })); }, }, + itemPriceId: { + type: "string", + label: "Item Price ID", + description: "The unique identifier of the plan item price.", + async options() { + const itemPrices = await this.getItemPrices(); + return itemPrices.list.map(({ item_price: { name, id } }) => ({ + label: name, + value: id, + })); + }, + }, }, methods: { instance() { - chargebee.configure({ + return new Chargebee({ site: this.$auth.sub_url, - api_key: this.$auth.api_key, + apiKey: this.$auth.api_key, }); - return chargebee; }, getSubscriptions(args = {}) { - return this.instance().subscription.list(args).request(); + return this.instance().subscription.list(args); }, getTransactions(args = {}) { - return this.instance().transaction.list(args).request(); + return this.instance().transaction.list(args); }, getCustomers(args = {}) { - return this.instance().customer.list(args).request(); + return this.instance().customer.list(args); }, getInvoices(args = {}) { - return this.instance().invoice.list(args).request(); + return this.instance().invoice.list(args); }, getPaymentSources(args = {}) { - return this.instance().payment_source.list(args).request(); + return this.instance().paymentSource.list(args); }, getEvents(args = {}) { - return this.instance().event.list(args).request(); + return this.instance().event.list(args); }, createCustomer(args = {}) { - return this.instance().customer.create(args).request(); + return this.instance().customer.create(args); }, createSubscription(customerId, args = {}) { - return this.instance().subscription.create_for_customer(customerId, args).request(); + return this.instance().subscription.createWithItems(customerId, args); + }, + getItemPrices(args = {}) { + return this.instance().itemPrice.list(args); }, }, }; diff --git a/components/chargebee/package.json b/components/chargebee/package.json index 9be2c6cbb6ccc..ea00c712495e8 100644 --- a/components/chargebee/package.json +++ b/components/chargebee/package.json @@ -12,7 +12,7 @@ "license": "MIT", "dependencies": { "@pipedream/platform": "^3.0.3", - "chargebee": "^2.22.3" + "chargebee": "^3.2.1" }, "publishConfig": { "access": "public" From 940d18226fa1ba3e2242ea9002f999b6122e537b Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Wed, 11 Dec 2024 17:09:41 -0300 Subject: [PATCH 07/12] pnpm-lock --- pnpm-lock.yaml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b9e4a8bf388c6..560af2676042c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1624,8 +1624,8 @@ importers: specifier: ^3.0.3 version: 3.0.3 chargebee: - specifier: ^2.22.3 - version: 2.44.0 + specifier: ^3.2.1 + version: 3.2.1 components/chargeblast: dependencies: @@ -17826,9 +17826,9 @@ packages: charenc@0.0.2: resolution: {integrity: sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==} - chargebee@2.44.0: - resolution: {integrity: sha512-yPAtwVJfVku6G8xWOGteXu5SzmCKy7H0KqCCU8yyl6FR2ae7Lu5Jr3dfSC/PdLO5XY7jhRo5E716j8rlenO4Uw==} - engines: {node: '>=0.6.0'} + chargebee@3.2.1: + resolution: {integrity: sha512-wrq52h+W2dRLSOV1XDbEKvIcTNXTUSZEQ7d1a7TZjhi8iXJBGdbkolTpFOKo2/NdMNtNMmfCp6iErzEyV8Odig==} + engines: {node: '>=18.*'} charm@1.0.2: resolution: {integrity: sha512-wqW3VdPnlSWT4eRiYX+hcs+C6ViBPUWk1qTCd+37qw9kEm/a5n2qcyQDMBWvSYKN/ctqZzeXNQaeBjOetJJUkw==} @@ -33690,10 +33690,7 @@ snapshots: charenc@0.0.2: {} - chargebee@2.44.0: - dependencies: - q: 1.5.1 - safer-buffer: 2.1.2 + chargebee@3.2.1: {} charm@1.0.2: dependencies: From 73c58d3510864c668fbde6a8a6e5edad3816a922 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Wed, 11 Dec 2024 17:22:33 -0300 Subject: [PATCH 08/12] ESLint fixes --- .../create-subscription.mjs | 42 +++++++++---------- components/chargebee/chargebee.app.mjs | 6 ++- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/components/chargebee/actions/create-subscription/create-subscription.mjs b/components/chargebee/actions/create-subscription/create-subscription.mjs index 20f9f4b255079..a2ffd68c86bf9 100644 --- a/components/chargebee/actions/create-subscription/create-subscription.mjs +++ b/components/chargebee/actions/create-subscription/create-subscription.mjs @@ -18,7 +18,7 @@ export default { itemPriceId: { propDefinition: [ chargebee, - "itemPriceId" + "itemPriceId", ], }, unitPrice: { @@ -58,26 +58,26 @@ export default { }, async run({ $ }) { try { - const response = await this.chargebee.createSubscription(this.customerId, clearObject({ - id: this.id, - net_term_days: this.netTermDays, - start_date: this.startDate && (Date.parse(this.startDate) / 1000), - subscription_items: [ - { - item_price_id: this.itemPriceId, - item_type: "plan", - unit_price: this.unitPrice, - quantity: this.quantity, - } - ], - ...this.additionalFields, - })); + const response = await this.chargebee.createSubscription(this.customerId, clearObject({ + id: this.id, + net_term_days: this.netTermDays, + start_date: this.startDate && (Date.parse(this.startDate) / 1000), + subscription_items: [ + { + item_price_id: this.itemPriceId, + item_type: "plan", + unit_price: this.unitPrice, + quantity: this.quantity, + }, + ], + ...this.additionalFields, + })); - $.export("$summary", `Successfully created subscription (ID: ${response?.subscription?.id})`); - return response; - } catch (error) { - $.export("debug", error); - throw new Error("Error creating subscription. Check the debug export for more information.") - } + $.export("$summary", `Successfully created subscription (ID: ${response?.subscription?.id})`); + return response; + } catch (error) { + $.export("debug", error); + throw new Error("Error creating subscription. Check the debug export for more information."); + } }, }; diff --git a/components/chargebee/chargebee.app.mjs b/components/chargebee/chargebee.app.mjs index 2fccc880da7fd..1788f26a136d6 100644 --- a/components/chargebee/chargebee.app.mjs +++ b/components/chargebee/chargebee.app.mjs @@ -22,7 +22,11 @@ export default { description: "The unique identifier of the plan item price.", async options() { const itemPrices = await this.getItemPrices(); - return itemPrices.list.map(({ item_price: { name, id } }) => ({ + return itemPrices.list.map(({ + item_price: { + name, id, + }, + }) => ({ label: name, value: id, })); From 52a723e65e09a4ae8c1beefa4e1e5cf1af83654a Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Thu, 12 Dec 2024 17:15:54 -0300 Subject: [PATCH 09/12] Adjusting return value and error message --- .../chargebee/actions/create-customer/create-customer.mjs | 2 +- .../actions/create-subscription/create-subscription.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/chargebee/actions/create-customer/create-customer.mjs b/components/chargebee/actions/create-customer/create-customer.mjs index e2ad5a4196cad..666a96f36da4b 100644 --- a/components/chargebee/actions/create-customer/create-customer.mjs +++ b/components/chargebee/actions/create-customer/create-customer.mjs @@ -64,6 +64,6 @@ export default { })); $.export("$summary", `Successfully created customer (ID: ${response?.customer?.id})`); - return response; + return response?.customer ?? response; }, }; diff --git a/components/chargebee/actions/create-subscription/create-subscription.mjs b/components/chargebee/actions/create-subscription/create-subscription.mjs index a2ffd68c86bf9..7314f5a222905 100644 --- a/components/chargebee/actions/create-subscription/create-subscription.mjs +++ b/components/chargebee/actions/create-subscription/create-subscription.mjs @@ -77,7 +77,7 @@ export default { return response; } catch (error) { $.export("debug", error); - throw new Error("Error creating subscription. Check the debug export for more information."); + throw new Error(`Error creating subscription: ${error.error_msg}`); } }, }; From 2cf7b191320d5ba4de8c930c3f112bfb75c30ebc Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Thu, 12 Dec 2024 17:26:29 -0300 Subject: [PATCH 10/12] Adding Plan Item Price ID filter --- components/chargebee/chargebee.app.mjs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/components/chargebee/chargebee.app.mjs b/components/chargebee/chargebee.app.mjs index 1788f26a136d6..963c375b68482 100644 --- a/components/chargebee/chargebee.app.mjs +++ b/components/chargebee/chargebee.app.mjs @@ -18,18 +18,16 @@ export default { }, itemPriceId: { type: "string", - label: "Item Price ID", + label: "Plan Item Price ID", description: "The unique identifier of the plan item price.", async options() { const itemPrices = await this.getItemPrices(); - return itemPrices.list.map(({ - item_price: { - name, id, - }, - }) => ({ - label: name, - value: id, - })); + return itemPrices.list + .filter(({ item_price: { item_type } }) => item_type === "plan") + .map(({ item_price: { name, id } }) => ({ + label: name, + value: id, + })); }, }, }, From fb367f4891fc30b7e8f4d8a16c1b94009368e998 Mon Sep 17 00:00:00 2001 From: GTFalcao Date: Thu, 12 Dec 2024 17:27:20 -0300 Subject: [PATCH 11/12] ESLint --- components/chargebee/chargebee.app.mjs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/chargebee/chargebee.app.mjs b/components/chargebee/chargebee.app.mjs index 963c375b68482..0978e19dbf037 100644 --- a/components/chargebee/chargebee.app.mjs +++ b/components/chargebee/chargebee.app.mjs @@ -24,7 +24,11 @@ export default { const itemPrices = await this.getItemPrices(); return itemPrices.list .filter(({ item_price: { item_type } }) => item_type === "plan") - .map(({ item_price: { name, id } }) => ({ + .map(({ + item_price: { + name, id, + }, + }) => ({ label: name, value: id, })); From 1d0dd0828d4bfad648c5559369d1ed5aea4c4a73 Mon Sep 17 00:00:00 2001 From: Leo Vu Date: Fri, 13 Dec 2024 08:52:28 +0700 Subject: [PATCH 12/12] Improve error message --- .../actions/create-subscription/create-subscription.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/chargebee/actions/create-subscription/create-subscription.mjs b/components/chargebee/actions/create-subscription/create-subscription.mjs index 7314f5a222905..f7d3f9a8fcd0a 100644 --- a/components/chargebee/actions/create-subscription/create-subscription.mjs +++ b/components/chargebee/actions/create-subscription/create-subscription.mjs @@ -77,7 +77,7 @@ export default { return response; } catch (error) { $.export("debug", error); - throw new Error(`Error creating subscription: ${error.error_msg}`); + throw new Error(`Error creating subscription: ${error.message}`); } }, };