Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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
Meteor 贝宝秀;“未传递令牌”;当点击PayPal按钮时_Meteor_Paypal - Fatal编程技术网

Meteor 贝宝秀;“未传递令牌”;当点击PayPal按钮时

Meteor 贝宝秀;“未传递令牌”;当点击PayPal按钮时,meteor,paypal,Meteor,Paypal,出于某种原因,PayPal express checkout不适用于我,它会显示一个空白页面,上面写着: 没有传递令牌 下面是我从url获取服务器响应的代码,因为包含代码的文件是全局的,任何页面都可以用来处理成功响应 setTimeout(function () { var paypalToken = Router.current().params.query.token; var paypalPayerId = Router.current().params.query.Pa

出于某种原因,PayPal express checkout不适用于我,它会显示一个空白页面,上面写着:

没有传递令牌

下面是我从url获取服务器响应的代码,因为包含代码的文件是全局的,任何页面都可以用来处理成功响应

 setTimeout(function () {
    var paypalToken = Router.current().params.query.token;
    var paypalPayerId = Router.current().params.query.PayerID;
    var price = '';
    var itemId = '';


    if (paypalToken != undefined && paypalPayerId != undefined) {

        check(paypalToken, String);
        check(paypalPayerId, String);
        check(price, String);
        check(itemId, String);

        Meteor.call('fetchItemId', paypalToken, function (err, data) {
            if (err) {
                alert(err);
            }
            else {
                itemId = data;
                Meteor.call('fetchPriceById', itemId, function (err, data) {
                    if (err) {
                        alert(err);
                    }
                    else {
                        price = data.toString();

                         Meteor.call('processPayment', paypalToken, paypalPayerId, price, function (error, result) {
                            Meteor.call('fetchLatestToken', function (err, data) {
                                if (err) {
                                    alert(err);
                                }
                                else {
                                    //console.log(data.itemId);
                                    pathPaypal = "https://domain/item/" + data.itemId;
                                    window.location = pathPaypal;
                                }
                            });
                        });
                     }
                 });
}
});
}
}
服务器端方法

   fetchItemId: function(paypalToken){

            check(paypalToken, String);

            purchasesData = Purchases.findOne( { paypalToken: paypalToken });
            return purchasesData.itemId;
        },

        fetchPriceById: function(itemId){
            check(itemId, String);
            itemData = Products.findOne( { _id: itemId });
            return itemData.price;
        },

        checkOut:function(itemId,price){

            check(itemId, String);
            check(price, String);

            Future = Npm.require('fibers/future');
            var accessToken = new Future();

            Meteor.http.call("POST", "https://api-3t.paypal.com/nvp", {
                headers: {
                    "Accept": "application/json",
                    "Accept-Language": "en_US",
                    "Content-Type": "application/x-www-form-urlencoded"
                },
                params: {
                    "USER": "user"
                    "PWD": "pass"
                    "SIGNATURE": "signature",
                    "METHOD": "SetExpressCheckout",
                    "VERSION": "93",
                    "PAYMENTREQUEST_0_AMT": price,
                    "PAYMENTREQUEST_0_PAYMENTACTION": "SALE",
                    "PAYMENTREQUEST_0_CURRENCYCODE": "USD",
                    "RETURNURL": "http://domain/item/"+itemId,
                    "CANCELURL": "http://domain/item/"+itemId,
                }

            },function(error,result){
                if (result.statusCode === 200) {
                    paypalToken = decodeURIComponent(result.content.split("&")[0].split("=")[1]);


                     /* database operations */

                    try {
                        Purchases.insert({
                            itemId: itemId,
                            clientId: Meteor.userId(),
                            paypalToken: paypalToken,
                            status: '0',
                            createdAt: new Date()
                        });
                    }
                    catch(e){
                        console.log('transaction in progress');
                    }
                    data = Purchases.find( { itemId: itemId }).fetch();
                    //console.log(data);

                    accessToken.return('');
                    return '';
                }
            });
            accessToken.wait();
        },

        processPayment:function(token, PayerID, price){

            var accessToken = new Future();

            check(token, String);
            check(PayerID, String);
            check(price, String);

            Meteor.http.call("POST", "https://api-3t.paypal.com/nvp", {
                headers: {
                    "Accept": "application/json",
                    "Accept-Language": "en_US",
                    "Content-Type": "application/x-www-form-urlencoded"
                },
                params: {
                    "USER": "user",
                    "PWD": "pwd",
                    "SIGNATURE": "signature",
                    "METHOD": "DoExpressCheckoutPayment",
                    "VERSION": "93",
                    "TOKEN": token,
                    "PAYERID": PayerID,
                    "PAYMENTREQUEST_0_PAYMENTACTION": "SALE",
                    "PAYMENTREQUEST_0_AMT": price,
                    "PAYMENTREQUEST_0_CURRENCYCODE": "USD",
                }

            },function(error,result){
                if (result.statusCode === 200) {
                    try {
                        var purchase;
                        var purchase2;
                        purchase = Purchases.findOne( { paypalToken: token }, {sort:{$natural:-1}});
                        Purchases.update(purchase._id, {$set: {status: '1'}});
                    }
                    catch(e){
                        console.log('transaction in progress');
                    }
                    accessToken.return(result);
                }
            });
            accessToken.wait();
        }