@blocklet/payment-react 1.13.210 → 1.13.212

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 (79) hide show
  1. package/es/checkout/donate.d.ts +20 -0
  2. package/es/checkout/donate.js +199 -0
  3. package/es/checkout/form.d.ts +2 -1
  4. package/es/checkout/form.js +13 -2
  5. package/es/components/blockchain/tx.d.ts +2 -0
  6. package/es/components/blockchain/tx.js +16 -5
  7. package/es/components/safe-guard.d.ts +3 -0
  8. package/es/components/safe-guard.js +4 -0
  9. package/es/index.d.ts +3 -1
  10. package/es/index.js +5 -1
  11. package/es/locales/en.js +8 -0
  12. package/es/locales/zh.js +8 -0
  13. package/es/payment/error.d.ts +3 -1
  14. package/es/payment/error.js +4 -3
  15. package/es/payment/form/currency.js +10 -12
  16. package/es/payment/form/index.d.ts +1 -1
  17. package/es/payment/form/index.js +15 -3
  18. package/es/payment/index.d.ts +3 -3
  19. package/es/payment/index.js +38 -13
  20. package/es/payment/product-donation.d.ts +7 -0
  21. package/es/payment/product-donation.js +99 -0
  22. package/es/payment/skeleton/overview.js +2 -2
  23. package/es/payment/skeleton/payment.js +2 -5
  24. package/es/payment/success.d.ts +2 -1
  25. package/es/payment/success.js +21 -12
  26. package/es/payment/summary.d.ts +8 -2
  27. package/es/payment/summary.js +46 -29
  28. package/es/types/index.d.ts +2 -0
  29. package/es/util.d.ts +2 -0
  30. package/es/util.js +47 -3
  31. package/lib/checkout/donate.d.ts +20 -0
  32. package/lib/checkout/donate.js +284 -0
  33. package/lib/checkout/form.d.ts +2 -1
  34. package/lib/checkout/form.js +5 -2
  35. package/lib/components/blockchain/tx.d.ts +2 -0
  36. package/lib/components/blockchain/tx.js +3 -1
  37. package/lib/components/safe-guard.d.ts +3 -0
  38. package/lib/components/safe-guard.js +12 -0
  39. package/lib/index.d.ts +3 -1
  40. package/lib/index.js +16 -0
  41. package/lib/locales/en.js +8 -0
  42. package/lib/locales/zh.js +8 -0
  43. package/lib/payment/error.d.ts +3 -1
  44. package/lib/payment/error.js +5 -3
  45. package/lib/payment/form/currency.js +10 -12
  46. package/lib/payment/form/index.d.ts +1 -1
  47. package/lib/payment/form/index.js +16 -4
  48. package/lib/payment/index.d.ts +3 -3
  49. package/lib/payment/index.js +56 -24
  50. package/lib/payment/product-donation.d.ts +7 -0
  51. package/lib/payment/product-donation.js +169 -0
  52. package/lib/payment/skeleton/overview.js +2 -2
  53. package/lib/payment/skeleton/payment.js +4 -8
  54. package/lib/payment/success.d.ts +2 -1
  55. package/lib/payment/success.js +3 -2
  56. package/lib/payment/summary.d.ts +8 -2
  57. package/lib/payment/summary.js +30 -7
  58. package/lib/types/index.d.ts +2 -0
  59. package/lib/util.d.ts +2 -0
  60. package/lib/util.js +44 -4
  61. package/package.json +6 -6
  62. package/src/checkout/donate.tsx +256 -0
  63. package/src/checkout/form.tsx +13 -4
  64. package/src/components/blockchain/tx.tsx +8 -1
  65. package/src/components/safe-guard.tsx +5 -0
  66. package/src/index.ts +4 -0
  67. package/src/locales/en.tsx +8 -0
  68. package/src/locales/zh.tsx +8 -0
  69. package/src/payment/error.tsx +4 -2
  70. package/src/payment/form/currency.tsx +11 -13
  71. package/src/payment/form/index.tsx +14 -4
  72. package/src/payment/index.tsx +40 -14
  73. package/src/payment/product-donation.tsx +118 -0
  74. package/src/payment/skeleton/overview.tsx +2 -2
  75. package/src/payment/skeleton/payment.tsx +1 -4
  76. package/src/payment/success.tsx +7 -2
  77. package/src/payment/summary.tsx +47 -28
  78. package/src/types/index.ts +2 -0
  79. package/src/util.ts +54 -3
