payment-kit 1.13.18 → 1.13.19

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 (109) hide show
  1. package/README.md +14 -0
  2. package/api/src/index.ts +17 -6
  3. package/api/src/integrations/stripe/handlers/index.ts +53 -0
  4. package/api/src/integrations/stripe/handlers/invoice.ts +252 -0
  5. package/api/src/integrations/stripe/handlers/payment-intent.ts +172 -0
  6. package/api/src/integrations/stripe/handlers/setup-intent.ts +42 -0
  7. package/api/src/integrations/stripe/handlers/subscription.ts +61 -0
  8. package/api/src/integrations/stripe/resource.ts +317 -0
  9. package/api/src/integrations/stripe/setup.ts +50 -0
  10. package/api/src/jobs/invoice.ts +11 -0
  11. package/api/src/jobs/payment.ts +15 -7
  12. package/api/src/jobs/subscription.ts +18 -2
  13. package/api/src/libs/session.ts +104 -8
  14. package/api/src/libs/util.ts +47 -1
  15. package/api/src/routes/checkout-sessions.ts +134 -27
  16. package/api/src/routes/connect/collect.ts +12 -4
  17. package/api/src/routes/connect/pay.ts +30 -20
  18. package/api/src/routes/connect/setup.ts +12 -4
  19. package/api/src/routes/connect/shared.ts +28 -4
  20. package/api/src/routes/connect/subscribe.ts +12 -5
  21. package/api/src/routes/customers.ts +5 -5
  22. package/api/src/routes/events.ts +9 -6
  23. package/api/src/routes/index.ts +2 -0
  24. package/api/src/routes/integrations/stripe.ts +64 -0
  25. package/api/src/routes/invoices.ts +19 -9
  26. package/api/src/routes/payment-intents.ts +19 -9
  27. package/api/src/routes/payment-links.ts +57 -15
  28. package/api/src/routes/payment-methods.ts +98 -1
  29. package/api/src/routes/prices.ts +71 -14
  30. package/api/src/routes/products.ts +79 -22
  31. package/api/src/routes/settings.ts +10 -11
  32. package/api/src/routes/subscription-items.ts +5 -5
  33. package/api/src/routes/subscriptions.ts +61 -10
  34. package/api/src/routes/usage-records.ts +52 -18
  35. package/api/src/routes/webhook-attempts.ts +5 -5
  36. package/api/src/routes/webhook-endpoints.ts +5 -5
  37. package/api/src/store/migrations/20230905-genesis.ts +2 -2
  38. package/api/src/store/migrations/20230911-seeding.ts +4 -3
  39. package/api/src/store/models/checkout-session.ts +15 -7
  40. package/api/src/store/models/index.ts +31 -7
  41. package/api/src/store/models/invoice.ts +1 -1
  42. package/api/src/store/models/payment-intent.ts +2 -5
  43. package/api/src/store/models/payment-link.ts +1 -1
  44. package/api/src/store/models/payment-method.ts +54 -33
  45. package/api/src/store/models/price.ts +52 -17
  46. package/api/src/store/models/product.ts +0 -3
  47. package/api/src/store/models/subscription.ts +3 -5
  48. package/api/src/store/models/types.ts +56 -2
  49. package/api/third.d.ts +2 -0
  50. package/blocklet.yml +1 -1
  51. package/package.json +13 -6
  52. package/public/currencies/dai.png +0 -0
  53. package/public/currencies/dollar.png +0 -0
  54. package/public/currencies/usdc.png +0 -0
  55. package/public/currencies/usdt.png +0 -0
  56. package/public/methods/arcblock.png +0 -0
  57. package/public/methods/binance.png +0 -0
  58. package/public/methods/coinbase.png +0 -0
  59. package/public/methods/ethereum.jpg +0 -0
  60. package/public/methods/stripe.png +0 -0
  61. package/src/components/checkout/form/address.tsx +86 -10
  62. package/src/components/checkout/form/index.tsx +169 -83
  63. package/src/components/checkout/form/phone.tsx +96 -0
  64. package/src/components/checkout/form/stripe.tsx +195 -0
  65. package/src/components/checkout/pay.tsx +115 -34
  66. package/src/components/checkout/product-item.tsx +4 -3
  67. package/src/components/checkout/summary.tsx +5 -4
  68. package/src/components/drawer-form.tsx +4 -4
  69. package/src/components/input.tsx +22 -4
  70. package/src/components/invoice/table.tsx +8 -3
  71. package/src/components/payment-link/before-pay.tsx +11 -6
  72. package/src/components/payment-link/chrome.tsx +13 -0
  73. package/src/components/payment-link/preview.tsx +31 -0
  74. package/src/components/payment-link/product-select.tsx +8 -3
  75. package/src/components/payment-method/arcblock.tsx +53 -0
  76. package/src/components/payment-method/bitcoin.tsx +53 -0
  77. package/src/components/payment-method/ethereum.tsx +53 -0
  78. package/src/components/payment-method/form.tsx +54 -0
  79. package/src/components/payment-method/stripe.tsx +45 -0
  80. package/src/components/portal/invoice/list.tsx +1 -1
  81. package/src/components/portal/subscription/list.tsx +1 -1
  82. package/src/components/price/currency-select.tsx +53 -0
  83. package/src/components/price/form.tsx +118 -24
  84. package/src/components/product/add-price.tsx +1 -1
  85. package/src/components/product/edit-price.tsx +6 -2
  86. package/src/components/subscription/items/index.tsx +7 -6
  87. package/src/components/subscription/items/usage-records.tsx +98 -0
  88. package/src/components/subscription/list.tsx +3 -2
  89. package/src/components/subscription/status.tsx +68 -0
  90. package/src/contexts/settings.tsx +2 -2
  91. package/src/env.d.ts +2 -0
  92. package/src/libs/util.ts +116 -21
  93. package/src/locales/en.tsx +71 -3
  94. package/src/pages/admin/billing/invoices/detail.tsx +5 -2
  95. package/src/pages/admin/billing/subscriptions/detail.tsx +6 -6
  96. package/src/pages/admin/customers/customers/detail.tsx +13 -1
  97. package/src/pages/admin/payments/intents/detail.tsx +8 -3
  98. package/src/pages/admin/payments/links/create.tsx +23 -3
  99. package/src/pages/admin/payments/links/detail.tsx +13 -26
  100. package/src/pages/admin/products/prices/detail.tsx +55 -11
  101. package/src/pages/admin/products/prices/list.tsx +7 -1
  102. package/src/pages/admin/products/products/create.tsx +1 -1
  103. package/src/pages/admin/products/products/detail.tsx +14 -7
  104. package/src/pages/admin/settings/index.tsx +16 -6
  105. package/src/pages/admin/settings/payment-methods/create.tsx +81 -0
  106. package/src/pages/admin/settings/{payment-methods.tsx → payment-methods/index.tsx} +9 -6
  107. package/src/pages/checkout/pay.tsx +3 -1
  108. package/src/pages/customer/index.tsx +12 -1
  109. package/public/.gitkeep +0 -0
