Advertisement
bennyp

Untitled

Mar 22nd, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     $scope.sendDonation = function() {
  2.       usSpinnerService.spin('loading');
  3.       $log.info('Token Request Submitted for ', $scope.donate.card.number.slice(-4));
  4.       return stripe.card.createToken($scope.donate.card)
  5.         .then(function(response) {
  6.           $log.info('token created for card ending in ', response.card.last4);
  7.           var payment = angular.copy($scope.donate);
  8.           payment.card = void 0;
  9.           payment.token = response.id;
  10.           return $http.post('payments/', payment);
  11.         })
  12.         .then(function(success) {
  13.           $log.info(success);
  14.           $log.info('Successfully submitted ',
  15.             success.data.description, ' for $',
  16.             success.data.amount / 100, '. Card Name:',
  17.             success.data.source.name, ' Card Last 4:',
  18.             success.data.source.last4);
  19.           $scope.successData = success.data;
  20.           $state.go('donate.success');
  21.         })
  22.         .catch(function(error) {
  23.           if (error.type && /^Stripe/.test(error.type)) {
  24.             $log.info('Stripe Error: ', error.message);
  25.             $scope.error = error;
  26.           } else {
  27.             $log.info('Other Error Occurred: ', error.data);
  28.           }
  29.           $scope.error = error;
  30.           $state.go('donate.error');
  31.         })
  32.         .finally(function() {
  33.           usSpinnerService.stop('loading');
  34.         });
  35.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement