Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions components/chargebee/actions/create-customer/create-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import chargebee from "../../chargebee.app.mjs";
import { clearObject } from "../../common/utils.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(clearObject({
id: this.id,
first_name: this.firstName,
last_name: this.lastName,
email: this.email,
phone: this.phone,
company: this.company,
...this.additionalFields,
}));

$.export("$summary", `Successfully created customer (ID: ${response?.customer?.id})`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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",
],
},
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",
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({ $ }) {
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.");
}
},
};
58 changes: 48 additions & 10 deletions components/chargebee/chargebee.app.mjs
Original file line number Diff line number Diff line change
@@ -1,33 +1,71 @@
import chargebee from "chargebee";
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,
}));
},
},
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);
},
createSubscription(customerId, args = {}) {
return this.instance().subscription.createWithItems(customerId, args);
},
getItemPrices(args = {}) {
return this.instance().itemPrice.list(args);
},
},
};
6 changes: 6 additions & 0 deletions components/chargebee/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function clearObject(obj) {
return Object.fromEntries(Object.entries(obj).filter(([
,
v,
]) => v !== undefined));
}
6 changes: 3 additions & 3 deletions components/chargebee/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/chargebee",
"version": "0.0.2",
"version": "0.1.0",
"description": "Pipedream Chargebee Components",
"main": "chargebee.app.mjs",
"keywords": [
Expand All @@ -11,8 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"license": "MIT",
"dependencies": {
"@pipedream/platform": "^1.4.1",
"chargebee": "^2.22.3"
"@pipedream/platform": "^3.0.3",
"chargebee": "^3.2.1"
},
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
export default {
...common,
key: "chargebee-customer-card-expired-instant",
name: "Customer Card Expired (Instant)",

Check warning on line 8 in components/chargebee/sources/customer-card-expired-instant/customer-card-expired-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
export default {
...common,
key: "chargebee-customer-changed-instant",
name: "Customer Changed (Instant)",

Check warning on line 8 in components/chargebee/sources/customer-changed-instant/customer-changed-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/chargebee/sources/new-event/new-event.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
export default {
...common,
key: "chargebee-payment-failed-instant",
name: "Payment Failed (Instant)",

Check warning on line 8 in components/chargebee/sources/payment-failed-instant/payment-failed-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
export default {
...common,
key: "chargebee-payment-source-updated-instant",
name: "Payment Source Updated (Instant)",

Check warning on line 8 in components/chargebee/sources/payment-source-updated-instant/payment-source-updated-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
export default {
...common,
key: "chargebee-payment-succeeded-instant",
name: "Payment Succeeded (Instant)",

Check warning on line 8 in components/chargebee/sources/payment-succeeded-instant/payment-succeeded-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
export default {
...common,
key: "chargebee-subscription-cancellation-scheduled-instant",
name: "Subscription Cancellation Scheduled (Instant)",

Check warning on line 7 in components/chargebee/sources/subscription-cancellation-scheduled-instant/subscription-cancellation-scheduled-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
export default {
...common,
key: "chargebee-subscription-cancelled-instant",
name: "Subscription Cancelled (Instant)",

Check warning on line 8 in components/chargebee/sources/subscription-cancelled-instant/subscription-cancelled-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
export default {
...common,
key: "chargebee-subscription-changed-instant",
name: "Subscription Changed (Instant)",

Check warning on line 8 in components/chargebee/sources/subscription-changed-instant/subscription-changed-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
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,
Expand Down
Loading
Loading