@@ -4,7 +4,7 @@ import type { LiteralUnion } from 'type-fest';
4
4
  export type Pagination<T = any> = T & {
5
5
  // offset based
6
6
  page?: number;
7
- size?: number;
7
+ pageSize?: number;
8
8
  // TODO: cursor based
9
9
  limit?: number;
10
10
  starting_after?: string;
@@ -31,7 +31,13 @@ export type PriceRecurring = {
31
31
  interval_count: number;
32
32
  aggregate_usage?: LiteralUnion<'sum' | 'last_during_period' | 'max' | 'last_ever', string>;
33
33
  usage_type?: LiteralUnion<'licensed' | 'metered', string>;
34
- metered?: boolean;
34
+ };
35
+
36
+ export type PriceCurrency = {
37
+ currency_id: string;
38
+ unit_amount: string;
39
+ tiers: PriceTier[] | null;
40
+ custom_unit_amount: CustomUnitAmount | null;
35
41
  };
36
42
 
37
43
  export type CustomUnitAmount = {
@@ -202,11 +208,59 @@ export type PaymentMethodOptions = {
202
208
  };
203
209
  };
204
210
 
211
+ export type PaymentMethodSettings = {
212
+ stripe?: {
213
+ publishable_key: string;
214
+ secret_key: string;
215
+ webhook_signing_secret: string;
216
+ };
217
+ arcblock?: {
218
+ chain_id: string;
219
+ api_host: string;
220
+ explorer_host: string;
221
+ };
222
+ ethereum?: {
223
+ chain_id: number;
224
+ api_host: string;
225
+ explorer_host: string;
226
+ };
227
+ bitcoin?: {
228
+ chain_id: number;
229
+ api_host: string;
230
+ explorer_host: string;
231
+ };
232
+ };
233
+
205
234
  export type PaymentSettings = {
206
235
  payment_method_options: PaymentMethodOptions;
207
236
  payment_method_types: string[];
208
237
  };
209
238
 
239
+ export type PaymentDetails = {
240
+ arcblock?: {
241
+ tx_hash: string;
242
+ payer: string;
243
+ };
244
+ stripe?: {
245
+ payment_intent_id?: string;
246
+ setup_intent_id?: string;
247
+ subscription_id?: string;
248
+ customer_id?: string;
249
+ };
250
+ ethereum?: {
251
+ tx_hash: string;
252
+ payer: string;
253
+ block_height: number;
254
+ confirmations: number;
255
+ };
256
+ bitcoin?: {
257
+ tx_hash: string;
258
+ payer: string;
259
+ block_height: number;
260
+ confirmations: number;
261
+ };
262
+ };
263
+
210
264
  export type EventType = LiteralUnion<
211
265
  | 'account.application.authorized'
212
266
  | 'account.application.deauthorized'
package/api/third.d.ts CHANGED
@@ -24,5 +24,7 @@ namespace Express {
24
24
  doc?: any;
25
25
  customer?: any;
26
26
  currency: any;
27
+ stripeEvent?: any;
28
+ stripeClient?: any;
27
29
  }
28
30
  }
