@blocklet/payment-react 1.14.17 → 1.14.19

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.
@@ -176,7 +176,7 @@ export default function PaymentForm({
176
176
  }
177
177
  };
178
178
  const onUserLoggedIn = async () => {
179
- const { data: profile } = await api.get("/api/customers/me");
179
+ const { data: profile } = await api.get("/api/customers/me?fallback=1");
180
180
  if (profile) {
181
181
  const values = getValues();
182
182
  if (!values.customer_name) {
@@ -250,7 +250,9 @@ export default function PaymentForm({
250
250
  if (result.data.stripeContext?.status === "succeeded") {
251
251
  setState({ paying: true });
252
252
  } else {
253
- setState({ stripePaying: true });
253
+ setTimeout(() => {
254
+ setState({ stripePaying: true });
255
+ }, 200);
254
256
  }
255
257
  }
256
258
  } catch (err) {
@@ -8,7 +8,7 @@ import { styled } from "@mui/system";
8
8
  import { Elements, PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js";
9
9
  import { loadStripe } from "@stripe/stripe-js";
10
10
  import { useSetState } from "ahooks";
11
- import { useEffect } from "react";
11
+ import { useEffect, useCallback } from "react";
12
12
  function StripeCheckoutForm({ clientSecret, intentType, customer, mode, onConfirm }) {
13
13
  const stripe = useStripe();
14
14
  const elements = useElements();
@@ -41,42 +41,46 @@ function StripeCheckoutForm({ clientSecret, intentType, customer, mode, onConfir
41
41
  }
42
42
  });
43
43
  }, [stripe, clientSecret]);
44
- const handleSubmit = async (e) => {
45
- e.preventDefault();
46
- if (!stripe || !elements) {
47
- return;
48
- }
49
- try {
50
- setState({ confirming: true });
51
- const method = intentType === "payment_intent" ? "confirmPayment" : "confirmSetup";
52
- const { error } = await stripe[method]({
53
- elements,
54
- redirect: "if_required",
55
- confirmParams: {
56
- payment_method_data: {
57
- billing_details: {
58
- name: customer.name,
59
- phone: customer.phone,
60
- email: customer.email,
61
- address: customer.address
44
+ const handleSubmit = useCallback(
45
+ async (e) => {
46
+ e.preventDefault();
47
+ if (!stripe || !elements) {
48
+ return;
49
+ }
50
+ try {
51
+ setState({ confirming: true });
52
+ const method = intentType === "payment_intent" ? "confirmPayment" : "confirmSetup";
53
+ const { error } = await stripe[method]({
54
+ elements,
55
+ redirect: "if_required",
56
+ confirmParams: {
57
+ payment_method_data: {
58
+ billing_details: {
59
+ name: customer.name,
60
+ phone: customer.phone,
61
+ email: customer.email,
62
+ address: customer.address
63
+ }
62
64
  }
63
65
  }
64
- }
65
- });
66
- setState({ confirming: false });
67
- if (error) {
68
- if (error.type === "validation_error") {
66
+ });
67
+ setState({ confirming: false });
68
+ if (error) {
69
+ if (error.type === "validation_error") {
70
+ return;
71
+ }
72
+ setState({ message: error.message });
69
73
  return;
70
74
  }
71
- setState({ message: error.message });
72
- return;
75
+ onConfirm();
76
+ } catch (err) {
77
+ console.error(err);
78
+ setState({ confirming: false, message: err.message });
73
79
  }
74
- onConfirm();
75
- } catch (err) {
76
- console.error(err);
77
- setState({ confirming: false, message: err.message });
78
- }
79
- };
80
+ },
81
+ [customer, intentType, stripe]
82
+ // eslint-disable-line
83
+ );
80
84
  return /* @__PURE__ */ jsxs(Content, { onSubmit: handleSubmit, children: [
81
85
  /* @__PURE__ */ jsx(
82
86
  PaymentElement,
@@ -204,7 +204,7 @@ function PaymentForm({
204
204
  const onUserLoggedIn = async () => {
205
205
  const {
206
206
  data: profile
207
- } = await _api.default.get("/api/customers/me");
207
+ } = await _api.default.get("/api/customers/me?fallback=1");
208
208
  if (profile) {
209
209
  const values = getValues();
210
210
  if (!values.customer_name) {
@@ -292,9 +292,11 @@ function PaymentForm({
292
292
  paying: true
293
293
  });
294
294
  } else {
295
- setState({
296
- stripePaying: true
297
- });
295
+ setTimeout(() => {
296
+ setState({
297
+ stripePaying: true
298
+ });
299
+ }, 200);
298
300
  }
299
301
  }
300
302
  } catch (err) {
@@ -63,7 +63,7 @@ function StripeCheckoutForm({
63
63
  }
64
64
  });
65
65
  }, [stripe, clientSecret]);
66
- const handleSubmit = async e => {
66
+ const handleSubmit = (0, _react.useCallback)(async e => {
67
67
  e.preventDefault();
68
68
  if (!stripe || !elements) {
69
69
  return;
@@ -109,7 +109,10 @@ function StripeCheckoutForm({
109
109
  message: err.message
110
110
  });
111
111
  }
112
- };
112
+ }, [customer, intentType, stripe]
113
+ // eslint-disable-line
114
+ );
115
+
113
116
  return /* @__PURE__ */(0, _jsxRuntime.jsxs)(Content, {
114
117
  onSubmit: handleSubmit,
115
118
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_reactStripeJs.PaymentElement, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.14.17",
3
+ "version": "1.14.19",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -91,7 +91,7 @@
91
91
  "@babel/core": "^7.25.2",
92
92
  "@babel/preset-env": "^7.25.2",
93
93
  "@babel/preset-react": "^7.24.7",
94
- "@blocklet/payment-types": "1.14.17",
94
+ "@blocklet/payment-types": "1.14.19",
95
95
  "@storybook/addon-essentials": "^7.6.20",
96
96
  "@storybook/addon-interactions": "^7.6.20",
97
97
  "@storybook/addon-links": "^7.6.20",
@@ -120,5 +120,5 @@
120
120
  "vite-plugin-babel": "^1.2.0",
121
121
  "vite-plugin-node-polyfills": "^0.21.0"
122
122
  },
123
- "gitHead": "822dc883b1d44a2bc92bc0739c1d2d22899fc934"
123
+ "gitHead": "5410d16f8fcc5c713ca9ba986af7653e5c54e5c2"
124
124
  }
@@ -238,7 +238,7 @@ export default function PaymentForm({
238
238
  };
239
239
 
240
240
  const onUserLoggedIn = async () => {
241
- const { data: profile } = await api.get('/api/customers/me');
241
+ const { data: profile } = await api.get('/api/customers/me?fallback=1');
242
242
  if (profile) {
243
243
  const values = getValues();
244
244
  if (!values.customer_name) {
@@ -315,7 +315,9 @@ export default function PaymentForm({
315
315
  if (result.data.stripeContext?.status === 'succeeded') {
316
316
  setState({ paying: true });
317
317
  } else {
318
- setState({ stripePaying: true });
318
+ setTimeout(() => {
319
+ setState({ stripePaying: true });
320
+ }, 200);
319
321
  }
320
322
  }
321
323
  } catch (err: any) {
@@ -8,7 +8,7 @@ import { styled } from '@mui/system';
8
8
  import { Elements, PaymentElement, useElements, useStripe } from '@stripe/react-stripe-js';
9
9
  import { loadStripe } from '@stripe/stripe-js';
10
10
  import { useSetState } from 'ahooks';
11
- import { useEffect } from 'react';
11
+ import { useEffect, useCallback } from 'react';
12
12
 
13
13
  type StripeCheckoutFormProps = {
14
14
  clientSecret: string;
@@ -57,47 +57,50 @@ function StripeCheckoutForm({ clientSecret, intentType, customer, mode, onConfir
57
57
  // eslint-disable-next-line react-hooks/exhaustive-deps
58
58
  }, [stripe, clientSecret]);
59
59
 
60
- const handleSubmit = async (e: any) => {
61
- e.preventDefault();
60
+ const handleSubmit = useCallback(
61
+ async (e: any) => {
62
+ e.preventDefault();
62
63
 
63
- if (!stripe || !elements) {
64
- return;
65
- }
64
+ if (!stripe || !elements) {
65
+ return;
66
+ }
66
67
 
67
- try {
68
- setState({ confirming: true });
69
- const method = intentType === 'payment_intent' ? 'confirmPayment' : 'confirmSetup';
70
- const { error } = await stripe[method]({
71
- elements,
72
- redirect: 'if_required',
73
- confirmParams: {
74
- payment_method_data: {
75
- billing_details: {
76
- name: customer.name,
77
- phone: customer.phone,
78
- email: customer.email,
79
- address: customer.address,
68
+ try {
69
+ setState({ confirming: true });
70
+ const method = intentType === 'payment_intent' ? 'confirmPayment' : 'confirmSetup';
71
+ const { error } = await stripe[method]({
72
+ elements,
73
+ redirect: 'if_required',
74
+ confirmParams: {
75
+ payment_method_data: {
76
+ billing_details: {
77
+ name: customer.name,
78
+ phone: customer.phone,
79
+ email: customer.email,
80
+ address: customer.address,
81
+ },
80
82
  },
81
83
  },
82
- },
83
- });
84
+ });
85
+
86
+ setState({ confirming: false });
87
+ if (error) {
88
+ if (error.type === 'validation_error') {
89
+ return;
90
+ }
84
91
 
85
- setState({ confirming: false });
86
- if (error) {
87
- if (error.type === 'validation_error') {
92
+ setState({ message: error.message as string });
88
93
  return;
89
94
  }
90
95
 
91
- setState({ message: error.message as string });
92
- return;
96
+ onConfirm();
97
+ } catch (err: any) {
98
+ console.error(err);
99
+ setState({ confirming: false, message: err.message as string });
93
100
  }
94
-
95
- onConfirm();
96
- } catch (err: any) {
97
- console.error(err);
98
- setState({ confirming: false, message: err.message as string });
99
- }
100
- };
101
+ },
102
+ [customer, intentType, stripe] // eslint-disable-line
103
+ );
101
104
 
102
105
  return (
103
106
  <Content onSubmit={handleSubmit}>