Skip to content

Commit

Permalink
v2.0.3
Browse files Browse the repository at this point in the history
Merge pull request #679 from TechforgoodCAST/develop
  • Loading branch information
suninthesky authored Jun 14, 2018
2 parents f601458 + 7f81fe0 commit f17ddb5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
12 changes: 5 additions & 7 deletions app/controllers/webhooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ def invoice_payment_succeeded
end

def customer_subscription_deleted
Subscription.find_by(stripe_user_id: @customer.id)
.update(active: false, percent_off: 0)
subscription = Subscription.find_by(stripe_user_id: @customer.id)
subscription.update(active: false, percent_off: 0)
subscription.recipient.users.each do |user|
SubscriptionMailer.deactivated(user).deliver_now
end
rescue NoMethodError
nil
end

def subscription_expired
# TODO: deactivate Beehive::Subscription at_period_end
# TODO: send reminder emails
end

private

def load_customer
Expand Down
6 changes: 6 additions & 0 deletions app/mailers/subscription_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class SubscriptionMailer < ApplicationMailer
def deactivated(user)
@user = user
mail(to: @user.email, subject: 'Subscription Expired - Beehive')
end
end
17 changes: 17 additions & 0 deletions app/views/subscription_mailer/deactivated.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Hi <%= @user&.first_name %>

Your 'Pro' subscription on www.beehivegiving.org (Beehive) has now come to an end.

As Beehive is a project of a charity, we really appreciate that you upgraded your account a year ago. Your contribution has helped us sustain the project and provide our grant funding suitability checking service to many more fund seekers - thank you!

We know there is plenty we could do to improve our service, and as a valued customer we'd love to ask you a few brief questions about this.

To say thank you for your feedback and support, we'll happily extend your 'Pro' subscription for another year (free of charge).

Just reply to this email and let us know you'd be happy to answer some questions.

Big thanks,
The Beehive Team

--
This is an automated message from www.beehivegiving.org
23 changes: 10 additions & 13 deletions spec/features/subscriptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@

scenario 'webhook customer-subscription-deleted', type: :request do
Subscription.last.update(percent_off: 10)
status = helper.stripe_subscription(@db[:recipient]).status

expect(Subscription.last.active).to eq true
expect(Subscription.last.percent_off).to eq 10
expect(helper.stripe_subscription(@db[:recipient]).status)
.to eq 'active'
expect(Subscription.last.active).to eq(true)
expect(Subscription.last.percent_off).to eq(10)
expect(status).to eq('active')

event = StripeMock.mock_webhook_event(
'customer.subscription.deleted',
Expand All @@ -172,16 +172,13 @@
params: event.to_json,
headers: { 'Content-Type': 'application/json' }

expect(Subscription.last.active).to eq false
expect(Subscription.last.percent_off).to eq 0
expect(event.data.object.status).to eq 'canceled'
end
expect(Subscription.last.active).to eq(false)
expect(Subscription.last.percent_off).to eq(0)
expect(event.data.object.status).to eq('canceled')

scenario 'remaining free checks hidden' do
@app.setup_funds
@db[:proposal].save!
visit fund_path(Fund.first, @db[:proposal])
expect(page).not_to have_button 'Check eligibility (3 left)'
deliveries = ActionMailer::Base.deliveries
expect(deliveries.size).to eq(1)
expect(deliveries.last.subject).to eq('Subscription Expired - Beehive')
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/mailers/previews/subscription_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class SubscriptionMailerPreview < ActionMailer::Preview
def deactivated
user = OpenStruct.new(email: 'email@example.com', first_name: 'John')
SubscriptionMailer.deactivated(user)
end
end

0 comments on commit f17ddb5

Please sign in to comment.