@@ -1,11 +1,11 @@
1
1
  /// <reference types="react" />
2
- import { LiteralUnion } from 'type-fest';
2
+ import type { LiteralUnion } from 'type-fest';
3
3
  import { CheckoutCallbacks, CheckoutContext } from '../types';
4
4
  type Props = CheckoutContext & CheckoutCallbacks & {
5
5
  completed?: boolean;
6
6
  error?: any;
7
7
  };
8
- declare function Payment({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, completed, error, mode, onPaid, onError, onChange, goBack, }: Props): import("react").JSX.Element;
8
+ declare function Payment({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, completed, error, mode, onPaid, onError, onChange, goBack, action, }: Props): import("react").JSX.Element;
9
9
  declare namespace Payment {
10
10
  var defaultProps: {
11
11
  completed: boolean;
@@ -16,7 +16,7 @@ export default Payment;
16
16
  type MainProps = CheckoutContext & CheckoutCallbacks & {
17
17
  completed?: boolean;
18
18
  };
19
- export declare function PaymentInner({ checkoutSession, paymentMethods, paymentLink, paymentIntent, customer, completed, mode, onPaid, onError, onChange, goBack, }: MainProps): import("react").JSX.Element;
19
+ export declare function PaymentInner({ checkoutSession, paymentMethods, paymentLink, paymentIntent, customer, completed, mode, onPaid, onError, onChange, goBack, action, }: MainProps): import("react").JSX.Element;
20
20
  export declare namespace PaymentInner {
21
21
  var defaultProps: {
22
22
  completed: boolean;
@@ -7,18 +7,18 @@ exports.PaymentInner = PaymentInner;
7
7
  exports.Root = void 0;
8
8
  module.exports = Payment;
9
9
  var _jsxRuntime = require("react/jsx-runtime");
10
- var _Center = _interopRequireDefault(require("@arcblock/ux/lib/Center"));
11
10
  var _context = require("@arcblock/ux/lib/Locale/context");
12
11
  var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
13
12
  var _iconsMaterial = require("@mui/icons-material");
14
13
  var _material = require("@mui/material");
15
14
  var _system = require("@mui/system");
15
+ var _util = require("@ocap/util");
16
16
  var _ahooks = require("ahooks");
17
17
  var _react = require("react");
18
18
  var _reactHookForm = require("react-hook-form");
19
19
  var _api = _interopRequireDefault(require("../api"));
20
20
  var _payment = require("../contexts/payment");
21
- var _util = require("../util");
21
+ var _util2 = require("../util");
22
22
  var _error = _interopRequireDefault(require("./error"));
23
23
  var _footer = _interopRequireDefault(require("./footer"));
24
24
  var _form = _interopRequireDefault(require("./form"));
@@ -44,7 +44,8 @@ function Payment({
44
44
  onPaid,
45
45
  onError,
46
46
  onChange,
47
- goBack
47
+ goBack,
48
+ action
48
49
  }) {
49
50
  const {
50
51
  t
@@ -72,8 +73,9 @@ function Payment({
72
73
  }, [checkoutSession, livemode, setLivemode, refresh]);
73
74
  if (error) {
74
75
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(_error.default, {
76
+ mode,
75
77
  title: "Oops",
76
- description: (0, _util.formatError)(error)
78
+ description: (0, _util2.formatError)(error)
77
79
  });
78
80
  }
79
81
  if (!checkoutSession || !delay) {
@@ -92,22 +94,22 @@ function Payment({
92
94
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
93
95
  className: "cko-payment",
94
96
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_payment2.default, {})
95
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_footer.default, {
97
+ }), mode === "standalone" && /* @__PURE__ */(0, _jsxRuntime.jsx)(_footer.default, {
96
98
  className: "cko-footer"
97
99
  })]
98
100
  })
99
101
  });
100
102
  }
101
103
  if (checkoutSession.expires_at <= Math.round(Date.now() / 1e3)) {
102
- return /* @__PURE__ */(0, _jsxRuntime.jsx)(_Center.default, {
103
- children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_error.default, {
104
- title: t("payment.checkout.expired.title"),
105
- description: t("payment.checkout.expired.description")
106
- })
104
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_error.default, {
105
+ mode,
106
+ title: t("payment.checkout.expired.title"),
107
+ description: t("payment.checkout.expired.description")
107
108
  });
108
109
  }
109
110
  if (checkoutSession.status === "complete") {
110
111
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(_error.default, {
112
+ mode,
111
113
  title: t("payment.checkout.complete.title"),
112
114
  description: t("payment.checkout.complete.description")
113
115
  });
@@ -123,7 +125,8 @@ function Payment({
123
125
  onError,
124
126
  onChange,
125
127
  goBack,
126
- mode
128
+ mode,
129
+ action
127
130
  });
128
131
  }
129
132
  PaymentInner.defaultProps = {
@@ -140,7 +143,8 @@ function PaymentInner({
140
143
  onPaid,
141
144
  onError,
142
145
  onChange,
143
- goBack
146
+ goBack,
147
+ action
144
148
  }) {
145
149
  const {
146
150
  t
@@ -169,7 +173,7 @@ function PaymentInner({
169
173
  line2: "",
170
174
  postal_code: ""
171
175
  }, customer?.address || {}, {
172
- country: (0, _util.isValidCountry)(customer?.address?.country || "") ? customer?.address?.country : "us"
176
+ country: (0, _util2.isValidCountry)(customer?.address?.country || "") ? customer?.address?.country : "us"
173
177
  })
174
178
  }
175
179
  });
@@ -178,7 +182,7 @@ function PaymentInner({
178
182
  name: "payment_currency",
179
183
  defaultValue: defaultCurrencyId
180
184
  });
181
- const currency = (0, _util.findCurrency)(paymentMethods, currencyId) || settings.baseCurrency;
185
+ const currency = (0, _util2.findCurrency)(paymentMethods, currencyId) || settings.baseCurrency;
182
186
  const method = paymentMethods.find(x => x.id === currency.payment_method_id);
183
187
  (0, _react.useEffect)(() => {
184
188
  if (onChange) {
@@ -198,7 +202,7 @@ function PaymentInner({
198
202
  });
199
203
  } catch (err) {
200
204
  console.error(err);
201
- _Toast.default.error((0, _util.formatError)(err));
205
+ _Toast.default.error((0, _util2.formatError)(err));
202
206
  }
203
207
  };
204
208
  const onDownsell = async from => {
@@ -213,7 +217,7 @@ function PaymentInner({
213
217
  });
214
218
  } catch (err) {
215
219
  console.error(err);
216
- _Toast.default.error((0, _util.formatError)(err));
220
+ _Toast.default.error((0, _util2.formatError)(err));
217
221
  }
218
222
  };
219
223
  const onApplyCrossSell = async to => {
@@ -228,7 +232,7 @@ function PaymentInner({
228
232
  });
229
233
  } catch (err) {
230
234
  console.error(err);
231
- _Toast.default.error((0, _util.formatError)(err));
235
+ _Toast.default.error((0, _util2.formatError)(err));
232
236
  }
233
237
  };
