handle some standard stripe fail stuff

This commit is contained in:
Rimian Perkins
2017-05-24 12:03:52 +10:00
parent be122744a3
commit a43f79d7a0
3 changed files with 26 additions and 8 deletions
+10 -3
View File
@@ -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
@@ -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'
+1 -1
View File
@@ -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