diff --git a/app/assets/javascripts/darkswarm/services/stripe_elements.js.coffee b/app/assets/javascripts/darkswarm/services/stripe_elements.js.coffee index 1fffcac18e..e656fbbbe0 100644 --- a/app/assets/javascripts/darkswarm/services/stripe_elements.js.coffee +++ b/app/assets/javascripts/darkswarm/services/stripe_elements.js.coffee @@ -19,6 +19,11 @@ Darkswarm.factory 'StripeElements', ($rootScope, Messages) -> secrets.cc_type = @mapTokenApiCardBrand(response.token.card.brand) secrets.card = response.token.card submit() + .catch (response) => + # Stripe handles errors in the response above. This code may never be + # reached. But if we get here, we want to know. + @reportError(response, t("js.stripe_elements.unknown_error_from_stripe")) + throw response # Create Payment Method to be used with the Stripe Payment Intents API createPaymentMethod: (secrets, submit, loading_message = t("processing_payment")) -> @@ -35,11 +40,17 @@ Darkswarm.factory 'StripeElements', ($rootScope, Messages) -> secrets.cc_type = @mapPaymentMethodsApiCardBrand(response.paymentMethod.card.brand) secrets.card = response.paymentMethod.card submit() + .catch (response) => + # Stripe handles errors in the response above. This code may never be + # reached. But if we get here, we want to know. + @reportError(response, t("js.stripe_elements.unknown_error_from_stripe")) + throw response reportError: (error, messageForUser) -> Messages.error(messageForUser) @triggerAngularDigest() - console.error(JSON.stringify(error)) + console.error(error) + Bugsnag.notify(new Error(JSON.stringify(error))) triggerAngularDigest: -> # $evalAsync is improved way of triggering a digest without calling $apply diff --git a/config/locales/en.yml b/config/locales/en.yml index 8759f90d9b..af121037a5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2767,6 +2767,11 @@ See the %{link} to find out more about %{sitename}'s features and to start using signup_or_login: "Start By Signing Up (or logging in)" have_an_account: "Already have an account?" action_login: "Log in now." + stripe_elements: + unknown_error_from_stripe: | + Uh oh, the Stripe integration failed. You can try again but there is + a very small chance that the payment came through already. It's best to + check your bank account first. # Singular and plural forms of commonly used words. # We use these entries to pluralize unit names in every language. diff --git a/spec/javascripts/unit/darkswarm/services/stripe_elements_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/stripe_elements_spec.js.coffee index 821df4b153..d7e7fa249a 100644 --- a/spec/javascripts/unit/darkswarm/services/stripe_elements_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/stripe_elements_spec.js.coffee @@ -46,10 +46,12 @@ describe 'StripeElements Service', -> it "doesn't submit the form, shows an error message instead", inject (Loading, RailsFlashLoader) -> spyOn(Loading, "clear") spyOn(RailsFlashLoader, "loadFlash") + spyOn(Bugsnag, "notify") StripeElements.requestToken(secrets, submit).then (data) -> expect(submit).not.toHaveBeenCalled() expect(Loading.clear).toHaveBeenCalled() expect(RailsFlashLoader.loadFlash).toHaveBeenCalledWith({error: "Error: There was a problem"}) + expect(Bugsnag.notify).toHaveBeenCalled() describe 'mapTokenApiCardBrand', -> it "maps the brand returned by Stripe's tokenAPI to that required by activemerchant", ->