Skip to content

Commit

Permalink
Merge branch 'pro-account-bans'
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Sep 29, 2023
2 parents 15b5e41 + e160de7 commit f57fd45
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/alavetelitheme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def prepend_theme_assets
'mailer_patches.rb',
'analytics_event.rb',
'help_page_history.rb',
'pro_account_bans.rb',
'public_body_questions.rb',
'school_late_calculator.rb',
'volunteer_contact_form.rb',
Expand Down
4 changes: 4 additions & 0 deletions lib/model_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def late_calculator
]
}

ProAccount.class_eval do
prepend ProAccountBans::ModelMethods
end

PublicBody.class_eval do
# Return the domain part of an email address, canonicalised and with common
# extra UK Government server name parts removed.
Expand Down
31 changes: 31 additions & 0 deletions lib/pro_account_bans.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module ProAccountBans
module ModelMethods
PRO_ACCOUNT_BANS_CONFIG = Rails.root.join('config/pro_account_bans.yml')

def update_source
return super unless pro_account_banned?

raise ProAccount::CardError, _("The card issuer couldn't authorize " \
"payment.")
end

def pro_account_banned?
return false unless bans_config

bans_config.any? do |ban|
ban.all? do |k, banned_value|
value = @token.card[k]
value.upcase.gsub(/\S/, '') if k == 'address_key'
value == banned_value
end
end
end

private

def bans_config
return unless File.exist?(PRO_ACCOUNT_BANS_CONFIG)
YAML.load_file(PRO_ACCOUNT_BANS_CONFIG)
end
end
end

0 comments on commit f57fd45

Please sign in to comment.