The gem adds a collection of translated error strings for 'All Stripe errors'
Supported Locales:
- en (English - US)
- es (Spanish)
- de (German)
- fr (French)
- it (Italian)
- nl (Dutch) -- TODO
- pt-BR (Portuguese - Brazil) -- TODO
- ru (Russian) -- TODO
- nb (Norwegian) -- TODO
- ja (Japanese) -- TODO
- zh-HK (Chinese - Hong Kong) -- TODO
Add this line to your application's Gemfile:
gem 'stripe-i18n'
And then execute:
$ bundle
Or install it yourself as:
$ gem install stripe-i18n
add this method in your helper.rb
def flash_stripe_errors(stripe_error)
body = stripe_error.json_body
err = body[:error] if body
code = err[:code] if err
if stripe_error.is_a?(Stripe::APIConnectionError)
msg = I18n.t("stripe.errors.connection_error")
else
if err[:decline_code]
msg = I18n.t("stripe.errors.#{code}") + " " + I18n.t("stripe.errors.reason") + ": " + I18n.t("stripe.errors.decline_reasons.#{err[:decline_code]}")
else
msg = I18n.t("stripe.errors.#{code}")
end
end
flash[:alert] = msg
end
Use the code on the error object to get the correct translation key.
def charge_token(token, amount)
Stripe::Charge.create(
amount: amount,
currency: 'usd',
card: token,
)
{ success: true, msg: I18n.translate('charge.success') }
rescue Stripe::CardError, Stripe::RateLimitError, Stripe::APIConnectionError, Stripe::InvalidRequestError, Stripe::AuthenticationError, Stripe::StripeError => e
flash_stripe_errors(e)
end
- Fork it ( https://github.com/ekosz/stripe-i18n/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request