[英]How to send a token from react to my server?
I am currently working on adding stripe payments to my Laravel app - I have the system all working with blate templates but I am now attempting to implement it into a react project I have.我目前正在向我的 Laravel 应用程序添加条带付款 - 我的系统都使用 blate 模板,但我现在正试图将它实施到我拥有的反应项目中。
I am searching for the best way to send a token I receive in a response to my server this is what I currently have:我正在寻找发送我收到的令牌以响应我的服务器的最佳方式,这就是我目前拥有的:
const CheckoutForm = ({intent}) => {
const stripe = useStripe();
const elements = useElements();
const handleSubmit = async (event) => {
event.preventDefault();
const { data, setData, transform , post } = useForm({
//Token here maybe?
})
if (!stripe || !elements) {
return;
}
const result = await stripe.confirmCardSetup(intent.client_secret, {
payment_method: {
card: elements.getElement(CardElement),
},
});
if (result.error) {
console.log(result.error.message);
} else {
// maybe add: result.setupIntent.payment_method to data?
// post(route('subscriptions'));
}
};
return (
<form onSubmit={handleSubmit}>
<CardElement/>
<Button disabled={!stripe}>
Pay Now
</Button>
</form>
)
};
I am very new to React so struggling to even google my answer - I am assuming I need an inertia post route as this is how I did it in the blade template application.我对 React 很陌生,所以甚至很难用谷歌搜索我的答案——我假设我需要一个惯性发布路线,因为我在刀片模板应用程序中就是这样做的。 However, this doesn't work now due to react states not updating in that way?但是,由于反应状态没有以这种方式更新,这现在不起作用?
Basically, I have no idea the best way to get result.setupIntent.payment_method
to my server after card setup.基本上,我不知道在卡设置后将result.setupIntent.payment_method
发送到我的服务器的最佳方法。
Thanks for your time!谢谢你的时间!
Found a solution using Inertia.visit使用 Inertia.visit 找到了解决方案
...
Inertia.visit(
route('subscriptions.start'),
{
method: 'post',
data: {
token: result.setupIntent.payment_method,
}
}
);
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.