diff --git a/README.md b/README.md index c40c259..3915f35 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Note: There's an issue upgrading to 1.8.0.beta11 with themes. You might be requi Visit `/admin/customize/site_texts` and search for 'discourse_donations'. You'll find a few entries you can customise for your site. -## Testing +## Test Suite * To run the rails specs, install the plugin and run `bundle exec rake plugin:spec[discourse-donations]` in the discourse root directory. * To run qunit tests: `MODULE='Acceptance: Discourse Donations' bundle exec rake qunit:test[20000]`. @@ -35,6 +35,13 @@ Visit `/admin/customize/site_texts` and search for 'discourse_donations'. You'll ## TODO +* Test card fails * Handle custom fields -* Handle fails from stripe -* Acceptance test in RSpec not qunit. +* Acceptance test in RSpec not qunit. + +## Tested Credit Card Numbers + +These numbers can be used in test mode to simulate a transaction. For more information see the [Stripe docs](https://stripe.com/docs/testing). + +* Payment successful: 5555 5555 5555 4444 +* Card declined: 4000 0000 0000 0002 diff --git a/app/controllers/discourse_donations/charges_controller.rb b/app/controllers/discourse_donations/charges_controller.rb index 5db7260..23c2d22 100644 --- a/app/controllers/discourse_donations/charges_controller.rb +++ b/app/controllers/discourse_donations/charges_controller.rb @@ -29,10 +29,21 @@ module DiscourseDonations payment = DiscourseDonations::Stripe.new(secret_key, stripe_options) - if params['amount'].present? - charge = payment.subscribe(email, params.merge(plan: params[:amount])) - else - charge = payment.subscribe(email, params) + begin + if params['amount'].present? + charge = payment.subscribe(email, params.merge(plan: params[:amount])) + else + charge = payment.subscribe(email, params) + end + rescue ::Stripe::CardError => e + err = e.json_body[:error] + + output['messages'] << "Error type: #{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 || charge['status'] == 'active' diff --git a/plugin.rb b/plugin.rb index ccee6ce..613b90e 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,6 +1,6 @@ # name: discourse-donations # about: Integrating Discourse with Stripe for donations -# version: 2.0.0 +# version: 2.1.0 # url: https://github.com/choiceaustralia/discourse-donations # authors: Rimian Perkins