Meteor方法不将ID返回给客户端

时间:2015-01-09 18:46:20

标签: meteor

我正在将条带付款整合到我的网站上,但我遇到了一个问题。 我想在提交付款表单(条带提供的iframe)时将用户转换为动态路由,但我在客户端调用的Meteor方法返回undefined而不是我希望转换到的新插入文档的ID < / p>

有什么建议吗?

ERROR

Error: Missing required parameters on path "/purchases/:purchaseId". The missing params are: ["purchaseId"]. The params object passed in was: undefined.

客户端:

Template.viewTab.events({
  'click #download': function(event) {
    handler.open({
      name: 'Tabr',
      description: this.title,
      amount: this.price
    });
    event.preventDefault();
  },
});

var handler = StripeCheckout.configure({
  key: '..............',
  token: function(token) {
    // Use the token to create the charge with a server-side script.
    // You can access the token ID with `token.id`

    tabId = Tabs.findOne()._id;
    Meteor.call('makePurchase', tabId, token, function(error, purchaseId) {
      if (error) {
        console.log('makePurchaseError: ' + error);
        FlashMessages.clear();
        return FlashMessages.sendError(error.message, {
          autoHide: true,
          hideDelay: 10000
        });
      }
      console.log(purchaseId);
      Router.go('viewPurchase', purchaseId);
    });
  }
});

服务器:

Meteor.methods({

  /**
   * [makePurchase attempts to charge the customer's credit card, and if succesful
   * it inserts a new purchaes document in the database]
   *
   * @return {[String]} [purchaseId]
   */
  makePurchase: function(tabId, token) {
    check(tabId, String);
    tab = Tabs.findOne(tabId);

    Stripe.charges.create({
      amount: tab.price,
      currency: "USD",
      card: token.id
    }, Meteor.bindEnvironment(function (error, result) {
      if (error) {
        console.log('makePurchaseError: ' + error);
        return error;
      }

      purchaseId = Purchases.insert({
        sellerId: tab.userId,
        tabId: tab._id,
        price: tab.price
      }, function(error, result) {
        if (error) {
          console.log('InsertionError: ' + error);
          return error;
        }
        return result;
      });
    }));

    console.log(purchaseId);
    return purchaseId;
  }

});

0 个答案:

没有答案