handle fails from stripe
This commit is contained in:
		
							parent
							
								
									17a43740d6
								
							
						
					
					
						commit
						dfd9e451c3
					
				|  | @ -36,5 +36,4 @@ Visit `/admin/customize/site_texts` and search for 'discourse_donations'. You'll | ||||||
| ## TODO | ## TODO | ||||||
| 
 | 
 | ||||||
| * Handle custom fields | * Handle custom fields | ||||||
| * Handle fails from stripe |  | ||||||
| * Acceptance test in RSpec not qunit.  | * Acceptance test in RSpec not qunit.  | ||||||
|  |  | ||||||
|  | @ -28,7 +28,19 @@ module DiscourseDonations | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       payment = DiscourseDonations::Stripe.new(secret_key, stripe_options) |       payment = DiscourseDonations::Stripe.new(secret_key, stripe_options) | ||||||
|  | 
 | ||||||
|  |       begin | ||||||
|         charge = payment.charge(email, params) |         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 |       if charge['paid'] == true | ||||||
|         output['messages'] << I18n.t('donations.payment.success') |         output['messages'] << I18n.t('donations.payment.success') | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| # name: discourse-donations | # name: discourse-donations | ||||||
| # about: Integrating Discourse with Stripe for donations | # about: Integrating Discourse with Stripe for donations | ||||||
| # version: 1.10.1 | # version: 1.10.2 | ||||||
| # url: https://github.com/choiceaustralia/discourse-donations | # url: https://github.com/choiceaustralia/discourse-donations | ||||||
| # authors: Rimian Perkins | # authors: Rimian Perkins | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue