当我处理订阅信用卡付款时,我想在继续下一步(设置实际帐户)之前包含用户的电子邮件地址。
我可以成功设置订阅/为卡充值,但似乎无法包含电子邮件地址。我正在使用 Angular 支付模块。
如何将电子邮件地址传递给 stripe?
形式:
<form stripe-form="stripeCallback" name="checkoutForm">
<input type="email" placeholder="Email" ng-model="email" name="email">
<input ng-model="number" placeholder="Card Number" payments-format="card" payments-validate="card" name="card" />
<input ng-model="expiry" placeholder="Expiration" payments-format="expiry" payments-validate="expiry" name="expiry" />
<input ng-model="cvc" placeholder="CVC" payments-format="cvc" payments-validate="cvc" name="cvc" />
<button type="submit" class="button cta payment">Subscribe</button>
</form>
Controller :
// Stripe Response Handler
$scope.stripeCallback = function (code, result) {
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');
});
}
};
节点:
// for subscriptions:
function subscribeUser(token, res){
// this assumes you've already created a plan (dashboard.stripe.com/plans) named 'test'
stripe.customers.create({
card: token,
plan: '001'
}, function(err, customer) {
// 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!'});
}
});
}
最佳答案
创建 token 时, strip 不需要电子邮件地址。 但是当您将表单发布到节点时。您可以使用 req.body.email 捕获电子邮件,并在创建客户时将其传递到节点端的 stripe 调用中
function subscribeUser(token, res){
//NOTE: stripe.customers.create does not create subscription
stripe.customers.create({
card: token,
plan: '001',
email: req.body.email // THIS IS HOW EMAIL IS SENT TO STRIPE
},
function(err, customer) {
if (err) console.log(err);
else console.log('customer create successfully',customer)
});
}
关于javascript - 如何使用 $http POST 和 Angular-Payments 传递电子邮件地址以及 strip token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26936946/