@blocklet/payment-react 1.15.8 → 1.15.9

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.
@@ -94,7 +94,7 @@ const InvoiceTable = React.memo((props) => {
94
94
  ignore_zero: true
95
95
  }),
96
96
  {
97
- refreshDeps: [search]
97
+ refreshDeps: [search, status, customer_id, currency_id, subscription_id, include_staking, include_recovered_from]
98
98
  }
99
99
  );
100
100
  useEffect(() => {
@@ -2,7 +2,7 @@
2
2
  import 'react-international-phone/style.css';
3
3
  import { CheckoutCallbacks, CheckoutContext } from '../../types';
4
4
  type PageData = CheckoutContext & CheckoutCallbacks;
5
- declare function PaymentForm({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, onPaid, onError, action, }: PageData): import("react").JSX.Element;
5
+ declare function PaymentForm({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, onPaid, onError, action, currencyId, }: PageData): import("react").JSX.Element;
6
6
  declare namespace PaymentForm {
7
7
  var defaultProps: {};
8
8
  }
@@ -61,7 +61,8 @@ export default function PaymentForm({
61
61
  onPaid,
62
62
  onError,
63
63
  // mode,
64
- action
64
+ action,
65
+ currencyId
65
66
  }) {
66
67
  const { t } = useLocaleContext();
67
68
  const { isMobile } = useMobile();
@@ -98,7 +99,8 @@ export default function PaymentForm({
98
99
  const currencies = flattenPaymentMethods(paymentMethods);
99
100
  const [paymentCurrencyIndex, setPaymentCurrencyIndex] = useState(() => {
100
101
  const query = getQueryParams(window.location.href);
101
- const index = currencies.findIndex((x) => x.id === query.currencyId);
102
+ const queryCurrencyId = query.currencyId || currencyId;
103
+ const index = currencies.findIndex((x) => x.id === queryCurrencyId);
102
104
  return index >= 0 ? index : 0;
103
105
  });
104
106
  const onCheckoutComplete = useMemoizedFn(async ({ response }) => {
@@ -12,7 +12,14 @@ import { FormProvider, useForm, useWatch } from "react-hook-form";
12
12
  import trim from "lodash/trim";
13
13
  import { usePaymentContext } from "../contexts/payment.js";
14
14
  import api from "../libs/api.js";
15
- import { findCurrency, formatError, getStatementDescriptor, isMobileSafari, isValidCountry } from "../libs/util.js";
15
+ import {
16
+ findCurrency,
17
+ formatError,
18
+ getQueryParams,
19
+ getStatementDescriptor,
20
+ isMobileSafari,
21
+ isValidCountry
22
+ } from "../libs/util.js";
16
23
  import PaymentError from "./error.js";
17
24
  import CheckoutFooter from "./footer.js";
18
25
  import PaymentForm from "./form/index.js";
@@ -43,7 +50,8 @@ function PaymentInner({
43
50
  const { settings, session } = usePaymentContext();
44
51
  const { isMobile } = useMobile();
45
52
  const [state, setState] = useSetState({ checkoutSession });
46
- const defaultCurrencyId = state.checkoutSession.currency_id || state.checkoutSession.line_items[0]?.price.currency_id;
53
+ const query = getQueryParams(window.location.href);
54
+ const defaultCurrencyId = query.currencyId || state.checkoutSession.currency_id || state.checkoutSession.line_items[0]?.price.currency_id;
47
55
  const defaultMethodId = paymentMethods.find((m) => m.payment_currencies.some((c) => c.id === defaultCurrencyId))?.id;
48
56
  const hideSummaryCard = mode.endsWith("-minimal") || !showCheckoutSummary;
49
57
  const methods = useForm({
@@ -86,6 +94,14 @@ function PaymentInner({
86
94
  document.body.removeEventListener("focusout", focusoutHandler);
87
95
  };
88
96
  }, []);
97
+ useEffect(() => {
98
+ if (!methods || query.currencyId) {
99
+ return;
100
+ }
101
+ if (state.checkoutSession.currency_id !== defaultCurrencyId) {
102
+ methods.setValue("payment_currency", state.checkoutSession.currency_id);
103
+ }
104
+ }, [state.checkoutSession, defaultCurrencyId, query.currencyId]);
89
105
  const currencyId = useWatch({ control: methods.control, name: "payment_currency", defaultValue: defaultCurrencyId });
90
106
  const currency = findCurrency(paymentMethods, currencyId) || settings.baseCurrency;
91
107
  const method = paymentMethods.find((x) => x.id === currency.payment_method_id);
@@ -207,6 +223,7 @@ function PaymentInner({
207
223
  !completed && /* @__PURE__ */ jsx(
208
224
  PaymentForm,
209
225
  {
226
+ currencyId,
210
227
  checkoutSession: state.checkoutSession,
211
228
  paymentMethods,
212
229
  paymentIntent,
@@ -10,6 +10,7 @@ export type CheckoutContext = {
10
10
  mode: LiteralUnion<'standalone' | 'inline' | 'popup', string>;
11
11
  action?: string;
12
12
  showCheckoutSummary?: boolean;
13
+ currencyId?: string;
13
14
  };
14
15
  export type CheckoutFormData = {
15
16
  customer_name: string;
@@ -96,7 +96,7 @@ const InvoiceTable = _react.default.memo(props => {
96
96
  include_recovered_from,
97
97
  ignore_zero: true
98
98
  }), {
99
- refreshDeps: [search]
99
+ refreshDeps: [search, status, customer_id, currency_id, subscription_id, include_staking, include_recovered_from]
100
100
  });
101
101
  (0, _react.useEffect)(() => {
102
102
  if (onTableDataChange) {
@@ -2,7 +2,7 @@
2
2
  import 'react-international-phone/style.css';
3
3
  import { CheckoutCallbacks, CheckoutContext } from '../../types';
4
4
  type PageData = CheckoutContext & CheckoutCallbacks;
5
- declare function PaymentForm({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, onPaid, onError, action, }: PageData): import("react").JSX.Element;
5
+ declare function PaymentForm({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, onPaid, onError, action, currencyId, }: PageData): import("react").JSX.Element;
6
6
  declare namespace PaymentForm {
7
7
  var defaultProps: {};
8
8
  }
@@ -63,7 +63,8 @@ function PaymentForm({
63
63
  onPaid,
64
64
  onError,
65
65
  // mode,
66
- action
66
+ action,
67
+ currencyId
67
68
  }) {
68
69
  const {
69
70
  t
@@ -110,7 +111,8 @@ function PaymentForm({
110
111
  const currencies = (0, _util.flattenPaymentMethods)(paymentMethods);
111
112
  const [paymentCurrencyIndex, setPaymentCurrencyIndex] = (0, _react.useState)(() => {
112
113
  const query = (0, _util.getQueryParams)(window.location.href);
113
- const index = currencies.findIndex(x => x.id === query.currencyId);
114
+ const queryCurrencyId = query.currencyId || currencyId;
115
+ const index = currencies.findIndex(x => x.id === queryCurrencyId);
114
116
  return index >= 0 ? index : 0;
115
117
  });
116
118
  const onCheckoutComplete = (0, _ahooks.useMemoizedFn)(async ({
@@ -60,7 +60,8 @@ function PaymentInner({
60
60
  const [state, setState] = (0, _ahooks.useSetState)({
61
61
  checkoutSession
62
62
  });
63
- const defaultCurrencyId = state.checkoutSession.currency_id || state.checkoutSession.line_items[0]?.price.currency_id;
63
+ const query = (0, _util2.getQueryParams)(window.location.href);
64
+ const defaultCurrencyId = query.currencyId || state.checkoutSession.currency_id || state.checkoutSession.line_items[0]?.price.currency_id;
64
65
  const defaultMethodId = paymentMethods.find(m => m.payment_currencies.some(c => c.id === defaultCurrencyId))?.id;
65
66
  const hideSummaryCard = mode.endsWith("-minimal") || !showCheckoutSummary;
66
67
  const methods = (0, _reactHookForm.useForm)({
@@ -100,6 +101,14 @@ function PaymentInner({
100
101
  document.body.removeEventListener("focusout", focusoutHandler);
101
102
  };
102
103
  }, []);
104
+ (0, _react.useEffect)(() => {
105
+ if (!methods || query.currencyId) {
106
+ return;
107
+ }
108
+ if (state.checkoutSession.currency_id !== defaultCurrencyId) {
109
+ methods.setValue("payment_currency", state.checkoutSession.currency_id);
110
+ }
111
+ }, [state.checkoutSession, defaultCurrencyId, query.currencyId]);
103
112
  const currencyId = (0, _reactHookForm.useWatch)({
104
113
  control: methods.control,
105
114
  name: "payment_currency",
@@ -257,6 +266,7 @@ function PaymentInner({
257
266
  subscriptionId: state.checkoutSession.subscription_id,
258
267
  message: paymentLink?.after_completion?.hosted_confirmation?.custom_message || t(`payment.checkout.completed.${state.checkoutSession.submit_type === "donate" ? "donate" : state.checkoutSession.mode}`)
259
268
  }), !completed && /* @__PURE__ */(0, _jsxRuntime.jsx)(_form.default, {
269
+ currencyId,
260
270
  checkoutSession: state.checkoutSession,
261
271
  paymentMethods,
262
272
  paymentIntent,
@@ -10,6 +10,7 @@ export type CheckoutContext = {
10
10
  mode: LiteralUnion<'standalone' | 'inline' | 'popup', string>;
11
11
  action?: string;
12
12
  showCheckoutSummary?: boolean;
13
+ currencyId?: string;
13
14
  };
14
15
  export type CheckoutFormData = {
15
16
  customer_name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.15.8",
3
+ "version": "1.15.9",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -92,7 +92,7 @@
92
92
  "@babel/core": "^7.25.2",
93
93
  "@babel/preset-env": "^7.25.2",
94
94
  "@babel/preset-react": "^7.24.7",
95
- "@blocklet/payment-types": "1.15.8",
95
+ "@blocklet/payment-types": "1.15.9",
96
96
  "@storybook/addon-essentials": "^7.6.20",
97
97
  "@storybook/addon-interactions": "^7.6.20",
98
98
  "@storybook/addon-links": "^7.6.20",
@@ -122,5 +122,5 @@
122
122
  "vite-plugin-babel": "^1.2.0",
123
123
  "vite-plugin-node-polyfills": "^0.21.0"
124
124
  },
125
- "gitHead": "d0e3c23bed5a41a9b16554fc3b7458e8dee4fd60"
125
+ "gitHead": "d2919fe52ba2b7aee1c6c1275c325f91b81027da"
126
126
  }
@@ -124,7 +124,7 @@ const InvoiceTable = React.memo((props: Props & { onPay: (invoiceId: string) =>
124
124
  ignore_zero: true,
125
125
  }),
126
126
  {
127
- refreshDeps: [search],
127
+ refreshDeps: [search, status, customer_id, currency_id, subscription_id, include_staking, include_recovered_from],
128
128
  }
129
129
  );
130
130
  useEffect(() => {
@@ -96,6 +96,7 @@ export default function PaymentForm({
96
96
  onError,
97
97
  // mode,
98
98
  action,
99
+ currencyId,
99
100
  }: PageData) {
100
101
  // const theme = useTheme();
101
102
  const { t } = useLocaleContext();
@@ -148,7 +149,8 @@ export default function PaymentForm({
148
149
 
149
150
  const [paymentCurrencyIndex, setPaymentCurrencyIndex] = useState(() => {
150
151
  const query = getQueryParams(window.location.href);
151
- const index = currencies.findIndex((x) => x.id === query.currencyId);
152
+ const queryCurrencyId = query.currencyId || currencyId;
153
+ const index = currencies.findIndex((x) => x.id === queryCurrencyId);
152
154
  return index >= 0 ? index : 0;
153
155
  });
154
156
 
@@ -23,7 +23,14 @@ import type { LiteralUnion } from 'type-fest';
23
23
 
24
24
  import { usePaymentContext } from '../contexts/payment';
25
25
  import api from '../libs/api';
26
- import { findCurrency, formatError, getStatementDescriptor, isMobileSafari, isValidCountry } from '../libs/util';
26
+ import {
27
+ findCurrency,
28
+ formatError,
29
+ getQueryParams,
30
+ getStatementDescriptor,
31
+ isMobileSafari,
32
+ isValidCountry,
33
+ } from '../libs/util';
27
34
  import { CheckoutCallbacks, CheckoutContext, CheckoutFormData } from '../types';
28
35
  import PaymentError from './error';
29
36
  import CheckoutFooter from './footer';
@@ -61,8 +68,9 @@ function PaymentInner({
61
68
  const { settings, session } = usePaymentContext();
62
69
  const { isMobile } = useMobile();
63
70
  const [state, setState] = useSetState<{ checkoutSession: TCheckoutSessionExpanded }>({ checkoutSession });
64
-
65
- const defaultCurrencyId = state.checkoutSession.currency_id || state.checkoutSession.line_items[0]?.price.currency_id;
71
+ const query = getQueryParams(window.location.href);
72
+ const defaultCurrencyId =
73
+ query.currencyId || state.checkoutSession.currency_id || state.checkoutSession.line_items[0]?.price.currency_id;
66
74
  const defaultMethodId = paymentMethods.find((m) => m.payment_currencies.some((c) => c.id === defaultCurrencyId))?.id;
67
75
  const hideSummaryCard = mode.endsWith('-minimal') || !showCheckoutSummary;
68
76
 
@@ -107,6 +115,16 @@ function PaymentInner({
107
115
  };
108
116
  }, []);
109
117
 
118
+ useEffect(() => {
119
+ if (!methods || query.currencyId) {
120
+ return;
121
+ }
122
+ if (state.checkoutSession.currency_id !== defaultCurrencyId) {
123
+ methods.setValue('payment_currency', state.checkoutSession.currency_id);
124
+ }
125
+ // eslint-disable-next-line react-hooks/exhaustive-deps
126
+ }, [state.checkoutSession, defaultCurrencyId, query.currencyId]);
127
+
110
128
  const currencyId = useWatch({ control: methods.control, name: 'payment_currency', defaultValue: defaultCurrencyId });
111
129
  const currency =
112
130
  (findCurrency(paymentMethods as TPaymentMethodExpanded[], currencyId as string) as TPaymentCurrency) ||
@@ -248,6 +266,7 @@ function PaymentInner({
248
266
  )}
249
267
  {!completed && (
250
268
  <PaymentForm
269
+ currencyId={currencyId}
251
270
  checkoutSession={state.checkoutSession}
252
271
  paymentMethods={paymentMethods as TPaymentMethodExpanded[]}
253
272
  paymentIntent={paymentIntent}
@@ -18,6 +18,7 @@ export type CheckoutContext = {
18
18
  mode: LiteralUnion<'standalone' | 'inline' | 'popup', string>;
19
19
  action?: string;
20
20
  showCheckoutSummary?: boolean;
21
+ currencyId?: string;
21
22
  };
22
23
 
23
24
  export type CheckoutFormData = {