Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
71 changes: 71 additions & 0 deletions components/chargebee/actions/create-customer/create-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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(([
_,

Check failure on line 64 in components/chargebee/actions/create-customer/create-customer.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'_' is defined but never used
v,
]) => v !== undefined)));

$.export("$summary", `Successfully created customer (ID: ${response?.customer?.id})`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -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;
},
};
20 changes: 20 additions & 0 deletions components/chargebee/chargebee.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -29,5 +43,11 @@ export default {
getEvents(args = {}) {
return this.instance().event.list(args).request();
},
createCustomer(args = {}) {
return this.instance().customer.create(args).request();
},
createSubscription(customerId, args = {}) {
return this.instance().subscription.create_for_customer(customerId, args).request();
},
},
};
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(([
_,

Check failure on line 3 in components/chargebee/common/utils.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'_' is defined but never used
v,
]) => v !== undefined));
}
4 changes: 2 additions & 2 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,7 +11,7 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"license": "MIT",
"dependencies": {
"@pipedream/platform": "^1.4.1",
"@pipedream/platform": "^3.0.3",
"chargebee": "^2.22.3"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading