|
| 1 | +import chargebee from "../../chargebee.app.mjs"; |
| 2 | + |
| 3 | +export default { |
| 4 | + key: "chargebee-create-customer", |
| 5 | + name: "Create Customer", |
| 6 | + description: "Create a customer in Chargebee. [See the documentation](https://apidocs.chargebee.com/docs/api/customers?lang=node-v3#create_a_customer)", |
| 7 | + version: "0.0.1", |
| 8 | + type: "action", |
| 9 | + props: { |
| 10 | + chargebee, |
| 11 | + id: { |
| 12 | + type: "string", |
| 13 | + label: "ID", |
| 14 | + description: "ID for the new customer. If not given, this will be auto-generated.", |
| 15 | + optional: true, |
| 16 | + }, |
| 17 | + firstName: { |
| 18 | + type: "string", |
| 19 | + label: "First Name", |
| 20 | + description: "First name of the customer.", |
| 21 | + optional: true, |
| 22 | + }, |
| 23 | + lastName: { |
| 24 | + type: "string", |
| 25 | + label: "Last Name", |
| 26 | + description: "Last name of the customer.", |
| 27 | + optional: true, |
| 28 | + }, |
| 29 | + email: { |
| 30 | + type: "string", |
| 31 | + label: "Email", |
| 32 | + description: "Email of the customer.", |
| 33 | + optional: true, |
| 34 | + }, |
| 35 | + phone: { |
| 36 | + type: "string", |
| 37 | + label: "Phone", |
| 38 | + description: "Phone number of the customer.", |
| 39 | + optional: true, |
| 40 | + }, |
| 41 | + company: { |
| 42 | + type: "string", |
| 43 | + label: "Company", |
| 44 | + description: "Company name of the customer.", |
| 45 | + optional: true, |
| 46 | + }, |
| 47 | + additionalFields: { |
| 48 | + type: "object", |
| 49 | + label: "Additional Fields", |
| 50 | + 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.", |
| 51 | + optional: true, |
| 52 | + }, |
| 53 | + }, |
| 54 | + async run({ $ }) { |
| 55 | + const response = await this.chargebee.createCustomer(Object.fromEntries(Object.entries({ |
| 56 | + id: this.id, |
| 57 | + first_name: this.firstName, |
| 58 | + last_name: this.lastName, |
| 59 | + email: this.email, |
| 60 | + phone: this.phone, |
| 61 | + company: this.company, |
| 62 | + ...this.additionalFields, |
| 63 | + }).filter(([_, v]) => v !== undefined))); |
| 64 | + |
| 65 | + $.export("$summary", `Successfully created customer (ID: ${response?.customer?.id})`); |
| 66 | + return response; |
| 67 | + }, |
| 68 | +}; |
0 commit comments