PayPal:当用户向我的 PayPal 开发者帐户发送付款时如何收到电子邮件? (使用 React.js )

发布于 2025-01-18 11:04:11 字数 878 浏览 3 评论 0原文

我已经使用react.js在网站中集成了PayPal按钮,并且每当用户使用该网站上的PayPal按钮付费时,我想收到一封电子邮件,我该如何实现?

PS:我正在使用贝宝沙盒,

我想做以下操作:

    
useEffect(() => {

    window.paypal.Buttons({
        createOrder: (data, actions, err) => {
            return actions.order.create({
                intent: "CAPTURE",
                purchase_units: [
                    {
                        amount: { currency_code: "CAD", value: 50 },
                    },],
            });
        }, onApprove: async (data, actions) => {

            setPaid(true);
            setCompleted(true);
            // *THEN SEND ME AN EMAIL THAT A PAYMENT HAS BEEN DONE*


        },
        onError: (err) => {
            setCompleted(true);
            console.log(err);
        },
    })
        .render(paypal.current)

}, []);

    

I've integrated PayPal buttons in my website using react.js, and I want to get an email every time a user pays using that PayPal button on my website, How can I implement that?

P.S: I'm using PayPal sandbox

I want to do the following:

    
useEffect(() => {

    window.paypal.Buttons({
        createOrder: (data, actions, err) => {
            return actions.order.create({
                intent: "CAPTURE",
                purchase_units: [
                    {
                        amount: { currency_code: "CAD", value: 50 },
                    },],
            });
        }, onApprove: async (data, actions) => {

            setPaid(true);
            setCompleted(true);
            // *THEN SEND ME AN EMAIL THAT A PAYMENT HAS BEEN DONE*


        },
        onError: (err) => {
            setCompleted(true);
            console.log(err);
        },
    })
        .render(paypal.current)

}, []);

    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌倦 2025-01-25 11:04:11

实际电子邮件应从后端发送。

请关注 paypal结帐集成集成指南,并在后端上进行2条路线,一条路线对于“创建订单”,一个用于“捕获顺序”。这两种路线都应仅返回JSON数据(无HTML或文本)。在第二路线内,当捕获API成功时,您可以将其产生的付款详细信息存储在数据库中(尤其是puphay_units [0] .payments.payments.captures [0] .id,这是PayPal Transaction ID )并在将返回json转发到前端呼叫者之前,请立即执行任何必要的业务逻辑(例如发送电子邮件或保留产品)(在您的情况下会做出反应)。

对于前端批准流,而不是您自己的使用在您的问题中实现,请考虑官方@paypal/react-paypal-js 。给IT CreateOrder和Onapprove函数参数,以调用您的后端(可能使用fetch)。有关此类功能的示例,请参见“集成指南”中的完整堆栈示例或 https://developer.paypal.com/demo/checkout/#/pattern/server (当前后一个是最好的,因为它显示了如何处理3种不同的案例以进行捕获响应)

The actual email should be sent from a backend.

Follow the PayPal Checkout integration guide and make 2 routes on your backend, one for 'Create Order' and one for 'Capture Order'. Both of these routes should return only JSON data (no HTML or text). Inside the 2nd route, when the capture API is successful you can store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id, which is the PayPal transaction ID) and perform any necessary business logic (such as sending emails or reserving product) immediately before forwarding your return JSON to the frontend caller (which will be react in your case).

For the frontend approval flow, instead of your own useEffect implementation in your question, consider the official @paypal/react-paypal-js. Give it createOrder and onApprove function parameters that call your backend (likely using fetch). For examples of such functions, see the full stack example in the integration guide or the one at https://developer.paypal.com/demo/checkout/#/pattern/server (currently this latter one is the best as it shows how to handle 3 different cases for the capture response)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文