Class: Adapters::PaymentHistoryAdapter
- Inherits:
-
Object
- Object
- Adapters::PaymentHistoryAdapter
- Defined in:
- app/models/adapters/payment_history_adapter.rb
Instance Attribute Summary collapse
-
#payments ⇒ Object
Returns the value of attribute payments.
-
#return_payments ⇒ Object
Returns the value of attribute return_payments.
Instance Method Summary collapse
- #get_payment_method(payment) ⇒ Object private
-
#initialize(input) ⇒ PaymentHistoryAdapter
constructor
A new instance of PaymentHistoryAdapter.
- #mask_account_number(address_eft, all_but = 4, char = '*') ⇒ Object private
- #process_payments(payments) ⇒ Object private
- #process_return_payments(returned_payments) ⇒ Object private
Constructor Details
#initialize(input) ⇒ PaymentHistoryAdapter
Returns a new instance of PaymentHistoryAdapter.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/adapters/payment_history_adapter.rb', line 7 def initialize(input) @input_payment = input.dig(:payments, :payment) if @input_payment.nil? || !Flipper.enabled?(:payment_history) @payments = [] @return_payments = [] else @input_payments = [@input_payment].flatten payments, return_payments = @input_payments.partition do |payment| payment.dig(:return_payment, :check_trace_number).blank? end @payments = process_payments(payments) @return_payments = process_return_payments(return_payments) end end |
Instance Attribute Details
#payments ⇒ Object
Returns the value of attribute payments.
5 6 7 |
# File 'app/models/adapters/payment_history_adapter.rb', line 5 def payments @payments end |
#return_payments ⇒ Object
Returns the value of attribute return_payments.
5 6 7 |
# File 'app/models/adapters/payment_history_adapter.rb', line 5 def return_payments @return_payments end |
Instance Method Details
#get_payment_method(payment) ⇒ Object (private)
52 53 54 55 56 57 58 |
# File 'app/models/adapters/payment_history_adapter.rb', line 52 def get_payment_method(payment) return 'Direct Deposit' if payment.dig(:address_eft, :account_number).present? return 'Paper Check' if payment.dig(:check_address, :address_line1).present? nil end |
#mask_account_number(address_eft, all_but = 4, char = '*') ⇒ Object (private)
60 61 62 63 64 65 66 67 |
# File 'app/models/adapters/payment_history_adapter.rb', line 60 def mask_account_number(address_eft, all_but = 4, char = '*') return if address_eft.blank? account_number = address_eft[:account_number] return if account_number.blank? account_number.gsub(/.(?=.{#{all_but}})/, char) end |
#process_payments(payments) ⇒ Object (private)
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/adapters/payment_history_adapter.rb', line 26 def process_payments(payments) payments.map do |payment| { pay_check_dt: payment[:payment_date], pay_check_amount: ActiveSupport::NumberHelper.number_to_currency(payment[:payment_amount]), pay_check_type: payment[:payment_type], payment_method: get_payment_method(payment), bank_name: payment.dig(:address_eft, :bank_name), account_number: mask_account_number(payment[:address_eft]) } end end |
#process_return_payments(returned_payments) ⇒ Object (private)
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/adapters/payment_history_adapter.rb', line 39 def process_return_payments(returned_payments) returned_payments.map do |payment| { returned_check_issue_dt: payment[:payment_date], returned_check_cancel_dt: payment[:return_payment][:return_date], returned_check_amount: ActiveSupport::NumberHelper.number_to_currency(payment[:payment_amount]), returned_check_number: payment[:return_payment][:check_trace_number], returned_check_type: payment[:payment_type], return_reason: payment[:return_payment][:return_reason] } end end |