234
238
  const onCancelCrossSell = async () => {
@@ -241,7 +245,26 @@ function PaymentInner({
241
245
  });
242
246
  } catch (err) {
243
247
  console.error(err);
244
- _Toast.default.error((0, _util.formatError)(err));
248
+ _Toast.default.error((0, _util2.formatError)(err));
249
+ }
250
+ };
251
+ const onChangeAmount = async ({
252
+ priceId,
253
+ amount
254
+ }) => {
255
+ try {
256
+ const {
257
+ data
258
+ } = await _api.default.put(`/api/checkout-sessions/${state.checkoutSession.id}/amount`, {
259
+ priceId,
260
+ amount: (0, _util.fromTokenToUnit)(amount, currency.decimal).toString()
261
+ });
262
+ setState({
263
+ checkoutSession: data
264
+ });
265
+ } catch (err) {
266
+ console.error(err);
267
+ _Toast.default.error((0, _util2.formatError)(err));
245
268
  }
246
269
  };
247
270
  const handlePaid = result => {
@@ -268,7 +291,7 @@ function PaymentInner({
268
291
  className: "cko-container",
269
292
  sx: {
270
293
  gap: {
271
- sm: mode === "standalone" ? 0 : 8
294
+ sm: mode === "standalone" ? 0 : mode === "inline" ? 4 : 8
272
295
  }
273
296
  },
274
297
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Fade, {
@@ -288,28 +311,37 @@ function PaymentInner({
288
311
  onDownsell,
289
312
  onApplyCrossSell,
290
313
  onCancelCrossSell,
314
+ onChangeAmount,
291
315
  checkoutSessionId: state.checkoutSession.id,
292
- crossSellBehavior: state.checkoutSession.cross_sell_behavior
316
+ crossSellBehavior: state.checkoutSession.cross_sell_behavior,
317
+ donationSettings: paymentLink?.donation_settings,
318
+ action
293
319
  })]
294
320
  })
295
321
  }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
