mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Merge pull request #6469 from andrewpbrett/sca-backend
Allow SCA cards to be setup and charged offline for subscriptions
This commit is contained in:
@@ -11,8 +11,7 @@ Darkswarm.factory 'CreditCards', ($http, $filter, savedCreditCards, Messages, Cu
|
||||
othercard.is_default = false
|
||||
$http.put("/credit_cards/#{card.id}", is_default: true).then (data) ->
|
||||
Messages.success(t('js.default_card_updated'))
|
||||
for customer in Customers.index()
|
||||
customer.allow_charges = false
|
||||
Customers.clearAllAllowCharges()
|
||||
, (response) ->
|
||||
Messages.flash(response.data.flash)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module("Darkswarm").factory 'Customer', ($resource, Messages) ->
|
||||
angular.module("Darkswarm").factory 'Customer', ($resource, $injector, Messages) ->
|
||||
Customer = $resource('/api/customers/:id/:action.json', {}, {
|
||||
'index':
|
||||
method: 'GET'
|
||||
@@ -12,8 +12,21 @@ angular.module("Darkswarm").factory 'Customer', ($resource, Messages) ->
|
||||
})
|
||||
|
||||
Customer.prototype.update = ->
|
||||
if @allow_charges
|
||||
Messages.loading(t('js.authorising'))
|
||||
@$update().then (response) =>
|
||||
Messages.success(t('js.changes_saved'))
|
||||
if response.gateway_recurring_payment_client_secret && $injector.has('stripePublishableKey')
|
||||
Messages.clear()
|
||||
stripe = Stripe($injector.get('stripePublishableKey'), { stripeAccount: response.gateway_shop_id })
|
||||
stripe.confirmCardSetup(response.gateway_recurring_payment_client_secret).then (result) =>
|
||||
if result.error
|
||||
@allow_charges = false
|
||||
@$update(allow_charges: false)
|
||||
Messages.error(result.error.message)
|
||||
else
|
||||
Messages.success(t('js.changes_saved'))
|
||||
else
|
||||
Messages.success(t('js.changes_saved'))
|
||||
, (response) =>
|
||||
Messages.error(response.data.error)
|
||||
|
||||
|
||||
@@ -12,3 +12,7 @@ angular.module("Darkswarm").factory 'Customers', (Customer) ->
|
||||
for customer in customers
|
||||
@all.push customer
|
||||
@byID[customer.id] = customer
|
||||
|
||||
clearAllAllowCharges: () ->
|
||||
for customer in @index()
|
||||
customer.allow_charges = false
|
||||
|
||||
Reference in New Issue
Block a user