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,75 @@
1
+ /* eslint-disable @typescript-eslint/lines-between-class-members */
2
+ import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model } from 'sequelize';
3
+
4
+ // eslint-disable-next-line prettier/prettier
5
+ export class Job extends Model<InferAttributes<Job>, InferCreationAttributes<Job>> {
6
+ declare id: CreationOptional<string>;
7
+
8
+ declare queue: string;
9
+ declare job: any;
10
+ declare retry_count: number;
11
+ declare delay?: number;
12
+ declare will_run_at?: number;
13
+ declare cancelled?: boolean;
14
+
15
+ declare created_at: CreationOptional<Date>;
16
+ declare updated_at: CreationOptional<Date>;
17
+
18
+ public static readonly GENESIS_ATTRIBUTES = {
19
+ id: {
20
+ type: DataTypes.STRING(30),
21
+ primaryKey: true,
22
+ allowNull: false,
23
+ },
24
+ queue: {
25
+ type: DataTypes.STRING(32),
26
+ allowNull: false,
27
+ },
28
+ job: {
29
+ type: DataTypes.JSON,
30
+ allowNull: false,
31
+ },
32
+ retry_count: {
33
+ type: DataTypes.INTEGER,
34
+ defaultValue: 0,
35
+ },
36
+ delay: {
37
+ type: DataTypes.INTEGER,
38
+ defaultValue: -1,
39
+ },
40
+ will_run_at: {
41
+ type: DataTypes.INTEGER,
42
+ defaultValue: -1,
43
+ },
44
+ cancelled: {
45
+ type: DataTypes.BOOLEAN,
46
+ defaultValue: false,
47
+ },
48
+ created_at: {
49
+ type: DataTypes.DATE,
50
+ defaultValue: DataTypes.NOW,
51
+ allowNull: false,
52
+ },
53
+ updated_at: {
54
+ type: DataTypes.DATE,
55
+ defaultValue: DataTypes.NOW,
56
+ allowNull: false,
57
+ },
58
+ };
59
+
60
+ public static initialize(sequelize: any) {
61
+ this.init(Job.GENESIS_ATTRIBUTES, {
62
+ sequelize,
63
+ modelName: 'Job',
64
+ tableName: 'jobs',
65
+ createdAt: 'created_at',
66
+ updatedAt: 'updated_at',
67
+ });
68
+ }
69
+
70
+ public static associate() {
71
+ // Do nothing
72
+ }
73
+ }
74
+
75
+ export type TJob = InferAttributes<Job>;
@@ -0,0 +1,139 @@
1
+ /* eslint-disable @typescript-eslint/lines-between-class-members */
2
+ import {
3
+ CreationOptional,
4
+ DataTypes,
5
+ FindOptions,
6
+ InferAttributes,
7
+ InferCreationAttributes,
8
+ Model,
9
+ Op,
10
+ } from 'sequelize';
11
+
12
+ import { createIdGenerator } from '../../libs/util';
13
+
14
+ const nextId = createIdGenerator('pc', 12);
15
+
16
+ // eslint-disable-next-line prettier/prettier
17
+ export class PaymentCurrency extends Model<InferAttributes<PaymentCurrency>, InferCreationAttributes<PaymentCurrency>> {
18
+ // Unique identifier for the object.
19
+ declare id: CreationOptional<string>;
20
+ declare payment_method_id: string;
21
+
22
+ declare active: boolean;
23
+ declare livemode: boolean;
24
+ declare locked: boolean;
25
+ declare is_base_currency: boolean;
26
+
27
+ declare name: string;
28
+ declare description: string;
29
+ declare logo: string;
30
+ declare symbol: string;
31
+ declare decimal: number;
32
+
33
+ declare minimum_payment_amount: string;
34
+ declare maximum_payment_amount: string;
35
+
36
+ // Contract address to interact with
37
+ declare contract?: string;
38
+ declare metadata: Record<string, any>;
39
+
40
+ declare created_at: CreationOptional<Date>;
41
+ declare updated_at: CreationOptional<Date>;
42
+
43
+ public static readonly GENESIS_ATTRIBUTES = {
44
+ id: {
45
+ type: DataTypes.STRING(15),
46
+ primaryKey: true,
47
+ allowNull: false,
48
+ defaultValue: nextId,
49
+ },
50
+ active: {
51
+ type: DataTypes.BOOLEAN,
52
+ allowNull: false,
53
+ },
54
+ livemode: {
55
+ type: DataTypes.BOOLEAN,
56
+ allowNull: false,
57
+ },
58
+ locked: {
59
+ type: DataTypes.BOOLEAN,
60
+ defaultValue: false,
61
+ },
62
+ is_base_currency: {
63
+ type: DataTypes.BOOLEAN,
64
+ defaultValue: false,
65
+ },
66
+ payment_method_id: {
67
+ type: DataTypes.STRING(30),
68
+ allowNull: false,
69
+ },
70
+ name: {
71
+ type: DataTypes.STRING(64),
72
+ allowNull: false,
73
+ },
74
+ description: {
75
+ type: DataTypes.STRING(512),
76
+ allowNull: true,
77
+ },
78
+ logo: {
79
+ type: DataTypes.STRING(512),
80
+ allowNull: false,
81
+ },
82
+ symbol: {
83
+ type: DataTypes.STRING(16),
84
+ allowNull: false,
85
+ unique: true,
86
+ },
87
+ decimal: {
88
+ type: DataTypes.NUMBER,
89
+ defaultValue: 2,
90
+ },
91
+ minimum_payment_amount: {
92
+ type: DataTypes.STRING(32),
93
+ defaultValue: '0',
94
+ },
95
+ maximum_payment_amount: {
96
+ type: DataTypes.STRING(32),
97
+ defaultValue: '0',
98
+ },
99
+ contract: {
100
+ type: DataTypes.STRING(256),
101
+ allowNull: true,
102
+ },
103
+ metadata: {
104
+ type: DataTypes.JSON,
105
+ allowNull: true,
106
+ },
107
+ created_at: {
108
+ type: DataTypes.DATE,
109
+ defaultValue: DataTypes.NOW,
110
+ allowNull: false,
111
+ },
112
+ updated_at: {
113
+ type: DataTypes.DATE,
114
+ defaultValue: DataTypes.NOW,
115
+ allowNull: false,
116
+ },
117
+ };
118
+
119
+ public static initialize(sequelize: any) {
120
+ this.init(PaymentCurrency.GENESIS_ATTRIBUTES, {
121
+ sequelize,
122
+ modelName: 'PaymentCurrency',
123
+ tableName: 'payment_currencies',
124
+ createdAt: 'created_at',
125
+ updatedAt: 'updated_at',
126
+ });
127
+ }
128
+
129
+ public static associate() {}
130
+
131
+ public static findByPkOrSymbol(id: string, options: FindOptions<PaymentCurrency> = {}) {
132
+ return this.findOne({
133
+ where: { [Op.or]: [{ id }, { symbol: id }] },
134
+ ...options,
135
+ });
136
+ }
137
+ }
138
+
139
+ export type TPaymentCurrency = InferAttributes<PaymentCurrency>;
@@ -0,0 +1,282 @@
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 } from './types';
9
+
10
+ const nextId = createIdGenerator('pi', 24);
11
+
12
+ // @link https://stripe.com/docs/api/payment_intents
13
+ // eslint-disable-next-line prettier/prettier
14
+ export class PaymentIntent extends Model<InferAttributes<PaymentIntent>, InferCreationAttributes<PaymentIntent>> {
15
+ // Unique identifier for the object.
16
+ declare id: CreationOptional<string>;
17
+
18
+ declare livemode: boolean;
19
+ declare description: string;
20
+
21
+ declare amount: string;
22
+ declare amount_received?: string;
23
+ declare amount_capturable?: string;
24
+ declare amount_details?: {
25
+ tip: string;
26
+ };
27
+
28
+ // Payment currency id
29
+ declare currency_id: string;
30
+ // ID of the Customer this PaymentIntent belongs to, if one exists
31
+ declare customer_id?: string;
32
+ declare payment_method_id: string;
33
+ declare invoice_id?: string;
34
+ // The latest charge created by this payment intent.
35
+ declare last_charge?: string;
36
+
37
+ // The payment error encountered in the previous PaymentIntent confirmation
38
+ declare last_payment_error?: PaymentError;
39
+
40
+ declare metadata?: Record<string, any>;
41
+
42
+ declare receipt_email?: string;
43
+
44
+ declare statement_descriptor: string;
45
+ declare statement_descriptor_suffix?: string;
46
+
47
+ declare status: LiteralUnion<
48
+ | 'requires_payment_method'
49
+ | 'requires_confirmation'
50
+ | 'requires_action'
51
+ | 'processing'
52
+ | 'requires_capture'
53
+ | 'canceled'
54
+ | 'succeeded',
55
+ string
56
+ >;
57
+
58
+ declare canceled_at?: number;
59
+ declare cancellation_reason?: LiteralUnion<
60
+ | 'abandoned'
61
+ | 'duplicate'
62
+ | 'requested_by_customer'
63
+ | 'fraudulent'
64
+ | 'failed_invoice'
65
+ | 'void_invoice'
66
+ | 'automatic',
67
+ string
68
+ >;
69
+
70
+ declare capture_method: LiteralUnion<'automatic' | 'manual', string>;
71
+ declare confirmation_method: LiteralUnion<'automatic' | 'manual', string>;
72
+
73
+ declare payment_method_types: string[];
74
+
75
+ declare review?: string;
76
+
77
+ // 3rd party payment tx hash
78
+ declare payment_details?: {
79
+ tx_hash?: string;
80
+ payer?: string;
81
+ };
82
+
83
+ declare setup_future_usage: LiteralUnion<'off_session' | 'on_session', string>;
84
+
85
+ // TODO: following fields not supported yet
86
+ // automatic_payment_methods
87
+ // client_secret
88
+ // next_action
89
+ // shipping
90
+ // application
91
+ // application_fee_amount
92
+ // on_behalf_of
93
+ // payment_method_options
94
+ // processing
95
+ // transfer_data
96
+ // transfer_group
97
+
98
+ declare created_at: CreationOptional<Date>;
99
+ declare updated_at: CreationOptional<Date>;
100
+
101
+ public static readonly GENESIS_ATTRIBUTES = {
102
+ id: {
103
+ type: DataTypes.STRING(30),
104
+ primaryKey: true,
105
+ allowNull: false,
106
+ defaultValue: nextId,
107
+ },
108
+ livemode: {
109
+ type: DataTypes.BOOLEAN,
110
+ allowNull: false,
111
+ },
112
+ amount: {
113
+ type: DataTypes.STRING(32),
114
+ allowNull: false,
115
+ },
116
+ amount_received: {
117
+ type: DataTypes.STRING(32),
118
+ default: '0',
119
+ },
120
+ amount_capturable: {
121
+ type: DataTypes.STRING(32),
122
+ default: '0',
123
+ },
124
+ amount_details: {
125
+ type: DataTypes.JSON,
126
+ allowNull: true,
127
+ },
128
+ currency_id: {
129
+ type: DataTypes.STRING(16),
130
+ allowNull: false,
131
+ },
132
+ customer_id: {
133
+ type: DataTypes.STRING(30),
134
+ allowNull: true,
135
+ },
136
+ description: {
137
+ type: DataTypes.STRING(512),
138
+ allowNull: true,
139
+ },
140
+ last_payment_error: {
141
+ type: DataTypes.JSON,
142
+ allowNull: true,
143
+ },
144
+ last_charge: {
145
+ type: DataTypes.STRING(30),
146
+ allowNull: true,
147
+ },
148
+ metadata: {
149
+ type: DataTypes.JSON,
150
+ allowNull: true,
151
+ },
152
+ invoice_id: {
153
+ type: DataTypes.STRING(30),
154
+ allowNull: true,
155
+ },
156
+ payment_method_id: {
157
+ type: DataTypes.STRING(30),
158
+ allowNull: false,
159
+ },
160
+ receipt_email: {
161
+ type: DataTypes.STRING(255),
162
+ allowNull: true,
163
+ },
164
+ statement_descriptor: {
165
+ type: DataTypes.STRING(32),
166
+ allowNull: true,
167
+ },
168
+ statement_descriptor_suffix: {
169
+ type: DataTypes.STRING(32),
170
+ allowNull: true,
171
+ },
172
+ status: {
173
+ type: DataTypes.ENUM(
174
+ 'requires_payment_method',
175
+ 'requires_confirmation',
176
+ 'requires_action',
177
+ 'processing',
178
+ 'requires_capture',
179
+ 'canceled',
180
+ 'succeeded'
181
+ ),
182
+ allowNull: false,
183
+ },
184
+ canceled_at: {
185
+ type: DataTypes.DATE,
186
+ allowNull: true,
187
+ },
188
+ cancellation_reason: {
189
+ type: DataTypes.ENUM(
190
+ 'abandoned',
191
+ 'duplicate',
192
+ 'requested_by_customer',
193
+ 'fraudulent',
194
+ 'failed_invoice',
195
+ 'void_invoice',
196
+ 'automatic'
197
+ ),
198
+ allowNull: true,
199
+ },
200
+ capture_method: {
201
+ type: DataTypes.ENUM('automatic', 'manual'),
202
+ },
203
+ confirmation_method: {
204
+ type: DataTypes.ENUM('automatic', 'manual'),
205
+ },
206
+ payment_method_types: {
207
+ type: DataTypes.JSON,
208
+ defaultValue: [],
209
+ },
210
+ review: {
211
+ type: DataTypes.STRING(30),
212
+ allowNull: true,
213
+ },
214
+ payment_details: {
215
+ type: DataTypes.JSON,
216
+ allowNull: true,
217
+ },
218
+ setup_future_usage: {
219
+ type: DataTypes.ENUM('on_session', 'off_session'),
220
+ allowNull: false,
221
+ },
222
+ created_at: {
223
+ type: DataTypes.DATE,
224
+ defaultValue: DataTypes.NOW,
225
+ allowNull: false,
226
+ },
227
+ updated_at: {
228
+ type: DataTypes.DATE,
229
+ defaultValue: DataTypes.NOW,
230
+ allowNull: false,
231
+ },
232
+ };
233
+
234
+ public static initialize(sequelize: any) {
235
+ this.init(PaymentIntent.GENESIS_ATTRIBUTES, {
236
+ sequelize,
237
+ modelName: 'PaymentIntent',
238
+ tableName: 'payment_intents',
239
+ createdAt: 'created_at',
240
+ updatedAt: 'updated_at',
241
+ hooks: {
242
+ afterCreate: (model: PaymentIntent, options) =>
243
+ createEvent('PaymentIntent', 'payment_intent.created', model, options).catch(console.error),
244
+ afterUpdate: (model: PaymentIntent, options) =>
245
+ createStatusEvent(
246
+ 'PaymentIntent',
247
+ 'payment_intent',
248
+ {
249
+ requires_action: 'requires_action',
250
+ processing: 'processing',
251
+ canceled: 'canceled',
252
+ succeeded: 'succeeded',
253
+ },
254
+ model,
255
+ options
256
+ ),
257
+ afterDestroy: (model: PaymentIntent, options) =>
258
+ createEvent('PaymentIntent', 'payment_intent.deleted', model, options).catch(console.error),
259
+ },
260
+ });
261
+ }
262
+
263
+ public static associate(models: any) {
264
+ this.hasOne(models.PaymentCurrency, {
265
+ sourceKey: 'currency_id',
266
+ foreignKey: 'id',
267
+ as: 'paymentCurrency',
268
+ });
269
+ this.hasOne(models.PaymentMethod, {
270
+ sourceKey: 'payment_method_id',
271
+ foreignKey: 'id',
272
+ as: 'paymentMethod',
273
+ });
274
+ this.hasOne(models.Customer, {
275
+ sourceKey: 'customer_id',
276
+ foreignKey: 'id',
277
+ as: 'customer',
278
+ });
279
+ }
280
+ }
281
+
282
+ export type TPaymentIntent = InferAttributes<PaymentIntent>;
@@ -0,0 +1,219 @@
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 { createEvent } from '../../libs/audit';
6
+ import { createIdGenerator } from '../../libs/util';
7
+ import type { AfterPayment, CustomField, LineItem } from './types';
8
+
9
+ const nextId = createIdGenerator('plink', 24);
10
+
11
+ // @link https://stripe.com/docs/api/payment_links/payment_links
12
+ export class PaymentLink extends Model<InferAttributes<PaymentLink>, InferCreationAttributes<PaymentLink>> {
13
+ // Unique identifier for the object.
14
+ declare id: CreationOptional<string>;
15
+
16
+ // Whether the PaymentLink is currently available for purchase.
17
+ declare active: boolean;
18
+ declare livemode: boolean;
19
+
20
+ declare name: string;
21
+
22
+ // The line items representing what is being sold. Each line item represents an item being sold. Up to 20 line items are supported.
23
+ declare line_items: LineItem[];
24
+
25
+ // Payment currency id
26
+ declare currency_id: string;
27
+
28
+ // The specified behavior after the purchase is complete.
29
+ declare after_completion?: AfterPayment;
30
+
31
+ // Enables user redeemable promotion codes.
32
+ declare allow_promotion_codes: boolean;
33
+
34
+ declare consent_collection?: {
35
+ promotions?: LiteralUnion<'auto' | 'none', string>;
36
+ terms_of_service?: LiteralUnion<'required' | 'none', string>;
37
+ };
38
+
39
+ // Collect additional information from your customer using custom fields. Up to 2 fields are supported.
40
+ declare custom_fields: CustomField[];
41
+ declare custom_text?: {
42
+ shipping_address?: string;
43
+ submit?: string;
44
+ };
45
+
46
+ declare customer_creation: LiteralUnion<'if_required' | 'always', string>;
47
+
48
+ // Generate a post-purchase Invoice for one-time payments.
49
+ declare invoice_creation?: {
50
+ enabled: boolean;
51
+ invoice_data?: any;
52
+ };
53
+
54
+ // The list of payment method types that customers can use
55
+ declare payment_method_types?: string[];
56
+
57
+ // Controls phone number collection settings during checkout.
58
+ declare phone_number_collection?: {
59
+ enabled: boolean;
60
+ };
61
+
62
+ // Configuration for collecting the customer’s billing address.
63
+ declare billing_address_collection?: LiteralUnion<'auto' | 'required', string>;
64
+
65
+ // Describes the type of transaction being performed in order to customize relevant text
66
+ declare submit_type: LiteralUnion<'auto' | 'book' | 'donate' | 'pay', string>;
67
+
68
+ // When creating a subscription, the specified configuration data will be used.
69
+ declare subscription_data?: {
70
+ description: string;
71
+ trial_period_days: number;
72
+ };
73
+
74
+ declare metadata?: Record<string, any>;
75
+
76
+ // TODO: following fields not supported
77
+ // application_fee_amount
78
+ // application_fee_percent
79
+ // transfer_data
80
+ // automatic_tax
81
+ // tax_id_collection
82
+ // consent_collection
83
+ // on_behalf_of
84
+ // payment_intent_data
85
+ // payment_method_collection
86
+ // shipping_address_collection
87
+ // shipping_options
88
+
89
+ declare created_at: CreationOptional<Date>;
90
+
91
+ declare created_via: LiteralUnion<'api' | 'dashboard' | 'portal', string>;
92
+
93
+ declare updated_at: CreationOptional<Date>;
94
+
95
+ public static readonly GENESIS_ATTRIBUTES = {
96
+ id: {
97
+ type: DataTypes.STRING(30),
98
+ primaryKey: true,
99
+ allowNull: false,
100
+ defaultValue: nextId,
101
+ },
102
+ active: {
103
+ type: DataTypes.BOOLEAN,
104
+ allowNull: false,
105
+ },
106
+ livemode: {
107
+ type: DataTypes.BOOLEAN,
108
+ allowNull: false,
109
+ },
110
+ line_items: {
111
+ type: DataTypes.JSON,
112
+ defaultValue: [],
113
+ },
114
+ name: {
115
+ type: DataTypes.STRING(255),
116
+ allowNull: true,
117
+ },
118
+ currency_id: {
119
+ type: DataTypes.STRING(16),
120
+ allowNull: true,
121
+ },
122
+ after_completion: {
123
+ type: DataTypes.JSON,
124
+ defaultValue: {
125
+ type: 'hosted_confirmation',
126
+ },
127
+ },
128
+ allow_promotion_codes: {
129
+ type: DataTypes.BOOLEAN,
130
+ defaultValue: false,
131
+ },
132
+ consent_collection: {
133
+ type: DataTypes.JSON,
134
+ allowNull: true,
135
+ },
136
+ custom_fields: {
137
+ type: DataTypes.JSON,
138
+ defaultValue: [],
139
+ },
140
+ custom_text: {
141
+ type: DataTypes.JSON,
142
+ allowNull: true,
143
+ },
144
+ customer_creation: {
145
+ type: DataTypes.ENUM('if_required', 'always'),
146
+ allowNull: false,
147
+ },
148
+ invoice_creation: {
149
+ type: DataTypes.JSON,
150
+ allowNull: true,
151
+ },
152
+ payment_method_types: {
153
+ type: DataTypes.JSON,
154
+ defaultValue: [],
155
+ },
156
+ phone_number_collection: {
157
+ type: DataTypes.JSON,
158
+ allowNull: true,
159
+ },
160
+ billing_address_collection: {
161
+ type: DataTypes.ENUM('auto', 'required'),
162
+ defaultValue: 'auto',
163
+ allowNull: false,
164
+ },
165
+ submit_type: {
166
+ type: DataTypes.ENUM('auto', 'book', 'donate', 'pay'),
167
+ allowNull: false,
168
+ },
169
+ subscription_data: {
170
+ type: DataTypes.JSON,
171
+ allowNull: true,
172
+ },
173
+ metadata: {
174
+ type: DataTypes.JSON,
175
+ allowNull: true,
176
+ },
177
+ created_at: {
178
+ type: DataTypes.DATE,
179
+ defaultValue: DataTypes.NOW,
180
+ allowNull: false,
181
+ },
182
+ created_via: {
183
+ type: DataTypes.ENUM('api', 'dashboard', 'portal'),
184
+ },
185
+ updated_at: {
186
+ type: DataTypes.DATE,
187
+ defaultValue: DataTypes.NOW,
188
+ allowNull: false,
189
+ },
190
+ };
191
+
192
+ public static initialize(sequelize: any) {
193
+ this.init(PaymentLink.GENESIS_ATTRIBUTES, {
194
+ sequelize,
195
+ modelName: 'PaymentLink',
196
+ tableName: 'payment_links',
197
+ createdAt: 'created_at',
198
+ updatedAt: 'updated_at',
199
+ hooks: {
200
+ afterCreate: (model: PaymentLink, options) =>
201
+ createEvent('PaymentLink', 'payment_link.created', model, options).catch(console.error),
202
+ afterUpdate: (model: PaymentLink, options) =>
203
+ createEvent('PaymentLink', 'payment_link.updated', model, options).catch(console.error),
204
+ afterDestroy: (model: PaymentLink, options) =>
205
+ createEvent('PaymentLink', 'payment_link.deleted', model, options).catch(console.error),
206
+ },
207
+ });
208
+ }
209
+
210
+ public static associate(models: any) {
211
+ this.hasOne(models.PaymentCurrency, {
212
+ sourceKey: 'currency_id',
213
+ foreignKey: 'id',
214
+ as: 'currency',
215
+ });
216
+ }
217
+ }
218
+
219
+ export type TPaymentLink = InferAttributes<PaymentLink>;