【问题标题】:Cannot add metadata to stripe customer subscription creation using nodejs?无法将元数据添加到使用 nodejs 创建条带化客户订阅?
【发布时间】:2015-03-31 02:10:34
【问题描述】:

创建带有条带的新订阅/客户时,我无法将元数据添加到客户对象。更新:我遇到的问题是元数据没有保存到客户对象。我在日志/事件中没有看到它。

// Stripe Response Handler
      $scope.stripeCallback = function (code, result) {
        result.email = $scope.email;
        result.metadata = {'team': $scope.team};
        if (result.error) {
          window.alert('it failed! error: ' + result.error.message);
        } else {
        $http.post('/charge', result)
        .success(function(data, status, headers, config) {
          alert('success');
        })
        .error(function(data, status, headers, config) {
          // console.log(status);
          alert('error');
        });
        }
      };

//on the server
app.post('/charge', function(req, res) {
    var stripeToken = req.body.id;
    var email = req.body.email;
    var team = req.body.team;
    subscribeUser(stripeToken, res, email, team);
});

// for subscriptions:
function subscribeUser(token, res, email, team){
    stripe.customers.create({
        card: token,
        plan: '001',
    email: email,
    metadata: team
    }, function(err, customer) {
    var cust = customer.id;
        // you'll probably want to store a reference (customer.id) to the customer
        if (err) {
            res.send({
        ok: false, message: 'There was a problem processing your card (error: ' + JSON.stringify(err) + ')'});
        } else {
            res.send({
        ok: true, message: 'You have been subscribed to a plan!'});
        }
    });
}

任何想法将不胜感激。

【问题讨论】:

    标签: javascript angularjs node.js stripe-payments


    【解决方案1】:

    如果这对其他人有帮助,我犯了一些愚蠢的错误:

    您需要确保已将其添加到元数据属性中

    result.metadata = {'team': $scope.team};
    

    您需要确保获取元数据

    var team = req.body.metadata;
    

    您需要将其作为元数据传入

    metadata: team
    

    【讨论】:

      猜你喜欢
      • 2017-04-02
      • 1970-01-01
      • 2014-07-11
      • 2016-10-02
      • 2016-09-05
      • 2016-07-28
      • 2021-07-15
      • 1970-01-01
      • 2023-03-07
      相关资源
      最近更新 更多