Class: Privatbank::P24::SendMoneyVisa

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

Instance Method Summary collapse

Constructor Details

#initialize(receiver, full_name, payment_id, amount, currency, details, options) ⇒ SendMoneyVisa

Returns a new instance of SendMoneyVisa.



14
15
16
17
18
19
20
21
22
23
# File 'lib/privatbank/p24/send_money_visa.rb', line 14

def initialize receiver, full_name, payment_id, amount, currency, details, options
  @receiver          = receiver
  @full_name         = full_name
  @payment_id        = payment_id
  @amount            = amount
  @details           = details
  @currency          = currency
  @merchant_id       = options[:merchant_id]
  @merchant_password = options[:merchant_password]
end

Instance Method Details

#outgoing_xmlObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/privatbank/p24/send_money_visa.rb', line 31

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: @payment_id) do |p|
        p.prop(name: 'b_card_or_acc',   value: @receiver)
        p.prop(name: 'amt',   value: @amount)
        p.prop(name: 'ccy', value: @currency)
        p.prop(name: 'b_name', value: @full_name)
        p.prop(name: 'details', value: @details)
      end
    end
  end
  builder.target!
end

#requestObject



25
26
27
28
29
# File 'lib/privatbank/p24/send_money_visa.rb', line 25

def request
  response = self.class.post('/p24api/pay_visa', body: outgoing_xml)
  return 'error' if response.fetch('error', nil)
  response['response']['data']
end

#request_xml_dataObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/privatbank/p24/send_money_visa.rb', line 55

def request_xml_data
  builder = Builder::XmlMarkup.new
  builder.oper('cmt')
  builder.wait(0)
  builder.test(0)
  builder.payment(id: @payment_id) do |p|
    p.prop(name: 'b_card_or_acc',   value: @receiver)
    p.prop(name: 'amt',   value: @amount)
    p.prop(name: 'ccy', value: @currency)
    p.prop(name: 'b_name', value: @full_name)
    p.prop(name: 'details', value: @details)
  end
  builder.target!
end

#signatureObject



70
71
72
# File 'lib/privatbank/p24/send_money_visa.rb', line 70

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