@blocklet/payment-react 1.13.160 → 1.13.161

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 (57) hide show
  1. package/es/components/input.d.ts +3 -1
  2. package/es/components/input.js +12 -3
  3. package/es/history/invoice/list.js +1 -1
  4. package/es/history/payment/list.js +1 -1
  5. package/es/index.d.ts +5 -1
  6. package/es/index.js +8 -0
  7. package/es/locales/en.js +13 -3
  8. package/es/locales/zh.js +13 -3
  9. package/es/payment/form/address.js +2 -1
  10. package/es/payment/form/currency.d.ts +9 -0
  11. package/es/payment/form/currency.js +81 -0
  12. package/es/payment/form/index.js +10 -44
  13. package/es/payment/index.js +11 -49
  14. package/es/payment/product-item.d.ts +4 -3
  15. package/es/payment/product-item.js +13 -4
  16. package/es/payment/success.d.ts +8 -2
  17. package/es/payment/success.js +5 -2
  18. package/es/payment/summary.d.ts +21 -8
  19. package/es/payment/summary.js +28 -12
  20. package/es/util.d.ts +6 -3
  21. package/es/util.js +19 -8
  22. package/lib/components/input.d.ts +3 -1
  23. package/lib/components/input.js +4 -2
  24. package/lib/history/invoice/list.js +1 -1
  25. package/lib/history/payment/list.js +1 -1
  26. package/lib/index.d.ts +5 -1
  27. package/lib/index.js +32 -0
  28. package/lib/locales/en.js +13 -3
  29. package/lib/locales/zh.js +13 -3
  30. package/lib/payment/form/address.js +4 -1
  31. package/lib/payment/form/currency.d.ts +9 -0
  32. package/lib/payment/form/currency.js +106 -0
  33. package/lib/payment/form/index.js +8 -60
  34. package/lib/payment/index.js +13 -49
  35. package/lib/payment/product-item.d.ts +4 -3
  36. package/lib/payment/product-item.js +5 -4
  37. package/lib/payment/success.d.ts +8 -2
  38. package/lib/payment/success.js +6 -2
  39. package/lib/payment/summary.d.ts +21 -8
  40. package/lib/payment/summary.js +26 -11
  41. package/lib/util.d.ts +6 -3
  42. package/lib/util.js +22 -9
  43. package/package.json +10 -10
  44. package/src/components/input.tsx +12 -2
  45. package/src/history/invoice/list.tsx +1 -1
  46. package/src/history/payment/list.tsx +1 -1
  47. package/src/index.ts +8 -0
  48. package/src/locales/en.tsx +14 -1
  49. package/src/locales/zh.tsx +12 -1
  50. package/src/payment/form/address.tsx +1 -0
  51. package/src/payment/form/currency.tsx +91 -0
  52. package/src/payment/form/index.tsx +12 -53
  53. package/src/payment/index.tsx +18 -50
  54. package/src/payment/product-item.tsx +16 -11
  55. package/src/payment/success.tsx +9 -2
  56. package/src/payment/summary.tsx +41 -21
  57. package/src/util.ts +24 -10
@@ -7,17 +7,19 @@ type InputProps = TextFieldProps & {
7
7
  placeholder?: string;
8
8
  errorPosition?: 'right' | 'bottom';
9
9
  rules?: RegisterOptions;
10
+ wrapperStyle?: React.CSSProperties;
10
11
  };
11
12
  export declare function FormInputError({ error }: {
12
13
  error: string;
13
14
  }): import("react").JSX.Element;
14
- declare function FormInput({ name, label, placeholder, rules, errorPosition, ...rest }: InputProps): import("react").JSX.Element;
15
+ declare function FormInput({ name, label, placeholder, rules, errorPosition, wrapperStyle, ...rest }: InputProps): import("react").JSX.Element;
15
16
  declare namespace FormInput {
16
17
  var defaultProps: {
17
18
  label: string;
18
19
  placeholder: string;
19
20
  errorPosition: string;
20
21
  rules: {};
22
+ wrapperStyle: {};
21
23
  };
22
24
  }
23
25
  export default FormInput;
@@ -6,12 +6,21 @@ FormInput.defaultProps = {
6
6
  label: "",
7
7
  placeholder: "",
8
8
  errorPosition: "bottom",
9
- rules: {}
9
+ rules: {},
10
+ wrapperStyle: {}
10
11
  };
