payment-kit 1.13.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/.eslintrc.js +15 -0
  2. package/README.md +3 -0
  3. package/api/dev.ts +6 -0
  4. package/api/hooks/pre-start.js +12 -0
  5. package/api/src/hooks/pre-start.ts +21 -0
  6. package/api/src/index.ts +92 -0
  7. package/api/src/jobs/event.ts +72 -0
  8. package/api/src/jobs/invoice.ts +148 -0
  9. package/api/src/jobs/payment.ts +208 -0
  10. package/api/src/jobs/subscription.ts +301 -0
  11. package/api/src/jobs/webhook.ts +113 -0
  12. package/api/src/libs/audit.ts +73 -0
  13. package/api/src/libs/auth.ts +40 -0
  14. package/api/src/libs/chain/arcblock.ts +13 -0
  15. package/api/src/libs/dayjs.ts +17 -0
  16. package/api/src/libs/env.ts +5 -0
  17. package/api/src/libs/hooks.ts +42 -0
  18. package/api/src/libs/logger.ts +27 -0
  19. package/api/src/libs/middleware.ts +12 -0
  20. package/api/src/libs/payment.ts +53 -0
  21. package/api/src/libs/queue/index.ts +263 -0
  22. package/api/src/libs/queue/store.ts +47 -0
  23. package/api/src/libs/security.ts +95 -0
  24. package/api/src/libs/session.ts +164 -0
  25. package/api/src/libs/util.ts +93 -0
  26. package/api/src/locales/en.ts +3 -0
  27. package/api/src/locales/index.ts +37 -0
  28. package/api/src/locales/zh.ts +3 -0
  29. package/api/src/routes/checkout-sessions.ts +536 -0
  30. package/api/src/routes/connect/collect.ts +109 -0
  31. package/api/src/routes/connect/pay.ts +116 -0
  32. package/api/src/routes/connect/setup.ts +121 -0
  33. package/api/src/routes/connect/shared.ts +410 -0
  34. package/api/src/routes/connect/subscribe.ts +128 -0
  35. package/api/src/routes/customers.ts +70 -0
  36. package/api/src/routes/events.ts +76 -0
  37. package/api/src/routes/index.ts +59 -0
  38. package/api/src/routes/invoices.ts +126 -0
  39. package/api/src/routes/payment-currencies.ts +38 -0
  40. package/api/src/routes/payment-intents.ts +122 -0
  41. package/api/src/routes/payment-links.ts +221 -0
  42. package/api/src/routes/payment-methods.ts +39 -0
  43. package/api/src/routes/prices.ts +134 -0
  44. package/api/src/routes/products.ts +191 -0
  45. package/api/src/routes/settings.ts +33 -0
  46. package/api/src/routes/subscription-items.ts +148 -0
  47. package/api/src/routes/subscriptions.ts +254 -0
  48. package/api/src/routes/usage-records.ts +120 -0
  49. package/api/src/routes/webhook-attempts.ts +57 -0
  50. package/api/src/routes/webhook-endpoints.ts +105 -0
  51. package/api/src/store/migrate.ts +16 -0
  52. package/api/src/store/migrations/20230905-genesis.ts +52 -0
  53. package/api/src/store/migrations/20230911-seeding.ts +145 -0
  54. package/api/src/store/models/checkout-session.ts +395 -0
  55. package/api/src/store/models/coupon.ts +137 -0
  56. package/api/src/store/models/customer.ts +199 -0
  57. package/api/src/store/models/discount.ts +116 -0
  58. package/api/src/store/models/event.ts +111 -0
  59. package/api/src/store/models/index.ts +165 -0
  60. package/api/src/store/models/invoice-item.ts +185 -0
  61. package/api/src/store/models/invoice.ts +492 -0
  62. package/api/src/store/models/job.ts +75 -0
  63. package/api/src/store/models/payment-currency.ts +139 -0
  64. package/api/src/store/models/payment-intent.ts +282 -0
  65. package/api/src/store/models/payment-link.ts +219 -0
  66. package/api/src/store/models/payment-method.ts +169 -0
  67. package/api/src/store/models/price.ts +266 -0
  68. package/api/src/store/models/product.ts +162 -0
  69. package/api/src/store/models/promotion-code.ts +112 -0
  70. package/api/src/store/models/setup-intent.ts +206 -0
  71. package/api/src/store/models/subscription-item.ts +103 -0
  72. package/api/src/store/models/subscription-schedule.ts +157 -0
  73. package/api/src/store/models/subscription.ts +307 -0
  74. package/api/src/store/models/types.ts +406 -0
  75. package/api/src/store/models/usage-record.ts +132 -0
  76. package/api/src/store/models/webhook-attempt.ts +96 -0
  77. package/api/src/store/models/webhook-endpoint.ts +96 -0
  78. package/api/src/store/sequelize.ts +15 -0
  79. package/api/third.d.ts +28 -0
  80. package/blocklet.md +3 -0
  81. package/blocklet.yml +89 -0
  82. package/index.html +14 -0
  83. package/logo.png +0 -0
  84. package/package.json +133 -0
  85. package/public/.gitkeep +0 -0
  86. package/screenshots/.gitkeep +0 -0
  87. package/screenshots/1-subscription.png +0 -0
  88. package/screenshots/2-customer-1.png +0 -0
  89. package/screenshots/3-customer-2.png +0 -0
  90. package/screenshots/4-admin-3.png +0 -0
  91. package/screenshots/5-admin-4.png +0 -0
  92. package/scripts/build-clean.js +6 -0
  93. package/scripts/bump-version.mjs +35 -0
  94. package/src/app.tsx +68 -0
  95. package/src/components/actions.tsx +85 -0
  96. package/src/components/blockchain/tx.tsx +29 -0
  97. package/src/components/checkout/amount.tsx +24 -0
  98. package/src/components/checkout/error.tsx +30 -0
  99. package/src/components/checkout/footer.tsx +12 -0
  100. package/src/components/checkout/form/address.tsx +38 -0
  101. package/src/components/checkout/form/index.tsx +295 -0
  102. package/src/components/checkout/header.tsx +23 -0
  103. package/src/components/checkout/pay.tsx +222 -0
  104. package/src/components/checkout/product-card.tsx +56 -0
  105. package/src/components/checkout/product-item.tsx +37 -0
  106. package/src/components/checkout/skeleton/overview.tsx +21 -0
  107. package/src/components/checkout/skeleton/payment.tsx +35 -0
  108. package/src/components/checkout/success.tsx +183 -0
  109. package/src/components/checkout/summary.tsx +34 -0
  110. package/src/components/collapse.tsx +50 -0
  111. package/src/components/confirm.tsx +55 -0
  112. package/src/components/copyable.tsx +38 -0
  113. package/src/components/currency.tsx +15 -0
  114. package/src/components/customer/actions.tsx +73 -0
  115. package/src/components/data.tsx +20 -0
  116. package/src/components/drawer-form.tsx +77 -0
  117. package/src/components/error-fallback.tsx +7 -0
  118. package/src/components/error.tsx +39 -0
  119. package/src/components/event/list.tsx +217 -0
  120. package/src/components/info-card.tsx +40 -0
  121. package/src/components/info-metric.tsx +35 -0
  122. package/src/components/info-row.tsx +28 -0
  123. package/src/components/input.tsx +40 -0
  124. package/src/components/invoice/action.tsx +94 -0
  125. package/src/components/invoice/list.tsx +225 -0
  126. package/src/components/invoice/table.tsx +110 -0
  127. package/src/components/layout.tsx +70 -0
  128. package/src/components/livemode.tsx +23 -0
  129. package/src/components/metadata/editor.tsx +57 -0
  130. package/src/components/metadata/form.tsx +45 -0
  131. package/src/components/payment-intent/actions.tsx +81 -0
  132. package/src/components/payment-intent/list.tsx +204 -0
  133. package/src/components/payment-link/actions.tsx +114 -0
  134. package/src/components/payment-link/after-pay.tsx +87 -0
  135. package/src/components/payment-link/before-pay.tsx +175 -0
  136. package/src/components/payment-link/item.tsx +135 -0
  137. package/src/components/payment-link/product-select.tsx +66 -0
  138. package/src/components/payment-link/rename.tsx +64 -0
  139. package/src/components/portal/invoice/list.tsx +110 -0
  140. package/src/components/portal/subscription/cancel.tsx +83 -0
  141. package/src/components/portal/subscription/list.tsx +232 -0
  142. package/src/components/price/actions.tsx +21 -0
  143. package/src/components/price/form.tsx +292 -0
  144. package/src/components/product/actions.tsx +125 -0
  145. package/src/components/product/add-price.tsx +59 -0
  146. package/src/components/product/create.tsx +97 -0
  147. package/src/components/product/edit-price.tsx +75 -0
  148. package/src/components/product/edit.tsx +67 -0
  149. package/src/components/product/features.tsx +32 -0
  150. package/src/components/product/form.tsx +76 -0
  151. package/src/components/relative-time.tsx +41 -0
  152. package/src/components/section/header.tsx +29 -0
  153. package/src/components/status.tsx +12 -0
  154. package/src/components/subscription/actions/cancel.tsx +66 -0
  155. package/src/components/subscription/actions/index.tsx +172 -0
  156. package/src/components/subscription/actions/pause.tsx +83 -0
  157. package/src/components/subscription/items/actions.tsx +31 -0
  158. package/src/components/subscription/items/index.tsx +107 -0
  159. package/src/components/subscription/list.tsx +200 -0
  160. package/src/components/switch.tsx +48 -0
  161. package/src/components/table.tsx +66 -0
  162. package/src/components/uploader.tsx +81 -0
  163. package/src/components/webhook/attempts.tsx +149 -0
  164. package/src/contexts/products.tsx +42 -0
  165. package/src/contexts/session.ts +10 -0
  166. package/src/contexts/settings.tsx +54 -0
  167. package/src/env.d.ts +17 -0
  168. package/src/global.css +97 -0
  169. package/src/hooks/mobile.ts +15 -0
  170. package/src/index.tsx +6 -0
  171. package/src/libs/api.ts +19 -0
  172. package/src/libs/dayjs.ts +17 -0
  173. package/src/libs/util.ts +474 -0
  174. package/src/locales/en.tsx +395 -0
  175. package/src/locales/index.tsx +8 -0
  176. package/src/locales/zh.tsx +389 -0
  177. package/src/pages/admin/billing/index.tsx +56 -0
  178. package/src/pages/admin/billing/invoices/detail.tsx +215 -0
  179. package/src/pages/admin/billing/invoices/index.tsx +5 -0
  180. package/src/pages/admin/billing/subscriptions/detail.tsx +237 -0
  181. package/src/pages/admin/billing/subscriptions/index.tsx +5 -0
  182. package/src/pages/admin/customers/customers/detail.tsx +209 -0
  183. package/src/pages/admin/customers/customers/index.tsx +109 -0
  184. package/src/pages/admin/customers/index.tsx +47 -0
  185. package/src/pages/admin/developers/events/detail.tsx +77 -0
  186. package/src/pages/admin/developers/events/index.tsx +5 -0
  187. package/src/pages/admin/developers/index.tsx +60 -0
  188. package/src/pages/admin/developers/logs.tsx +3 -0
  189. package/src/pages/admin/developers/overview.tsx +3 -0
  190. package/src/pages/admin/developers/webhooks/detail.tsx +109 -0
  191. package/src/pages/admin/developers/webhooks/index.tsx +102 -0
  192. package/src/pages/admin/index.tsx +120 -0
  193. package/src/pages/admin/overview.tsx +3 -0
  194. package/src/pages/admin/payments/index.tsx +65 -0
  195. package/src/pages/admin/payments/intents/detail.tsx +205 -0
  196. package/src/pages/admin/payments/intents/index.tsx +5 -0
  197. package/src/pages/admin/payments/links/create.tsx +141 -0
  198. package/src/pages/admin/payments/links/detail.tsx +318 -0
  199. package/src/pages/admin/payments/links/index.tsx +167 -0
  200. package/src/pages/admin/products/coupons/index.tsx +3 -0
  201. package/src/pages/admin/products/index.tsx +81 -0
  202. package/src/pages/admin/products/prices/actions.tsx +151 -0
  203. package/src/pages/admin/products/prices/detail.tsx +203 -0
  204. package/src/pages/admin/products/prices/list.tsx +95 -0
  205. package/src/pages/admin/products/pricing-tables.tsx +3 -0
  206. package/src/pages/admin/products/products/create.tsx +105 -0
  207. package/src/pages/admin/products/products/detail.tsx +246 -0
  208. package/src/pages/admin/products/products/index.tsx +154 -0
  209. package/src/pages/admin/settings/branding.tsx +3 -0
  210. package/src/pages/admin/settings/business.tsx +3 -0
  211. package/src/pages/admin/settings/index.tsx +47 -0
  212. package/src/pages/admin/settings/payment-methods.tsx +80 -0
  213. package/src/pages/checkout/index.tsx +38 -0
  214. package/src/pages/checkout/pay.tsx +89 -0
  215. package/src/pages/customer/index.tsx +93 -0
  216. package/src/pages/customer/invoice.tsx +147 -0
  217. package/src/pages/home.tsx +9 -0
  218. package/tsconfig.api.json +9 -0
  219. package/tsconfig.eslint.json +7 -0
  220. package/tsconfig.json +99 -0
  221. package/tsconfig.types.json +11 -0
  222. package/vite.config.ts +19 -0
@@ -0,0 +1,206 @@
1
+ /* eslint-disable @typescript-eslint/lines-between-class-members */
2
+ /* eslint-disable @typescript-eslint/indent */
3
+ import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model } from 'sequelize';
4
+ import type { LiteralUnion } from 'type-fest';
5
+
6
+ import { createEvent, createStatusEvent } from '../../libs/audit';
7
+ import { createIdGenerator } from '../../libs/util';
8
+ import type { PaymentError, PaymentMethodOptions } from './types';
9
+
10
+ const nextId = createIdGenerator('seti', 24);
11
+
12
+ // @link https://stripe.com/docs/api/setup_intents
13
+ // eslint-disable-next-line prettier/prettier
14
+ export class SetupIntent extends Model<InferAttributes<SetupIntent>, InferCreationAttributes<SetupIntent>> {
15
+ // Unique identifier for the object.
16
+ declare id: CreationOptional<string>;
17
+
18
+ declare livemode: boolean;
19
+ declare description: string;
20
+
21
+ declare currency_id: string;
22
+ declare customer_id: string;
23
+
24
+ // The setup error encountered in the previous SetupIntent confirmation
25
+ declare last_setup_error?: PaymentError;
26
+
27
+ declare metadata?: Record<string, any>;
28
+
29
+ declare status: LiteralUnion<
30
+ | 'requires_payment_method'
31
+ | 'requires_confirmation'
32
+ | 'requires_action'
33
+ | 'processing'
34
+ | 'requires_capture'
35
+ | 'canceled'
36
+ | 'succeeded',
37
+ string
38
+ >;
39
+
40
+ declare usage: LiteralUnion<'on_session' | 'off_session', string>;
41
+
42
+ declare canceled_at?: number;
43
+ declare cancellation_reason?: LiteralUnion<'abandoned' | 'duplicate' | 'requested_by_customer', string>;
44
+
45
+ declare flow_directions: LiteralUnion<'inbound' | 'outbound', string>[];
46
+
47
+ declare payment_method_options?: PaymentMethodOptions;
48
+ declare payment_method_types?: string[];
49
+ declare payment_method_id: string;
50
+
51
+ // 3rd party payment tx hash
52
+ declare setup_details?: {
53
+ tx_hash?: string;
54
+ payer?: string;
55
+ };
56
+
57
+ // TODO: following fields not supported yet
58
+ // application
59
+ // attach_to_self
60
+ // client_secret
61
+ // latest_attempt
62
+ // mandate
63
+ // next_action
64
+ // on_behalf_of
65
+ // single_use_mandate
66
+
67
+ declare created_at: CreationOptional<Date>;
68
+ declare updated_at: CreationOptional<Date>;
69
+
70
+ public static readonly GENESIS_ATTRIBUTES = {
71
+ id: {
72
+ type: DataTypes.STRING(30),
73
+ primaryKey: true,
74
+ allowNull: false,
75
+ defaultValue: nextId,
76
+ },
77
+ livemode: {
78
+ type: DataTypes.BOOLEAN,
79
+ allowNull: false,
80
+ },
81
+ currency_id: {
82
+ type: DataTypes.STRING(16),
83
+ allowNull: false,
84
+ },
85
+ customer_id: {
86
+ type: DataTypes.STRING(30),
87
+ allowNull: true,
88
+ },
89
+ description: {
90
+ type: DataTypes.STRING(512),
91
+ allowNull: true,
92
+ },
93
+ last_setup_error: {
94
+ type: DataTypes.JSON,
95
+ allowNull: true,
96
+ },
97
+ last_attempt: {
98
+ type: DataTypes.STRING(30),
99
+ allowNull: true,
100
+ },
101
+ metadata: {
102
+ type: DataTypes.JSON,
103
+ allowNull: true,
104
+ },
105
+ status: {
106
+ type: DataTypes.ENUM(
107
+ 'requires_payment_method',
108
+ 'requires_confirmation',
109
+ 'requires_action',
110
+ 'processing',
111
+ 'requires_capture',
112
+ 'canceled',
113
+ 'succeeded'
114
+ ),
115
+ allowNull: false,
116
+ },
117
+ usage: {
118
+ type: DataTypes.ENUM('on_session', 'off_session'),
119
+ allowNull: false,
120
+ },
121
+ canceled_at: {
122
+ type: DataTypes.INTEGER,
123
+ allowNull: true,
124
+ },
125
+ cancellation_reason: {
126
+ type: DataTypes.ENUM('abandoned', 'duplicate', 'requested_by_customer'),
127
+ allowNull: true,
128
+ },
129
+ flow_directions: {
130
+ type: DataTypes.JSON,
131
+ defaultValue: ['inbound', 'outbound'],
132
+ },
133
+ payment_method_types: {
134
+ type: DataTypes.JSON,
135
+ defaultValue: [],
136
+ },
137
+ payment_method_options: {
138
+ type: DataTypes.JSON,
139
+ allowNull: true,
140
+ },
141
+ payment_method_id: {
142
+ type: DataTypes.STRING(30),
143
+ allowNull: false,
144
+ },
145
+ setup_details: {
146
+ type: DataTypes.JSON,
147
+ allowNull: true,
148
+ },
149
+ created_at: {
150
+ type: DataTypes.DATE,
151
+ defaultValue: DataTypes.NOW,
152
+ allowNull: false,
153
+ },
154
+ updated_at: {
155
+ type: DataTypes.DATE,
156
+ defaultValue: DataTypes.NOW,
157
+ allowNull: false,
158
+ },
159
+ };
160
+
161
+ public static initialize(sequelize: any) {
162
+ this.init(SetupIntent.GENESIS_ATTRIBUTES, {
163
+ sequelize,
164
+ modelName: 'SetupIntent',
165
+ tableName: 'setup_intents',
166
+ createdAt: 'created_at',
167
+ updatedAt: 'updated_at',
168
+ hooks: {
169
+ afterCreate: (model: SetupIntent, options) =>
170
+ createEvent('SetupIntent', 'setup_intent.created', model, options).catch(console.error),
171
+ afterUpdate: (model: SetupIntent, options) =>
172
+ createStatusEvent(
173
+ 'SetupIntent',
174
+ 'setup_intent',
175
+ {
176
+ requires_action: 'requires_action',
177
+ canceled: 'canceled',
178
+ succeeded: 'succeeded',
179
+ },
180
+ model,
181
+ options
182
+ ),
183
+ },
184
+ });
185
+ }
186
+
187
+ public static associate(models: any) {
188
+ this.hasOne(models.PaymentCurrency, {
189
+ sourceKey: 'currency_id',
190
+ foreignKey: 'id',
191
+ as: 'paymentCurrency',
192
+ });
193
+ this.hasOne(models.PaymentMethod, {
194
+ sourceKey: 'payment_method_id',
195
+ foreignKey: 'id',
196
+ as: 'paymentMethod',
197
+ });
198
+ this.hasOne(models.Customer, {
199
+ sourceKey: 'customer_id',
200
+ foreignKey: 'id',
201
+ as: 'customer',
202
+ });
203
+ }
204
+ }
205
+
206
+ export type TSetupIntent = InferAttributes<SetupIntent>;
@@ -0,0 +1,103 @@
1
+ /* eslint-disable @typescript-eslint/lines-between-class-members */
2
+ import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model } from 'sequelize';
3
+
4
+ import { createIdGenerator } from '../../libs/util';
5
+
6
+ const nextId = createIdGenerator('si', 14);
7
+
8
+ // eslint-disable-next-line prettier/prettier
9
+ export class SubscriptionItem extends Model<InferAttributes<SubscriptionItem>, InferCreationAttributes<SubscriptionItem>> {
10
+ declare id: CreationOptional<string>;
11
+ declare livemode: boolean;
12
+
13
+ // The identifier of the subscription this item belongs to.
14
+ declare subscription_id: string;
15
+
16
+ // The price the customer is subscribed to.
17
+ declare price_id: string;
18
+
19
+ declare quantity: number;
20
+
21
+ declare metadata: Record<string, any>;
22
+
23
+ declare billing_thresholds?: {
24
+ usage_gte: number;
25
+ };
26
+
27
+ // Fields exists on creation
28
+ // declare proration_behavior: LiteralUnion<'always_invoice' | 'create_prorations' | 'none', string>;
29
+ // declare payment_behavior: LiteralUnion<'allow_incomplete' | 'error_if_incomplete' | 'pending_if_incomplete', string>;
30
+
31
+ // TODO: following fields not supported
32
+ // tax_rates
33
+
34
+ declare created_at: CreationOptional<Date>;
35
+ declare updated_at: CreationOptional<Date>;
36
+
37
+ public static readonly GENESIS_ATTRIBUTES = {
38
+ id: {
39
+ type: DataTypes.STRING(18),
40
+ primaryKey: true,
41
+ allowNull: false,
42
+ defaultValue: nextId,
43
+ },
44
+ livemode: {
45
+ type: DataTypes.BOOLEAN,
46
+ allowNull: false,
47
+ },
48
+ subscription_id: {
49
+ type: DataTypes.STRING(30),
50
+ allowNull: false,
51
+ },
52
+ price_id: {
53
+ type: DataTypes.STRING(30),
54
+ allowNull: false,
55
+ },
56
+ quantity: {
57
+ type: DataTypes.INTEGER,
58
+ allowNull: false,
59
+ },
60
+ metadata: {
61
+ type: DataTypes.JSON,
62
+ allowNull: true,
63
+ },
64
+ billing_threshold: {
65
+ type: DataTypes.JSON,
66
+ allowNull: true,
67
+ },
68
+ created_at: {
69
+ type: DataTypes.DATE,
70
+ defaultValue: DataTypes.NOW,
71
+ allowNull: false,
72
+ },
73
+ updated_at: {
74
+ type: DataTypes.DATE,
75
+ defaultValue: DataTypes.NOW,
76
+ allowNull: false,
77
+ },
78
+ };
79
+
80
+ public static initialize(sequelize: any) {
81
+ this.init(SubscriptionItem.GENESIS_ATTRIBUTES, {
82
+ sequelize,
83
+ modelName: 'SubscriptionItem',
84
+ tableName: 'subscription_items',
85
+ createdAt: 'created_at',
86
+ updatedAt: 'updated_at',
87
+ });
88
+ }
89
+
90
+ public static associate(models: any) {
91
+ this.belongsTo(models.Subscription, {
92
+ foreignKey: 'subscription_id',
93
+ as: 'subscription',
94
+ });
95
+ this.hasOne(models.Price, {
96
+ sourceKey: 'price_id',
97
+ foreignKey: 'id',
98
+ as: 'price',
99
+ });
100
+ }
101
+ }
102
+
103
+ export type TSubscriptionItem = InferAttributes<SubscriptionItem>;
@@ -0,0 +1,157 @@
1
+ /* eslint-disable @typescript-eslint/lines-between-class-members */
2
+ import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model } from 'sequelize';
3
+ import type { LiteralUnion } from 'type-fest';
4
+
5
+ import { createIdGenerator } from '../../libs/util';
6
+ import type { SubscriptionSchedulePhase } from './types';
7
+
8
+ const nextId = createIdGenerator('ss', 24);
9
+
10
+ // eslint-disable-next-line prettier/prettier
11
+ export class SubscriptionSchedule extends Model<InferAttributes<SubscriptionSchedule>, InferCreationAttributes<SubscriptionSchedule>> {
12
+ declare id: CreationOptional<string>;
13
+
14
+ declare livemode: boolean;
15
+
16
+ declare current_phase: {
17
+ end_date: Date;
18
+ start_date: Date;
19
+ };
20
+
21
+ declare customer_id: string;
22
+ declare subscription_id: string;
23
+
24
+ declare metadata: Record<string, any>;
25
+
26
+ declare status: LiteralUnion<'active' | 'canceled' | 'completed' | 'not_started' | 'released', string>;
27
+
28
+ declare phases?: SubscriptionSchedulePhase[];
29
+
30
+ // Object representing the subscription schedule’s default settings.
31
+ declare default_settings?: {
32
+ billing_cycle_anchor: LiteralUnion<'phase_start' | 'automatic', string>;
33
+ billing_thresholds: {
34
+ amount_gte: number;
35
+ reset_billing_cycle_anchor: boolean;
36
+ };
37
+ collection_method: LiteralUnion<'charge_automatically' | 'send_invoice', string>;
38
+ default_payment_method: string;
39
+ description: string;
40
+ invoice_settings: {
41
+ days_until_due: number;
42
+ };
43
+ // TODO: following fields not supported
44
+ // application_fee_percent?: number;
45
+ // automatic_tax?: {
46
+ // enabled: boolean;
47
+ // };
48
+ // on_behalf_of?: string;
49
+ // transfer_data?: any;
50
+ };
51
+
52
+ declare end_behavior: LiteralUnion<'cancel' | 'release', string>;
53
+
54
+ declare released_subscription_id?: string;
55
+
56
+ declare test_clock_id?: string;
57
+
58
+ // TODO: following fields not supported
59
+ // application
60
+
61
+ declare canceled_at: number;
62
+ declare completed_at: number;
63
+ declare released_at: number;
64
+
65
+ declare created_at: CreationOptional<Date>;
66
+ declare updated_at: CreationOptional<Date>;
67
+
68
+ public static readonly GENESIS_ATTRIBUTES = {
69
+ id: {
70
+ type: DataTypes.STRING(30),
71
+ primaryKey: true,
72
+ allowNull: false,
73
+ defaultValue: nextId,
74
+ },
75
+ livemode: {
76
+ type: DataTypes.BOOLEAN,
77
+ allowNull: false,
78
+ },
79
+ current_phase: {
80
+ type: DataTypes.JSON,
81
+ allowNull: false,
82
+ },
83
+ customer_id: {
84
+ type: DataTypes.STRING(30),
85
+ allowNull: false,
86
+ },
87
+ subscription_id: {
88
+ type: DataTypes.STRING(30),
89
+ allowNull: false,
90
+ },
91
+ released_subscription_id: {
92
+ type: DataTypes.STRING(30),
93
+ allowNull: true,
94
+ },
95
+ status: {
96
+ type: DataTypes.ENUM('active', 'canceled', 'completed', 'not_started', 'released'),
97
+ allowNull: false,
98
+ },
99
+ default_settings: {
100
+ type: DataTypes.JSON,
101
+ allowNull: true,
102
+ },
103
+ end_behavior: {
104
+ type: DataTypes.ENUM('cancel', 'release'),
105
+ allowNull: false,
106
+ },
107
+ test_clock_id: {
108
+ type: DataTypes.STRING(30),
109
+ allowNull: true,
110
+ },
111
+ metadata: {
112
+ type: DataTypes.JSON,
113
+ allowNull: true,
114
+ },
115
+ canceled_at: {
116
+ type: DataTypes.INTEGER,
117
+ allowNull: true,
118
+ },
119
+ completed_at: {
120
+ type: DataTypes.INTEGER,
121
+ allowNull: true,
122
+ },
123
+ released_at: {
124
+ type: DataTypes.INTEGER,
125
+ allowNull: true,
126
+ },
127
+ created_at: {
128
+ type: DataTypes.DATE,
129
+ defaultValue: DataTypes.NOW,
130
+ allowNull: false,
131
+ },
132
+ updated_at: {
133
+ type: DataTypes.DATE,
134
+ defaultValue: DataTypes.NOW,
135
+ allowNull: false,
136
+ },
137
+ };
138
+
139
+ public static initialize(sequelize: any) {
140
+ this.init(SubscriptionSchedule.GENESIS_ATTRIBUTES, {
141
+ sequelize,
142
+ modelName: 'SubscriptionSchedule',
143
+ tableName: 'subscription_schedules',
144
+ createdAt: 'created_at',
145
+ updatedAt: 'updated_at',
146
+ });
147
+ }
148
+
149
+ public static associate(models: any) {
150
+ this.belongsTo(models.Subscription, {
151
+ foreignKey: 'subscription_id',
152
+ as: 'subscription',
153
+ });
154
+ }
155
+ }
156
+
157
+ export type TSubscriptionSchedule = InferAttributes<SubscriptionSchedule>;