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,222 @@
1
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
+ import type {
3
+ TCheckoutSessionExpanded,
4
+ TCustomer,
5
+ TPaymentIntent,
6
+ TPaymentLink,
7
+ TPaymentMethodExpanded,
8
+ } from '@did-pay/types';
9
+ import { Box, Fade, Stack } from '@mui/material';
10
+ import { styled } from '@mui/system';
11
+ import { useEffect } from 'react';
12
+
13
+ import { useSettingsContext } from '../../contexts/settings';
14
+ import { formatError, getStatementDescriptor } from '../../libs/util';
15
+ import PaymentError from './error';
16
+ import CheckoutFooter from './footer';
17
+ import PaymentForm from './form';
18
+ import PaymentHeader from './header';
19
+ import OverviewSkeleton from './skeleton/overview';
20
+ import PaymentSkeleton from './skeleton/payment';
21
+ import PaymentSuccess from './success';
22
+ import PaymentSummary from './summary';
23
+
24
+ type Props = {
25
+ onPaid: (res: any, paymentIntent: TPaymentIntent) => void;
26
+ onError: (err: any) => void;
27
+ checkoutSession?: TCheckoutSessionExpanded;
28
+ paymentMethods?: TPaymentMethodExpanded[];
29
+ paymentLink?: TPaymentLink;
30
+ paymentIntent?: TPaymentIntent;
31
+ customer?: TCustomer;
32
+ completed?: boolean;
33
+ error?: any;
34
+ };
35
+
36
+ CheckoutPay.defaultProps = {
37
+ checkoutSession: null,
38
+ paymentMethods: [],
39
+ paymentLink: null,
40
+ paymentIntent: null,
41
+ customer: null,
42
+ completed: false,
43
+ error: null,
44
+ };
45
+
46
+ export default function CheckoutPay({
47
+ checkoutSession,
48
+ paymentMethods,
49
+ paymentIntent,
50
+ paymentLink,
51
+ customer,
52
+ completed,
53
+ error,
54
+ onPaid,
55
+ onError,
56
+ }: Props) {
57
+ const { t } = useLocaleContext();
58
+ const { refresh, livemode, setLivemode } = useSettingsContext();
59
+
60
+ useEffect(() => {
61
+ if (checkoutSession) {
62
+ if (livemode !== checkoutSession.livemode) {
63
+ setLivemode(checkoutSession.livemode);
64
+ setTimeout(() => {
65
+ refresh();
66
+ }, 10);
67
+ }
68
+ }
69
+ }, [checkoutSession, livemode, setLivemode, refresh]);
70
+
71
+ if (error) {
72
+ return <PaymentError title="Oops" description={formatError(error)} />;
73
+ }
74
+
75
+ if (!checkoutSession) {
76
+ return (
77
+ <PaymentRoot>
78
+ <Stack direction="row" className="cko-container">
79
+ <Stack className="cko-overview">
80
+ <OverviewSkeleton />
81
+ </Stack>
82
+ <Stack className="cko-payment">
83
+ <PaymentSkeleton />
84
+ </Stack>
85
+ <CheckoutFooter className="cko-footer" />
86
+ </Stack>
87
+ </PaymentRoot>
88
+ );
89
+ }
90
+
91
+ // expired session
92
+ if (checkoutSession.expires_at <= Math.round(Date.now() / 1000)) {
93
+ return (
94
+ <PaymentError
95
+ title="Expired Link"
96
+ description="This link has expired. This means that your payment has already been processed or your session has expired."
97
+ />
98
+ );
99
+ }
100
+
101
+ // completed session
102
+ if (checkoutSession.status === 'complete') {
103
+ return (
104
+ <PaymentError
105
+ title="Checkout Completed"
106
+ description="This checkout session has completed. This means that your payment has already been successfully processed."
107
+ />
108
+ );
109
+ }
110
+
111
+ const brand = getStatementDescriptor(checkoutSession.line_items);
112
+
113
+ return (
114
+ <PaymentRoot>
115
+ <Stack direction="row" className="cko-container">
116
+ <Fade in>
117
+ <Stack className="cko-overview" direction="column">
118
+ <PaymentHeader checkoutSession={checkoutSession} />
119
+ <PaymentSummary checkoutSession={checkoutSession} />
120
+ </Stack>
121
+ </Fade>
122
+ <Stack className="cko-payment" direction="column" spacing={4}>
123
+ {completed && (
124
+ <PaymentSuccess
125
+ payee={brand}
126
+ action={checkoutSession.mode}
127
+ message={
128
+ paymentLink?.after_completion?.hosted_confirmation?.custom_message ||
129
+ t(`checkout.completed.${checkoutSession.mode}`)
130
+ }
131
+ />
132
+ )}
133
+ {!completed && (
134
+ <PaymentForm
135
+ checkoutSession={checkoutSession}
136
+ paymentMethods={paymentMethods as TPaymentMethodExpanded[]}
137
+ paymentIntent={paymentIntent}
138
+ customer={customer}
139
+ onPaid={onPaid}
140
+ onError={onError}
141
+ />
142
+ )}
143
+ </Stack>
144
+ <CheckoutFooter className="cko-footer" />
145
+ </Stack>
146
+ </PaymentRoot>
147
+ );
148
+ }
149
+
150
+ export const PaymentRoot = styled(Box)`
151
+ box-sizing: border-box;
152
+ display: flex;
153
+ flex-wrap: nowrap;
154
+ justify-content: center;
155
+ min-height: 0;
156
+
157
+ &:before {
158
+ animation-fill-mode: both;
159
+ background: #ffffff;
160
+ content: ' ';
161
+ height: 100%;
162
+ position: fixed;
163
+ right: 0;
164
+ top: 0;
165
+ transform-origin: right;
166
+ width: 50%;
167
+ box-shadow: 15px 0 30px 0 rgba(0, 0, 0, 0.18);
168
+ }
169
+
170
+ .cko-container {
171
+ width: 100%;
172
+ max-width: 920px;
173
+ display: flex;
174
+ align-items: flex-start;
175
+ justify-content: space-between;
176
+ position: relative;
177
+ transform: translateY(max(48px, calc(50vh - 55%)));
178
+ }
179
+
180
+ .cko-overview {
181
+ width: 380px;
182
+ }
183
+
184
+ .cko-payment {
185
+ width: 380px;
186
+ .MuiInputBase-root {
187
+ border-radius: 0;
188
+ }
189
+ }
190
+
191
+ .cko-payment-form {
192
+ .MuiInputAdornment-positionStart {
193
+ width: 50px;
194
+ }
195
+
196
+ .MuiBox-root {
197
+ border: 1px solid #ccc;
198
+ margin: -1px 0 0 -1px;
199
+ }
200
+
201
+ .MuiOutlinedInput-notchedOutline {
202
+ border: none;
203
+ }
204
+ }
205
+
206
+ .cko-payment-methods {
207
+ }
208
+
209
+ .cko-payment-submit {
210
+ .MuiButtonBase-root {
211
+ border-radius: 0;
212
+ font-size: 1.3rem;
213
+ }
214
+ }
215
+
216
+ .cko-footer {
217
+ position: absolute;
218
+ bottom: 0;
219
+ left: 0;
220
+ margin: 12px 0;
221
+ }
222
+ `;
@@ -0,0 +1,56 @@
1
+ import { Avatar, Stack, Typography } from '@mui/material';
2
+ import type { LiteralUnion } from 'type-fest';
3
+
4
+ type Props = {
5
+ name: string;
6
+ description?: string;
7
+ logo?: string;
8
+ size?: number;
9
+ extra?: React.ReactNode;
10
+ variant?: LiteralUnion<'square' | 'rounded' | 'circular', string>;
11
+ };
12
+
13
+ // FIXME: @wangshijun add image filter for logo
14
+ export default function ProductCard({ size, variant, name, logo, description, extra }: Props) {
15
+ const s = { width: size, height: size };
16
+ return (
17
+ <Stack direction="row" alignItems="center" spacing={1} flex={2}>
18
+ {logo ? (
19
+ // @ts-ignore
20
+ <Avatar src={logo} alt={name} variant={variant} sx={s} />
21
+ ) : (
22
+ // @ts-ignore
23
+ <Avatar variant={variant} sx={s}>
24
+ {name.slice(0, 1)}
25
+ </Avatar>
26
+ )}
27
+ <Stack direction="column" alignItems="flex-start" justifyContent="space-around">
28
+ <Typography variant="body1" sx={{ fontWeight: 500 }} color="text.primary" gutterBottom>
29
+ {name}
30
+ </Typography>
31
+ {description && (
32
+ <Typography
33
+ variant="body1"
34
+ sx={{ fontSize: '0.85rem', lineHeight: '120%' }}
35
+ color="text.secondary"
36
+ gutterBottom>
37
+ {description}
38
+ </Typography>
39
+ )}
40
+ {extra && (
41
+ <Typography variant="body1" sx={{ fontSize: '0.85rem' }} color="text.secondary">
42
+ {extra}
43
+ </Typography>
44
+ )}
45
+ </Stack>
46
+ </Stack>
47
+ );
48
+ }
49
+
50
+ ProductCard.defaultProps = {
51
+ logo: '',
52
+ size: 48,
53
+ description: '',
54
+ variant: 'rounded',
55
+ extra: undefined,
56
+ };
@@ -0,0 +1,37 @@
1
+ import type { TCheckoutSessionExpanded, TLineItemExpanded } from '@did-pay/types';
2
+ import { Stack, Typography } from '@mui/material';
3
+
4
+ import { formatLineItemPricing, formatRecurring } from '../../libs/util';
5
+ import ProductCard from './product-card';
6
+
7
+ type Props = {
8
+ item: TLineItemExpanded;
9
+ session: TCheckoutSessionExpanded;
10
+ };
11
+
12
+ export default function ProductItem({ item, session }: Props) {
13
+ const pricing = formatLineItemPricing(item, session.currency, session.subscription_data?.trial_period_days || 0);
14
+ const metered = item.price?.recurring?.usage_type === 'metered' ? ' based on usage' : '';
15
+ return (
16
+ <Stack direction="row" alignItems="center" justifyContent="space-between">
17
+ <ProductCard
18
+ logo={item.price.product?.images[0]}
19
+ name={item.price.product?.name}
20
+ description={item.price.product?.description}
21
+ extra={
22
+ item.price.type === 'recurring' && item.price.recurring
23
+ ? `Billed ${formatRecurring(item.price.recurring)} ${metered}`
24
+ : undefined
25
+ }
26
+ />
27
+ <Stack direction="column" alignItems="flex-end" flex={1}>
28
+ <Typography sx={{ color: 'text.primary', fontWeight: 500 }} gutterBottom>
29
+ {pricing.primary}
30
+ </Typography>
31
+ {pricing.secondary && (
32
+ <Typography sx={{ fontSize: '0.85rem', color: 'text.secondary' }}>{pricing.secondary}</Typography>
33
+ )}
34
+ </Stack>
35
+ </Stack>
36
+ );
37
+ }
@@ -0,0 +1,21 @@
1
+ import { Fade, Skeleton, Stack, Typography } from '@mui/material';
2
+
3
+ export default function OverviewSkeleton() {
4
+ return (
5
+ <Fade in>
6
+ <Stack direction="column">
7
+ <Stack direction="row" alignItems="center" spacing={2}>
8
+ <Skeleton variant="circular" width={32} height={32} />
9
+ <Skeleton variant="text" sx={{ fontSize: '2rem', width: '40%' }} />
10
+ </Stack>
11
+ <Typography mt={3} component="div" variant="h4">
12
+ <Skeleton />
13
+ </Typography>
14
+ <Typography component="div" variant="h2">
15
+ <Skeleton />
16
+ </Typography>
17
+ <Skeleton sx={{ mt: 3 }} variant="rounded" width={200} height={200} />
18
+ </Stack>
19
+ </Fade>
20
+ );
21
+ }
@@ -0,0 +1,35 @@
1
+ import { Box, Fade, Skeleton, Stack, Typography } from '@mui/material';
2
+
3
+ export default function PaymentSkeleton() {
4
+ return (
5
+ <Fade in>
6
+ <Stack direction="column" spacing={3}>
7
+ <Skeleton variant="text" sx={{ fontSize: '2rem', width: '40%' }} />
8
+ <Box>
9
+ <Typography component="div" variant="h4">
10
+ <Skeleton />
11
+ </Typography>
12
+ <Typography component="div" variant="h1">
13
+ <Skeleton />
14
+ </Typography>
15
+ </Box>
16
+ <Box>
17
+ <Typography component="div" variant="h4">
18
+ <Skeleton />
19
+ </Typography>
20
+ <Typography component="div" variant="h1">
21
+ <Skeleton />
22
+ </Typography>
23
+ </Box>
24
+ <Box>
25
+ <Typography component="div" variant="h4">
26
+ <Skeleton />
27
+ </Typography>
28
+ <Typography component="div" variant="h1">
29
+ <Skeleton />
30
+ </Typography>
31
+ </Box>
32
+ </Stack>
33
+ </Fade>
34
+ );
35
+ }
@@ -0,0 +1,183 @@
1
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
+ import { Grow, Stack, Typography } from '@mui/material';
3
+ import { styled } from '@mui/system';
4
+ import { Link } from 'react-router-dom';
5
+
6
+ type Props = {
7
+ message: string;
8
+ action: string;
9
+ payee: string;
10
+ };
11
+
12
+ export default function PaymentSuccess({ message, action, payee }: Props) {
13
+ const { t } = useLocaleContext();
14
+ return (
15
+ <Grow in>
16
+ <Stack direction="column" alignItems="center" justifyContent="center" sx={{ height: 360 }}>
17
+ <Div>
18
+ <div className="check-icon">
19
+ <span className="icon-line line-tip" />
20
+ <span className="icon-line line-long" />
21
+ <div className="icon-circle" />
22
+ <div className="icon-fix" />
23
+ </div>
24
+ </Div>
25
+ <Typography variant="h5" color="text.primary" mb={3}>
26
+ {message}
27
+ </Typography>
28
+ <Typography variant="body1" color="text.secondary" textAlign="center">
29
+ {t('checkout.completed.tip', { payee })}
30
+ </Typography>
31
+ {['subscription', 'setup'].includes(action) && (
32
+ <Typography textAlign="center" sx={{ mt: 2 }}>
33
+ <Link to="/customer">{t('checkout.portal', { payee })}</Link>
34
+ </Typography>
35
+ )}
36
+ </Stack>
37
+ </Grow>
38
+ );
39
+ }
40
+
41
+ const Div = styled('div')`
42
+ width: 80px;
43
+ height: 115px;
44
+
45
+ .check-icon {
46
+ width: 80px;
47
+ height: 80px;
48
+ position: relative;
49
+ border-radius: 50%;
50
+ box-sizing: content-box;
51
+ border: 4px solid ${(props) => props.theme.palette.success.main};
52
+ }
53
+ .check-icon::before {
54
+ top: 3px;
55
+ left: -2px;
56
+ width: 30px;
57
+ transform-origin: 100% 50%;
58
+ border-radius: 100px 0 0 100px;
59
+ }
60
+ .check-icon::after {
61
+ top: 0;
62
+ left: 30px;
63
+ width: 60px;
64
+ transform-origin: 0 50%;
65
+ border-radius: 0 100px 100px 0;
66
+ animation: rotate-circle 4.25s ease-in;
67
+ }
68
+ .check-icon::before,
69
+ .check-icon::after {
70
+ content: '';
71
+ height: 100px;
72
+ position: absolute;
73
+ background: #ffffff;
74
+ transform: rotate(-45deg);
75
+ }
76
+ .check-icon .icon-line {
77
+ height: 5px;
78
+ background-color: ${(props) => props.theme.palette.success.main};
79
+ display: block;
80
+ border-radius: 2px;
81
+ position: absolute;
82
+ z-index: 10;
83
+ }
84
+ .check-icon .icon-line.line-tip {
85
+ top: 46px;
86
+ left: 14px;
87
+ width: 25px;
88
+ transform: rotate(45deg);
89
+ animation: icon-line-tip 0.75s;
90
+ }
91
+ .check-icon .icon-line.line-long {
92
+ top: 38px;
93
+ right: 8px;
94
+ width: 47px;
95
+ transform: rotate(-45deg);
96
+ animation: icon-line-long 0.75s;
97
+ }
98
+ .check-icon .icon-circle {
99
+ top: -4px;
100
+ left: -4px;
101
+ z-index: 10;
102
+ width: 80px;
103
+ height: 80px;
104
+ border-radius: 50%;
105
+ position: absolute;
106
+ box-sizing: content-box;
107
+ border: 4px solid rgba(76, 175, 80, 0.5);
108
+ }
109
+ .check-icon .icon-fix {
110
+ top: 8px;
111
+ width: 5px;
112
+ left: 26px;
113
+ z-index: 1;
114
+ height: 85px;
115
+ position: absolute;
116
+ transform: rotate(-45deg);
117
+ background-color: #ffffff;
118
+ }
119
+
120
+ @keyframes rotate-circle {
121
+ 0% {
122
+ transform: rotate(-45deg);
123
+ }
124
+ 5% {
125
+ transform: rotate(-45deg);
126
+ }
127
+ 12% {
128
+ transform: rotate(-405deg);
129
+ }
130
+ 100% {
131
+ transform: rotate(-405deg);
132
+ }
133
+ }
134
+ @keyframes icon-line-tip {
135
+ 0% {
136
+ width: 0;
137
+ left: 1px;
138
+ top: 19px;
139
+ }
140
+ 54% {
141
+ width: 0;
142
+ left: 1px;
143
+ top: 19px;
144
+ }
145
+ 70% {
146
+ width: 50px;
147
+ left: -8px;
148
+ top: 37px;
149
+ }
150
+ 84% {
151
+ width: 17px;
152
+ left: 21px;
153
+ top: 48px;
154
+ }
155
+ 100% {
156
+ width: 25px;
157
+ left: 14px;
158
+ top: 45px;
159
+ }
160
+ }
161
+ @keyframes icon-line-long {
162
+ 0% {
163
+ width: 0;
164
+ right: 46px;
165
+ top: 54px;
166
+ }
167
+ 65% {
168
+ width: 0;
169
+ right: 46px;
170
+ top: 54px;
171
+ }
172
+ 84% {
173
+ width: 55px;
174
+ right: 0px;
175
+ top: 35px;
176
+ }
177
+ 100% {
178
+ width: 47px;
179
+ right: 8px;
180
+ top: 38px;
181
+ }
182
+ }
183
+ `;
@@ -0,0 +1,34 @@
1
+ import type { TCheckoutSessionExpanded, TLineItemExpanded } from '@did-pay/types';
2
+ import { Fade, Stack, Typography } from '@mui/material';
3
+
4
+ import { formatCheckoutHeadlines } from '../../libs/util';
5
+ import PaymentAmount from './amount';
6
+ import ProductItem from './product-item';
7
+
8
+ type Props = {
9
+ checkoutSession: TCheckoutSessionExpanded;
10
+ };
11
+
12
+ export default function PaymentSummary({ checkoutSession }: Props) {
13
+ const headlines = formatCheckoutHeadlines(checkoutSession);
14
+ return (
15
+ <Fade in>
16
+ <Stack className="cko-product" direction="column" sx={{ mt: 4 }}>
17
+ <Stack className="cko-product-summary" sx={{ mb: 4 }}>
18
+ <Typography sx={{ fontWeight: 500, fontSize: '1.15rem', color: 'text.secondary' }}>
19
+ {headlines.action}
20
+ </Typography>
21
+ <PaymentAmount amount={headlines.amount} />
22
+ {headlines.then && (
23
+ <Typography sx={{ fontSize: '0.9rem', color: 'text.secondary' }}>{headlines.then}</Typography>
24
+ )}
25
+ </Stack>
26
+ <Stack spacing={2}>
27
+ {checkoutSession.line_items.map((x: TLineItemExpanded) => (
28
+ <ProductItem key={x.price_id} item={x} session={checkoutSession} />
29
+ ))}
30
+ </Stack>
31
+ </Stack>
32
+ </Fade>
33
+ );
34
+ }
@@ -0,0 +1,50 @@
1
+ import { ExpandLessOutlined, ExpandMoreOutlined } from '@mui/icons-material';
2
+ import { Box, Collapse, Stack } from '@mui/material';
3
+ import { useState } from 'react';
4
+
5
+ type Props = {
6
+ trigger: string | Function | React.ReactNode;
7
+ children: React.ReactNode;
8
+ expanded?: boolean;
9
+ addons?: React.ReactNode;
10
+ style?: Record<string, any>;
11
+ };
12
+
13
+ export default function IconCollapse(props: Props) {
14
+ const [expanded, setExpanded] = useState(props.expanded || false);
15
+ const toggleExpanded = () => {
16
+ setExpanded((prev) => !prev);
17
+ };
18
+
19
+ return (
20
+ <>
21
+ <Stack
22
+ direction="row"
23
+ alignItems="center"
24
+ justifyContent="space-between"
25
+ onClick={toggleExpanded}
26
+ sx={{
27
+ width: 1,
28
+ cursor: 'pointer',
29
+ fontWeight: 500,
30
+ color: 'text.primary',
31
+ '& :hover': { color: 'primary.main' },
32
+ ...props.style,
33
+ }}>
34
+ <Box>{typeof props.trigger === 'function' ? props.trigger(expanded) : props.trigger} </Box>
35
+ <Stack direction="row" alignItems="center" spacing={2}>
36
+ {props.addons} {expanded ? <ExpandLessOutlined /> : <ExpandMoreOutlined />}
37
+ </Stack>
38
+ </Stack>
39
+ <Collapse in={expanded}>
40
+ <Box>{props.children}</Box>
41
+ </Collapse>
42
+ </>
43
+ );
44
+ }
45
+
46
+ IconCollapse.defaultProps = {
47
+ expanded: false,
48
+ addons: null,
49
+ style: {},
50
+ };
@@ -0,0 +1,55 @@
1
+ import { Confirm } from '@arcblock/ux/lib/Dialog';
2
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
3
+ import { Typography } from '@mui/material';
4
+ import type { EventHandler } from 'react';
5
+
6
+ export default function ConfirmDialog({
7
+ onConfirm,
8
+ onCancel,
9
+ title,
10
+ message,
11
+ loading,
12
+ }: {
13
+ onConfirm: EventHandler<any>;
14
+ onCancel: EventHandler<any>;
15
+ title: string | React.ReactNode;
16
+ message: string | React.ReactNode;
17
+ loading?: boolean;
18
+ }) {
19
+ const { t } = useLocaleContext();
20
+ const handleConfirm = (e: any) => {
21
+ try {
22
+ e.stopPropagation();
23
+ e.preventDefault();
24
+ // eslint-disable-next-line no-empty
25
+ } catch {}
26
+ onConfirm(e);
27
+ };
28
+ const handleCancel = (e: any) => {
29
+ try {
30
+ e.stopPropagation();
31
+ e.preventDefault();
32
+ // eslint-disable-next-line no-empty
33
+ } catch {}
34
+ onCancel(e);
35
+ };
36
+
37
+ return (
38
+ <Confirm
39
+ open
40
+ title={title}
41
+ onConfirm={handleConfirm}
42
+ onCancel={handleCancel}
43
+ confirmButton={{
44
+ text: t('common.confirm'),
45
+ props: { color: 'error', size: 'small', variant: 'contained', disabled: !!loading },
46
+ }}
47
+ cancelButton={{ text: t('common.cancel'), props: { color: 'inherit', size: 'small' } }}>
48
+ <Typography>{message}</Typography>
49
+ </Confirm>
50
+ );
51
+ }
52
+
53
+ ConfirmDialog.defaultProps = {
54
+ loading: false,
55
+ };