Backend code to create Stripe customers and store their IDs in CreditCards. Page refresh not working

This commit is contained in:
stveep
2017-05-01 20:21:30 +01:00
committed by Rob Harrington
parent 1449169b16
commit c9c4680ef6
5 changed files with 101 additions and 16 deletions

View File

@@ -10,16 +10,5 @@ Darkswarm.controller "CreditCardsCtrl", ($scope, $timeout, CreditCard, savedCred
$scope.secrets = CreditCard.secrets
$scope.storeCard = =>
Loading.message = "Saving"
CreditCard.requestToken($scope.secrets)
# Need to call Spree::Gateway::StripeConnect#provider.store(creditcard)
# creditcard should be formatted as for a payment
# The token then needs to be associated with the Customer (in Stripe) - can be done in Ruby.

View File

@@ -1,16 +1,33 @@
Darkswarm.factory 'CreditCard', ($injector, $rootScope, StripeJS, Navigation, $http, RailsFlashLoader, Loading)->
new class CreditCard
errors: {}
secrets: {}
requestToken: (secrets) ->
#$scope.secrets.name = $scope.secrets.first_name + " " + $scope.secrets.last_name
secrets.name = @full_name(secrets)
StripeJS.requestToken(secrets, @submit)
StripeJS.requestToken(secrets, @submit, t("saving_credit_card"))
submit: =>
$rootScope.$apply ->
Loading.clear()
Navigation.go '/account'
params = @process_params()
$http.put('/credit_cards/new_from_token', params )
.success (data, status) ->
$rootScope.$apply ->
Loading.clear()
Navigation.go '/account'
.error (response, status) ->
if response.path
Navigation.go response.path
else
Loading.clear()
@errors = response.errors
RailsFlashLoader.loadFlash(response.flash)
full_name: (secrets) ->
secrets.first_name + " " + secrets.last_name
process_params: ->
{"exp_month": @secrets.card.exp_month,
"exp_year": @secrets.card.exp_year,
"last4": @secrets.card.last4,
"token": @secrets.token,
"cc_type": @secrets.card.brand}