Skip to content

Commit

Permalink
Fix ProAccountBans module
Browse files Browse the repository at this point in the history
Since Stripe API version upgrade [1] in core this hasn't worked as
expected.

This is because of changes to ProAccount#update_stripe_customer required
to support the newer API and changes to prevent deprecation warnings.

[1] mysociety/alaveteli#8405
  • Loading branch information
gbp committed Nov 22, 2024
1 parent 1d1412b commit 32565b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/pro_account_bans.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module ProAccountBans
module ModelMethods
PRO_ACCOUNT_BANS_CONFIG = Rails.root.join('config/pro_account_bans.yml')

def update_source
def update_stripe_customer
return unless feature_enabled?(:pro_pricing)
return super unless @token
return super unless pro_account_banned?

sleep (4...10).to_a.sample unless Rails.env.test? # simulate random delay
Expand Down
6 changes: 3 additions & 3 deletions spec/pro_account_bans_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let(:card_params) { { number: '4242424242424242', address_zip: 'AB1 1AB' } }

let(:pro_account) { FactoryBot.build(:pro_account, token: stripe_token) }
let(:customer) { Stripe::Customer.new(id: 'test_cus_123') }
let(:customer) { Stripe::Customer.create(id: 'test_cus_123') }

let(:stripe_token) do
token_id = stripe_helper.generate_card_token(card_params)
Expand All @@ -21,13 +21,13 @@
before do
allow(pro_account).to receive(:bans_config).and_return(bans_config)
allow(pro_account).to receive(:stripe_customer).and_return(customer)
allow(customer).to receive(:save)
allow(Stripe::Customer).to receive(:update).and_return(customer)
end

context 'with a valid token' do
it 'updates the Stripe customer successfully' do
expect(pro_account.update_stripe_customer).to be_truthy
expect(customer).to have_received(:save)
expect(Stripe::Customer).to have_received(:update)
end
end

Expand Down

0 comments on commit 32565b8

Please sign in to comment.