diff --git a/Rakefile b/Rakefile index e69de29b..c3c83252 100644 --- a/Rakefile +++ b/Rakefile @@ -0,0 +1,9 @@ +## +# To run theme rake tasks from the core Alaveteli directory you need to: +# rails -f lib/themes/whatdotheyknow-theme/Rakefile +# +require "#{ENV['PWD']}/config/application" + +Rails.application.load_tasks + +Dir[File.join(__dir__, 'lib', 'tasks', '*.rake')].each { |file| load(file) } diff --git a/lib/mailer_patches.rb b/lib/mailer_patches.rb index 0b9e929a..4fb1ef00 100644 --- a/lib/mailer_patches.rb +++ b/lib/mailer_patches.rb @@ -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 diff --git a/lib/tasks/alavetelitheme_tasks.rake b/lib/tasks/alavetelitheme_tasks.rake index 1f1925bf..3d3f31cc 100644 --- a/lib/tasks/alavetelitheme_tasks.rake +++ b/lib/tasks/alavetelitheme_tasks.rake @@ -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 diff --git a/lib/views/alaveteli_pro/subscription_mailer/notify_price_increase.text.erb b/lib/views/alaveteli_pro/subscription_mailer/notify_price_increase.text.erb new file mode 100644 index 00000000..0948b85d --- /dev/null +++ b/lib/views/alaveteli_pro/subscription_mailer/notify_price_increase.text.erb @@ -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 communications@mysociety.org. + +------------------- +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