296
322
  className: "cko-payment",
297
323
  direction: "column",
298
- spacing: 4,
324
+ spacing: {
325
+ xs: 2,
326
+ sm: 4
327
+ },
299
328
  children: [completed && /* @__PURE__ */(0, _jsxRuntime.jsx)(_success.default, {
300
- payee: (0, _util.getStatementDescriptor)(state.checkoutSession.line_items),
329
+ mode,
330
+ payee: (0, _util2.getStatementDescriptor)(state.checkoutSession.line_items),
301
331
  action: state.checkoutSession.mode,
302
332
  invoiceId: state.checkoutSession.invoice_id,
303
333
  subscriptionId: state.checkoutSession.subscription_id,
304
- message: paymentLink?.after_completion?.hosted_confirmation?.custom_message || t(`payment.checkout.completed.${state.checkoutSession.mode}`)
334
+ message: paymentLink?.after_completion?.hosted_confirmation?.custom_message || t(`payment.checkout.completed.${paymentLink?.donation_settings ? "donate" : state.checkoutSession.mode}`)
305
335
  }), !completed && /* @__PURE__ */(0, _jsxRuntime.jsx)(_form.default, {
306
336
  checkoutSession: state.checkoutSession,
307
337
  paymentMethods,
308
338
  paymentIntent,
339
+ paymentLink,
309
340
  customer,
310
341
  onPaid: handlePaid,
311
342
  onError,
312
- mode
343
+ mode,
344
+ action
313
345
  })]
