-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Chargebee new actions #14906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Chargebee new actions #14906
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9a70095
Create Customer action
GTFalcao 141c90f
Create Subscription action
GTFalcao e04c3ec
ESLint and pnpm-lock
GTFalcao 9eb9542
Source version bumps
GTFalcao f87ab92
ESLint fixes
GTFalcao e1fae49
Create Subscription adjustments
GTFalcao 940d182
pnpm-lock
GTFalcao 73c58d3
ESLint fixes
GTFalcao 52a723e
Adjusting return value and error message
GTFalcao 2cf7b19
Adding Plan Item Price ID filter
GTFalcao fb367f4
ESLint
GTFalcao 1d0dd08
Improve error message
vunguyenhung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
components/chargebee/actions/create-customer/create-customer.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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?.customer ?? response; | ||
| }, | ||
| }; | ||
83 changes: 83 additions & 0 deletions
83
components/chargebee/actions/create-subscription/create-subscription.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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: ${error.error_msg}`); | ||
| } | ||
| }, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
GTFalcao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.