handle fails from stripe

This commit is contained in:
Rimian Perkins 2017-05-24 12:22:00 +10:00
parent 17a43740d6
commit dfd9e451c3
3 changed files with 14 additions and 3 deletions

View File

@ -36,5 +36,4 @@ Visit `/admin/customize/site_texts` and search for 'discourse_donations'. You'll
## TODO
* Handle custom fields
* Handle fails from stripe
* Acceptance test in RSpec not qunit.

View File

@ -28,7 +28,19 @@ module DiscourseDonations
end
payment = DiscourseDonations::Stripe.new(secret_key, stripe_options)
charge = payment.charge(email, params)
begin
charge = payment.charge(email, params)
rescue ::Stripe::CardError => e
err = e.json_body[:error]
output['messages'] << "There was an error (#{err[:type]})."
#output['messages'] << "Error code: #{err[:code]}" if err[:code]
#output['messages'] << "Decline code: #{err[:decline_code]}" if err[:decline_code]
output['messages'] << "Message: #{err[:message]}" if err[:message]
render(:json => output) and return
end
if charge['paid'] == true
output['messages'] << I18n.t('donations.payment.success')

View File

@ -1,6 +1,6 @@
# name: discourse-donations
# about: Integrating Discourse with Stripe for donations
# version: 1.10.1
# version: 1.10.2
# url: https://github.com/choiceaustralia/discourse-donations
# authors: Rimian Perkins