11
12
  export function FormInputError({ error }) {
12
13
  return /* @__PURE__ */ jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx(Typography, { component: "span", color: "error", children: error }) });
13
14
  }
14
- export default function FormInput({ name, label, placeholder, rules, errorPosition, ...rest }) {
15
+ export default function FormInput({
16
+ name,
17
+ label,
18
+ placeholder,
19
+ rules,
20
+ errorPosition,
21
+ wrapperStyle,
22
+ ...rest
23
+ }) {
15
24
  const { control, formState } = useFormContext();
16
25
  const error = get(formState.errors, name)?.message;
17
26
  return /* @__PURE__ */ jsx(
@@ -20,7 +29,7 @@ export default function FormInput({ name, label, placeholder, rules, errorPositi
20
29
  name,
21
30
  control,
22
31
  rules,
23
- render: ({ field }) => /* @__PURE__ */ jsxs(Box, { sx: { width: "100%", height: "40px" }, children: [
32
+ render: ({ field }) => /* @__PURE__ */ jsxs(Box, { sx: { width: "100%", ...wrapperStyle }, children: [
24
33
  !!label && /* @__PURE__ */ jsx(FormLabel, { children: label }),
25
34
  /* @__PURE__ */ jsx(
26
35
  TextField,
@@ -97,5 +97,5 @@ CustomerInvoiceList.defaultProps = {
97
97
  subscription_id: "",
98
98
  status: "open,paid,uncollectible",
99
99
  pageSize: 10,
100
- target: "self"
100
+ target: "_self"
101
101
  };
@@ -65,7 +65,7 @@ export default function CustomerPaymentList({ customer_id }) {
65
65
  children: [
66
66
  /* @__PURE__ */ jsx(Box, { flex: 3, children: /* @__PURE__ */ jsx(Typography, { children: formatToDate(item.created_at) }) }),
67
67
  /* @__PURE__ */ jsx(Box, { flex: 2, children: /* @__PURE__ */ jsxs(Typography, { textAlign: "right", children: [
68
- fromUnitToToken(item.amount, item.paymentCurrency.decimal),
68
+ fromUnitToToken(item.amount_received, item.paymentCurrency.decimal),
69
69
  "\xA0",
70
70
  item.paymentCurrency.symbol
71
71
  ] }) }),
package/es/index.d.ts CHANGED
@@ -13,10 +13,14 @@ import CustomerInvoiceList from './history/invoice/list';
13
13
  import MiniInvoiceList from './history/mini-invoice/list';
14
14
  import CustomerPaymentList from './history/payment/list';
15
15
  import Amount from './payment/amount';
16
+ import AddressForm from './payment/form/address';
17
+ import CurrencySelector from './payment/form/currency';
16
18
  import PhoneInput from './payment/form/phone';
19
+ import StripeForm from './payment/form/stripe';
17
20
  import Payment from './payment/index';
18
21
  import ProductSkeleton from './payment/product-skeleton';
22
+ import PaymentSummary from './payment/summary';
19
23
  export * from './util';
20
24
  export * from './contexts/payment';
21
25
  export { translations, createTranslator } from './locales';
22
- export { api, dayjs, FormInput, PhoneInput, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, Payment, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, MiniInvoiceList, TxLink, };
26
+ export { api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, MiniInvoiceList, TxLink, };
package/es/index.js CHANGED
@@ -13,9 +13,13 @@ import CustomerInvoiceList from "./history/invoice/list.js";
13
13
  import MiniInvoiceList from "./history/mini-invoice/list.js";
14
14
  import CustomerPaymentList from "./history/payment/list.js";
15
15
  import Amount from "./payment/amount.js";
16
+ import AddressForm from "./payment/form/address.js";
17
+ import CurrencySelector from "./payment/form/currency.js";
16
18
  import PhoneInput from "./payment/form/phone.js";
19
+ import StripeForm from "./payment/form/stripe.js";
17
20
  import Payment from "./payment/index.js";
18
21
  import ProductSkeleton from "./payment/product-skeleton.js";
22
+ import PaymentSummary from "./payment/summary.js";
19
23
  export * from "./util.js";
20
24
  export * from "./contexts/payment.js";
21
25
  export { translations, createTranslator } from "./locales/index.js";
@@ -24,13 +28,17 @@ export {
24
28
  dayjs,
25
29
  FormInput,
26
30
  PhoneInput,
31
+ AddressForm,
32
+ StripeForm,
27
33
  Status,
28
34
  Livemode,
29
35
  Switch,
30
36
  ConfirmDialog,
31
37
  CheckoutForm,
32
38
  CheckoutTable,
39
+ CurrencySelector,
33
40
  Payment,
41
+ PaymentSummary,
34
42
  PricingTable,
35
43
  ProductSkeleton,
36
44
  Amount,
package/es/locales/en.js CHANGED
@@ -183,7 +183,7 @@ export default flat({
183
183
  title: "Renew your subscription",
184
184
  description: "Your subscription will no longer be canceled, it will renew on {date}"
185
185
  },
186
- upgrade: {
186
+ changePlan: {
187
187
  button: "Update",
188
188
  current: "Current",
189
189
  pay: "Payment Required",
@@ -196,7 +196,16 @@ export default flat({
196
196
  total: "Total (metered items excluded)",
197
197
  appliedCredit: "Credit applied",
198
198
  newCredit: "Credit issued",
199
- remaining: "Amount due today"
199
+ remaining: "Amount due today",
200
+ tableNotFound: "Plan updates are not available"
201
+ },
202
+ changePayment: {
203
+ limit: "Your changes to payment method will not affect existing open or past-due invoices, all future payments will use the new payment method unless you change it again.",
204
+ review: "Review subscription items",
205
+ select: "Select payment method",
206
+ submit: "Confirm change",
207
+ confirm: "By confirming this change, you allow {payee} to charge {symbol} from your account for future payments in accordance with their terms. You can always change your payment method.",
208
+ completed: "Your payment method has been successfully updated, all future payments will use the new payment method unless you change it again."
200
209
  },
201
210
  invoice: {
202
211
  summary: "Summary",
@@ -226,7 +235,8 @@ export default flat({
226
235
  nextInvoice: "Next Invoice",
227
236
  title: "Manage subscriptions",
228
237
  current: "Current subscription",
229
- empty: "There are no subscriptions here"
238
+ empty: "There are no subscriptions here",
239
+ changePayment: "Change payment method"
230
240
  }
231
241
  }
232
242
  }
package/es/locales/zh.js CHANGED
@@ -183,7 +183,7 @@ export default flat({
183
183
  title: "\u7EED\u8BA2\u60A8\u7684\u8BA2\u9605",
184
184
  description: "\u60A8\u7684\u8BA2\u9605\u5C06\u4E0D\u518D\u88AB\u53D6\u6D88\uFF0C\u5C06\u5728{date}\u7EED\u8BA2"
185
185
  },
186
- upgrade: {
186
+ changePlan: {
187
187
  button: "\u66F4\u65B0",
188
188
  current: "\u5F53\u524D\u8BA2\u9605",
189
189
  pay: "\u9700\u8981\u652F\u4ED8",
@@ -196,7 +196,16 @@ export default flat({
196
196
  total: "\u5957\u9910\u5B9A\u4EF7\uFF08\u4E0D\u542B\u6309\u91CF\u90E8\u5206\uFF09",
197
197
  appliedCredit: "\u4FE1\u7528\u6263\u9664",
198
198
  newCredit: "\u4FE1\u7528\u589E\u52A0",
199
- remaining: "\u8FD8\u9700\u652F\u4ED8"
199
+ remaining: "\u8FD8\u9700\u652F\u4ED8",
200
+ tableNotFound: "\u5957\u9910\u53D8\u66F4\u4E0D\u53EF\u7528"
201
+ },
202
+ changePayment: {
203
+ limit: "\u4F60\u5BF9\u652F\u4ED8\u65B9\u5F0F\u7684\u53D8\u66F4\u4E0D\u4F1A\u5F71\u54CD\u5DF2\u7ECF\u751F\u6210\u6216\u8005\u6B20\u8D39\u7684\u8D26\u5355\uFF0C\u53EA\u4F1A\u5F71\u54CD\u672A\u6765\u7684\u8D26\u5355\u3002\u4F60\u53EF\u4EE5\u5728\u4E0B\u4E00\u5F20\u8D26\u5355\u751F\u6210\u4E4B\u524D\u53D8\u66F4\u652F\u4ED8\u65B9\u5F0F\u3002",
204
+ review: "\u67E5\u770B\u8BA2\u9605\u8BE6\u60C5",
205
+ select: "\u9009\u62E9\u652F\u4ED8\u65B9\u5F0F",
206
+ submit: "\u786E\u8BA4\u53D8\u66F4",
207
+ confirm: "\u786E\u8BA4\u53D8\u66F4\u65B9\u5F0F\u610F\u5473\u7740\u4F60\u5141\u8BB8{payee}\u4F7F\u7528\u65B0\u7684\u652F\u4ED8\u65B9\u5F0F\u652F\u4ED8\u4F60\u7684\u672A\u6765\u8D26\u5355\u3002\u4F60\u53EF\u4EE5\u968F\u65F6\u518D\u6B21\u53D8\u66F4\u652F\u4ED8\u65B9\u5F0F\u3002",
208
+ completed: "\u4F60\u7684\u652F\u4ED8\u65B9\u5F0F \u5DF2\u7ECF\u66F4\u65B0\u6210\u529F\u3002\u4F60\u53EF\u4EE5\u5728\u4F60\u7684\u8D26\u6237\u4E2D\u67E5\u770B\u6B64\u652F\u4ED8\u65B9\u5F0F\u7684\u8BE6\u7EC6\u4FE1\u606F\u3002"
200
209
  },
201
210
  invoice: {
202
211
  summary: "\u6458\u8981",
@@ -226,7 +235,8 @@ export default flat({
226
235
  nextInvoice: "\u4E0B\u4E00\u5F20\u53D1\u7968",
227
236
  title: "\u8BA2\u9605\u7BA1\u7406",
228
237
  current: "\u5F53\u524D\u8BA2\u9605",
229
- empty: "\u6CA1\u6709\u4EFB\u4F55\u8BA2\u9605"
238
+ empty: "\u6CA1\u6709\u4EFB\u4F55\u8BA2\u9605",
239
+ changePayment: "\u5207\u6362\u652F\u4ED8\u65B9\u5F0F"
230
240
  }
231
241
  }
232
242
  }
@@ -109,7 +109,8 @@ export default function AddressForm({ mode, stripe }) {
109
109
  rules: { required: t("payment.checkout.required") },
110
110
  errorPosition: "right",
111
111
  variant: "outlined",
112
- placeholder: t("payment.checkout.billing.postal_code")
112
+ placeholder: t("payment.checkout.billing.postal_code"),
113
+ wrapperStyle: { height: "40px" }
113
114
  }
114
115
  )
115
116
  ] }) })
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import type { TPaymentCurrency } from '@blocklet/payment-types';
3
+ type Props = {
4
+ value: number;
5
+ currencies: TPaymentCurrency[];
6
+ onChange: Function;
7
+ };
8
+ export default function CurrencySelector({ value, currencies, onChange }: Props): import("react").JSX.Element;
9
+ export {};
@@ -0,0 +1,81 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Avatar, Card, Stack, Typography } from "@mui/material";
3
+ import { styled } from "@mui/system";
4
+ export default function CurrencySelector({ value, currencies, onChange }) {
5
+ return /* @__PURE__ */ jsx(
6
+ Root,
7
+ {
8
+ style: {
9
+ display: currencies.length > 1 ? "grid" : "block",
10
+ gridTemplateColumns: "50% 50%",
11
+ width: "100%"
12
+ },
13
+ children: currencies.map((x, i) => {
14
+ const selected = i === value;
15
+ return /* @__PURE__ */ jsx(
16
+ Card,
17
+ {
18
+ variant: "outlined",
19
+ onClick: () => onChange(i),
20
+ className: selected ? "cko-payment-card" : "cko-payment-card-unselect",
21
+ children: /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", children: [
22
+ /* @__PURE__ */ jsx(Avatar, { src: x.logo, alt: x.name, sx: { width: 30, height: 30, marginRight: "10px" } }),
23
+ /* @__PURE__ */ jsxs("div", { children: [
24
+ /* @__PURE__ */ jsx(Typography, { variant: "h5", component: "div", sx: { fontSize: "18px" }, children: x.symbol }),
25
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 14 }, color: "text.secondary", gutterBottom: true, children: x.method.name })
26
+ ] })
27
+ ] })
28
+ },
29
+ x.id
30
+ );
31
+ })
32
+ }
33
+ );
34
+ }
35
+ const Root = styled("section")`
36
+ .cko-payment-card {
37
+ position: relative;
38
+ border: 2px solid ${(props) => props.theme.palette.primary.main};
39
+ padding: 5px 10px;
40
+ margin: 5px 0;
41
+ cursor: pointer;
42
+ }
43
+
44
+ .cko-payment-card::before {
45
+ content: '';
46
+ position: absolute;
47
+ right: 0;
48
+ bottom: 0;
49
+ border: 12px solid ${(props) => props.theme.palette.primary.main};
50
+ border-top-color: transparent;
51
+ border-left-color: transparent;
52
+ }
53
+
54
+ .cko-payment-card-unselect {
55
+ border: 2px solid #ddd;
56
+ padding: 5px 10px;
57
+ margin: 5px 0;
58
+ cursor: pointer;
59
+ }
60
+
61
+ .cko-payment-card:nth-child(odd) {
62
+ margin-right: 8px;
63
+ }
64
+
65
+ .cko-payment-card-unselect:nth-child(odd) {
66
+ margin-right: 8px;
67
+ }
68
+
69
+ .cko-payment-card::after {
70
+ content: '';
71
+ width: 6px;
72
+ height: 10px;
73
+ position: absolute;
74
+ right: 3px;
75
+ bottom: 3px;
76
+ border: 2px solid #fff;
77
+ border-top-color: transparent;
78
+ border-left-color: transparent;
79
+ transform: rotate(35deg);
80
+ }
81
+ `;
@@ -4,7 +4,7 @@ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
4
4
  import { useTheme } from "@arcblock/ux/lib/Theme";
5
5
  import Toast from "@arcblock/ux/lib/Toast";
6
6
  import { LoadingButton } from "@mui/lab";
7
- import { Avatar, Card, Fade, InputAdornment, Stack, Typography } from "@mui/material";
7
+ import { Fade, InputAdornment, Stack, Typography } from "@mui/material";
8
8
  import { useCreation, useSetState, useSize } from "ahooks";
9
9
  import { PhoneNumberUtil } from "google-libphonenumber";
10
10
  import pWaitFor from "p-wait-for";
@@ -17,9 +17,10 @@ import api from "../../api.js";
17
17
  import ConfirmDialog from "../../components/confirm.js";
18
18
  import FormInput from "../../components/input.js";
19
19
  import { usePaymentContext } from "../../contexts/payment.js";
20
- import { formatError, getPrefix, getStatementDescriptor } from "../../util.js";
20
+ import { flattenPaymentMethods, formatError, getPrefix, getStatementDescriptor } from "../../util.js";
21
21
  import UserButtons from "./addon.js";
22
22
  import AddressForm from "./address.js";
23
+ import CurrencySelector from "./currency.js";
23
24
  import PhoneInput from "./phone.js";
24
25
  import StripeCheckout from "./stripe.js";
25
26
  const phoneUtil = PhoneNumberUtil.getInstance();
@@ -38,19 +39,6 @@ const waitForCheckoutComplete = async (sessionId) => {
38
39
  );
39
40
  return result;
40
41
  };
41
- const flatPaymentMethods = (methods = []) => {
42
- const out = [];
43
- methods.forEach((method) => {
44
- const currencies = method.paymentCurrencies || method.payment_currencies || [];
45
- currencies.forEach((currency) => {
46
- out.push({
47
- ...currency,
48
- method
49
- });
50
- });
51
- });
52
- return out;
53
- };
54
42
  PaymentForm.defaultProps = {};
55
43
  export default function PaymentForm({
56
44
  checkoutSession,
@@ -75,7 +63,7 @@ export default function PaymentForm({
75
63
  customerLimited: false,
76
64
  stripePaying: false
77
65
  });
78
- const currencies = flatPaymentMethods(paymentMethods);
66
+ const currencies = flattenPaymentMethods(paymentMethods);
79
67
  const [paymentCurrencyIndex, setPaymentCurrencyIndex] = useState(0);
80
68
  useEffect(() => {
81
69
  if (session?.user) {
@@ -108,9 +96,6 @@ export default function PaymentForm({
108
96
  const payee = getStatementDescriptor(checkoutSession.line_items);
109
97
  const buttonText = session?.user ? t(`payment.checkout.${checkoutSession.mode}`) : t("payment.checkout.connect", { action: t(`payment.checkout.${checkoutSession.mode}`) });
110
98
  const method = paymentMethods.find((x) => x.id === paymentMethod);
111
- const handleCurrencyChange = (index) => {
112
- setPaymentCurrencyIndex(index);
113
- };
114
99
  const handleConnected = async () => {
115
100
  try {
116
101
  const result = await waitForCheckoutComplete(checkoutSession.id);
@@ -184,6 +169,7 @@ export default function PaymentForm({
184
169
  setState({ submitting: false, paying: false });
185
170
  },
186
171
  onError: (err) => {
172
+ console.error(err);
187
173
  setState({ submitting: false, paying: false });
188
174
  onError(err);
189
175
  }
@@ -198,6 +184,7 @@ export default function PaymentForm({
198
184
  }
199
185
  }
200
186
  } catch (err) {
187
+ console.error(err);
201
188
  let shouldToast = true;
202
189
  if (err.response?.data?.code) {
203
190
  dispatch(`error.${err.response?.data?.code}`);
@@ -298,32 +285,11 @@ export default function PaymentForm({
298
285
  name: "payment_currency",
299
286
  control,
300
287
  render: () => /* @__PURE__ */ jsx(
301
- "section",
288
+ CurrencySelector,
302
289
  {
303
- style: {
304
- display: currencies.length > 1 ? "grid" : "block",
305
- gridTemplateColumns: "50% 50%",
306
- width: "100%"
307
- },
308
- children: currencies.map((x, i) => {
309
- const selected = i === paymentCurrencyIndex;
310
- return /* @__PURE__ */ jsx(
311
- Card,
312
- {
313
- variant: "outlined",
314
- onClick: () => handleCurrencyChange(i),
315
- className: selected ? "cko-payment-card" : "cko-payment-card-unselect",
316
- children: /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", children: [
317
- /* @__PURE__ */ jsx(Avatar, { src: x.logo, alt: x.name, sx: { width: 30, height: 30, marginRight: "10px" } }),
318
- /* @__PURE__ */ jsxs("div", { children: [
319
- /* @__PURE__ */ jsx(Typography, { variant: "h5", component: "div", sx: { fontSize: "18px" }, children: x.symbol }),
320
- /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 14 }, color: "text.secondary", gutterBottom: true, children: x.method.name })
321
- ] })
322
- ] })
323
- },
324
- x.id
325
- );
326
- })
290
+ value: paymentCurrencyIndex,
291
+ currencies,
292
+ onChange: setPaymentCurrencyIndex
327
293
  }
328
294
  )
329
295
  }
@@ -176,6 +176,10 @@ export function PaymentInner({
176
176
  Toast.error(formatError(err));
177
177
  }
178
178
  };
179
+ const handlePaid = (result) => {
180
+ setState({ checkoutSession: result.checkoutSession });
181
+ onPaid(result);
182
+ };
179
183
  return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsxs(Root, { mode, children: [
180
184
  goBack && /* @__PURE__ */ jsx(
181
185
  ArrowBackOutlined,
@@ -191,12 +195,15 @@ export function PaymentInner({
191
195
  /* @__PURE__ */ jsx(
192
196
  PaymentSummary,
193
197
  {
194
- checkoutSession: state.checkoutSession,
198
+ items: state.checkoutSession.line_items,
199
+ trialInDays: state.checkoutSession.subscription_data?.trial_period_days || 0,
195
200
  currency,
196
201
  onUpsell,
197
202
  onDownsell,
198
203
  onApplyCrossSell,
199
- onCancelCrossSell
204
+ onCancelCrossSell,
205
+ checkoutSessionId: state.checkoutSession.id,
206
+ crossSellBehavior: state.checkoutSession.cross_sell_behavior
200
207
  }
201
208
  )
202
209
  ] }) }),
@@ -206,6 +213,7 @@ export function PaymentInner({
206
213
  {
207
214
  payee: getStatementDescriptor(state.checkoutSession.line_items),
208
215
  action: state.checkoutSession.mode,
216
+ subscriptionId: state.checkoutSession.subscription_id,
209
217
  message: paymentLink?.after_completion?.hosted_confirmation?.custom_message || t(`payment.checkout.completed.${state.checkoutSession.mode}`)
210
218
  }
211
219
  ),
@@ -216,7 +224,7 @@ export function PaymentInner({
216
224
  paymentMethods,
217
225
  paymentIntent,
218
226
  customer,
219
- onPaid,
227
+ onPaid: handlePaid,
220
228
  onError,
221
229
  mode
222
230
  }
@@ -307,52 +315,6 @@ export const Root = styled(Box)`
307
315
  .cko-payment-methods {
308
316
  }
309
317
 
310
- .cko-payment-card {
311
- position: relative;
312
- border: 2px solid #3773f2;
313
- padding: 5px 10px;
314
- margin: 5px 0;
315
- cursor: pointer;
316
- }
317
-
318
- .cko-payment-card::before {
319
- content: '';
320
- position: absolute;
321
- right: 0;
322
- top: 0;
323
- border: 12px solid #3773f2;
324
- border-bottom-color: transparent;
325
- border-left-color: transparent;
326
- }
327
-
328
- .cko-payment-card-unselect {
329
- border: 2px solid #ddd;
330
- padding: 5px 10px;
331
- margin: 5px 0;
332
- cursor: pointer;
333
- }
334
-
335
- .cko-payment-card:nth-child(odd) {
336
- margin-right: 8px;
337
- }
338
-
339
- .cko-payment-card-unselect:nth-child(odd) {
340
- margin-right: 8px;
341
- }
342
-
343
- .cko-payment-card::after {
344
- content: '';
345
- width: 6px;
346
- height: 10px;
347
- position: absolute;
348
- right: 3px;
349
- top: 0px;
350
- border: 2px solid #fff;
351
- border-top-color: transparent;
352
- border-left-color: transparent;
353
- transform: rotate(35deg);
354
- }
355
-
356
318
  .cko-payment-submit {
357
319
  .MuiButtonBase-root {
358
320
  border-radius: 0;
@@ -1,15 +1,16 @@
1
1
  /// <reference types="react" />
2
- import type { TCheckoutSessionExpanded, TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
2
+ import type { TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
3
3
  type Props = {
4
4
  item: TLineItemExpanded;
5
- session: TCheckoutSessionExpanded;
5
+ items: TLineItemExpanded[];
6
+ trialInDays: number;
6
7
  currency: TPaymentCurrency;
7
8
  onUpsell: Function;
8
9
  onDownsell: Function;
9
10
  mode?: 'normal' | 'cross-sell';
10
11
  children?: React.ReactNode;
11
12
  };
12
- declare function ProductItem({ item, session, currency, mode, children, onUpsell, onDownsell }: Props): import("react").JSX.Element;
13
+ declare function ProductItem({ item, items, trialInDays, currency, mode, children, onUpsell, onDownsell, }: Props): import("react").JSX.Element;
13
14
  declare namespace ProductItem {
14
15
  var defaultProps: {
15
16
  mode: string;
@@ -9,12 +9,21 @@ ProductItem.defaultProps = {
9
9
  mode: "normal",
10
10
  children: null
11
11
  };
12
- export default function ProductItem({ item, session, currency, mode, children, onUpsell, onDownsell }) {
12
+ export default function ProductItem({
13
+ item,
14
+ items,
15
+ trialInDays,
16
+ currency,
17
+ mode,
18
+ children,
19
+ onUpsell,
20
+ onDownsell
21
+ }) {
13
22
  const { t, locale } = useLocaleContext();
14
- const pricing = formatLineItemPricing(item, currency, session.subscription_data?.trial_period_days || 0, locale);
15
- const saving = formatUpsellSaving(session, currency);
23
+ const pricing = formatLineItemPricing(item, currency, trialInDays, locale);
24
+ const saving = formatUpsellSaving(items, currency);
16
25
  const metered = item.price?.recurring?.usage_type === "metered" ? t("common.metered") : "";
17
- const canUpsell = mode === "normal" && session.line_items.length === 1;
26
+ const canUpsell = mode === "normal" && items.length === 1;
18
27
  return /* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-start", spacing: 1, sx: { width: "100%" }, children: [
19
28
  /* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-end", sx: { width: "100%" }, children: [
20
29
  /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", justifyContent: "space-between", sx: { width: "100%" }, children: [
@@ -3,6 +3,12 @@ type Props = {
3
3
  message: string;
4
4
  action: string;
5
5
  payee: string;
6
+ subscriptionId?: string;
6
7
  };
7
- export default function PaymentSuccess({ message, action, payee }: Props): import("react").JSX.Element;
8
- export {};
8
+ declare function PaymentSuccess({ message, action, payee, subscriptionId }: Props): import("react").JSX.Element;
9
+ declare namespace PaymentSuccess {
10
+ var defaultProps: {
11
+ subscriptionId: string;
12
+ };
13
+ }
14
+ export default PaymentSuccess;
@@ -4,7 +4,7 @@ import { Grow, Link, Stack, Typography } from "@mui/material";
4
4
  import { styled } from "@mui/system";
5
5
  import { joinURL } from "ufo";
6
6
  import { usePaymentContext } from "../contexts/payment.js";
7
- export default function PaymentSuccess({ message, action, payee }) {
7
+ export default function PaymentSuccess({ message, action, payee, subscriptionId }) {
8
8
  const { t } = useLocaleContext();
9
9
  const { prefix } = usePaymentContext();
10
10
  return /* @__PURE__ */ jsx(Grow, { in: true, children: /* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "center", justifyContent: "center", sx: { height: 360 }, children: [
@@ -16,9 +16,12 @@ export default function PaymentSuccess({ message, action, payee }) {
16
16
  ] }) }),
17
17
  /* @__PURE__ */ jsx(Typography, { variant: "h5", color: "text.primary", mb: 3, children: message }),
18
18
  /* @__PURE__ */ jsx(Typography, { variant: "body1", color: "text.secondary", textAlign: "center", children: t("payment.checkout.completed.tip", { payee }) }),
19
- ["subscription", "setup"].includes(action) && /* @__PURE__ */ jsx(Typography, { textAlign: "center", sx: { mt: 2 }, children: /* @__PURE__ */ jsx(Link, { href: joinURL(prefix, "/customer"), children: t("payment.checkout.portal", { payee }) }) })
19
+ ["subscription", "setup"].includes(action) && /* @__PURE__ */ jsx(Typography, { textAlign: "center", sx: { mt: 2 }, children: /* @__PURE__ */ jsx(Link, { href: joinURL(prefix, `/customer/subscription/${subscriptionId}`), children: t("payment.checkout.portal", { payee }) }) })
20
20
  ] }) });
21
21
  }
22
+ PaymentSuccess.defaultProps = {
23
+ subscriptionId: ""
24
+ };
22
25
  const Div = styled("div")`
23
26
  width: 80px;
24
27
  height: 115px;
@@ -1,12 +1,25 @@
1
1
  /// <reference types="react" />
2
- import type { TCheckoutSessionExpanded, TPaymentCurrency } from '@blocklet/payment-types';
2
+ import type { TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
3
3
  type Props = {
4
- checkoutSession: TCheckoutSessionExpanded;
4
+ items: TLineItemExpanded[];
5
5
  currency: TPaymentCurrency;
6
- onUpsell: Function;
7
- onDownsell: Function;
8
- onApplyCrossSell: Function;
9
- onCancelCrossSell: Function;
6
+ trialInDays: number;
7
+ onUpsell?: Function;
8
+ onDownsell?: Function;
9
+ onApplyCrossSell?: Function;
10
+ onCancelCrossSell?: Function;
11
+ checkoutSessionId?: string;
12
+ crossSellBehavior?: string;
10
13
  };
11
- export default function PaymentSummary({ checkoutSession, currency, onUpsell, onDownsell, onApplyCrossSell, onCancelCrossSell, }: Props): import("react").JSX.Element;
12
- export {};
14
+ declare function PaymentSummary({ items, currency, trialInDays, onUpsell, onDownsell, onApplyCrossSell, onCancelCrossSell, checkoutSessionId, crossSellBehavior, ...rest }: Props): import("react").JSX.Element;
15
+ declare namespace PaymentSummary {
16
+ var defaultProps: {
17
+ onUpsell: any;
18
+ onDownsell: any;
19
+ onApplyCrossSell: any;
20
+ onCancelCrossSell: any;
21
+ checkoutSessionId: string;
22
+ crossSellBehavior: string;
23
+ };
24
+ }
25
+ export default PaymentSummary;