Class: Privatbank::P24::AccountStatement
- Inherits:
-
Object
- Object
- Privatbank::P24::AccountStatement
- Includes:
- HTTParty
- Defined in:
- lib/privatbank/p24/account_statement.rb
Instance Method Summary collapse
- #from_date ⇒ Object
-
#initialize(card_number, options = {}) ⇒ AccountStatement
constructor
A new instance of AccountStatement.
- #outgoing_xml ⇒ Object
- #request ⇒ Object
- #request_xml_data ⇒ Object
- #signature ⇒ Object
- #till_date ⇒ Object
Constructor Details
#initialize(card_number, options = {}) ⇒ AccountStatement
Returns a new instance of AccountStatement.
15 16 17 18 19 20 21 |
# File 'lib/privatbank/p24/account_statement.rb', line 15 def initialize card_number, ={} @card_number = card_number @from_date = [:from_date] @till_date = [:till_date] @merchant_id = [:merchant_id] @merchant_password = [:merchant_password] end |
Instance Method Details
#from_date ⇒ Object
77 78 79 |
# File 'lib/privatbank/p24/account_statement.rb', line 77 def from_date @from_date.strftime('%d.%m.%Y') end |
#outgoing_xml ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# 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 ⇒ Object
72 73 74 |
# File 'lib/privatbank/p24/account_statement.rb', line 72 def signature Privatbank::Signature.generate(request_xml_data, @merchant_password) end |
#till_date ⇒ Object
81 82 83 |
# File 'lib/privatbank/p24/account_statement.rb', line 81 def till_date @till_date.strftime('%d.%m.%Y') end |