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,199 @@
1
+ /* eslint-disable @typescript-eslint/lines-between-class-members */
2
+ import padStart from 'lodash/padStart';
3
+ import {
4
+ CreationOptional,
5
+ DataTypes,
6
+ FindOptions,
7
+ InferAttributes,
8
+ InferCreationAttributes,
9
+ Model,
10
+ Op,
11
+ } from 'sequelize';
12
+
13
+ import { createEvent } from '../../libs/audit';
14
+ import { createIdGenerator } from '../../libs/util';
15
+ import type { CustomerAddress, CustomerShipping } from './types';
16
+
17
+ const nextId = createIdGenerator('cus', 14);
18
+
19
+ // eslint-disable-next-line prettier/prettier
20
+ export class Customer extends Model<InferAttributes<Customer>, InferCreationAttributes<Customer>> {
21
+ declare id: CreationOptional<string>;
22
+ declare livemode: boolean;
23
+
24
+ declare did: string;
25
+ declare description: string;
26
+ declare name: string;
27
+ declare email: string;
28
+ declare phone: string;
29
+
30
+ declare address?: CustomerAddress;
31
+ declare shipping?: CustomerShipping;
32
+
33
+ declare balance?: string;
34
+ declare currency_id?: string;
35
+ declare delinquent: boolean;
36
+ declare discount_id?: string;
37
+
38
+ declare metadata: Record<string, any>;
39
+
40
+ declare invoice_credit_balance?: any;
41
+ declare invoice_prefix?: string;
42
+ declare invoice_settings?: {
43
+ custom_fields?: {
44
+ name: string;
45
+ value: string;
46
+ }[];
47
+ default_payment_method?: string;
48
+ footer?: string;
49
+ };
50
+ declare next_invoice_sequence?: number;
51
+
52
+ // TODO: following fields not supported
53
+ // declare preferred_locales?: string[];
54
+ // declare tax_exempt?: LiteralUnion<'exempt' | 'none' | 'reverse', string>;
55
+ // declare tax_ids?: any;
56
+
57
+ declare created_at: CreationOptional<Date>;
58
+ declare updated_at: CreationOptional<Date>;
59
+
60
+ public static readonly GENESIS_ATTRIBUTES = {
61
+ id: {
62
+ type: DataTypes.STRING(18),
63
+ primaryKey: true,
64
+ allowNull: false,
65
+ defaultValue: nextId,
66
+ },
67
+ livemode: {
68
+ type: DataTypes.BOOLEAN,
69
+ allowNull: false,
70
+ },
71
+ did: {
72
+ type: DataTypes.STRING(40),
73
+ allowNull: false,
74
+ },
75
+ address: {
76
+ type: DataTypes.JSON,
77
+ allowNull: true,
78
+ },
79
+ description: {
80
+ type: DataTypes.STRING(512),
81
+ allowNull: true,
82
+ },
83
+ name: {
84
+ type: DataTypes.STRING(64),
85
+ allowNull: true,
86
+ },
87
+ email: {
88
+ type: DataTypes.STRING(128),
89
+ allowNull: true,
90
+ },
91
+ phone: {
92
+ type: DataTypes.STRING(32),
93
+ allowNull: true,
94
+ },
95
+ shipping: {
96
+ type: DataTypes.JSON,
97
+ allowNull: true,
98
+ },
99
+ balance: {
100
+ type: DataTypes.STRING(32),
101
+ defaultValue: '0',
102
+ },
103
+ currency_id: {
104
+ type: DataTypes.STRING(15),
105
+ allowNull: true,
106
+ },
107
+ delinquent: {
108
+ type: DataTypes.BOOLEAN,
109
+ allowNull: false,
110
+ },
111
+ discount_id: {
112
+ type: DataTypes.STRING(32),
113
+ allowNull: true,
114
+ },
115
+ metadata: {
116
+ type: DataTypes.JSON,
117
+ allowNull: true,
118
+ },
119
+ invoice_credit_balance: {
120
+ type: DataTypes.JSON,
121
+ allowNull: true,
122
+ },
123
+ invoice_prefix: {
124
+ type: DataTypes.STRING(30),
125
+ allowNull: true,
126
+ },
127
+ invoice_settings: {
128
+ type: DataTypes.JSON,
129
+ allowNull: true,
130
+ },
131
+ next_invoice_sequence: {
132
+ type: DataTypes.NUMBER,
133
+ defaultValue: 1,
134
+ },
135
+ created_at: {
136
+ type: DataTypes.DATE,
137
+ defaultValue: DataTypes.NOW,
138
+ allowNull: false,
139
+ },
140
+ updated_at: {
141
+ type: DataTypes.DATE,
142
+ defaultValue: DataTypes.NOW,
143
+ allowNull: false,
144
+ },
145
+ };
146
+
147
+ public async getInvoiceNumber() {
148
+ const sequence = this.next_invoice_sequence || 1;
149
+ await this.increment('next_invoice_sequence', { by: 1 });
150
+ return `${this.invoice_prefix}-${padStart(sequence.toString(), 4, '0')}`;
151
+ }
152
+
153
+ public static initialize(sequelize: any) {
154
+ this.init(Customer.GENESIS_ATTRIBUTES, {
155
+ sequelize,
156
+ modelName: 'Customer',
157
+ tableName: 'customers',
158
+ createdAt: 'created_at',
159
+ updatedAt: 'updated_at',
160
+ hooks: {
161
+ afterCreate: (model: Customer, options) =>
162
+ createEvent('Customer', 'customer.created', model, options).catch(console.error),
163
+ afterUpdate: (model: Customer, options) =>
164
+ createEvent('Customer', 'customer.updated', model, options).catch(console.error),
165
+ afterDestroy: (model: Customer, options) =>
166
+ createEvent('Customer', 'customer.deleted', model, options).catch(console.error),
167
+ },
168
+ });
169
+ }
170
+
171
+ public static associate(models: any) {
172
+ this.hasOne(models.PaymentCurrency, {
173
+ sourceKey: 'currency_id',
174
+ foreignKey: 'id',
175
+ as: 'currency',
176
+ });
177
+ this.hasMany(models.PaymentIntent, {
178
+ foreignKey: 'customer_id',
179
+ as: 'payments',
180
+ });
181
+ this.hasMany(models.Subscription, {
182
+ foreignKey: 'customer_id',
183
+ as: 'subscriptions',
184
+ });
185
+ this.hasMany(models.Invoice, {
186
+ foreignKey: 'customer_id',
187
+ as: 'invoices',
188
+ });
189
+ }
190
+
191
+ public static findByPkOrDid(id: string, options: FindOptions<Customer> = {}) {
192
+ return this.findOne({
193
+ where: { [Op.or]: [{ id }, { did: id }] },
194
+ ...options,
195
+ });
196
+ }
197
+ }
198
+
199
+ export type TCustomer = InferAttributes<Customer>;
@@ -0,0 +1,116 @@
1
+ /* eslint-disable @typescript-eslint/lines-between-class-members */
2
+ import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model } from 'sequelize';
3
+
4
+ import { createCodeGenerator } from '../../libs/util';
5
+
6
+ const nextId = createCodeGenerator('', 8);
7
+
8
+ // @link https://stripe.com/docs/api/discounts
9
+ // eslint-disable-next-line prettier/prettier
10
+ export class Discount extends Model<InferAttributes<Discount>, InferCreationAttributes<Discount>> {
11
+ declare id: CreationOptional<string>;
12
+ declare livemode: boolean;
13
+
14
+ declare coupon_id: string;
15
+ declare promotion_code_id?: string;
16
+ declare customer_id: string;
17
+ declare subscription_id?: string;
18
+ declare checkout_session_id?: string;
19
+ declare invoice_id?: string;
20
+ declare invoice_item_id?: string;
21
+
22
+ declare start: number;
23
+ declare end: number;
24
+
25
+ declare created_at: CreationOptional<Date>;
26
+ declare updated_at: CreationOptional<Date>;
27
+
28
+ public static readonly GENESIS_ATTRIBUTES = {
29
+ id: {
30
+ type: DataTypes.STRING(15),
31
+ primaryKey: true,
32
+ allowNull: false,
33
+ defaultValue: nextId,
34
+ },
35
+ livemode: {
36
+ type: DataTypes.BOOLEAN,
37
+ allowNull: false,
38
+ },
39
+ coupon_id: {
40
+ type: DataTypes.STRING(30),
41
+ allowNull: false,
42
+ },
43
+ customer_id: {
44
+ type: DataTypes.STRING(30),
45
+ allowNull: false,
46
+ },
47
+ promotion_code_id: {
48
+ type: DataTypes.STRING(30),
49
+ allowNull: true,
50
+ },
51
+ subscription_id: {
52
+ type: DataTypes.STRING(30),
53
+ allowNull: true,
54
+ },
55
+ checkout_session_id: {
56
+ type: DataTypes.STRING(30),
57
+ allowNull: true,
58
+ },
59
+ invoice_id: {
60
+ type: DataTypes.STRING(30),
61
+ allowNull: true,
62
+ },
63
+ invoice_item_id: {
64
+ type: DataTypes.STRING(30),
65
+ allowNull: true,
66
+ },
67
+ start: {
68
+ type: DataTypes.DATE,
69
+ allowNull: false,
70
+ },
71
+ end: {
72
+ type: DataTypes.DATE,
73
+ allowNull: true,
74
+ },
75
+ metadata: {
76
+ type: DataTypes.JSON,
77
+ allowNull: true,
78
+ },
79
+ created_at: {
80
+ type: DataTypes.DATE,
81
+ defaultValue: DataTypes.NOW,
82
+ allowNull: false,
83
+ },
84
+ updated_at: {
85
+ type: DataTypes.DATE,
86
+ defaultValue: DataTypes.NOW,
87
+ allowNull: false,
88
+ },
89
+ };
90
+
91
+ public static initialize(sequelize: any) {
92
+ this.init(Discount.GENESIS_ATTRIBUTES, {
93
+ sequelize,
94
+ modelName: 'Discount',
95
+ tableName: 'discounts',
96
+ createdAt: 'created_at',
97
+ updatedAt: 'updated_at',
98
+ });
99
+ }
100
+
101
+ // FIXME:
102
+ public static associate(models: any) {
103
+ this.hasOne(models.Customer, {
104
+ sourceKey: 'customer_id',
105
+ foreignKey: 'id',
106
+ as: 'customer',
107
+ });
108
+ this.hasOne(models.Coupon, {
109
+ sourceKey: 'coupon_id',
110
+ foreignKey: 'id',
111
+ as: 'coupon',
112
+ });
113
+ }
114
+ }
115
+
116
+ export type TDiscount = InferAttributes<Discount>;
@@ -0,0 +1,111 @@
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
+ import type { EventType } from './types';
6
+
7
+ const nextId = createIdGenerator('evt', 24);
8
+
9
+ // eslint-disable-next-line prettier/prettier
10
+ export class Event extends Model<InferAttributes<Event>, InferCreationAttributes<Event>> {
11
+ declare id: CreationOptional<string>;
12
+
13
+ declare livemode: boolean;
14
+
15
+ declare type: EventType;
16
+ declare api_version: string;
17
+
18
+ declare data: Record<string, any>;
19
+
20
+ // the object that this event belongs to
21
+ declare object_type: string;
22
+ declare object_id: string;
23
+
24
+ declare request: {
25
+ id: string;
26
+ idempotency_key: string;
27
+ };
28
+
29
+ // Number of webhooks that have yet to be successfully delivered
30
+ declare pending_webhooks: number;
31
+
32
+ declare metadata: Record<string, any>;
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(30),
40
+ primaryKey: true,
41
+ allowNull: false,
42
+ defaultValue: nextId,
43
+ },
44
+ livemode: {
45
+ type: DataTypes.BOOLEAN,
46
+ allowNull: false,
47
+ },
48
+ type: {
49
+ type: DataTypes.STRING(64),
50
+ allowNull: false,
51
+ },
52
+ api_version: {
53
+ type: DataTypes.STRING(16),
54
+ allowNull: false,
55
+ },
56
+ object_type: {
57
+ type: DataTypes.STRING(32),
58
+ allowNull: false,
59
+ },
60
+ object_id: {
61
+ type: DataTypes.STRING(32),
62
+ allowNull: false,
63
+ },
64
+ data: {
65
+ type: DataTypes.JSON,
66
+ allowNull: false,
67
+ },
68
+ request: {
69
+ type: DataTypes.JSON,
70
+ allowNull: false,
71
+ },
72
+ pending_webhooks: {
73
+ type: DataTypes.NUMBER,
74
+ allowNull: false,
75
+ },
76
+ metadata: {
77
+ type: DataTypes.JSON,
78
+ allowNull: true,
79
+ },
80
+ created_at: {
81
+ type: DataTypes.DATE,
82
+ defaultValue: DataTypes.NOW,
83
+ allowNull: false,
84
+ },
85
+ updated_at: {
86
+ type: DataTypes.DATE,
87
+ defaultValue: DataTypes.NOW,
88
+ allowNull: false,
89
+ },
90
+ };
91
+
92
+ public static initialize(sequelize: any) {
93
+ this.init(Event.GENESIS_ATTRIBUTES, {
94
+ sequelize,
95
+ modelName: 'Event',
96
+ tableName: 'events',
97
+ createdAt: 'created_at',
98
+ updatedAt: 'updated_at',
99
+ });
100
+ }
101
+
102
+ public static associate(models: any) {
103
+ this.hasMany(models.WebhookAttempt, {
104
+ sourceKey: 'id',
105
+ foreignKey: 'event_id',
106
+ as: 'webhookAttempts',
107
+ });
108
+ }
109
+ }
110
+
111
+ export type TEvent = InferAttributes<Event>;
@@ -0,0 +1,165 @@
1
+ import { CheckoutSession, TCheckoutSession } from './checkout-session';
2
+ import { Coupon } from './coupon';
3
+ import { Customer, TCustomer } from './customer';
4
+ import { Discount } from './discount';
5
+ import { Event, TEvent } from './event';
6
+ import { Invoice, TInvoice } from './invoice';
7
+ import { InvoiceItem, TInvoiceItem } from './invoice-item';
8
+ import { Job } from './job';
9
+ import { PaymentCurrency, TPaymentCurrency } from './payment-currency';
10
+ import { PaymentIntent, TPaymentIntent } from './payment-intent';
11
+ import { PaymentLink, TPaymentLink } from './payment-link';
12
+ import { PaymentMethod, TPaymentMethod } from './payment-method';
13
+ import { Price, TPrice } from './price';
14
+ import { Product, TProduct } from './product';
15
+ import { PromotionCode } from './promotion-code';
16
+ import { SetupIntent, TSetupIntent } from './setup-intent';
17
+ import { Subscription, TSubscription } from './subscription';
18
+ import { SubscriptionItem, TSubscriptionItem } from './subscription-item';
19
+ import { SubscriptionSchedule } from './subscription-schedule';
20
+ import type { LineItem } from './types';
21
+ import { UsageRecord } from './usage-record';
22
+ import { TWebhookAttempt, WebhookAttempt } from './webhook-attempt';
23
+ import { TWebhookEndpoint, WebhookEndpoint } from './webhook-endpoint';
24
+
25
+ const models = {
26
+ CheckoutSession,
27
+ Coupon,
28
+ Customer,
29
+ Discount,
30
+ Event,
31
+ Invoice,
32
+ InvoiceItem,
33
+ PaymentCurrency,
34
+ PaymentIntent,
35
+ PaymentLink,
36
+ PaymentMethod,
37
+ Price,
38
+ Product,
39
+ PromotionCode,
40
+ SetupIntent,
41
+ Subscription,
42
+ SubscriptionItem,
43
+ SubscriptionSchedule,
44
+ UsageRecord,
45
+ WebhookEndpoint,
46
+ WebhookAttempt,
47
+ Job,
48
+ };
49
+
50
+ export function initialize(sequelize: any) {
51
+ Object.values(models).forEach((model) => {
52
+ model.initialize(sequelize);
53
+ });
54
+ Object.values(models).forEach((model) => {
55
+ model.associate(models);
56
+ });
57
+ }
58
+
59
+ export default models;
60
+
61
+ export * from './checkout-session';
62
+ export * from './coupon';
63
+ export * from './customer';
64
+ export * from './discount';
65
+ export * from './event';
66
+ export * from './invoice';
67
+ export * from './invoice-item';
68
+ export * from './job';
69
+ export * from './payment-currency';
70
+ export * from './payment-intent';
71
+ export * from './payment-link';
72
+ export * from './payment-method';
73
+ export * from './price';
74
+ export * from './product';
75
+ export * from './promotion-code';
76
+ export * from './subscription';
77
+ export * from './subscription-item';
78
+ export * from './subscription-schedule';
79
+ export * from './usage-record';
80
+ export * from './webhook-attempt';
81
+ export * from './webhook-endpoint';
82
+ export * from './types';
83
+
84
+ export type TPriceExpanded = TPrice & { product: TProduct; currency: TPaymentCurrency };
85
+
86
+ export type TLineItemExpanded = LineItem & { price: TPriceExpanded };
87
+
88
+ export type TProductExpanded = TProduct & { prices: TPrice[]; default_price: TPrice };
89
+
90
+ export type TPaymentLinkExpanded = TPaymentLink & { line_items: TLineItemExpanded[] };
91
+
92
+ export type TPaymentMethodExpanded = TPaymentMethod & { payment_currencies: TPaymentCurrency[] };
93
+
94
+ export type TCheckoutSessionExpanded = TCheckoutSession & {
95
+ line_items: TLineItemExpanded[];
96
+ payment_link?: TPaymentLink;
97
+ payment_intent?: TPaymentIntent;
98
+ subscription?: TSubscription;
99
+ currency: TPaymentCurrency;
100
+ };
101
+
102
+ export type TPaymentIntentExpanded = TPaymentIntent & {
103
+ customer: TCustomer;
104
+ paymentCurrency: TPaymentCurrency;
105
+ paymentMethod: TPaymentMethod;
106
+ checkoutSession?: TCheckoutSession;
107
+ subscription?: TSubscription;
108
+ invoice?: TInvoice;
109
+ };
110
+
111
+ export type TSubscriptionExpanded = TSubscription & {
112
+ customer: TCustomer;
113
+ paymentCurrency: TPaymentCurrency;
114
+ paymentMethod: TPaymentMethod;
115
+ items: TSubscriptionItemExpanded[];
116
+ };
117
+
118
+ export type TSubscriptionItemExpanded = TSubscriptionItem & {
119
+ price: TPriceExpanded;
120
+ };
121
+
122
+ export type TCustomerExpanded = TCustomer & {
123
+ payments: TPaymentIntent[];
124
+ subscriptions: TSubscription[];
125
+ invoices: TInvoice[];
126
+ };
127
+
128
+ export type TInvoiceExpanded = TInvoice & {
129
+ customer: TCustomer;
130
+ paymentCurrency: TPaymentCurrency;
131
+ paymentMethod: TPaymentMethod;
132
+ paymentIntent: TPaymentIntent;
133
+ subscription?: TSubscription;
134
+ lines: TInvoiceItemExpanded[];
135
+ };
136
+
137
+ export type TInvoiceItemExpanded = TInvoiceItem & {
138
+ price: TPriceExpanded;
139
+ };
140
+
141
+ export type TEventExpanded = TEvent & {
142
+ webhooks: TWebhookEndpointExpanded[];
143
+ };
144
+
145
+ export type TWebhookAttemptExpanded = TWebhookAttempt & {
146
+ event: TEvent;
147
+ endpoint: TWebhookEndpoint;
148
+ };
149
+
150
+ export type TWebhookEndpointExpanded = TWebhookEndpoint & {
151
+ attempts: TWebhookAttemptExpanded[];
152
+ };
153
+
154
+ export type TUsageRecordSummary = {
155
+ livemode: boolean;
156
+ invoice_id: string;
157
+ subscription_item_id: string;
158
+ total_usage: number;
159
+ period: {
160
+ start: number;
161
+ end: number;
162
+ };
163
+ };
164
+
165
+ export type TSetupIntentExpanded = TSetupIntent & {};