314
346
  }), mode === "standalone" && /* @__PURE__ */(0, _jsxRuntime.jsx)(_footer.default, {
315
347
  className: "cko-footer"
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import type { DonationSettings, TLineItemExpanded } from '@blocklet/payment-types';
3
+ export default function ProductDonation({ item, settings, onChange, }: {
4
+ item: TLineItemExpanded;
5
+ settings: DonationSettings;
6
+ onChange: Function;
7
+ }): import("react").JSX.Element;
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ module.exports = ProductDonation;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _context = require("@arcblock/ux/lib/Locale/context");
9
+ var _material = require("@mui/material");
10
+ var _ahooks = require("ahooks");
11
+ var _react = require("react");
12
+ var _switchButton = _interopRequireDefault(require("../components/switch-button"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ function ProductDonation({
15
+ item,
16
+ settings,
17
+ onChange
18
+ }) {
19
+ const {
20
+ t
21
+ } = (0, _context.useLocaleContext)();
22
+ const preset = settings.amount.preset || settings.amount.presets?.[0] || "0";
23
+ const [state, setState] = (0, _ahooks.useSetState)({
24
+ selected: preset,
25
+ input: "",
26
+ custom: settings.amount.presets?.length === 0,
27
+ error: ""
28
+ });
29
+ (0, _react.useEffect)(() => {
30
+ if (settings.amount.preset) {
31
+ setState({
32
+ selected: settings.amount.preset,
33
+ custom: false
34
+ });
35
+ } else if (settings.amount.presets && settings.amount.presets.length > 0) {
36
+ setState({
37
+ selected: settings.amount.presets[0],
38
+ custom: false
39
+ });
40
+ }
41
+ }, [settings.amount.preset, settings.amount.presets, setState]);
42
+ const handleSelect = amount => {
43
+ setState({
44
+ selected: amount,
45
+ custom: false,
46
+ error: ""
47
+ });
48
+ onChange({
49
+ priceId: item.price_id,
50
+ amount
51
+ });
52
+ };
53
+ const handleInput = event => {
54
+ const {
55
+ value
56
+ } = event.target;
57
+ const min = parseFloat(settings.amount.minimum || "0");
58
+ const max = settings.amount.maximum ? parseFloat(settings.amount.maximum) : Infinity;
59
+ if (value < min || value > max) {
60
+ setState({
61
+ input: value,
62
+ error: t("payment.checkout.donation.between", {
63
+ min,
64
+ max
65
+ })
66
+ });
67
+ return;
68
+ }
69
+ setState({
70
+ error: "",
71
+ input: value
72
+ });
73
+ onChange({
74
+ priceId: item.price_id,
75
+ amount: value
76
+ });
77
+ };
78
+ const handleToggle = event => {
79
+ if (event.target.checked) {
80
+ setState({
81
+ custom: true,
82
+ input: state.selected,
83
+ error: ""
84
+ });
85
+ } else {
86
+ setState({
87
+ custom: false,
88
+ input: "",
89
+ error: ""
90
+ });
91
+ }
92
+ };
93
+ return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
94
+ display: "flex",
95
+ flexDirection: "column",
96
+ alignItems: "flex-start",
97
+ gap: 1.5,
98
+ children: [settings.amount.custom && preset !== "0" && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.FormControlLabel, {
99
+ control: /* @__PURE__ */(0, _jsxRuntime.jsx)(_switchButton.default, {
100
+ checked: state.custom,
101
+ sx: {
102
+ marginRight: 0.4
103
+ },
104
+ onChange: handleToggle
105
+ }),
106
+ label: state.custom ? t("payment.checkout.donation.select") : t("payment.checkout.donation.custom"),
107
+ sx: {
108
+ marginRight: 2,
109
+ marginLeft: 0.5,
110
+ color: "text.secondary"
111
+ }
112
+ }), !state.custom && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
113
+ display: "flex",
114
+ flexWrap: "wrap",
115
+ alignItems: "center",
116
+ gap: 1.5,
117
+ children: settings.amount.presets && settings.amount.presets.length > 0 && settings.amount.presets.map(amount => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Card, {
118
+ variant: "outlined",
119
+ sx: {
120
+ minWidth: 120,
121
+ textAlign: "center",
122
+ ...(state.selected === amount && !state.custom ? {
123
+ borderColor: "primary.main"
124
+ } : {})
125
+ },
126
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CardActionArea, {
127
+ onClick: () => handleSelect(amount),
128
+ children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
129
+ direction: "row",
130
+ sx: {
131
+ py: 1
132
+ },
133
+ spacing: 0.5,
134
+ alignItems: "flex-end",
135
+ justifyContent: "center",
136
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
137
+ component: "strong",
138
+ lineHeight: 1,
139
+ variant: "h5",
140
+ sx: {
141
+ fontVariantNumeric: "tabular-nums",
142
+ fontWeight: 400
143
+ },
144
+ children: amount
145
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
146
+ component: "small",
147
+ lineHeight: 1,
148
+ fontSize: 12,
149
+ children: "ABT"
150
+ }), " "]
151
+ })
152
+ })
153
+ }, amount))
154
+ }), state.custom && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.TextField, {
155
+ label: preset !== "0" ? null : t("payment.checkout.donation.custom"),
156
+ type: "number",
157
+ value: state.input,
158
+ onChange: handleInput,
159
+ inputProps: {
160
+ min: settings.amount.minimum,
161
+ max: settings.amount.maximum
162
+ },
163
+ margin: "none",
164
+ fullWidth: true,
165
+ error: !!state.error,
166
+ helperText: state.error
167
+ })]
168
+ });
169
+ }
@@ -27,7 +27,7 @@ function OverviewSkeleton() {
27
27
  }