package/blocklet.yml CHANGED
@@ -14,7 +14,7 @@ repository:
14
14
  type: git
15
15
  url: git+https://github.com/blocklet/payment-kit.git
16
16
  specVersion: 1.2.8
17
- version: 1.13.18
17
+ version: 1.13.19
18
18
  logo: logo.png
19
19
  files:
20
20
  - dist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payment-kit",
3
- "version": "1.13.18",
3
+ "version": "1.13.19",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev",
6
6
  "eject": "vite eject",
@@ -58,8 +58,11 @@
58
58
  "@ocap/mcrypto": "^1.18.92",
59
59
  "@ocap/util": "^1.18.92",
60
60
  "@ocap/wallet": "^1.18.92",
61
+ "@stripe/react-stripe-js": "^2.3.1",
62
+ "@stripe/stripe-js": "^2.1.7",
61
63
  "ahooks": "^3.7.8",
62
64
  "axios": "^0.27.2",
65
+ "body-parser": "^1.20.2",
63
66
  "cookie-parser": "^1.4.6",
64
67
  "cors": "^2.8.5",
65
68
  "dayjs": "^1.11.10",
@@ -69,31 +72,35 @@
69
72
  "express-history-api-fallback": "^2.2.1",
70
73
  "fastq": "^1.15.0",
71
74
  "flat": "^5.0.2",
75
+ "google-libphonenumber": "^3.2.33",
72
76
  "iframe-resizer-react": "^1.1.0",
73
77
  "joi": "^17.11.0",
74
78
  "json-stable-stringify": "^1.0.2",
75
79
  "lodash": "^4.17.21",
76
80
  "morgan": "^1.10.0",
77
- "nanoid": "3.3.6",
78
- "p-wait-for": "^5.0.2",
81
+ "nanoid": "3",
82
+ "p-wait-for": "3",
79
83
  "pretty-ms-i18n": "^1.0.3",
80
84
  "react": "^18.2.0",
81
85
  "react-dom": "^18.2.0",
82
86
  "react-error-boundary": "^4.0.11",
83
87
  "react-hook-form": "^7.47.0",
88
+ "react-international-phone": "^3.1.2",
84
89
  "react-router-dom": "^6.16.0",
85
90
  "rimraf": "^3.0.2",
86
91
  "sequelize": "^6.33.0",
87
92
  "sqlite3": "^5.1.6",
93
+ "stripe": "^13.10.0",
88
94
  "typewriter-effect": "^2.21.0",
89
95
  "ufo": "^1.3.1",
90
96
  "umzug": "^3.3.1",
91
- "use-bus": "^2.5.2"
97
+ "use-bus": "^2.5.2",
98
+ "validator": "^13.11.0"
92
99
  },
93
100
  "devDependencies": {
94
101
  "@arcblock/eslint-config": "^0.2.4",
95
102
  "@arcblock/eslint-config-ts": "^0.2.4",
96
- "@did-pay/types": "1.13.18",
103
+ "@did-pay/types": "1.13.19",
97
104
  "@types/cookie-parser": "^1.4.4",
98
105
  "@types/cors": "^2.8.14",
99
106
  "@types/dotenv-flow": "^3.3.1",
@@ -130,5 +137,5 @@
130
137
  "parser": "typescript"
131
138
  }
132
139
  },
133
- "gitHead": "0ead128fae75087e5d817d6315b94c3378d7e5e9"
140
+ "gitHead": "ffc58582731d2f1c1057346cee8127b26266ccd8"
134
141
  }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,5 +1,7 @@
