Reputation: 727
When i process a subscription credit card payment I want to include the users email address before I move on to the next step (setup actual account).
I can successfully setup the subscription/charge the card but cannot seem to include an email address. I'm using the angular-payments module.
How can I pass the email address to stripe?
The form:
<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>
The 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');
});
}
};
The node:
// 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!'});
}
});
}
Upvotes: 1
Views: 930
Reputation: 181
Email address is not expected by stripe when a token is being created. but when you post the form to node. you can capture the email with req.body.email and pass it in the stripe call on the node side when you create a customer
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)
});
}
Upvotes: 1