Class: RockRMS::Response::Transaction

Inherits:
Base
  • Object
show all
Defined in:
lib/rock_rms/response/transaction.rb

Constant Summary collapse

MAP =
{
  date: 'TransactionDateTime',
  person: 'AuthorizedPersonAlias',
  person_id: 'AuthorizedPersonAliasId',
  batch_id: 'BatchId',
  gateway_id: 'FinancialGatewayId',
  recurring_donation_id: 'ScheduledTransactionId',
  summary: 'Summary',
  transaction_code: 'TransactionCode',
  details: 'TransactionDetails',
  payment_details: 'FinancialPaymentDetail',
  payment_detail_id: 'FinancialPaymentDetailId',
  transaction_type_id: 'TransactionTypeValueId'
}.freeze

Constants inherited from Base

Base::BASE_MAPPING

Instance Attribute Summary

Attributes inherited from Base

#data

Instance Method Summary collapse

Methods inherited from Base

format, #format, #format_attributes, #initialize, #to_h

Constructor Details

This class inherits a constructor from RockRMS::Response::Base

Instance Method Details

#calculate_total(details) ⇒ Object



34
35
36
# File 'lib/rock_rms/response/transaction.rb', line 34

def calculate_total(details)
  details.reduce(0) { |sum, td| sum + td[:amount] }
end

#format_person(res) ⇒ Object



29
30
31
32
# File 'lib/rock_rms/response/transaction.rb', line 29

def format_person(res)
  return res if res.nil?
  Person.format(res['Person'])
end

#format_single(data) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/rock_rms/response/transaction.rb', line 20

def format_single(data)
  response                   = to_h(MAP, data)
  response[:details]         = TransactionDetail.format(response[:details])
  response[:payment_details] = PaymentDetail.format(response[:payment_details])
  response[:person]          = format_person(response[:person])
  response[:amount]          = calculate_total(response[:details])
  response
end