Skip to content

Commit

Permalink
close issue RailsApps#17, handle 'card declined' errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielKehoe committed Dec 1, 2012
1 parent 354ecb0 commit 0a02d7f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
16 changes: 16 additions & 0 deletions app/helpers/devise_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module DeviseHelper
def devise_error_messages!
return '' if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg| content_tag(:p, msg) }.join
sentence = I18n.t('errors.messages.not_saved',
count: resource.errors.count,
resource: resource.class.model_name.human.downcase)
html = <<-HTML
<div class="alert alert-error alert-block">
<button type="button" class="close" data-dismiss="alert">&#215;</button>
#{messages}
</div>
HTML
html.html_safe
end
end
10 changes: 5 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def update_stripe
self.customer_id = customer.id
self.stripe_token = nil
rescue Stripe::StripeError => e
logger.error e.message
errors.add :base, "Unable to create your subscription. #{e.message}"
stripe_token = nil
logger.error "Stripe Error: " + e.message
errors.add :base, "Unable to create your subscription. #{e.message}."
self.stripe_token = nil
false
end

Expand All @@ -60,8 +60,8 @@ def cancel_subscription
end
end
rescue Stripe::StripeError => e
logger.error e.message
errors.add :base, "Unable to cancel your subscription. #{e.message}"
logger.error "Stripe Error: " + e.message
errors.add :base, "Unable to cancel your subscription. #{e.message}."
false
end

Expand Down
1 change: 1 addition & 0 deletions app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div id="stripe_error" class="alert alert-error" style="display:none" ></div>
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :class => 'form-vertical' }) do |f| %>
<%= f.error_notification %>
<%= devise_error_messages! %>
<%= f.input :name, :autofocus => true %>
<%= f.input :email, :required => true %>
<%= f.input :password, :autocomplete => "off", :hint => "leave it blank if you don't want to change it", :required => false %>
Expand Down
1 change: 1 addition & 0 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<h3><%= params[:plan].titleize if params[:plan] %> Subscription Plan</h3>
<%= hidden_field_tag 'plan', params[:plan] %>
<%= f.error_notification %>
<%= devise_error_messages! %>
<%= f.input :name, :autofocus => true %>
<%= f.input :email, :required => true %>
<%= f.input :password, :required => true %>
Expand Down

0 comments on commit 0a02d7f

Please sign in to comment.