Class: Payzilla::Gateways::Osmp

Inherits:
Gateway
  • Object
show all
Defined in:
lib/payzilla/gateways/osmp.rb

Instance Attribute Summary

Attributes inherited from Gateway

#config, #logger, #revision_page_size

Instance Method Summary collapse

Methods inherited from Gateway

available_attachments, available_settings, available_switches, can_list_providers, #can_list_providers?, can_list_providers?, #initialize, register_attachments, register_settings, register_switches, require_payment_fields, required_payment_fields, requires_revision, requires_revision?, #requires_revision?, #revise

Constructor Details

This class inherits a constructor from Payzilla::Gateways::Gateway

Instance Method Details

#check(payment) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/payzilla/gateways/osmp.rb', line 11

def check(payment)
  builder = Builder::XmlMarkup.new
  builder.instruct!
  data = builder.request do
    builder.tag! "request-type", 32
    builder.tag! "terminal-id", @config.setting_client
    builder.extra @config.setting_password, "name" => "password"
    builder.extra payment.,          "name" => "phone"
  end

  begin
    result = send data
    result = Crack::XML.parse(result)
    # TODO: Change returning code, when user doesn't exist
    code = if result["response"]["exist"] == "0"
             "1"
           else
             result["response"]["result_code"]
           end
  rescue Errno::ECONNRESET
    code = -1000
  end

  retval(code)
end

#pay(payment) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/payzilla/gateways/osmp.rb', line 37

def pay(payment)
  builder = Builder::XmlMarkup.new
  builder.instruct!
  data = builder.request do
    builder.tag! "request-type", 10
    builder.extra @config.setting_password, "name" => "password"
    builder.tag! "terminal-id", @config.setting_client
    builder.auth do
      builder.payment do
        builder.tag! "transaction-number", Time.now.to_i
        builder.to do
          builder.amount payment.paid_amount
          builder.tag! "service-id", 99
          builder.tag! "account-number", payment.
        end
      end
    end
  end
  begin
    result = send data
    code = Nokogiri.XML(result).css("payment").
      first.attributes["status"].value
  rescue Errno::ECONNRESET
    code = -1000
  end

  retval(code, true)
end