28
28
  })]
29
29
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
30
- mt: 3,
30
+ mt: 2,
31
31
  component: "div",
32
32
  variant: "h4",
33
33
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {})
@@ -37,7 +37,7 @@ function OverviewSkeleton() {
37
37
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {})
38
38
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
39
39
  sx: {
40
- mt: 3
40
+ mt: 2
41
41
  },
42
42
  variant: "rounded",
43
43
  width: 200,
@@ -11,7 +11,7 @@ function PaymentSkeleton() {
11
11
  in: true,
12
12
  children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
13
13
  direction: "column",
14
- spacing: 3,
14
+ spacing: 2,
15
15
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
16
16
  variant: "text",
17
17
  sx: {
@@ -38,16 +38,12 @@ function PaymentSkeleton() {
38
38
  variant: "h1",
39
39
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {})
40
40
  })]
41
- }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
42
- children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
41
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
42
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
43
43
  component: "div",
44
44
  variant: "h4",
45
45
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {})
46
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
47
- component: "div",
48
- variant: "h1",
49
- children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {})
50
- })]
46
+ })
51
47
  })]
52
48
  })
53
49
  });
@@ -1,12 +1,13 @@
1
1
  /// <reference types="react" />
2
2
  type Props = {
3
+ mode: string;
3
4
  message: string;
4
5
  action: string;
5
6
  payee: string;
6
7
  invoiceId?: string;
7
8
  subscriptionId?: string;
8
9
  };
