简体   繁体   English

如何将令牌从反应发送到我的服务器?

[英]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.

相关问题 如何将我的Instagram访问令牌从Express服务器发送到React客户端? - How can I send my Instagram access token from my Express server to React client? 如何从 React Native App 将我的长度变量发送到我的 HTTPS 服务器 - How do I send out my length variable to my HTTPS server from React Native App 如何在“react”中将“token”发送到“Api” - How to send "token" to "Api" in "react" 如何从 android 工作室发送 firebase 令牌到后端服务器 - How to send firebase token to backend server from android studio react-router如何从客户端向服务器中间件发送请求? - How react-router send request to server middleware from client? React WebPack-将我的工作发送到在线服务器 - React WebPack - Send My Work to online Server 如何将文件/图像从 React 发送到 node.js 服务器 - How to send a file/image from React to node.js server 如何从 web 应用程序/服务器发送数据以响应本机应用程序? - How to send data from web app/server to react native app? 如何将请求参数从 Express 服务器发送到 React 应用程序? - How to send request parameter from Express server to React application? React和NodeJS:如何从服务器向客户端发送数据? - React and NodeJS: How can i send data from server to client?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM