handle some standard stripe fail stuff
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user