Class: Privatbank::P24::Info

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/privatbank/p24/info.rb

Instance Method Summary collapse

Constructor Details

#initialize(card_number, country, options) ⇒ Info

Returns a new instance of Info.



14
15
16
17
18
19
# File 'lib/privatbank/p24/info.rb', line 14

def initialize card_number, country, options
  @card_number       = card_number
  @country           = country
  @merchant_id       = options[:merchant_id]
  @merchant_password = options[:merchant_password]
end

Instance Method Details

#outgoing_xmlObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/privatbank/p24/info.rb', line 26

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.test(0)
      d.payment(id: '') do |p|
        p.prop(name: 'cardnum',   value: @card_number)
        p.prop(name: 'country',   value: @country)
      end
    end
  end
  builder.target!
end

#requestObject



21
22
23
24
# File 'lib/privatbank/p24/info.rb', line 21

def request
  response = self.class.post('/p24api/balance', body: outgoing_xml)
  response['error'] || response['response']['data']['info']['cardbalance']
end

#request_xml_dataObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/privatbank/p24/info.rb', line 47

def request_xml_data
  builder = Builder::XmlMarkup.new
  builder.oper('cmt')
  builder.wait(0)
  builder.test(0)
  builder.payment(id: '') do |p|
    p.prop(name: 'cardnum',   value: @card_number)
    p.prop(name: 'country',   value: @country)
  end
  builder.target!
end

#signatureObject



59
60
61
# File 'lib/privatbank/p24/info.rb', line 59

def signature
  Privatbank::Signature.generate(request_xml_data, @merchant_password)
end