1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| angular.module('registercontroller',[]) .controller('registerCtrl', ['$scope', '$ionicPopup', registerCtrl]) function registerCtrl($s, $i) { $s.profile = { username: '', number: '', expiry: '', cvc: '', stripeToken: '' }; $s.signUp = function(form){ if(form.$valid) { var stripeForm = { number: $s.profile.number.replace(/ /g,''), exp_month: $s.profile.expiry.month, exp_year: $s.profile.expiry.year, cvc: $s.profile.cvc };
var f = document.createElement("form"); f.setAttribute('method',"post"); f.setAttribute('action',"");
var number = document.createElement("input"); number.setAttribute('type',"text"); number.setAttribute('data-stripe',"number"); number.setAttribute('value', stripeForm.number);
var cvc = document.createElement("input"); cvc.setAttribute('type',"text"); cvc.setAttribute('data-stripe',"cvc"); cvc.setAttribute('value', $s.profile.cvc);
var exp_month = document.createElement("input"); exp_month.setAttribute('type',"text"); exp_month.setAttribute('data-stripe',"exp_month"); exp_month.setAttribute('value', stripeForm.exp_month);
var exp_year = document.createElement("input"); exp_year.setAttribute('type',"text"); exp_year.setAttribute('data-stripe',"exp_year"); exp_year.setAttribute('value', stripeForm.exp_year);
f.appendChild(number); f.appendChild(cvc); f.appendChild(exp_month); f.appendChild(exp_year);
window.Stripe.card.createToken(f, function (status, response) { console.log('status', status); console.log('response', response); if (response.error) { var alert = $i.alert({ title: 'Credit Card Error', template: "Sorry your credit card information is not correct", buttons: [ { text: 'Ok', type: 'button-calm' } ] }); } else { $s.profile.stripeToken = response.id; register($s.profile); } });
} }; }
|