@blocklet/payment-react 1.13.113

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 (173) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +29 -0
  3. package/babel.config.es.js +8 -0
  4. package/build.config.ts +29 -0
  5. package/es/api.d.ts +2 -0
  6. package/es/api.js +18 -0
  7. package/es/checkout/index.d.ts +15 -0
  8. package/es/checkout/index.js +61 -0
  9. package/es/components/input.d.ts +23 -0
  10. package/es/components/input.js +44 -0
  11. package/es/components/livemode.d.ts +2 -0
  12. package/es/components/livemode.js +24 -0
  13. package/es/components/pricing-table.d.ts +18 -0
  14. package/es/components/pricing-table.js +175 -0
  15. package/es/components/status.d.ts +3 -0
  16. package/es/components/status.js +20 -0
  17. package/es/components/switch.d.ts +6 -0
  18. package/es/components/switch.js +42 -0
  19. package/es/contexts/payment.d.ts +29 -0
  20. package/es/contexts/payment.js +45 -0
  21. package/es/dayjs.d.ts +2 -0
  22. package/es/dayjs.js +14 -0
  23. package/es/index.d.ts +16 -0
  24. package/es/index.js +29 -0
  25. package/es/locales/en.d.ts +2 -0
  26. package/es/locales/en.js +213 -0
  27. package/es/locales/index.d.ts +10 -0
  28. package/es/locales/index.js +20 -0
  29. package/es/locales/zh.d.ts +2 -0
  30. package/es/locales/zh.js +213 -0
  31. package/es/payment/amount.d.ts +12 -0
  32. package/es/payment/amount.js +22 -0
  33. package/es/payment/error.d.ts +13 -0
  34. package/es/payment/error.js +12 -0
  35. package/es/payment/footer.d.ts +4 -0
  36. package/es/payment/footer.js +9 -0
  37. package/es/payment/form/addon.d.ts +2 -0
  38. package/es/payment/form/addon.js +14 -0
  39. package/es/payment/form/address.d.ts +7 -0
  40. package/es/payment/form/address.js +119 -0
  41. package/es/payment/form/index.d.ts +9 -0
  42. package/es/payment/form/index.js +337 -0
  43. package/es/payment/form/phone.d.ts +4 -0
  44. package/es/payment/form/phone.js +97 -0
  45. package/es/payment/form/stripe.d.ts +13 -0
  46. package/es/payment/form/stripe.js +158 -0
  47. package/es/payment/header.d.ts +7 -0
  48. package/es/payment/header.js +29 -0
  49. package/es/payment/index.d.ts +28 -0
  50. package/es/payment/index.js +327 -0
  51. package/es/payment/product-card.d.ts +21 -0
  52. package/es/payment/product-card.js +34 -0
  53. package/es/payment/product-item.d.ts +19 -0
  54. package/es/payment/product-item.js +107 -0
  55. package/es/payment/product-skeleton.d.ts +4 -0
  56. package/es/payment/product-skeleton.js +34 -0
  57. package/es/payment/skeleton/overview.d.ts +2 -0
  58. package/es/payment/skeleton/overview.js +13 -0
  59. package/es/payment/skeleton/payment.d.ts +2 -0
  60. package/es/payment/skeleton/payment.js +19 -0
  61. package/es/payment/success.d.ts +8 -0
  62. package/es/payment/success.js +164 -0
  63. package/es/payment/summary.d.ts +12 -0
  64. package/es/payment/summary.js +178 -0
  65. package/es/theme.d.ts +1 -0
  66. package/es/theme.js +17 -0
  67. package/es/types/index.d.ts +19 -0
  68. package/es/types/index.js +0 -0
  69. package/es/types/shims.d.ts +18 -0
  70. package/es/util.d.ts +52 -0
  71. package/es/util.js +390 -0
  72. package/lib/api.d.ts +2 -0
  73. package/lib/api.js +26 -0
  74. package/lib/checkout/index.d.ts +15 -0
  75. package/lib/checkout/index.js +83 -0
  76. package/lib/components/input.d.ts +23 -0
  77. package/lib/components/input.js +72 -0
  78. package/lib/components/livemode.d.ts +2 -0
  79. package/lib/components/livemode.js +29 -0
  80. package/lib/components/pricing-table.d.ts +18 -0
  81. package/lib/components/pricing-table.js +232 -0
  82. package/lib/components/status.d.ts +3 -0
  83. package/lib/components/status.js +23 -0
  84. package/lib/components/switch.d.ts +6 -0
  85. package/lib/components/switch.js +51 -0
  86. package/lib/contexts/payment.d.ts +29 -0
  87. package/lib/contexts/payment.js +73 -0
  88. package/lib/dayjs.d.ts +2 -0
  89. package/lib/dayjs.js +21 -0
  90. package/lib/index.d.ts +16 -0
  91. package/lib/index.js +143 -0
  92. package/lib/locales/en.d.ts +2 -0
  93. package/lib/locales/en.js +220 -0
  94. package/lib/locales/index.d.ts +10 -0
  95. package/lib/locales/index.js +33 -0
  96. package/lib/locales/zh.d.ts +2 -0
  97. package/lib/locales/zh.js +220 -0
  98. package/lib/payment/amount.d.ts +12 -0
  99. package/lib/payment/amount.js +28 -0
  100. package/lib/payment/error.d.ts +13 -0
  101. package/lib/payment/error.js +52 -0
  102. package/lib/payment/footer.d.ts +4 -0
  103. package/lib/payment/footer.js +25 -0
  104. package/lib/payment/form/addon.d.ts +2 -0
  105. package/lib/payment/form/addon.js +37 -0
  106. package/lib/payment/form/address.d.ts +7 -0
  107. package/lib/payment/form/address.js +152 -0
  108. package/lib/payment/form/index.d.ts +9 -0
  109. package/lib/payment/form/index.js +464 -0
  110. package/lib/payment/form/phone.d.ts +4 -0
  111. package/lib/payment/form/phone.js +133 -0
  112. package/lib/payment/form/stripe.d.ts +13 -0
  113. package/lib/payment/form/stripe.js +213 -0
  114. package/lib/payment/header.d.ts +7 -0
  115. package/lib/payment/header.js +58 -0
  116. package/lib/payment/index.d.ts +28 -0
  117. package/lib/payment/index.js +382 -0
  118. package/lib/payment/product-card.d.ts +21 -0
  119. package/lib/payment/product-card.js +81 -0
  120. package/lib/payment/product-item.d.ts +19 -0
  121. package/lib/payment/product-item.js +160 -0
  122. package/lib/payment/product-skeleton.d.ts +4 -0
  123. package/lib/payment/product-skeleton.js +71 -0
  124. package/lib/payment/skeleton/overview.d.ts +2 -0
  125. package/lib/payment/skeleton/overview.js +48 -0
  126. package/lib/payment/skeleton/payment.d.ts +2 -0
  127. package/lib/payment/skeleton/payment.js +54 -0
  128. package/lib/payment/success.d.ts +8 -0
  129. package/lib/payment/success.js +215 -0
  130. package/lib/payment/summary.d.ts +12 -0
  131. package/lib/payment/summary.js +225 -0
  132. package/lib/theme.d.ts +1 -0
  133. package/lib/theme.js +19 -0
  134. package/lib/types/index.d.ts +19 -0
  135. package/lib/types/index.js +1 -0
  136. package/lib/types/shims.d.ts +18 -0
  137. package/lib/util.d.ts +52 -0
  138. package/lib/util.js +487 -0
  139. package/package.json +104 -0
  140. package/src/api.ts +24 -0
  141. package/src/checkout/index.tsx +74 -0
  142. package/src/components/input.tsx +58 -0
  143. package/src/components/livemode.tsx +23 -0
  144. package/src/components/pricing-table.tsx +207 -0
  145. package/src/components/status.tsx +19 -0
  146. package/src/components/switch.tsx +48 -0
  147. package/src/contexts/payment.tsx +74 -0
  148. package/src/dayjs.ts +17 -0
  149. package/src/index.ts +32 -0
  150. package/src/locales/en.tsx +218 -0
  151. package/src/locales/index.tsx +30 -0
  152. package/src/locales/zh.tsx +214 -0
  153. package/src/payment/amount.tsx +24 -0
  154. package/src/payment/error.tsx +29 -0
  155. package/src/payment/footer.tsx +12 -0
  156. package/src/payment/form/addon.tsx +24 -0
  157. package/src/payment/form/address.tsx +119 -0
  158. package/src/payment/form/index.tsx +401 -0
  159. package/src/payment/form/phone.tsx +103 -0
  160. package/src/payment/form/stripe.tsx +195 -0
  161. package/src/payment/header.tsx +40 -0
  162. package/src/payment/index.tsx +367 -0
  163. package/src/payment/product-card.tsx +55 -0
  164. package/src/payment/product-item.tsx +121 -0
  165. package/src/payment/product-skeleton.tsx +39 -0
  166. package/src/payment/skeleton/overview.tsx +21 -0
  167. package/src/payment/skeleton/payment.tsx +35 -0
  168. package/src/payment/success.tsx +186 -0
  169. package/src/payment/summary.tsx +198 -0
  170. package/src/theme.ts +18 -0
  171. package/src/types/index.ts +29 -0
  172. package/src/types/shims.d.ts +18 -0
  173. package/src/util.ts +543 -0
