DRY error reporting during payment

This commit is contained in:
Maikel Linke
2020-08-27 09:54:19 +10:00
parent f435039061
commit 9d07295480

View File

@@ -13,9 +13,7 @@ Darkswarm.factory 'StripeElements', ($rootScope, Messages) ->
@stripe.createToken(@card, cardData).then (response) =>
if(response.error)
Messages.error(t("error") + ": #{response.error.message}")
@triggerAngularDigest()
console.error(JSON.stringify(response.error))
@reportError(response.error, t("error") + ": #{response.error.message}")
else
secrets.token = response.token.id
secrets.cc_type = @mapTokenApiCardBrand(response.token.card.brand)
@@ -31,15 +29,18 @@ Darkswarm.factory 'StripeElements', ($rootScope, Messages) ->
@stripe.createPaymentMethod({ type: 'card', card: @card }, @card, cardData).then (response) =>
if(response.error)
Messages.error(t("error") + ": #{response.error.message}")
@triggerAngularDigest()
console.error(JSON.stringify(response.error))
@reportError(response.error, t("error") + ": #{response.error.message}")
else
secrets.token = response.paymentMethod.id
secrets.cc_type = @mapPaymentMethodsApiCardBrand(response.paymentMethod.card.brand)
secrets.card = response.paymentMethod.card
submit()
reportError: (error, messageForUser) ->
Messages.error(messageForUser)
@triggerAngularDigest()
console.error(JSON.stringify(error))
triggerAngularDigest: ->
# $evalAsync is improved way of triggering a digest without calling $apply
$rootScope.$evalAsync()