Session 流星:会话问题

Session 流星:会话问题,session,meteor,Session,Meteor,我得到这个错误 TypeError: Cannot read property 'set' of undefined 代码是: Router.map(function() { this.route('/payment_return/:invoice_no/:amount/', { where: 'server', onBeforeAction: function() { console.lo

我得到这个错误

TypeError: Cannot read property 'set' of undefined
代码是:

    Router.map(function() {
        this.route('/payment_return/:invoice_no/:amount/', {
            where: 'server',
            onBeforeAction: function() {
                console.log("result");
                result = paypal_return(this.params.invoice_no,this.params.amount,this.params.query.token,this.params.query.PayerID);
                console.log(result);
                if (result)
                {
                    var tokens = this.params.amount*10;
                    console.log(tokens);
                var playerId = this._id;
                Session.set('selectedUser', playerId);
                    var selectedUser = Session.get('selectedUser');
                    Meteor.call('updateTokens', selectedUser, tokens);
                    this.response.end("Payment captured successfully");
                }
                else
                {
                    this.response.end("Error in processing payment");
                }


            }
        });
    });
在中,methods.js

Meteor.methods({
    'updateTokens': function(selectedUser, tokens){
        check(selectedUser, String);
        check(tokens, Number);
        var currentUserId = Meteor.userId();
        if(currentUserId){
            Meteor.users.update(selectedUser,
                { $inc: { 'profile.tokens': tokens}});
        }
    }
})

基本上,尝试在成功支付后更新用户的令牌金额,但不幸的是,它返回的只是那个错误

会话仅在客户端可用。。。不确定您尝试调用会话的位置,但如果包含会话包并且您正在调用Sessions.set/get on client,它应该可以工作。

会话仅在客户端可用。。。不确定您试图在何处调用会话,但如果包含会话包并且您正在调用Sessions.set/get on client,它应该可以工作。

我觉得这像是API调用,所以我建议您使用meteorhacks:picker

然后,您可以在服务器端添加:

    var paymentRoutes= Picker.filter(function(req, res) {
  return req.method == "POST"; //OR GET WHATEVER YOU NEED
});

    paymentRoutes.route('/payment_return/:invoice_no/:amount/', 
    function(params, req, res, next) {
      //UPDATE TOKEN
    });

这看起来像是API调用,所以我建议您使用meteorhacks:picker

然后,您可以在服务器端添加:

    var paymentRoutes= Picker.filter(function(req, res) {
  return req.method == "POST"; //OR GET WHATEVER YOU NEED
});

    paymentRoutes.route('/payment_return/:invoice_no/:amount/', 
    function(params, req, res, next) {
      //UPDATE TOKEN
    });
我希望这会有帮助,干杯


我希望这会有所帮助,干杯

它们存储在lib下的my routes.js中。我不完全确定,如果这些sre客户端或服务器端tbh。。。如果它们是服务器,如何使其工作?它们存储在lib下的my routes.js中。我不完全确定,如果这些sre客户端或服务器端tbh。。。如果他们是服务器,如何使其工作?我可以使用这个或我拥有的其他路由代码,还是只有一个或另一个?你可以使用它们,只是不要使用相同的路由。我的意思是你可以通过路由器路由你的blaze模板等,并使用picker进行REST API调用,就像这样。如果我错了,请原谅我,但是我调用的fromREST API有什么信息?这会解决返回用户ID的问题吗?这是唯一需要的信息。。对不起,我是新来的,只是弄糊涂了。我可以用这个还是我有的其他路线代码?或者只有一个或另一个?你可以用它们,只是不要用同一条路线。我的意思是你可以通过路由器路由你的blaze模板等,并使用picker进行REST API调用,就像这样。如果我错了,请原谅我,但是我调用的fromREST API有什么信息?这会解决返回用户ID的问题吗?这是唯一需要的信息。。抱歉,我是新来的,只是混淆了这个路由实际上依赖于另一个名为“payment”的路由,代码是Router.map(function(){this.route('/payment/:invoice\u no/:amount/,{where:'server',action:function(){var amount=parseInt(this.params.amount);var url=generate\u url\u用于支付授权(this.params.invoice_no,this.params.amount);if(url==null){this.response.end(“错误”);}this.response.writeHead(301,{‘位置’:url});this.response.end();}})…我是否复制相同的?另外,不是这个.response.writeHead,而是isi t res.writeHead?我假设它依赖于该路由,因为我返回的是TypeError:无法读取未定义的属性“invoice\u no”,因此它没有被传递,可能是我不确定,也可能是基于模板的?因为在用户输入invoice\u no和amo的地方有一个事件代码unt..可能是这样吗?此路由实际上依赖于另一个名为“payment”的路由,其代码是Router.map(function(){This.route('/payment/:invoice\u no/:amount/,{其中:'server',action:function(){var amount=parseInt(This.params.amount);var url=generate\u url\u用于支付授权(this.params.invoice_no,this.params.amount);if(url==null){this.response.end(“错误”);}this.response.writeHead(301,{‘位置’:url});this.response.end();}})…我是否复制相同的?另外,不是这个.response.writeHead,而是isi t res.writeHead?我假设它依赖于该路由,因为我返回的是TypeError:无法读取未定义的属性“invoice\u no”,因此它没有被传递,可能是我不确定,也可能是基于模板的?因为在用户输入invoice\u no和amo的地方有一个事件代码可能是这样吗?