-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When a YAML config file is present, check the payment card before the pro subscription is created. With the YAML: ```yaml - fingerprint: 123abc456DEF789gh address_zip: AB11AB - address_zip: CD11CD ``` This would add two bans. Prevent sign up if the payment card entered matches: 1. the fingerprint and postcode `AB1 1AB`, or 2. the postcode `cd11cd` For fingerprint, these come from the Stripe dashboard and are unique for a given card. See: https://stripe.com/docs/api/cards/object#card_object-fingerprint For postcodes/address zip we upcase and strip all white space from what is provided on the payment form.
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |