Detailed changes
@@ -7,16 +7,19 @@ class BuyAccountCreditForm
# Returns a TrustLevelRepo instance, allowing for dependency injection.
# Either creates a new instance given kwargs or returns the existing instance.
# @param kwargs [Hash] keyword arguments.
- # @option kwargs [TrustLevelRepo] :trust_level_repo An existing TrustLevelRepo instance.
+ # @option kwargs [TrustLevelRepo] :trust_level_repo An existing TrustLevelRepo
+ # instance.
# @return [TrustLevelRepo] An instance of TrustLevelRepo.
def self.trust_level_repo(**kwargs)
kwargs[:trust_level_repo] || TrustLevelRepo.new(**kwargs)
end
# Factory method to create a BuyAccountCreditForm for a given customer.
- # It fetches the customer's trust level to determine the maximum top-up amount.
+ # It fetches the customer's trust level to determine the maximum top-up
+ # amount.
# @param customer [Customer] The customer for whom the form is being created.
- # @return [EMPromise<BuyAccountCreditForm>] A promise that resolves with the new form instance.
+ # @return [EMPromise<BuyAccountCreditForm>] A promise that resolves with the
+ # new form instance.
def self.for(customer)
trust_level_repo.find(customer).then do |trust_level|
customer.payment_methods.then do |payment_methods|
@@ -27,8 +30,10 @@ class BuyAccountCreditForm
# Initializes a new BuyAccountCreditForm.
# @param balance [BigDecimal] The current balance of the customer.
- # @param payment_methods [PaymentMethods] The available payment methods for the customer.
- # @param max_top_up_amount [Numeric] The maximum amount the customer is allowed to top up, based on their trust level.
+ # @param payment_methods [PaymentMethods] The available payment methods for
+ # the customer.
+ # @param max_top_up_amount [Numeric] The maximum amount the customer is
+ # allowed to top up, based on their trust level.
def initialize(balance, payment_methods, max_top_up_amount)
@balance = balance
@payment_methods = payment_methods
@@ -36,7 +41,8 @@ class BuyAccountCreditForm
end
# Generates the form template for topping up account credit.
- # The form will include a range for the amount field, constrained by a minimum of $15
+ # The form will include a range for the amount field, constrained by a minimum
+ # of $15
# and the customer's specific maximum top-up amount.
# @return [FormTemplate::OneRender] The rendered form template.
def form
@@ -42,7 +42,8 @@ class AmountTooLowError < TransactionDeclinedError
end
end
-# Error raised when a transaction is declined, potentially due to exceeding decline limits.
+# Error raised when a transaction is declined, potentially due to exceeding
+# decline limits.
class DeclinedError < TransactionDeclinedError
# @return [Integer, nil] The number of declines the customer has.
attr_reader :declines
@@ -110,12 +111,17 @@ class CreditCardSale
protected
- # Validates the transaction against customer locks, trust level, and decline history.
- # @raise [TransactionDeclinedError] if the customer has made too many payments recently.
- # @raise [AmountTooHighError] if the amount exceeds the trust level's maximum top-up amount.
+ # Validates the transaction against customer locks, trust level, and decline
+ # history.
+ # @raise [TransactionDeclinedError] if the customer has made too many payments
+ # recently.
+ # @raise [AmountTooHighError] if the amount exceeds the trust level's maximum
+ # top-up amount.
# @raise [AmountTooLowError] if the amount is below any applicable minimum.
- # @raise [DeclinedError] if the transaction is declined due to too many previous declines or other trust level restrictions.
- # @return [EMPromise<void>] A promise that resolves if validation passes, or rejects with an error.
+ # @raise [DeclinedError] if the transaction is declined due to too many
+ # previous declines or other trust level restrictions.
+ # @return [EMPromise<void>] A promise that resolves if validation passes, or
+ # rejects with an error.
def validate!
EMPromise.all([
REDIS.exists("jmp_customer_credit_card_lock-#{@customer.customer_id}"),
@@ -90,7 +90,8 @@ module TrustLevel
# @param amount [BigDecimal] The amount of the transaction.
# @param declines [Integer] The number of recent declines for the customer.
# @raise [DeclinedError] if the number of declines exceeds `max_declines`.
- # @raise [AmountTooHighError] if the transaction amount exceeds `max_top_up_amount`.
+ # @raise [AmountTooHighError] if the transaction amount exceeds
+ # `max_top_up_amount`.
def validate_credit_card_transaction!(amount, declines)
raise DeclinedError.new(declines, max_declines) if declines > max_declines
return unless amount > max_top_up_amount
@@ -143,7 +144,8 @@ module TrustLevel
# @param amount [BigDecimal] The amount of the transaction.
# @param declines [Integer] The number of recent declines for the customer.
# @raise [DeclinedError] if the number of declines exceeds `max_declines`.
- # @raise [AmountTooHighError] if the transaction amount exceeds `max_top_up_amount`.
+ # @raise [AmountTooHighError] if the transaction amount exceeds
+ # `max_top_up_amount`.
def validate_credit_card_transaction!(amount, declines)
raise DeclinedError.new(declines, max_declines) if declines > max_declines
return unless amount > max_top_up_amount
@@ -193,9 +195,8 @@ module TrustLevel
end
# Validates a credit card transaction for an Olympias trust level user.
- # Users at this level have no restrictions on credit card transactions through this method.
- # @param _amount [BigDecimal] The amount of the transaction (ignored).
- # @param _declines [Integer] The number of recent declines (ignored).
+ # Users at this level have no restrictions on credit card transactions
+ # through this method.
# @return [void]
def validate_credit_card_transaction!(*) end
@@ -244,7 +245,8 @@ module TrustLevel
# @param amount [BigDecimal] The amount of the transaction.
# @param declines [Integer] The number of recent declines for the customer.
# @raise [DeclinedError] if the number of declines exceeds `max_declines`.
- # @raise [AmountTooHighError] if the transaction amount exceeds `max_top_up_amount`.
+ # @raise [AmountTooHighError] if the transaction amount exceeds
+ # `max_top_up_amount`.
def validate_credit_card_transaction!(amount, declines)
raise DeclinedError.new(declines, max_declines) if declines > max_declines
return unless amount > max_top_up_amount