mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Backend code to create Stripe customers and store their IDs in CreditCards. Page refresh not working
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user