javascript - How can I pass an email address along with stripe token using $http POST and angular-payments? -
when process subscription credit card payment want include users email address before move on next step (setup actual account).
i can setup subscription/charge card cannot seem include email address. i'm using angular-payments module.
how can pass email address 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:
// subscriptions: function subscribeuser(token, res){ // assumes you've created plan (dashboard.stripe.com/plans) named 'test' stripe.customers.create({ card: token, plan: '001' }, function(err, customer) { // you'll want store reference (customer.id) customer if (err) { res.send({ ok: false, message: 'there problem processing card (error: ' + json.stringify(err) + ')'}); } else { res.send({ ok: true, message: 'you have been subscribed plan!'}); } }); }
email address not expected stripe when token being created. when post form node. can capture email req.body.email , pass in stripe call on node side when create customer
function subscribeuser(token, res){ //note: stripe.customers.create not create subscription stripe.customers.create({ card: token, plan: '001', email: req.body.email // how email sent stripe }, function(err, customer) { if (err) console.log(err); else console.log('customer create successfully',customer) }); }
Comments
Post a Comment