1
1
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
2
  import { Fade, Stack, Typography } from '@mui/material';
3
+ import { Controller, useFormContext } from 'react-hook-form';
4
+ import { CountrySelector } from 'react-international-phone';
3
5
 
4
6
  import FormInput from '../../input';
5
7
 
@@ -9,24 +11,98 @@ type Props = {
9
11
 
10
12
  export default function AddressForm({ mode }: Props) {
11
13
  const { t } = useLocaleContext();
14
+ const { control, setValue } = useFormContext();
15
+
16
+ if (mode === 'required') {
17
+ return (
18
+ <Fade in>
19
+ <Stack className="cko-payment-address cko-payment-form">
20
+ <Typography sx={{ mb: 1, color: 'text.primary', fontWeight: 600 }}>
21
+ {t(`checkout.billing.${mode}`)}
22
+ </Typography>
23
+ <Stack direction="column" className="cko-payment-form" spacing={0}>
24
+ <Stack direction="row" spacing={0}>
25
+ <Controller
26
+ name="billing_address.country"
27
+ control={control}
28
+ render={({ field }) => (
29
+ <CountrySelector
30
+ selectedCountry={field.value}
31
+ onSelect={({ iso2 }) => setValue(field.name, iso2)}
32
+ buttonStyle={{
33
+ width: '64px',
34
+ height: '40px',
35
+ border: '1px solid #ccc',
36
+ marginLeft: -1,
37
+ marginTop: -1,
38
+ }}
39
+ />
40
+ )}
41
+ />
42
+ <FormInput
43
+ name="billing_address.postal_code"
44
+ rules={{ required: t('checkout.required') }}
45
+ errorPosition="right"
46
+ variant="outlined"
47
+ placeholder={t('checkout.billing.postal_code')}
48
+ />
49
+ </Stack>
50
+ <FormInput
51
+ name="billing_address.state"
52
+ rules={{ required: t('checkout.required') }}
53
+ errorPosition="right"
54
+ variant="outlined"
55
+ placeholder={t('checkout.billing.state')}
56
+ />
57
+ <FormInput
58
+ name="billing_address.line1"
59
+ rules={{ required: t('checkout.required') }}
60
+ errorPosition="right"
61
+ variant="outlined"
62
+ placeholder={t('checkout.billing.line1')}
63
+ />
64
+ <Stack direction="row" spacing={0}>
65
+ <FormInput
66
+ name="billing_address.city"
67
+ rules={{ required: t('checkout.required') }}
68
+ errorPosition="right"
69
+ variant="outlined"
70
+ placeholder={t('checkout.billing.city')}
71
+ />
72
+ </Stack>
73
+ </Stack>
74
+ </Stack>
75
+ </Fade>
76
+ );
77
+ }
78
+
12
79
  return (
13
80
  <Fade in>
14
81
  <Stack className="cko-payment-address cko-payment-form">
15
82
  <Typography sx={{ mb: 1, color: 'text.primary', fontWeight: 600 }}>{t(`checkout.billing.${mode}`)}</Typography>
16
83
  <Stack direction="column" className="cko-payment-form" spacing={0}>
17
- <FormInput name="billing_address.country" variant="outlined" placeholder={t('checkout.billing.country')} />
18
- {mode === 'required' && (
19
- <FormInput name="billing_address.state" variant="outlined" placeholder={t('checkout.billing.state')} />
20
- )}
21
- {mode === 'required' && (
22
- <FormInput name="billing_address.line1" variant="outlined" placeholder={t('checkout.billing.line1')} />
23
- )}
24
84
  <Stack direction="row" spacing={0}>
25
- {mode === 'required' && (
26
- <FormInput name="billing_address.city" variant="outlined" placeholder={t('checkout.billing.city')} />
27
- )}
85
+ <Controller
86
+ name="billing_address.country"
87
+ control={control}
88
+ render={({ field }) => (
89
+ <CountrySelector
90
+ selectedCountry={field.value}
91
+ onSelect={({ iso2 }) => setValue(field.name, iso2)}
92
+ buttonStyle={{
93
+ width: '64px',
94
+ height: '40px',
95
+ border: '1px solid #ccc',
96
+ marginLeft: -1,
97
+ marginTop: -1,
98
+ }}
99
+ />
100
+ )}
101
+ />
28
102
  <FormInput
29
103
  name="billing_address.postal_code"
104
+ rules={{ required: t('checkout.required') }}
105
+ errorPosition="right"
30
106
  variant="outlined"
31
107
  placeholder={t('checkout.billing.postal_code')}
32
108
  />