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,10 @@
1
+ import { createAuthServiceSessionContext } from '@arcblock/did-connect/lib/Session';
2
+ import { useContext } from 'react';
3
+
4
+ const { SessionProvider, SessionContext, SessionConsumer, withSession } = createAuthServiceSessionContext();
5
+
6
+ export function useSessionContext(): any {
7
+ return useContext(SessionContext);
8
+ }
9
+
10
+ export { SessionProvider, SessionContext, SessionConsumer, withSession };
@@ -0,0 +1,54 @@
1
+ import type { TPaymentCurrency, TPaymentMethod } from '@did-pay/types';
2
+ import { Alert, CircularProgress } from '@mui/material';
3
+ import { useLocalStorageState, useRequest } from 'ahooks';
4
+ import type { Axios } from 'axios';
5
+ import { createContext, useContext } from 'react';
6
+
7
+ import api from '../libs/api';
8
+
9
+ export interface Settings {
10
+ paymentMethods: TPaymentMethod[];
11
+ baseCurrency: TPaymentCurrency;
12
+ }
13
+
14
+ export type SettingsContextType = {
15
+ livemode: boolean;
16
+ settings: Settings;
17
+ refresh: () => void;
18
+ setLivemode: (livemode: boolean) => void;
19
+ api: Axios;
20
+ };
21
+
22
+ // @ts-ignore
23
+ const SettingsContext = createContext<SettingsContextType>({ api });
24
+ const { Provider, Consumer } = SettingsContext;
25
+
26
+ const getSettings = async () => {
27
+ const { data } = await api.get('/api/settings');
28
+ return data;
29
+ };
30
+
31
+ // eslint-disable-next-line react/prop-types
32
+ function SettingsProvider({ children }: { children: any }): JSX.Element {
33
+ const { data, error, run, loading } = useRequest(getSettings);
34
+ const [livemode, setLivemode] = useLocalStorageState('livemode', { defaultValue: true });
35
+
36
+ if (error) {
37
+ return <Alert severity="error">{error.message}</Alert>;
38
+ }
39
+
40
+ if (loading) {
41
+ return <CircularProgress />;
42
+ }
43
+
44
+ return (
45
+ <Provider value={{ livemode: !!livemode, settings: data, refresh: run, setLivemode, api }}>{children}</Provider>
46
+ );
47
+ }
48
+
49
+ function useSettingsContext() {
50
+ const context = useContext(SettingsContext);
51
+ return context;
52
+ }
53
+
54
+ export { SettingsContext, SettingsProvider, Consumer as SettingsConsumer, useSettingsContext };
package/src/env.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ declare var blocklet: {
2
+ appName: string;
3
+ appLogo: string;
4
+ appUrl: string;
5
+ prefix: string;
6
+ languages: { code: string; name: string }[];
7
+ };
8
+
9
+ declare module '*.svg';
10
+
11
+ declare module 'flat';
12
+
13
+ declare module '@arcblock/*';
14
+
15
+ declare module '@blocklet/*';
16
+
17
+ declare module 'pretty-ms-i18n';
package/src/global.css ADDED
@@ -0,0 +1,97 @@
1
+ html,
2
+ body {
3
+ padding: 0;
4
+ margin: 0;
5
+ font-size: 14px;
6
+ }
7
+
8
+ a {
9
+ text-decoration: none;
10
+ color: rgba(0, 0, 0, 0.87);
11
+ }
12
+ a:hover {
13
+ color: rgba(0, 0, 0, 0.87);
14
+ text-decoration: underline;
15
+ }
16
+ a:visited {
17
+ color: rgba(0, 0, 0, 0.87);
18
+ }
19
+
20
+ .MuiButton-sizeSmall {
21
+ font-weight: 500;
22
+ font-size: 1rem;
23
+ line-height: 1.5;
24
+ border-color: #ccc;
25
+ }
26
+
27
+ .MuiTab-root {
28
+ padding: 0;
29
+ margin-right: 24px;
30
+ min-height: 32px;
31
+ min-width: auto;
32
+ }
33
+
34
+ .MuiTabs-root {
35
+ min-height: 32px;
36
+ margin-bottom: 8px;
37
+ }
38
+
39
+ .MuiTabs-scroller {
40
+ border-bottom: 1px solid #eee;
41
+ }
42
+
43
+ .MuiCheckbox-root {
44
+ padding: 0;
45
+ padding-right: 4px;
46
+ }
47
+
48
+ .MuiFormLabel-root {
49
+ color: rgba(0, 0, 0, 0.8);
50
+ display: block;
51
+ margin-bottom: 8px;
52
+ font-weight: 500;
53
+ }
54
+
55
+ .MuiToggleButton-root {
56
+ padding: 4px 16px;
57
+ }
58
+
59
+ .MuiDialogContent-root {
60
+ padding: 0 24px 16px;
61
+ }
62
+
63
+ .MuiTableCell-root {
64
+ font-size: 1rem !important;
65
+ padding-right: 24px;
66
+ }
67
+
68
+ th.MuiTableCell-head {
69
+ padding: 8px 0;
70
+ }
71
+
72
+ .MuiRadio-root {
73
+ padding: 4px;
74
+ }
75
+
76
+ .MuiDialogActions-root {
77
+ padding-top: 16px;
78
+ }
79
+
80
+ .MuiDialogContent-root {
81
+ padding-top: 0px !important;
82
+ }
83
+
84
+ .MuiFormHelperText-root {
85
+ margin-left: 0;
86
+ }
87
+
88
+ .codeblock__inner {
89
+ display: block;
90
+ width: 100%;
91
+ max-height: 100% !important;
92
+ overflow: auto !important;
93
+ }
94
+
95
+ .MuiTableRow-hover {
96
+ cursor: pointer;
97
+ }
@@ -0,0 +1,15 @@
1
+ import { useTheme } from '@mui/material/styles';
2
+ import useMediaQuery from '@mui/material/useMediaQuery';
3
+
4
+ const MOBILE_POINT = 'md';
5
+
6
+ function useMobile() {
7
+ const theme = useTheme();
8
+
9
+ return {
10
+ isMobile: useMediaQuery(theme.breakpoints.down(MOBILE_POINT)),
11
+ mobileSize: `${theme.breakpoints.values[MOBILE_POINT]}px`,
12
+ };
13
+ }
14
+
15
+ export default useMobile;
package/src/index.tsx ADDED
@@ -0,0 +1,6 @@
1
+ import ReactDOM from 'react-dom/client';
2
+
3
+ import App from './app';
4
+
5
+ const root = ReactDOM.createRoot(document.getElementById('app')!);
6
+ root.render(<App />);
@@ -0,0 +1,19 @@
1
+ import { getLocale } from '@arcblock/ux/lib/Locale/context';
2
+ import axios from 'axios';
3
+
4
+ axios.interceptors.request.use(
5
+ (config) => {
6
+ const prefix = window.blocklet ? window.blocklet.prefix : '/';
7
+ config.baseURL = prefix || '';
8
+ config.timeout = 200000;
9
+
10
+ const livemode = localStorage.getItem('livemode');
11
+ const locale = getLocale(window.blocklet.languages);
12
+ config.params = { ...(config.params || {}), livemode, locale };
13
+
14
+ return config;
15
+ },
16
+ (error) => Promise.reject(error)
17
+ );
18
+
19
+ export default axios;
@@ -0,0 +1,17 @@
1
+ import dayjs from 'dayjs';
2
+ import duration from 'dayjs/plugin/duration';
3
+ import localizedFormat from 'dayjs/plugin/localizedFormat';
4
+ import relativeTime from 'dayjs/plugin/relativeTime';
5
+ import timezone from 'dayjs/plugin/timezone'; // dependent on utc plugin
6
+ import utc from 'dayjs/plugin/utc';
7
+
8
+ import('dayjs/locale/en');
9
+ import('dayjs/locale/zh');
10
+
11
+ dayjs.extend(relativeTime);
12
+ dayjs.extend(localizedFormat);
13
+ dayjs.extend(duration);
14
+ dayjs.extend(utc);
15
+ dayjs.extend(timezone);
16
+
17
+ export default dayjs;