I'm integrating stripe with my angular app and if possible I would like to have better control over when I generate a token to allow more versatility in the user flow. More specifically I have a few forms (payment info, shipping address, additional info) that I would like to keep separate but I would like to process them all at the same time. So far I'm using this directive https://github.com/gtramontina/stripe-angular/blob/master/stripe-angular.js
angular.module('stripe', []).directive('stripeForm', ['$window',
function($window) {
var directive = { restrict: 'A' };
directive.link = function(scope, element, attributes) {
var form = angular.element(element);
form.bind('submit', function() {
var button = form.find('button');
button.prop('disabled', true);
$window.Stripe.createToken(form[0], function() {
var args = arguments;
scope.$apply(function() {
scope[attributes.stripeForm].apply(scope, args);
});
button.prop('disabled', false);
});
});
};
return directive;
}]);
It allows me to catch the response in a controller but not trigger the tokenization call.
.controller('IndexController', function($scope, $rootScope) {
$scope.saveCustomer = function(status, response) {
$rootScope.user.stripeCustomerId = response.id;
$rootScope.user.save();
};
});
Any ideas?