在创建带有条带的新订阅/客户时,我无法向客户对象添加元数据。更新:我遇到的问题是元数据不会保存到客户对象。我没有在日志/事件中看到它的条纹。
// 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!'});
}
});
}
任何想法都会非常感激。
答案 0 :(得分:4)
如果这有助于其他人,我犯了一些愚蠢的错误:
您需要确保将其添加到元数据属性
result.metadata = {'team': $scope.team};
您需要确保获取元数据
var team = req.body.metadata;
您需要将其作为元数据传递
metadata: team