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,307 @@
1
+ /* eslint-disable @typescript-eslint/indent */
2
+ /* eslint-disable @typescript-eslint/lines-between-class-members */
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 { PaymentSettings, PriceRecurring } from './types';
9
+
10
+ const nextId = createIdGenerator('sub', 24);
11
+
12
+ // eslint-disable-next-line prettier/prettier
13
+ export class Subscription extends Model<InferAttributes<Subscription>, InferCreationAttributes<Subscription>> {
14
+ declare id: CreationOptional<string>;
15
+
16
+ declare livemode: boolean;
17
+
18
+ declare currency_id: string;
19
+ declare customer_id: string;
20
+
21
+ declare current_period_end: number;
22
+ declare current_period_start: number;
23
+
24
+ declare default_payment_method_id: string;
25
+ declare description?: string;
26
+ declare latest_invoice_id?: string;
27
+
28
+ declare metadata: Record<string, any>;
29
+
30
+ declare pending_setup_intent?: string;
31
+ declare pending_update?: {
32
+ billing_cycle_anchor?: number;
33
+ expires_at?: number;
34
+ subscription_items?: any[];
35
+ trial_end?: number;
36
+ };
37
+
38
+ declare status: LiteralUnion<
39
+ 'active' | 'past_due' | 'unpaid' | 'canceled' | 'incomplete' | 'incomplete_expired' | 'trialing' | 'paused',
40
+ string
41
+ >;
42
+
43
+ declare cancel_at_period_end: boolean;
44
+ declare cancel_at: CreationOptional<number>;
45
+ declare canceled_at: CreationOptional<number>;
46
+ declare cancelation_details?: {
47
+ comment: string;
48
+ feedback: LiteralUnion<
49
+ | 'too_expensive'
50
+ | 'missing_features'
51
+ | 'switched_service'
52
+ | 'unused'
53
+ | 'customer_service'
54
+ | 'too_complex'
55
+ | 'low_quality'
56
+ | 'other',
57
+ string
58
+ >;
59
+ reason: LiteralUnion<'cancellation_requested' | 'payment_disputed' | 'payment_failed', string>;
60
+ };
61
+
62
+ declare billing_cycle_anchor: number;
63
+ declare billing_thresholds?: {
64
+ amount_gte: number;
65
+ reset_billing_cycle_anchor: boolean;
66
+ };
67
+
68
+ declare collection_method: LiteralUnion<'charge_automatically' | 'send_invoice', string>;
69
+
70
+ // Number of days a customer has to pay invoices generated by this subscription. This value will be null for subscriptions where collection_method=charge_automatically.
71
+ declare days_until_due?: number;
72
+
73
+ declare discount_id?: string;
74
+
75
+ declare next_pending_invoice_item_invoice?: number;
76
+
77
+ declare pause_collection?: {
78
+ behavior: LiteralUnion<'keep_as_draft' | 'mark_uncollectible' | 'void', string>;
79
+ resumes_at: number;
80
+ };
81
+
82
+ declare payment_settings?: PaymentSettings;
83
+
84
+ declare pending_invoice_item_interval: PriceRecurring;
85
+
86
+ declare schedule_id?: string;
87
+
88
+ // If the subscription has ended, the date the subscription ended.
89
+ declare ended_at?: number;
90
+ declare start_date: number;
91
+ declare trail_end?: number;
92
+ declare trail_start?: number;
93
+ declare trail_settings?: {
94
+ end_behavior: {
95
+ missing_payment_method: LiteralUnion<'cancel' | 'pause' | 'create_invoice', string>;
96
+ };
97
+ };
98
+
99
+ // 3rd party payment tx hash
100
+ declare payment_details?: {
101
+ tx_hash?: string;
102
+ payer?: string;
103
+ };
104
+
105
+ // TODO: following fields not supported
106
+ // application
107
+ // application_fee_percent
108
+ // automatic_tax
109
+ // default_tax_rates
110
+ // on_behalf_of
111
+ // transfer_data
112
+
113
+ declare created_at: CreationOptional<Date>;
114
+ declare updated_at: CreationOptional<Date>;
115
+
116
+ public static readonly GENESIS_ATTRIBUTES = {
117
+ id: {
118
+ type: DataTypes.STRING(30),
119
+ primaryKey: true,
120
+ allowNull: false,
121
+ defaultValue: nextId,
122
+ },
123
+ livemode: {
124
+ type: DataTypes.BOOLEAN,
125
+ allowNull: false,
126
+ },
127
+ currency_id: {
128
+ type: DataTypes.STRING(15),
129
+ allowNull: false,
130
+ },
131
+ customer_id: {
132
+ type: DataTypes.STRING(18),
133
+ allowNull: false,
134
+ },
135
+ cancel_at_period_end: {
136
+ type: DataTypes.BOOLEAN,
137
+ allowNull: false,
138
+ },
139
+ current_period_end: {
140
+ type: DataTypes.INTEGER,
141
+ allowNull: false,
142
+ },
143
+ current_period_start: {
144
+ type: DataTypes.INTEGER,
145
+ allowNull: false,
146
+ },
147
+ default_payment_method_id: {
148
+ type: DataTypes.STRING(30),
149
+ allowNull: true,
150
+ },
151
+ description: {
152
+ type: DataTypes.STRING(512),
153
+ allowNull: true,
154
+ },
155
+ latest_invoice_id: {
156
+ type: DataTypes.STRING(30),
157
+ allowNull: true,
158
+ },
159
+ pending_setup_intent: {
160
+ type: DataTypes.STRING(30),
161
+ allowNull: true,
162
+ },
163
+ pending_update: {
164
+ type: DataTypes.JSON,
165
+ allowNull: true,
166
+ },
167
+ status: {
168
+ type: DataTypes.ENUM('active', 'canceled', 'incomplete', 'incomplete_expired', 'past_due', 'trialing', 'unpaid'),
169
+ allowNull: false,
170
+ },
171
+ cancel_at: {
172
+ type: DataTypes.INTEGER,
173
+ allowNull: true,
174
+ },
175
+ canceled_at: {
176
+ type: DataTypes.INTEGER,
177
+ allowNull: true,
178
+ },
179
+ cancelation_details: {
180
+ type: DataTypes.JSON,
181
+ allowNull: true,
182
+ },
183
+ billing_cycle_anchor: {
184
+ type: DataTypes.INTEGER,
185
+ allowNull: false,
186
+ },
187
+ billing_thresholds: {
188
+ type: DataTypes.JSON,
189
+ allowNull: true,
190
+ },
191
+ collection_method: {
192
+ type: DataTypes.ENUM('charge_automatically', 'send_invoice'),
193
+ },
194
+ days_until_due: {
195
+ type: DataTypes.NUMBER,
196
+ allowNull: true,
197
+ },
198
+ discount_id: {
199
+ type: DataTypes.STRING(30),
200
+ allowNull: true,
201
+ },
202
+ next_pending_invoice_item_invoice_id: {
203
+ type: DataTypes.STRING(30),
204
+ allowNull: true,
205
+ },
206
+ pause_collection: {
207
+ type: DataTypes.JSON,
208
+ allowNull: true,
209
+ },
210
+ payment_settings: {
211
+ type: DataTypes.JSON,
212
+ allowNull: true,
213
+ },
214
+ pending_invoice_item_interval: {
215
+ type: DataTypes.JSON,
216
+ allowNull: false,
217
+ },
218
+ schedule_id: {
219
+ type: DataTypes.STRING(30),
220
+ allowNull: true,
221
+ },
222
+ end_at: {
223
+ type: DataTypes.INTEGER,
224
+ allowNull: true,
225
+ },
226
+ start_date: {
227
+ type: DataTypes.INTEGER,
228
+ allowNull: false,
229
+ },
230
+ trail_end: {
231
+ type: DataTypes.INTEGER,
232
+ allowNull: true,
233
+ },
234
+ trail_start: {
235
+ type: DataTypes.INTEGER,
236
+ allowNull: true,
237
+ },
238
+ trail_settings: {
239
+ type: DataTypes.JSON,
240
+ allowNull: true,
241
+ },
242
+ payment_details: {
243
+ type: DataTypes.JSON,
244
+ allowNull: true,
245
+ },
246
+ metadata: {
247
+ type: DataTypes.JSON,
248
+ allowNull: true,
249
+ },
250
+ created_at: {
251
+ type: DataTypes.DATE,
252
+ defaultValue: DataTypes.NOW,
253
+ allowNull: false,
254
+ },
255
+ updated_at: {
256
+ type: DataTypes.DATE,
257
+ defaultValue: DataTypes.NOW,
258
+ allowNull: false,
259
+ },
260
+ };
261
+
262
+ public static initialize(sequelize: any) {
263
+ this.init(Subscription.GENESIS_ATTRIBUTES, {
264
+ sequelize,
265
+ modelName: 'Subscription',
266
+ tableName: 'subscriptions',
267
+ createdAt: 'created_at',
268
+ updatedAt: 'updated_at',
269
+ hooks: {
270
+ afterCreate: (model: Subscription, options) =>
271
+ createEvent('Subscription', 'customer.subscription.created', model, options).catch(console.error),
272
+ afterUpdate: (model: Subscription, options) => {
273
+ createEvent('Subscription', 'customer.subscription.updated', model, options).catch(console.error);
274
+ createStatusEvent('Subscription', 'customer.subscription', { canceled: 'canceled' }, model, options).catch(
275
+ console.error
276
+ );
277
+ },
278
+ afterDestroy: (model: Subscription, options) =>
279
+ createEvent('Subscription', 'customer.subscription.deleted', model, options).catch(console.error),
280
+ },
281
+ });
282
+ }
283
+
284
+ public static associate(models: any) {
285
+ this.hasOne(models.PaymentCurrency, {
286
+ sourceKey: 'currency_id',
287
+ foreignKey: 'id',
288
+ as: 'paymentCurrency',
289
+ });
290
+ this.hasOne(models.PaymentMethod, {
291
+ sourceKey: 'default_payment_method_id',
292
+ foreignKey: 'id',
293
+ as: 'paymentMethod',
294
+ });
295
+ this.hasOne(models.Customer, {
296
+ sourceKey: 'customer_id',
297
+ foreignKey: 'id',
298
+ as: 'customer',
299
+ });
300
+ this.hasMany(models.SubscriptionItem, {
301
+ foreignKey: 'subscription_id',
302
+ as: 'items',
303
+ });
304
+ }
305
+ }
306
+
307
+ export type TSubscription = InferAttributes<Subscription>;
@@ -0,0 +1,406 @@
1
+ /* eslint-disable @typescript-eslint/indent */
2
+ import type { LiteralUnion } from 'type-fest';
3
+
4
+ export type Pagination<T = any> = T & {
5
+ // offset based
6
+ page?: number;
7
+ size?: number;
8
+ // TODO: cursor based
9
+ limit?: number;
10
+ starting_after?: string;
11
+ ending_before?: string;
12
+
13
+ // extra
14
+ [key: string]: any;
15
+ };
16
+
17
+ export type Paginated<T = any> = {
18
+ count: number;
19
+ list: T[];
20
+ };
21
+
22
+ export type InferFormType<T> = Omit<
23
+ T,
24
+ 'id' | 'created_at' | 'created_via' | 'updated_at' | 'active' | 'livemode' | 'metadata'
25
+ > & {
26
+ metadata: { key: string; value: string }[];
27
+ };
28
+
29
+ export type PriceRecurring = {
30
+ interval: LiteralUnion<'hour' | 'day' | 'week' | 'month' | 'year', string>;
31
+ interval_count: number;
32
+ aggregate_usage?: LiteralUnion<'sum' | 'last_during_period' | 'max' | 'last_ever', string>;
33
+ usage_type?: LiteralUnion<'licensed' | 'metered', string>;
34
+ metered?: boolean;
35
+ };
36
+
37
+ export type CustomUnitAmount = {
38
+ maximum: string;
39
+ minimum: string;
40
+ preset: string;
41
+ };
42
+
43
+ export type PriceTier = {
44
+ // The flat billing amount for an entire tier, regardless of the number of units in the tier.
45
+ flat_amount?: number;
46
+
47
+ // The per unit billing amount for each individual unit for which this tier applies.
48
+ unit_amount?: string;
49
+
50
+ // The upper bound of this tier.
51
+ up_to?: number;
52
+ };
53
+
54
+ export type TransformQuantity = {
55
+ divide_by: number;
56
+ round: LiteralUnion<'up' | 'down', string>;
57
+ };
58
+
59
+ export type CustomField = {
60
+ key: string;
61
+ label: string;
62
+ type: LiteralUnion<'text' | 'numeric' | 'dropdown', string>;
63
+ optional: boolean;
64
+ text?: {
65
+ maximum_length: number;
66
+ minimum_length: number;
67
+ };
68
+ numeric?: {
69
+ maximum_length: number;
70
+ minimum_length: number;
71
+ };
72
+ dropdown?: {
73
+ options: { label: string; value: string }[];
74
+ };
75
+ };
76
+
77
+ export type AfterPayment = {
78
+ type: LiteralUnion<'redirect' | 'hosted_confirmation', string>;
79
+ redirect?: {
80
+ url: string;
81
+ };
82
+ hosted_confirmation?: {
83
+ custom_message: string;
84
+ };
85
+ };
86
+
87
+ export type SimpleCustomField = {
88
+ name: string;
89
+ value: string;
90
+ };
91
+
92
+ export type DiscountAmount = {
93
+ amount: number;
94
+ discount: string;
95
+ };
96
+
97
+ export type CustomerAddress = {
98
+ city?: string;
99
+ country?: string;
100
+ line1?: string;
101
+ line2?: string;
102
+ postal_code?: string;
103
+ state?: string;
104
+ };
105
+
106
+ export type CustomerShipping = {
107
+ address: CustomerAddress;
108
+ name: string;
109
+ phone: string;
110
+ };
111
+
112
+ export type CustomerDetail = {
113
+ address?: CustomerAddress;
114
+ email?: string;
115
+ name?: string;
116
+ phone?: string;
117
+ // TODO: following are not supported
118
+ // tax_exempt: any;
119
+ // tax_ids: any
120
+ };
121
+
122
+ export type PaymentError = {
123
+ type: LiteralUnion<'api_error' | 'card_error' | 'idempotency_error' | 'invalid_request_error', string>;
124
+ charge?: string;
125
+ code?: string;
126
+ decline_code?: string;
127
+ doc_url?: string;
128
+ message?: string;
129
+ param?: string;
130
+ payment_settings?: any;
131
+ payment_method_id?: string;
132
+ payment_method_type?: string;
133
+ };
134
+
135
+ export type LineItem = {
136
+ price_id: string;
137
+ quantity: number;
138
+ adjustable_quantity?: {
139
+ enabled: boolean;
140
+ maximum: number;
141
+ minimum: number;
142
+ };
143
+ // TODO: following are not supported
144
+ // price_data?: any;
145
+ // dynamic_tax_rates?: any;
146
+ // tax_rates?: any;
147
+ };
148
+
149
+ export type InvoiceData = Record<string, any>;
150
+
151
+ // @see https://stripe.com/docs/currencies/conversions
152
+ // If presentment currency is different from settlement currency, this is the exchange rate snapshot used.
153
+ export type CurrencyConversion = {
154
+ amount_subtotal: string;
155
+ amount_total: string;
156
+ fx_rate: string;
157
+ source_currency: string;
158
+ };
159
+
160
+ export type SubscriptionSchedulePhase = {
161
+ billing_cycle_anchor: LiteralUnion<'phase_start' | 'automatic', string>;
162
+ billing_thresholds?: {
163
+ amount_gte: string;
164
+ reset_billing_cycle_anchor: boolean;
165
+ };
166
+ collection_method: LiteralUnion<'charge_automatically' | 'send_invoice', string>;
167
+ coupon_id?: string;
168
+ currency_id?: string;
169
+ description?: string;
170
+ start_date?: number;
171
+ end_date?: number;
172
+ trail_end?: number;
173
+ invoice_settings?: {
174
+ days_until_due?: number;
175
+ };
176
+ items: {
177
+ price: string;
178
+ quantity?: number;
179
+ billing_thresholds?: {
180
+ usage_gte: number;
181
+ };
182
+ // tax_rates?: string[];
183
+ }[];
184
+ metadata?: Record<string, any>;
185
+ // TODO: following fields not supported
186
+ // application_fee_percent?: number;
187
+ // default_payment_method?: string;
188
+ // default_tax_rates?: string[];
189
+ // on_behalf_of?: string;
190
+ // transfer_data?: any;
191
+ };
192
+
193
+ export type PaymentMethodOptions = {
194
+ arcblock?: {
195
+ payer: string;
196
+ };
197
+ ethereum?: {
198
+ payer: string;
199
+ };
200
+ stripe?: {
201
+ payer: string;
202
+ };
203
+ };
204
+
205
+ export type PaymentSettings = {
206
+ payment_method_options: PaymentMethodOptions;
207
+ payment_method_types: string[];
208
+ };
209
+
210
+ export type EventType = LiteralUnion<
211
+ | 'account.application.authorized'
212
+ | 'account.application.deauthorized'
213
+ | 'account.external_account.created'
214
+ | 'account.external_account.deleted'
215
+ | 'account.external_account.updated'
216
+ | 'account.updated'
217
+ | 'application_fee.created'
218
+ | 'application_fee.refund.updated'
219
+ | 'application_fee.refunded'
220
+ | 'balance.available'
221
+ | 'billing_portal.configuration.created'
222
+ | 'billing_portal.configuration.updated'
223
+ | 'billing_portal.session.created'
224
+ | 'capability.updated'
225
+ | 'cash_balance.funds_available'
226
+ | 'charge.captured'
227
+ | 'charge.dispute.closed'
228
+ | 'charge.dispute.created'
229
+ | 'charge.dispute.funds_reinstated'
230
+ | 'charge.dispute.funds_withdrawn'
231
+ | 'charge.dispute.updated'
232
+ | 'charge.expired'
233
+ | 'charge.failed'
234
+ | 'charge.pending'
235
+ | 'charge.refund.updated'
236
+ | 'charge.refunded'
237
+ | 'charge.succeeded'
238
+ | 'charge.updated'
239
+ | 'checkout.session.async_payment_failed'
240
+ | 'checkout.session.async_payment_succeeded'
241
+ | 'checkout.session.completed'
242
+ | 'checkout.session.expired'
243
+ | 'coupon.created'
244
+ | 'coupon.deleted'
245
+ | 'coupon.updated'
246
+ | 'credit_note.created'
247
+ | 'credit_note.updated'
248
+ | 'credit_note.voided'
249
+ | 'customer_cash_balance_transaction.created'
250
+ | 'customer.created'
251
+ | 'customer.deleted'
252
+ | 'customer.discount.created'
253
+ | 'customer.discount.deleted'
254
+ | 'customer.discount.updated'
255
+ | 'customer.source.created'
256
+ | 'customer.source.deleted'
257
+ | 'customer.source.expiring'
258
+ | 'customer.source.updated'
259
+ | 'customer.subscription.created'
260
+ | 'customer.subscription.deleted'
261
+ | 'customer.subscription.paused'
262
+ | 'customer.subscription.pending_update_applied'
263
+ | 'customer.subscription.pending_update_expired'
264
+ | 'customer.subscription.resumed'
265
+ | 'customer.subscription.trial_will_end'
266
+ | 'customer.subscription.updated'
267
+ | 'customer.tax_id.created'
268
+ | 'customer.tax_id.deleted'
269
+ | 'customer.tax_id.updated'
270
+ | 'customer.updated'
271
+ | 'file.created'
272
+ | 'financial_connections.account.created'
273
+ | 'financial_connections.account.deactivated'
274
+ | 'financial_connections.account.disconnected'
275
+ | 'financial_connections.account.reactivated'
276
+ | 'financial_connections.account.refreshed_balance'
277
+ | 'identity.verification_session.canceled'
278
+ | 'identity.verification_session.created'
279
+ | 'identity.verification_session.processing'
280
+ | 'identity.verification_session.redacted'
281
+ | 'identity.verification_session.requires_input'
282
+ | 'identity.verification_session.verified'
283
+ | 'invoice.created'
284
+ | 'invoice.deleted'
285
+ | 'invoice.finalization_failed'
286
+ | 'invoice.finalized'
287
+ | 'invoice.marked_uncollectible'
288
+ | 'invoice.paid'
289
+ | 'invoice.payment_action_required'
290
+ | 'invoice.payment_failed'
291
+ | 'invoice.payment_succeeded'
292
+ | 'invoice.sent'
293
+ | 'invoice.upcoming'
294
+ | 'invoice.updated'
295
+ | 'invoice.voided'
296
+ | 'invoiceitem.created'
297
+ | 'invoiceitem.deleted'
298
+ | 'issuing_authorization.created'
299
+ | 'issuing_authorization.request'
300
+ | 'issuing_authorization.updated'
301
+ | 'issuing_card.created'
302
+ | 'issuing_card.updated'
303
+ | 'issuing_cardholder.created'
304
+ | 'issuing_cardholder.updated'
305
+ | 'issuing_dispute.closed'
306
+ | 'issuing_dispute.created'
307
+ | 'issuing_dispute.funds_reinstated'
308
+ | 'issuing_dispute.submitted'
309
+ | 'issuing_dispute.updated'
310
+ | 'issuing_transaction.created'
311
+ | 'issuing_transaction.updated'
312
+ | 'mandate.updated'
313
+ | 'order.created'
314
+ | 'payment_intent.amount_capturable_updated'
315
+ | 'payment_intent.canceled'
316
+ | 'payment_intent.created'
317
+ | 'payment_intent.partially_funded'
318
+ | 'payment_intent.payment_failed'
319
+ | 'payment_intent.processing'
320
+ | 'payment_intent.requires_action'
321
+ | 'payment_intent.succeeded'
322
+ | 'payment_link.created'
323
+ | 'payment_link.updated'
324
+ | 'payment_method.attached'
325
+ | 'payment_method.automatically_updated'
326
+ | 'payment_method.detached'
327
+ | 'payment_method.updated'
328
+ | 'payout.canceled'
329
+ | 'payout.created'
330
+ | 'payout.failed'
331
+ | 'payout.paid'
332
+ | 'payout.reconciliation_completed'
333
+ | 'payout.updated'
334
+ | 'person.created'
335
+ | 'person.deleted'
336
+ | 'person.updated'
337
+ | 'plan.created'
338
+ | 'plan.deleted'
339
+ | 'plan.updated'
340
+ | 'price.created'
341
+ | 'price.deleted'
342
+ | 'price.updated'
343
+ | 'product.created'
344
+ | 'product.deleted'
345
+ | 'product.updated'
346
+ | 'promotion_code.created'
347
+ | 'promotion_code.updated'
348
+ | 'quote.accepted'
349
+ | 'quote.canceled'
350
+ | 'quote.created'
351
+ | 'quote.finalized'
352
+ | 'radar.early_fraud_warning.created'
353
+ | 'radar.early_fraud_warning.updated'
354
+ | 'recipient.created'
355
+ | 'recipient.deleted'
356
+ | 'recipient.updated'
357
+ | 'refund.created'
358
+ | 'refund.updated'
359
+ | 'reporting.report_run.failed'
360
+ | 'reporting.report_run.succeeded'
361
+ | 'reporting.report_type.updated'
362
+ | 'review.closed'
363
+ | 'review.opened'
364
+ | 'setup_intent.canceled'
365
+ | 'setup_intent.created'
366
+ | 'setup_intent.requires_action'
367
+ | 'setup_intent.setup_failed'
368
+ | 'setup_intent.succeeded'
369
+ | 'sigma.scheduled_query_run.created'
370
+ | 'sku.created'
371
+ | 'sku.deleted'
372
+ | 'sku.updated'
373
+ | 'source.canceled'
374
+ | 'source.chargeable'
375
+ | 'source.failed'
376
+ | 'source.mandate_notification'
377
+ | 'source.refund_attributes_required'
378
+ | 'source.transaction.created'
379
+ | 'source.transaction.updated'
380
+ | 'subscription_schedule.aborted'
381
+ | 'subscription_schedule.canceled'
382
+ | 'subscription_schedule.completed'
383
+ | 'subscription_schedule.created'
384
+ | 'subscription_schedule.expiring'
385
+ | 'subscription_schedule.released'
386
+ | 'subscription_schedule.updated'
387
+ | 'tax_rate.created'
388
+ | 'tax_rate.updated'
389
+ | 'tax.settings.updated'
390
+ | 'terminal.reader.action_failed'
391
+ | 'terminal.reader.action_succeeded'
392
+ | 'test_helpers.test_clock.advancing'
393
+ | 'test_helpers.test_clock.created'
394
+ | 'test_helpers.test_clock.deleted'
395
+ | 'test_helpers.test_clock.internal_failure'
396
+ | 'test_helpers.test_clock.ready'
397
+ | 'topup.canceled'
398
+ | 'topup.created'
399
+ | 'topup.failed'
400
+ | 'topup.reversed'
401
+ | 'topup.succeeded'
402
+ | 'transfer.created'
403
+ | 'transfer.reversed'
404
+ | 'transfer.updated',
405
+ string
406
+ >;