|
1 | | -import chargebee from "chargebee"; |
| 1 | +import Chargebee from "chargebee"; |
2 | 2 |
|
3 | 3 | export default { |
4 | 4 | type: "app", |
5 | 5 | app: "chargebee", |
| 6 | + propDefinitions: { |
| 7 | + customerId: { |
| 8 | + type: "string", |
| 9 | + label: "Customer ID", |
| 10 | + description: "The ID of the customer to create the subscription for.", |
| 11 | + async options() { |
| 12 | + const customers = await this.getCustomers(); |
| 13 | + return customers.list.map(({ customer }) => ({ |
| 14 | + label: `${customer.first_name ?? ""} ${customer.last_name ?? ""} (${customer.email ?? customer.id})`, |
| 15 | + value: customer.id, |
| 16 | + })); |
| 17 | + }, |
| 18 | + }, |
| 19 | + itemPriceId: { |
| 20 | + type: "string", |
| 21 | + label: "Plan Item Price ID", |
| 22 | + description: "The unique identifier of the plan item price.", |
| 23 | + async options() { |
| 24 | + const itemPrices = await this.getItemPrices(); |
| 25 | + return itemPrices.list |
| 26 | + .filter(({ item_price: { item_type } }) => item_type === "plan") |
| 27 | + .map(({ |
| 28 | + item_price: { |
| 29 | + name, id, |
| 30 | + }, |
| 31 | + }) => ({ |
| 32 | + label: name, |
| 33 | + value: id, |
| 34 | + })); |
| 35 | + }, |
| 36 | + }, |
| 37 | + }, |
6 | 38 | methods: { |
7 | 39 | instance() { |
8 | | - chargebee.configure({ |
| 40 | + return new Chargebee({ |
9 | 41 | site: this.$auth.sub_url, |
10 | | - api_key: this.$auth.api_key, |
| 42 | + apiKey: this.$auth.api_key, |
11 | 43 | }); |
12 | | - return chargebee; |
13 | 44 | }, |
14 | 45 | getSubscriptions(args = {}) { |
15 | | - return this.instance().subscription.list(args).request(); |
| 46 | + return this.instance().subscription.list(args); |
16 | 47 | }, |
17 | 48 | getTransactions(args = {}) { |
18 | | - return this.instance().transaction.list(args).request(); |
| 49 | + return this.instance().transaction.list(args); |
19 | 50 | }, |
20 | 51 | getCustomers(args = {}) { |
21 | | - return this.instance().customer.list(args).request(); |
| 52 | + return this.instance().customer.list(args); |
22 | 53 | }, |
23 | 54 | getInvoices(args = {}) { |
24 | | - return this.instance().invoice.list(args).request(); |
| 55 | + return this.instance().invoice.list(args); |
25 | 56 | }, |
26 | 57 | getPaymentSources(args = {}) { |
27 | | - return this.instance().payment_source.list(args).request(); |
| 58 | + return this.instance().paymentSource.list(args); |
28 | 59 | }, |
29 | 60 | getEvents(args = {}) { |
30 | | - return this.instance().event.list(args).request(); |
| 61 | + return this.instance().event.list(args); |
| 62 | + }, |
| 63 | + createCustomer(args = {}) { |
| 64 | + return this.instance().customer.create(args); |
| 65 | + }, |
| 66 | + createSubscription(customerId, args = {}) { |
| 67 | + return this.instance().subscription.createWithItems(customerId, args); |
| 68 | + }, |
| 69 | + getItemPrices(args = {}) { |
| 70 | + return this.instance().itemPrice.list(args); |
31 | 71 | }, |
32 | 72 | }, |
33 | 73 | }; |
0 commit comments