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
75 76 77 |
# File 'lib/privatbank/p24/account_statement.rb', line 75 def from_date @from_date.strftime('%d.%m.%Y') end |
#outgoing_xml ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/privatbank/p24/account_statement.rb', line 37 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 |
# 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) response['response']['data']['info']['statements']['statement'].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
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/privatbank/p24/account_statement.rb', line 58 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
70 71 72 |
# File 'lib/privatbank/p24/account_statement.rb', line 70 def signature Privatbank::Signature.generate(request_xml_data, @merchant_password) end |
#till_date ⇒ Object
79 80 81 |
# File 'lib/privatbank/p24/account_statement.rb', line 79 def till_date @till_date.strftime('%d.%m.%Y') end |