Class: RubyPaypalNvp::Model::Statement
- Inherits:
-
Object
- Object
- RubyPaypalNvp::Model::Statement
- Defined in:
- lib/ruby_paypal_nvp/model/statement.rb
Constant Summary collapse
- IGNORED_STATUSES =
%w[Cleared Placed Removed].freeze
Instance Attribute Summary collapse
-
#amount_sum ⇒ Object
Returns the value of attribute amount_sum.
-
#currency_code ⇒ Object
Returns the value of attribute currency_code.
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#fee_amount_sum ⇒ Object
Returns the value of attribute fee_amount_sum.
-
#items ⇒ Object
Returns the value of attribute items.
-
#items_count ⇒ Object
Returns the value of attribute items_count.
-
#net_amount_sum ⇒ Object
Returns the value of attribute net_amount_sum.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#generate_csv(filename = nil) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
-
#initialize(result) ⇒ Statement
constructor
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
- #to_iis_json ⇒ Object
-
#to_json ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength.
Constructor Details
#initialize(result) ⇒ Statement
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 14 def initialize(result) @timestamp = result[:meta]['timestamp'] @start_date = result[:meta]['start_date'] @end_date = result[:meta]['end_date'] @subject = result[:meta]['subject'] @currency_code = result[:meta]['currency_code'] @items = result[:values].map do |value| Item.new(value) unless IGNORED_STATUSES.include?(value['L_STATUS']) end.compact.uniq(&:transaction_id) @items_count = @items.count @amount_sum = @items.sum(&:amount) @fee_amount_sum = @items.sum(&:fee_amount) @net_amount_sum = @items.sum(&:net_amount) @raw = result end |
Instance Attribute Details
#amount_sum ⇒ Object
Returns the value of attribute amount_sum.
6 7 8 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 6 def amount_sum @amount_sum end |
#currency_code ⇒ Object
Returns the value of attribute currency_code.
6 7 8 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 6 def currency_code @currency_code end |
#end_date ⇒ Object
Returns the value of attribute end_date.
6 7 8 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 6 def end_date @end_date end |
#fee_amount_sum ⇒ Object
Returns the value of attribute fee_amount_sum.
6 7 8 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 6 def fee_amount_sum @fee_amount_sum end |
#items ⇒ Object
Returns the value of attribute items.
6 7 8 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 6 def items @items end |
#items_count ⇒ Object
Returns the value of attribute items_count.
6 7 8 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 6 def items_count @items_count end |
#net_amount_sum ⇒ Object
Returns the value of attribute net_amount_sum.
6 7 8 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 6 def net_amount_sum @net_amount_sum end |
#start_date ⇒ Object
Returns the value of attribute start_date.
6 7 8 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 6 def start_date @start_date end |
#subject ⇒ Object
Returns the value of attribute subject.
6 7 8 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 6 def subject @subject end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 6 def @timestamp end |
Instance Method Details
#generate_csv(filename = nil) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 34 def generate_csv(filename = nil) raise 'Missing filename/path' unless filename ::CSV.open(filename, 'w') do |csv| csv << ['HEADER'] csv << ['', 'timestamp', @timestamp] csv << ['', 'start_date', @start_date] csv << ['', 'end_date', @end_date] csv << ['', 'subject', @subject] csv << ['', 'currency_code', @currency_code] csv << ['', 'items_count', @items_count] csv << ['', 'amount_sum', @amount_sum] csv << ['', 'fee_amount_sum', @fee_amount_sum] csv << ['', 'net_amount_sum', @net_amount_sum] csv << ['ITEMS'] csv << RubyPaypalNvp::Model::Item.attributes @items.each do |item| csv << item.to_csv end end end |
#to_iis_json ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 61 def to_iis_json { 'meta': { 'timestamp': @timestamp, 'start_date': @start_date, 'end_date': @end_date, 'subject': @subject, 'currency_code': @currency_code }, 'values': raw_items }.to_json end |
#to_json ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength
57 58 59 |
# File 'lib/ruby_paypal_nvp/model/statement.rb', line 57 def to_json raw_items.to_json end |