9
- declare function PaymentSuccess({ message, action, payee, invoiceId, subscriptionId }: Props): import("react").JSX.Element;
10
+ declare function PaymentSuccess({ mode, message, action, payee, invoiceId, subscriptionId }: Props): import("react").JSX.Element;
10
11
  declare namespace PaymentSuccess {
11
12
  var defaultProps: {
12
13
  invoiceId: string;
@@ -11,6 +11,7 @@ var _system = require("@mui/system");
11
11
  var _ufo = require("ufo");
12
12
  var _payment = require("../contexts/payment");
13
13
  function PaymentSuccess({
14
+ mode,
14
15
  message,
15
16
  action,
16
17
  payee,
@@ -56,9 +57,9 @@ function PaymentSuccess({
56
57
  children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
57
58
  direction: "column",
58
59
  alignItems: "center",
59
- justifyContent: "center",
60
+ justifyContent: mode === "standalone" ? "center" : "flex-start",
60
61
  sx: {
61
- height: 360
62
+ height: mode === "standalone" ? 360 : 300
62
63
  },
63
64
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(Div, {
64
65
  children: /* @__PURE__ */(0, _jsxRuntime.jsxs)("div", {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import type { TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
2
+ import type { DonationSettings, TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
3
3
  type Props = {
4
4
  items: TLineItemExpanded[];
5
5
  currency: TPaymentCurrency;
@@ -8,21 +8,27 @@ type Props = {
8
8
  showStaking?: boolean;
9
9
  onUpsell?: Function;
10
10
  onDownsell?: Function;
11
+ onChangeAmount?: Function;
11
12
  onApplyCrossSell?: Function;
12
13
  onCancelCrossSell?: Function;
13
14
  checkoutSessionId?: string;
14
15
  crossSellBehavior?: string;
16
+ donationSettings?: DonationSettings;
17
+ action?: string;
15
18
  };
16
- declare function PaymentSummary({ items, currency, trialInDays, billingThreshold, onUpsell, onDownsell, onApplyCrossSell, onCancelCrossSell, checkoutSessionId, crossSellBehavior, showStaking, ...rest }: Props): import("react").JSX.Element;
19
+ declare function PaymentSummary({ items, currency, trialInDays, billingThreshold, onUpsell, onDownsell, onApplyCrossSell, onCancelCrossSell, onChangeAmount, checkoutSessionId, crossSellBehavior, showStaking, donationSettings, action, ...rest }: Props): import("react").JSX.Element;
17
20
  declare namespace PaymentSummary {
18
21
  var defaultProps: {
19
22
  onUpsell: any;
20
23
  onDownsell: any;
21
24
  onApplyCrossSell: any;
22
25
  onCancelCrossSell: any;
26
+ onChangeAmount: any;
23
27
  checkoutSessionId: string;
24
28
  crossSellBehavior: string;
25
29
  showStaking: boolean;
30
+ donationSettings: null;
31
+ action: string;
26
32
  };
27
33
  }
28
34
  export default PaymentSummary;
@@ -17,6 +17,7 @@ var _api = _interopRequireDefault(require("../api"));
17
17
  var _status = _interopRequireDefault(require("../components/status"));
18
18
  var _util2 = require("../util");
19
19
  var _amount = _interopRequireDefault(require("./amount"));
20
+ var _productDonation = _interopRequireDefault(require("./product-donation"));
20
21
  var _productItem = _interopRequireDefault(require("./product-item"));
21
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
23
  const shake = (0, _material.keyframes)`
@@ -78,9 +79,12 @@ PaymentSummary.defaultProps = {
78
79
  onDownsell: _noop.default,
79
80
  onApplyCrossSell: _noop.default,
80
81
  onCancelCrossSell: _noop.default,
82
+ onChangeAmount: _noop.default,
81
83
  checkoutSessionId: "",
82
84
  crossSellBehavior: "",
83
- showStaking: false
85
+ showStaking: false,
86
+ donationSettings: null,
87
+ action: ""
84
88
  };
85
89
  function PaymentSummary({
86
90
  items,
@@ -91,9 +95,12 @@ function PaymentSummary({
91
95
  onDownsell,
92
96
  onApplyCrossSell,
93
97
  onCancelCrossSell,
98
+ onChangeAmount,
94
99
  checkoutSessionId,
95
100
  crossSellBehavior,
96
101
  showStaking,
102
+ donationSettings,
103
+ action,
97
104
  ...rest
98
105
  }) {
99
106
  const {
@@ -169,7 +176,10 @@ function PaymentSummary({
169
176
  direction: "column",
170
177
  alignItems: "flex-start",
171
178
  sx: {
172
- mb: 4
179
+ mb: {
180
+ xs: 0,
181
+ sm: 3
182
+ }
173
183
  },
174
184
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
175
185
  sx: {
@@ -177,7 +187,7 @@ function PaymentSummary({
177
187
  fontSize: "1.15rem",
178
188
  color: "text.secondary"
179
189
  },
180
- children: headlines.action
190
+ children: action || headlines.action
181
191
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_amount.default, {
182
192
  amount: headlines.amount
183
193
  }), headlines.then && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
@@ -188,8 +198,15 @@ function PaymentSummary({
188
198
  children: headlines.then
189
199
  })]
190
200
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
191
- spacing: 2,
192
- children: items.map(x => /* @__PURE__ */(0, _jsxRuntime.jsx)(_productItem.default, {
201
+ spacing: {
202
+ xs: 1,
203
+ sm: 2
204
+ },
205
+ children: items.map(x => x.price.custom_unit_amount && onChangeAmount && donationSettings ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_productDonation.default, {
206
+ item: x,
207
+ settings: donationSettings,
208
+ onChange: onChangeAmount
209
+ }, `${x.price_id}-${currency.id}`) : /* @__PURE__ */(0, _jsxRuntime.jsx)(_productItem.default, {
193
210
  item: x,
194
211
  items,
195
212
  trialInDays,
@@ -217,7 +234,10 @@ function PaymentSummary({
217
234
  borderRadius: 1,
218
235
  padding: 1,
219
236
  animation: state.shake ? `${shake} 0.2s 5 ease-in-out` : "none",
220
- mt: 3
237
+ mt: {
238
+ xs: 1,
239
+ sm: 2
240
+ }
221
241
  },
222
242
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_productItem.default, {
223
243
  item: {
@@ -267,7 +287,10 @@ function PaymentSummary({
267
287
  border: "1px solid #eee",
268
288
  borderRadius: 1,
269
289
  padding: 1,
270
- mt: 3
290
+ mt: {
291
+ xs: 1,
292
+ sm: 2
293
+ }
271
294
  },
272
295
  children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
273
296
  direction: "row",
@@ -7,6 +7,7 @@ export type CheckoutContext = {
7
7
  paymentIntent?: TPaymentIntent;
8
8
  customer?: TCustomer;
9
9
  mode: LiteralUnion<'standalone' | 'inline' | 'popup', string>;
10
+ action?: string;
10
11
  };
11
12
  export type CheckoutFormData = {
12
13
  customer_name: string;
@@ -26,6 +27,7 @@ export type CheckoutFormData = {
26
27
  export type CheckoutProps = Partial<CheckoutCallbacks> & {
27
28
  id: string;
28
29
  extraParams?: Record<string, any>;
30
+ action?: string;
29
31
  mode?: LiteralUnion<'standalone' | 'inline' | 'popup' | 'inline-minimal' | 'popup-minimal', string>;
30
32
  };
31
33
  export type CheckoutCallbacks = {
package/lib/util.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import type { PaymentDetails, PriceCurrency, PriceRecurring, TLineItemExpanded, TPaymentCurrency, TPaymentMethod, TPaymentMethodExpanded, TPrice, TSubscriptionExpanded, TSubscriptionItemExpanded } from '@blocklet/payment-types';
3
3
  export declare const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
4
+ export declare const isPaymentKitMounted: () => any;
4
5
  export declare const getPrefix: () => any;
5
6
  export declare function formatToDate(date: Date | string | number, locale?: string): any;
6
7
  export declare function formatToDatetime(date: Date | string | number, locale?: string): any;
@@ -25,6 +26,7 @@ export declare function formatLineItemPricing(item: TLineItemExpanded, currency:
25
26
  export declare function getSubscriptionStatusColor(status: string): "success" | "primary" | "warning" | "error" | "default";
26
27
  export declare function getPaymentIntentStatusColor(status: string): "success" | "warning" | "default";
27
28
  export declare function getRefundStatusColor(status: string): "success" | "warning" | "default";
29
+ export declare function getPayoutStatusColor(status: string): "success" | "warning" | "default";
28
30
  export declare function getInvoiceStatusColor(status: string): "success" | "warning" | "default" | "secondary";
29
31
  export declare function getWebhookStatusColor(status: string): "success" | "default";
30
32
  export declare function getCheckoutAmount(items: TLineItemExpanded[], currency: TPaymentCurrency, trialing?: boolean, upsell?: boolean): {