Skip to content

Commit

Permalink
Make sure to close the Recurly account when the user close his account
Browse files Browse the repository at this point in the history
  • Loading branch information
thbar committed Nov 16, 2013
1 parent cda3d18 commit 8130e80
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
15 changes: 15 additions & 0 deletions app/controllers/registrations_controller.rb
@@ -0,0 +1,15 @@
class RegistrationsController < Devise::RegistrationsController
# Here is the right place to notify yourself if you'd like
after_filter({:only => :create}) do
end

def destroy
if current_user.recurly_enabled
BillingService.close_account(current_user.recurly_account_code)
end
# Here you can send the user a specific email
# You could also send you the reason entered by the user
# + LTV + activity before cancellation
super
end
end
12 changes: 12 additions & 0 deletions app/services/billing_service.rb
Expand Up @@ -15,4 +15,16 @@ def confirm_subscription(user, token)
user.update_attribute(:recurly_enabled, true)
return true
end

def close_account(account_unique_identifier)
# no need to verify the output of find since it will raise if no match is found
account = Recurly::Account.find(account_unique_identifier)
# close the account
account.destroy
# as well, terminate subscription without refund, immediately, so that
# our MRR and active subscriptions are reported properly, otherwise they
# will remain live until the termination date
account.subscriptions.live.each { |s| s.terminate(:none) }
end

end
4 changes: 3 additions & 1 deletion app/views/dashboard/index.html.erb
@@ -1 +1,3 @@
Yes! You are in, with a paid subscription.
Yes! You are in, with a paid subscription.

<%= link_to "Cancel my account", user_registration_path, :confirm => "Are you sure?", :method => :delete %>.
1 change: 1 addition & 0 deletions app/views/devise/registrations/new.html.erb
Expand Up @@ -6,6 +6,7 @@

<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>
<span>^ Careful! Recurly will send emails there! ^</span>

<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
@@ -1,5 +1,5 @@
RailsRecurlyJsSampleApplication::Application.routes.draw do
devise_for :users
devise_for :users, :controllers => { :registrations => 'registrations' }

root 'site#index'

Expand Down

0 comments on commit 8130e80

Please sign in to comment.