【发布时间】:2020-12-13 14:40:18
【问题描述】:
直到上周,一切都运行良好。现在我在使用 react-stripe-checkout 时遇到了一些问题(我注意到上次更新是在 3 年前,所以可能与它有关)
我已经生成了我的 API 令牌,并且已经有一个后端和前端代码相互通信。
首先我创建我的结帐组件:
import StripeCheckout from 'react-stripe-checkout'
...
<StripeCheckout
stripeKey="{token}"
token={handleToken}>
</StripeCheckout>
而我的handleToken函数是:
const handleToken = async (token) => {
const response = await fetch(`http://localhost:3002/checkout`, {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
token,
product,
quantity,
address: user.address,
})
})
}
但是,控制台上有这些警告:
A cookie associated with a cross-site resource at <URL> was set without the `SameSite` attribute.
It has been blocked, as Chrome now only delivers cookies with cross-site requests if they are set with `SameSite=None` and `Secure`.
You can review cookies in developer tools under Application>Storage>Cookies and see more details at <URL> and <URL>.
react_devtools_backend.js:2273 You’re using the legacy version of Stripe Checkout.
We released a new version of Checkout in April 2019, which supports mobile wallets and other payment methods:
https://stripe.com/docs/payments/checkout
Learn how to upgrade to the new version:
https://stripe.com/docs/payments/checkout/migration
这就是后端发生的事情
const {
source = {},
token,
product,
quantity,
address
} = httpRequest.body
const { ip, headers } = httpRequest
source.ip = ip
source.browser = headers["User-Agent"]
if (headers["Referer"]) {
source.referer = headers["Referer"]
}
const body = await checkoutAction({ token, product, quantity, address })
return {
statusCode: 200,
body: {
message: 'Successfully purchased!',
...body
}
}
预期的行为是能够购买产品。但是,当我单击“react-stripe-checkout”组件时,页面会刷新并且没有任何反应。
【问题讨论】:
-
您是否在后端的响应中设置了 cookie?
-
不...应该吗?我将包括后端的源代码
-
stripe.com/docs/js/checkout/redirect_to_checkout。您是否使用给定的方法来使用重定向结帐操作?另外请升级您的条带包版本,以便您在那里使用最新版本。
-
没有。我正在为此使用 react-stripe-checkout