Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 节点和贝宝:付款后检索用户信息_Node.js_Paypal - Fatal编程技术网

Node.js 节点和贝宝:付款后检索用户信息

Node.js 节点和贝宝:付款后检索用户信息,node.js,paypal,Node.js,Paypal,我正在使用本教程: 它实现PayPal的方式是: // start payment process app.get('/buy' , ( req , res ) => { // create payment object var payment = { "intent": "authorize", "payer": { "payment_method": "paypal" }, "redirect_url

我正在使用本教程:

它实现PayPal的方式是:

// start payment process 
app.get('/buy' , ( req , res ) => {
    // create payment object 
    var payment = {
            "intent": "authorize",
    "payer": {
        "payment_method": "paypal"
    },
    "redirect_urls": {
        "return_url": "http://127.0.0.1:3000/success",
        "cancel_url": "http://127.0.0.1:3000/err"
    },
    "transactions": [{
        "amount": {
            "total": 39.00,
            "currency": "USD"
        },
        "description": " a book on mean stack "
    }]
    }   

    // call the create Pay method 
    createPay( payment ) 
        .then( ( transaction ) => {
            var id = transaction.id; 
            var links = transaction.links;
            var counter = links.length; 
            while( counter -- ) {
                if ( links[counter].method == 'REDIRECT') {
                    // redirect to paypal where user approves the transaction 
                    return res.redirect( links[counter].href )
                }
            }
        })
        .catch( ( err ) => { 
            console.log( err ); 
            res.redirect('/err');
        });
}); 
// helper functions 
var createPay = ( payment ) => {
    return new Promise( ( resolve , reject ) => {
        paypal.payment.create( payment , function( err , payment ) {
         if ( err ) {
             reject(err); 
         }
        else {
            resolve(payment); 
        }
        }); 
    });
}       
然后相应地重定向用户:

app.get('/success' , (req ,res ) => {
    res.redirect('/success.html');
    console.log(req.query);
})

// error page
app.get('/err' , (req , res) => {
    console.log(req.query);
    res.redirect('/err.html');
})
我使用的是沙盒,虚拟支付是成功的。我想在付款完成后给买家(在本例中是我自己)发送一封电子邮件。我如何检索该信息(如果付款正常,用户电子邮件和姓名等)

还有,关于在node.js内部使用库来实现自动邮件的建议(NodeEmailer是一个选项,还是不推荐使用?)


谢谢

我不熟悉贝宝api。但我认为有两件事需要记住

  • 创建webhook以接收通知(处理状态更改很重要)

  • 在重定向端点捕获即时结果

请仔细检查您的重定向端点已从paypal收到的内容

app.get('/success' , (req ,res ) => {
    console.log(req.query); // should include payer id
    res.redirect('/success.html');
})