|
| 1 | +import chargebee from "../../chargebee.app.mjs"; |
| 2 | +import { clearObject } from "../../common/utils.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "chargebee-create-subscription", |
| 6 | + name: "Create Subscription", |
| 7 | + 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)", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + chargebee, |
| 12 | + customerId: { |
| 13 | + propDefinition: [ |
| 14 | + chargebee, |
| 15 | + "customerId", |
| 16 | + ] |
| 17 | + }, |
| 18 | + id: { |
| 19 | + type: "string", |
| 20 | + label: "ID", |
| 21 | + description: "A unique and immutable identifier for the subscription. If not provided, it is autogenerated.", |
| 22 | + optional: true, |
| 23 | + }, |
| 24 | + netTermDays: { |
| 25 | + type: "integer", |
| 26 | + label: "Net Term Days", |
| 27 | + 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.", |
| 28 | + optional: true, |
| 29 | + }, |
| 30 | + startDate: { |
| 31 | + type: "string", |
| 32 | + label: "Start Date", |
| 33 | + 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.", |
| 34 | + optional: true, |
| 35 | + }, |
| 36 | + additionalFields: { |
| 37 | + type: "object", |
| 38 | + label: "Additional Fields", |
| 39 | + 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.", |
| 40 | + optional: true, |
| 41 | + }, |
| 42 | + }, |
| 43 | + async run({ $ }) { |
| 44 | + const response = await this.chargebee.createCustomer(this.customerId, clearObject({ |
| 45 | + id: this.id, |
| 46 | + net_term_days: this.netTermDays, |
| 47 | + start_date: this.startDate && (Date.parse(this.startDate) / 1000), |
| 48 | + ...this.additionalFields, |
| 49 | + })); |
| 50 | + |
| 51 | + $.export("$summary", `Successfully created subscription (ID: ${response?.subscription?.id})`); |
| 52 | + return response; |
| 53 | + }, |
| 54 | +}; |
0 commit comments