Skip to content

Commit

Permalink
Merge branch 'pro-pricing-increase-email'
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Dec 3, 2024
2 parents e2b21c3 + c009f59 commit 14f595d
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
##
# To run theme rake tasks from the core Alaveteli directory you need to:
# rails -f lib/themes/whatdotheyknow-theme/Rakefile <task>
#
require "#{ENV['PWD']}/config/application"

Rails.application.load_tasks

Dir[File.join(__dir__, 'lib', 'tasks', '*.rake')].each { |file| load(file) }
29 changes: 29 additions & 0 deletions lib/mailer_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,33 @@
RequestMailer.class_eval do
prepend ExcelAnalyzer::RequestMailer
end

AlaveteliPro::SubscriptionMailer.class_eval do
include CurrencyHelper

def notify_price_increase(user, price_id)
auto_generated_headers(user)

subject = _('Changes to your {{pro_site_name}} subscription',
pro_site_name: pro_site_name)

@user_name = user.name

price = AlaveteliPro::Price.new(Stripe::Price.retrieve(price_id))
@amount = format_currency(
price.unit_amount_with_tax, no_cents_if_whole: true
)
@interval = price.recurring['interval']
case @interval
when 'month'; @intervally = 'monthly'
when 'year'; @intervally = 'yearly'
end

mail_user(
user,
from: contact_for_user(@user),
subject: subject
)
end
end
end
50 changes: 50 additions & 0 deletions lib/tasks/alavetelitheme_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,53 @@
# task :alavetelitheme do
# # Task goes here
# end

namespace :subscriptions do
task send_price_update_notice: :environment do
old_price, new_price = *load_prices

scope = Stripe::Subscription.list(price: old_price.id)
count = scope.data.size

scope.auto_paging_each.with_index do |subscription, index|
coupon = subscription.discount&.coupon
next if coupon&.percent_off == 100 && coupon&.duration == "forever"

user = User.joins(:pro_account).find_by(
pro_accounts: { stripe_customer_id: subscription.customer }
)
next unless user

AlaveteliPro::SubscriptionMailer.notify_price_increase(
user, new_price.id
).deliver_later

erase_line
print "Queued email to WDTK Pro subscribers: #{index + 1}/#{count}"
end

erase_line
puts "Queued email to WDTK Pro subscribers: completed"
end

def load_prices
old_price = Stripe::Price.retrieve(ENV['OLD_PRICE']) if ENV['OLD_PRICE']
new_price = Stripe::Price.retrieve(ENV['NEW_PRICE']) if ENV['NEW_PRICE']

if !old_price
puts "ERROR: Can't find OLD_PRICE"
exit 1
elsif !new_price
puts "ERROR: Can't find NEW_PRICE"
exit 1
elsif old_price.recurring != new_price.recurring
puts "ERROR: Price interval and interval_count need to match"
exit 1
elsif !AlaveteliPro::Price.list.map(&:id).include?(new_price.id)
puts "ERROR: New price is not defined in general.yml"
exit 1
end

[old_price, new_price]
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Dear <%= @user_name %>,

We're writing to let you know that the cost of your
WhatDoTheyKnow Pro - https://www.whatdotheyknow.com/pro
subscription is rising to <%= @amount %> per <%= @interval %>. You'll see this change
reflected in your next bill.

We hope you continue to see the value in your subscription
https://www.whatdotheyknow.com/profile/subscriptions.

This is the first time we've increased the cost of Pro since we
launched with our introductory pricing in 2017. There are many
features we want to introduce, to make WhatDoTheyKnow an even
more powerful platform for your work, so we invest your <%= @intervally %>
subscription directly into development and maintenance.

People do great things with WhatDoTheyKnow Pro. Here are a few
of the impacts we've seen from our users. We hope these will
inspire you to think of new directions you could go in with Pro
and if you've achieved something amazing through your usage too,
please do let us know about it [email protected].

-------------------
Sold From Under You
-------------------
The Bureau of Investigative Journalism revealed how much
publicly-owed property had been sold off by councils as a result
of austerity measures.

https://www.mysociety.org/2019/06/05/case-study-sold-from-under-you-by-the-bureau-of-investigative-journalism/
-------------------

--------------------
Chinese CCTV cameras
--------------------
Big Brother Watch secured a change in government policy when they
showed that public authorities were using CCTV cameras with
serious privacy vulnerabilities.

https://www.mysociety.org/2023/02/09/foi-and-chinese-cctv-cameras/
--------------------

---------------------------
Anti-environmental lobbying
---------------------------
Journalist Lucas Amin has broken several critical stories in
national newspapers, uncovering the interests behind climate
decisions made in government.

https://www.mysociety.org/2023/06/02/revealing-vital-environmental-information-with-whatdotheyknow-pro/
---------------------------

Questions? Thoughts? Let us know - just hit 'reply' on this
email.

All the best,

Gareth and the WhatDoTheyKnow team

0 comments on commit 14f595d

Please sign in to comment.