class Privatbank::P24::AccountStatement

Public Class Methods

new(card_number, options={}) click to toggle source
# File lib/privatbank/p24/account_statement.rb, line 15
def initialize card_number, options={}
  @card_number       = card_number
  @from_date         = options[:from_date]
  @till_date         = options[:till_date]
  @merchant_id       = options[:merchant_id]
  @merchant_password = options[:merchant_password]
end

Public Instance Methods

from_date() click to toggle source
# File lib/privatbank/p24/account_statement.rb, line 77
def from_date
  @from_date.strftime('%d.%m.%Y')
end
outgoing_xml() click to toggle source
# File lib/privatbank/p24/account_statement.rb, line 39
def outgoing_xml
  builder = Builder::XmlMarkup.new
  builder.instruct!
  builder.request(version: '1.0') do |req|
    req.merchant do |merch|
      merch.id(@merchant_id)
      merch.signature(signature)
    end
    req.data do |d|
      d.oper('cmt')
      d.wait(0)
      d.payment(id: '') do |p|
        p.prop(name: 'sd',   value: from_date)
        p.prop(name: 'ed',   value: till_date)
        p.prop(name: 'card', value: @card_number)
      end
    end
  end
  builder.target!
end
request() click to toggle source
# File lib/privatbank/p24/account_statement.rb, line 23
def request
  response = self.class.post('/p24api/rest_fiz', body: outgoing_xml)
  return [] if response.fetch('error', nil)
  statements = response['response']['data']['info']['statements']['statement']
  statements = [statements] if statements.is_a?(Hash)
  statements.map do |operation|
    Items::Transaction.new( date:           operation['trandate'],
                            time:           operation['trantime'],
                            amount:         operation['amount'],
                            card_amount:    operation['cardamount'],
                            rest:           operation['rest'],
                            description:    operation['terminal'],
                            transaction_id: operation['appcode'])
  end
end
request_xml_data() click to toggle source
# File lib/privatbank/p24/account_statement.rb, line 60
def request_xml_data
  builder = Builder::XmlMarkup.new
  builder.oper('cmt')
  builder.wait(0)
  builder.payment(id: '') do |p|
    p.prop(name: 'sd',   value: from_date)
    p.prop(name: 'ed',   value: till_date)
    p.prop(name: 'card', value: @card_number)
  end
  builder.target!
end
signature() click to toggle source
# File lib/privatbank/p24/account_statement.rb, line 72
def signature
  Privatbank::Signature.generate(request_xml_data, @merchant_password)
end
till_date() click to toggle source
# File lib/privatbank/p24/account_statement.rb, line 81
def till_date
  @till_date.strftime('%d.%m.%Y')
end