@@ -0,0 +1,382 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PaymentInner = PaymentInner;
7
+ exports.Root = void 0;
8
+ module.exports = Payment;
9
+ var _jsxRuntime = require("react/jsx-runtime");
10
+ var _context = require("@arcblock/ux/lib/Locale/context");
11
+ var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
12
+ var _material = require("@mui/material");
13
+ var _system = require("@mui/system");
14
+ var _ahooks = require("ahooks");
15
+ var _react = require("react");
16
+ var _reactHookForm = require("react-hook-form");
17
+ var _api = _interopRequireDefault(require("../api"));
18
+ var _payment = require("../contexts/payment");
19
+ var _util = require("../util");
20
+ var _error = _interopRequireDefault(require("./error"));
21
+ var _footer = _interopRequireDefault(require("./footer"));
22
+ var _form = _interopRequireDefault(require("./form"));
23
+ var _header = _interopRequireDefault(require("./header"));
24
+ var _overview = _interopRequireDefault(require("./skeleton/overview"));
25
+ var _payment2 = _interopRequireDefault(require("./skeleton/payment"));
26
+ var _success = _interopRequireDefault(require("./success"));
27
+ var _summary = _interopRequireDefault(require("./summary"));
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
+ Payment.defaultProps = {
30
+ completed: false,
31
+ error: null
32
+ };
33
+ function Payment({
34
+ checkoutSession,
35
+ paymentMethods,
36
+ paymentIntent,
37
+ paymentLink,
38
+ customer,
39
+ completed,
40
+ error,
41
+ mode,
42
+ onPaid,
43
+ onError
44
+ }) {
45
+ const {
46
+ t
47
+ } = (0, _context.useLocaleContext)();
48
+ const {
49
+ refresh,
50
+ livemode,
51
+ setLivemode
52
+ } = (0, _payment.usePaymentContext)();
53
+ (0, _react.useEffect)(() => {
54
+ if (checkoutSession) {
55
+ if (livemode !== checkoutSession.livemode) {
56
+ setLivemode(checkoutSession.livemode);
57
+ setTimeout(() => {
58
+ refresh();
59
+ }, 10);
60
+ }
61
+ }
62
+ }, [checkoutSession, livemode, setLivemode, refresh]);
63
+ if (error) {
64
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_error.default, {
65
+ title: "Oops",
66
+ description: (0, _util.formatError)(error)
67
+ });
68
+ }
69
+ if (!checkoutSession) {
70
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(Root, {
71
+ mode,
72
+ children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
73
+ className: "cko-container",
74
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
75
+ className: "cko-overview",
76
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_overview.default, {})
77
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
78
+ className: "cko-payment",
79
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_payment2.default, {})
80
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_footer.default, {
81
+ className: "cko-footer"
82
+ })]
83
+ })
84
+ });
85
+ }
86
+ if (checkoutSession.expires_at <= Math.round(Date.now() / 1e3)) {
87
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_error.default, {
88
+ title: t("payment.checkout.expired.title"),
89
+ description: t("payment.checkout.expired.description")
90
+ });
91
+ }
92
+ if (checkoutSession.status === "complete") {
93
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_error.default, {
94
+ title: t("payment.checkout.complete.title"),
95
+ description: t("payment.checkout.complete.description")
96
+ });
97
+ }
98
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(PaymentInner, {
99
+ checkoutSession,
100
+ paymentMethods,
101
+ paymentLink,
102
+ paymentIntent,
103
+ completed,
104
+ customer,
105
+ onPaid,
106
+ onError,
107
+ mode
108
+ });
109
+ }
110
+ PaymentInner.defaultProps = {
111
+ completed: false
112
+ };
113
+ function PaymentInner({
114
+ checkoutSession,
115
+ paymentMethods,
116
+ paymentLink,
117
+ paymentIntent,
118
+ customer,
119
+ completed,
120
+ mode,
121
+ onPaid,
122
+ onError
123
+ }) {
124
+ const {
125
+ t
126
+ } = (0, _context.useLocaleContext)();
127
+ const {
128
+ settings,
129
+ session
130
+ } = (0, _payment.usePaymentContext)();
131
+ const [state, setState] = (0, _ahooks.useSetState)({
132
+ checkoutSession
133
+ });
134
+ const defaultCurrencyId = state.checkoutSession.currency_id || state.checkoutSession.line_items[0]?.price.currency_id;
135
+ const defaultMethodId = paymentMethods.find(m => m.payment_currencies.some(c => c.id === defaultCurrencyId))?.id;
136
+ const methods = (0, _reactHookForm.useForm)({
137
+ defaultValues: {
138
+ customer_name: customer?.name || session.user?.fullName || "",
139
+ customer_email: customer?.email || session.user?.email || "",
140
+ customer_phone: customer?.phone || session.user?.phone || "",
141
+ payment_method: defaultMethodId,
142
+ payment_currency: defaultCurrencyId,
143
+ billing_address: Object.assign({
144
+ country: "",
145
+ state: "",
146
+ city: "",
147
+ line1: "",
148
+ line2: "",
149
+ postal_code: ""
150
+ }, customer?.address || {}, {
151
+ country: (0, _util.isValidCountry)(customer?.address?.country || "") ? customer?.address?.country : "us"
152
+ })
153
+ }
154
+ });
155
+ const currencyId = methods.watch("payment_currency");
156
+ const currency = (0, _util.findCurrency)(paymentMethods, currencyId) || settings.baseCurrency;
157
+ const onUpsell = async (from, to) => {
158
+ try {
159
+ const {
160
+ data
161
+ } = await _api.default.put(`/api/checkout-sessions/${state.checkoutSession.id}/upsell`, {
162
+ from,
163
+ to
164
+ });
165
+ setState({
166
+ checkoutSession: data
167
+ });
168
+ } catch (err) {
169
+ console.error(err);
170
+ _Toast.default.error((0, _util.formatError)(err));
171
+ }
172
+ };
173
+ const onDownsell = async from => {
174
+ try {
175
+ const {
176
+ data
177
+ } = await _api.default.put(`/api/checkout-sessions/${state.checkoutSession.id}/downsell`, {
178
+ from
179
+ });
180
+ setState({
181
+ checkoutSession: data
182
+ });
183
+ } catch (err) {
184
+ console.error(err);
185
+ _Toast.default.error((0, _util.formatError)(err));
186
+ }
187
+ };
188
+ const onApplyCrossSell = async to => {
189
+ try {
190
+ const {
191
+ data
192
+ } = await _api.default.put(`/api/checkout-sessions/${state.checkoutSession.id}/cross-sell`, {
193
+ to
194
+ });
195
+ setState({
196
+ checkoutSession: data
197
+ });
198
+ } catch (err) {
199
+ console.error(err);
200
+ _Toast.default.error((0, _util.formatError)(err));
201
+ }
202
+ };
203
+ const onCancelCrossSell = async () => {
204
+ try {
205
+ const {
206
+ data
207
+ } = await _api.default.delete(`/api/checkout-sessions/${state.checkoutSession.id}/cross-sell`);
208
+ setState({
209
+ checkoutSession: data
210
+ });
211
+ } catch (err) {
212
+ console.error(err);
213
+ _Toast.default.error((0, _util.formatError)(err));
214
+ }
215
+ };
216
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_reactHookForm.FormProvider, {
217
+ ...methods,
218
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(Root, {
219
+ mode,
220
+ children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
221
+ className: "cko-container",
222
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Fade, {
223
+ in: true,
224
+ children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
225
+ className: "cko-overview",
226
+ direction: "column",
227
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_header.default, {
228
+ checkoutSession: state.checkoutSession
229
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_summary.default, {
230
+ checkoutSession: state.checkoutSession,
231
+ currency,
232
+ onUpsell,
233
+ onDownsell,
234
+ onApplyCrossSell,
235
+ onCancelCrossSell
236
+ })]
237
+ })
238
+ }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
239
+ className: "cko-payment",
240
+ direction: "column",
241
+ spacing: 4,
242
+ children: [completed && /* @__PURE__ */(0, _jsxRuntime.jsx)(_success.default, {
243
+ payee: (0, _util.getStatementDescriptor)(state.checkoutSession.line_items),
244
+ action: state.checkoutSession.mode,
245
+ message: paymentLink?.after_completion?.hosted_confirmation?.custom_message || t(`payment.checkout.completed.${state.checkoutSession.mode}`)
246
+ }), !completed && /* @__PURE__ */(0, _jsxRuntime.jsx)(_form.default, {
247
+ checkoutSession: state.checkoutSession,
248
+ paymentMethods,
249
+ paymentIntent,
250
+ customer,
251
+ onPaid,
252
+ onError,
253
+ mode
254
+ })]
255
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_footer.default, {
256
+ className: "cko-footer"
257
+ })]
258
+ })
259
+ })
260
+ });
261
+ }
262
+ const Root = exports.Root = (0, _system.styled)(_material.Box)`
263
+ box-sizing: border-box;
264
+ display: flex;
265
+ flex-direction: column;
266
+ justify-content: center;
267
+ align-items: center;
268
+ min-height: 100vh;
269
+ position: relative;
270
+
271
+ &:before {
272
+ animation-fill-mode: both;
273
+ background: #ffffff;
274
+ content: '';
275
+ height: 100%;
276
+ position: fixed;
277
+ right: 0;
278
+ top: 0;
279
+ transform-origin: right;
280
+ width: 50%;
281
+ box-shadow: 15px 0 30px 0 rgba(0, 0, 0, 0.18);
282
+ }
283
+
284
+ .cko-container {
285
+ width: 100%;
286
+ max-width: 1000px;
287
+ display: flex;
288
+ flex-direction: row;
289
+ justify-content: space-between;
290
+ position: relative;
291
+ padding: 0 16px;
292
+ }
293
+
294
+ .cko-overview {
295
+ width: 400px;
296
+ min-height: 540px;
297
+ position: relative;
298
+ }
299
+ .cko-header {
300
+ left: 0;
301
+ margin-bottom: 0;
302
+ position: absolute;
303
+ right: 0;
304
+ top: 0;
305
+ transition: background-color 0.15s ease, box-shadow 0.15s ease-out;
306
+ }
307
+ .cko-product-summary {
308
+ }
309
+
310
+ .cko-payment {
311
+ width: 400px;
312
+ .MuiInputBase-root {
313
+ border-radius: 0;
314
+ }
315
+ }
316
+
317
+ .cko-payment-form {
318
+ .MuiInputAdornment-positionStart {
319
+ width: 50px;
320
+ }
321
+
322
+ .MuiBox-root {
323
+ border: 1px solid #ccc;
324
+ margin: -1px 0 0 -1px;
325
+ }
326
+
327
+ .MuiFormHelperText-root {
328
+ margin-left: 14px;
329
+ }
330
+
331
+ .MuiOutlinedInput-notchedOutline {
332
+ border: none;
333
+ }
334
+ }
335
+
336
+ .cko-payment-methods {
337
+ }
338
+
339
+ .cko-payment-submit {
340
+ .MuiButtonBase-root {
341
+ border-radius: 0;
342
+ font-size: 1.3rem;
343
+ }
344
+ }
345
+
346
+ .cko-header {
347
+ }
348
+
349
+ .cko-footer {
350
+ position: absolute;
351
+ bottom: 0;
352
+ left: 12px;
353
+ margin: 12px 0;
354
+ }
355
+
356
+ @media (max-width: ${({
357
+ theme
358
+ }) => theme.breakpoints.values.md}px) {
359
+ &:before {
360
+ display: none;
361
+ }
362
+ .cko-container {
363
+ flex-direction: column;
364
+ align-items: center;
365
+ gap: 24px;
366
+ min-width: 350px;
367
+ max-width: 400px;
368
+ }
369
+ .cko-overview {
370
+ width: 100%;
371
+ min-height: auto;
372
+ }
373
+ .cko-payment {
374
+ width: 100%;
375
+ }
376
+
377
+ .cko-footer {
378
+ position: static;
379
+ margin-top: 0;
380
+ }
381
+ }
382
+ `;
@@ -0,0 +1,21 @@
1
+ /// <reference types="react" />
2
+ import type { LiteralUnion } from 'type-fest';
3
+ type Props = {
4
+ name: string;
5
+ description?: string;
6
+ logo?: string;
7
+ size?: number;
8
+ extra?: React.ReactNode;
9
+ variant?: LiteralUnion<'square' | 'rounded' | 'circular', string>;
10
+ };
11
+ declare function ProductCard({ size, variant, name, logo, description, extra }: Props): import("react").JSX.Element;
12
+ declare namespace ProductCard {
13
+ var defaultProps: {
14
+ logo: string;
15
+ size: number;
16
+ description: string;
17
+ variant: string;
18
+ extra: undefined;
19
+ };
20
+ }
21
+ export default ProductCard;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ module.exports = ProductCard;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _material = require("@mui/material");
9
+ function ProductCard({
10
+ size,
11
+ variant,
12
+ name,
13
+ logo,
14
+ description,
15
+ extra
16
+ }) {
17
+ const s = {
18
+ width: size,
19
+ height: size
20
+ };
21
+ return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
22
+ direction: "row",
23
+ alignItems: "flex-start",
24
+ spacing: 1,
25
+ flex: 2,
26
+ children: [logo ?
27
+ // @ts-ignore
28
+ /* @__PURE__ */
29
+ (0, _jsxRuntime.jsx)(_material.Avatar, {
30
+ src: logo,
31
+ alt: name,
32
+ variant,
33
+ sx: s
34
+ }) :
35
+ // @ts-ignore
36
+ /* @__PURE__ */
37
+ (0, _jsxRuntime.jsx)(_material.Avatar, {
38
+ variant,
39
+ sx: s,
40
+ children: name.slice(0, 1)
41
+ }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
42
+ direction: "column",
43
+ alignItems: "flex-start",
44
+ justifyContent: "space-around",
45
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
46
+ variant: "body1",
47
+ sx: {
48
+ fontWeight: 500,
49
+ mb: 0.5,
50
+ lineHeight: 1
51
+ },
52
+ color: "text.primary",
53
+ children: name
54
+ }), description && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
55
+ variant: "body1",
56
+ sx: {
57
+ fontSize: "0.85rem",
58
+ mb: 0.5,
59
+ lineHeight: 1,
60
+ textAlign: "left"
61
+ },
62
+ color: "text.secondary",
63
+ children: description
64
+ }), extra && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
65
+ variant: "body1",
66
+ sx: {
67
+ fontSize: "0.85rem"
68
+ },
69
+ color: "text.secondary",
70
+ children: extra
71
+ })]
72
+ })]
73
+ });
74
+ }
75
+ ProductCard.defaultProps = {
76
+ logo: "",
77
+ size: 48,
78
+ description: "",
79
+ variant: "rounded",
80
+ extra: void 0
81
+ };
@@ -0,0 +1,19 @@
1
+ /// <reference types="react" />
2
+ import type { TCheckoutSessionExpanded, TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
3
+ type Props = {
4
+ item: TLineItemExpanded;
5
+ session: TCheckoutSessionExpanded;
6
+ currency: TPaymentCurrency;
7
+ onUpsell: Function;
8
+ onDownsell: Function;
9
+ mode?: 'normal' | 'cross-sell';
10
+ children?: React.ReactNode;
11
+ };
12
+ declare function ProductItem({ item, session, currency, mode, children, onUpsell, onDownsell }: Props): import("react").JSX.Element;
13
+ declare namespace ProductItem {
14
+ var defaultProps: {
15
+ mode: string;
16
+ children: null;
17
+ };
18
+ }
19
+ export default ProductItem;
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ module.exports = ProductItem;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _context = require("@arcblock/ux/lib/Locale/context");
9
+ var _material = require("@mui/material");
10
+ var _status = _interopRequireDefault(require("../components/status"));
11
+ var _switch = _interopRequireDefault(require("../components/switch"));
12
+ var _util = require("../util");
13
+ var _productCard = _interopRequireDefault(require("./product-card"));
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ ProductItem.defaultProps = {
16
+ mode: "normal",
17
+ children: null
18
+ };
19
+ function ProductItem({
20
+ item,
21
+ session,
22
+ currency,
23
+ mode,
24
+ children,
25
+ onUpsell,
26
+ onDownsell
27
+ }) {
28
+ const {
29
+ t,
30
+ locale
31
+ } = (0, _context.useLocaleContext)();
32
+ const pricing = (0, _util.formatLineItemPricing)(item, currency, session.subscription_data?.trial_period_days || 0, locale);
33
+ const saving = (0, _util.formatUpsellSaving)(session, currency);
34
+ const metered = item.price?.recurring?.usage_type === "metered" ? t("common.metered") : "";
35
+ const canUpsell = mode === "normal" && session.line_items.length === 1;
36
+ return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
37
+ direction: "column",
38
+ alignItems: "flex-start",
39
+ spacing: 1,
40
+ sx: {
41
+ width: "100%"
42
+ },
43
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
44
+ direction: "column",
45
+ alignItems: "flex-end",
46
+ sx: {
47
+ width: "100%"
48
+ },
49
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
50
+ direction: "row",
51
+ alignItems: "center",
52
+ justifyContent: "space-between",
53
+ sx: {
54
+ width: "100%"
55
+ },
56
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_productCard.default, {
57
+ logo: item.price.product?.images[0],
58
+ name: item.price.product?.name,
59
+ description: item.price.product?.description,
60
+ extra: item.price.type === "recurring" && item.price.recurring ? [pricing.quantity, t("common.billed", {
61
+ rule: `${(0, _util.formatRecurring)(item.upsell_price?.recurring || item.price.recurring, true, "per", locale)} ${metered}`
62
+ })].filter(Boolean).join(", ") : pricing.quantity
63
+ }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
64
+ direction: "column",
65
+ alignItems: "flex-end",
66
+ flex: 1,
67
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
68
+ sx: {
69
+ color: "text.primary",
70
+ fontWeight: 500
71
+ },
72
+ gutterBottom: true,
73
+ children: pricing.primary
74
+ }), pricing.secondary && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
75
+ sx: {
76
+ fontSize: "0.85rem",
77
+ color: "text.secondary"
78
+ },
79
+ children: pricing.secondary
80
+ })]
81
+ })]
82
+ }), children]
83
+ }), canUpsell && !item.upsell_price_id && item.price.upsell?.upsells_to && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
84
+ direction: "row",
85
+ alignItems: "center",
86
+ justifyContent: "space-between",
87
+ sx: {
88
+ width: "100%"
89
+ },
90
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
91
+ component: "label",
92
+ htmlFor: "upsell-switch",
93
+ sx: {
94
+ fontSize: 12,
95
+ cursor: "pointer",
96
+ color: "text.primary"
97
+ },
98
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_switch.default, {
99
+ id: "upsell-switch",
100
+ sx: {
101
+ mr: 1
102
+ },
103
+ variant: "success",
104
+ checked: false,
105
+ onChange: () => onUpsell(item.price_id, item.price.upsell?.upsells_to_id)
106
+ }), t("payment.checkout.upsell.save", {
107
+ recurring: (0, _util.formatRecurring)(item.price.upsell.upsells_to.recurring, true, "per", locale)
108
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
109
+ label: t("payment.checkout.upsell.off", {
110
+ saving
111
+ }),
112
+ color: "primary",
113
+ variant: "outlined",
114
+ sx: {
115
+ ml: 1
116
+ }
117
+ })]
118
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
119
+ component: "span",
120
+ sx: {
121
+ fontSize: 12
122
+ },
123
+ children: (0, _util.formatPrice)(item.price.upsell.upsells_to, currency, item.price.product?.unit_label, 1, true, locale)
124
+ })]
125
+ }), canUpsell && item.upsell_price_id && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
126
+ direction: "row",
127
+ alignItems: "center",
128
+ justifyContent: "space-between",
129
+ sx: {
130
+ width: "100%"
131
+ },
132
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
133
+ component: "label",
134
+ htmlFor: "upsell-switch",
135
+ sx: {
136
+ fontSize: 12,
137
+ cursor: "pointer",
138
+ color: "text.secondary"
139
+ },
140
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_switch.default, {
141
+ id: "upsell-switch",
142
+ sx: {
143
+ mr: 1
144
+ },
145
+ variant: "success",
146
+ checked: true,
147
+ onChange: () => onDownsell(item.upsell_price_id)
148
+ }), t("payment.checkout.upsell.revert", {
149
+ recurring: t(`common.${(0, _util.formatRecurring)(item.price.recurring)}`)
150
+ })]
151
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
152
+ component: "span",
153
+ sx: {
154
+ fontSize: 12
155
+ },
156
+ children: (0, _util.formatPrice)(item.price, currency, item.price.product?.unit_label, 1, true, locale)
157
+ })]
158
+ })]
159
+ });
160
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export default function ProductSkeleton({ count }: {
3
+ count: number;
4
+ }): import("react").JSX.Element;