diff --git a/Gemfile b/Gemfile index ea229ede5d..cab0da032d 100644 --- a/Gemfile +++ b/Gemfile @@ -126,7 +126,7 @@ gem 'sidekiq', '~> 6.5.12' gem 'sidekiq-limit_fetch', '~> 4.4.1' gem 'statistics2', '~> 0.54' gem 'strip_attributes', git: 'https://github.com/mysociety/strip_attributes.git', branch: 'globalize3-rails7' -gem 'stripe', '~> 5.55.0' +gem 'stripe', '~> 11.7.0' gem 'syck', '~> 1.4.1', require: false gem 'syslog_protocol', '~> 0.9.0' gem 'vpim', '~> 24.2.20' @@ -181,8 +181,7 @@ group :test do gem 'simplecov', '~> 0.22.0' gem 'simplecov-lcov', '~> 0.7.0' gem 'capybara', '~> 3.40.0' - gem 'stripe-ruby-mock', git: 'https://github.com/stripe-ruby-mock/stripe-ruby-mock', - ref: '6ceea96' + gem 'stripe-ruby-mock', '~> 4.0.0' gem 'rails-controller-testing' end diff --git a/Gemfile.lock b/Gemfile.lock index 13083948f8..8649215ee1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,16 +32,6 @@ GIT concurrent-ruby (~> 1.0) rack (> 1, < 3) -GIT - remote: https://github.com/stripe-ruby-mock/stripe-ruby-mock - revision: 6ceea9679bb573cb8bc6830f1bdf670b220a9859 - ref: 6ceea96 - specs: - stripe-ruby-mock (3.1.0.rc3) - dante (>= 0.2.0) - multi_json (~> 1.0) - stripe (> 5, < 6) - PATH remote: gems/alaveteli_features specs: @@ -532,7 +522,11 @@ GEM statistics2 (0.54) stimulus-rails (1.3.4) railties (>= 6.0.0) - stripe (5.55.0) + stripe (11.7.0) + stripe-ruby-mock (4.0.0) + dante (>= 0.2.0) + multi_json (~> 1.0) + stripe (> 5, < 12) syck (1.4.1) syslog_protocol (0.9.2) text (1.3.1) @@ -668,8 +662,8 @@ DEPENDENCIES statistics2 (~> 0.54) stimulus-rails (~> 1.3.4) strip_attributes! - stripe (~> 5.55.0) - stripe-ruby-mock! + stripe (~> 11.7.0) + stripe-ruby-mock (~> 4.0.0) syck (~> 1.4.1) syslog_protocol (~> 0.9.0) turbo-rails (~> 2.0.10) diff --git a/app/controllers/alaveteli_pro/plans_controller.rb b/app/controllers/alaveteli_pro/plans_controller.rb index 23f4f5fa51..fde8cdfd79 100644 --- a/app/controllers/alaveteli_pro/plans_controller.rb +++ b/app/controllers/alaveteli_pro/plans_controller.rb @@ -12,7 +12,9 @@ def index end def show - stripe_plan = Stripe::Plan.retrieve(plan_name) + stripe_plan = Stripe::Plan.retrieve( + id: plan_name, expand: ['product'] + ) @plan = AlaveteliPro::WithTax.new(stripe_plan) rescue Stripe::InvalidRequestError raise ActiveRecord::RecordNotFound diff --git a/app/controllers/alaveteli_pro/subscriptions_controller.rb b/app/controllers/alaveteli_pro/subscriptions_controller.rb index e7bbb87514..24fd5a2f74 100644 --- a/app/controllers/alaveteli_pro/subscriptions_controller.rb +++ b/app/controllers/alaveteli_pro/subscriptions_controller.rb @@ -151,13 +151,9 @@ def destroy @customer = current_user.pro_account.try(:stripe_customer) raise ActiveRecord::RecordNotFound unless @customer - @subscription = Stripe::Subscription.retrieve(params[:id]) - - unless @subscription.customer == @customer.id - raise ActiveRecord::RecordNotFound - end - - @subscription.delete(at_period_end: true) + @subscription = current_user.pro_account.subscriptions. + retrieve(params[:id]) + @subscription.update(cancel_at_period_end: true) flash[:notice] = _('You have successfully cancelled your subscription ' \ 'to {{pro_site_name}}', diff --git a/app/models/alaveteli_pro/invoice.rb b/app/models/alaveteli_pro/invoice.rb index 750fb0827c..b43b113b61 100644 --- a/app/models/alaveteli_pro/invoice.rb +++ b/app/models/alaveteli_pro/invoice.rb @@ -14,7 +14,7 @@ def paid? end # attributes - def date + def created Time.at(super).to_date end diff --git a/app/models/alaveteli_pro/subscription.rb b/app/models/alaveteli_pro/subscription.rb index 78f3e6c011..32e44dfa25 100644 --- a/app/models/alaveteli_pro/subscription.rb +++ b/app/models/alaveteli_pro/subscription.rb @@ -37,6 +37,14 @@ def require_authorisation? ].include?(payment_intent.status) end + def update(attributes) + __setobj__(Stripe::Subscription.update(id, attributes)) + end + + def delete + Stripe::Subscription.cancel(id) + end + private def method_missing(*args) diff --git a/app/models/pro_account.rb b/app/models/pro_account.rb index d668a17847..d227314c8b 100644 --- a/app/models/pro_account.rb +++ b/app/models/pro_account.rb @@ -73,6 +73,11 @@ def update_source end def stripe_customer! - Stripe::Customer.retrieve(stripe_customer_id) if stripe_customer_id + return unless stripe_customer_id + + Stripe::Customer.retrieve( + id: stripe_customer_id, + expand: ['subscriptions.data.plan.product'] + ) end end diff --git a/app/views/alaveteli_pro/invoices/_invoice.html.erb b/app/views/alaveteli_pro/invoices/_invoice.html.erb index 6ca5480be9..318cb631fa 100644 --- a/app/views/alaveteli_pro/invoices/_invoice.html.erb +++ b/app/views/alaveteli_pro/invoices/_invoice.html.erb @@ -1,5 +1,5 @@