Class: Payzilla::Gateways::Mts

Inherits:
Gateway
  • Object
show all
Includes:
Transports::HTTP
Defined in:
lib/payzilla/gateways/mts.rb

Instance Attribute Summary

Attributes inherited from Gateway

#config, #logger, #revision_page_size

Instance Method Summary collapse

Methods included from Transports::HTTP

#get, #post, #resource, #ssl

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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/payzilla/gateways/mts.rb', line 14

def check(payment)
  return retval(-1001) if settings_miss?

  begin
    xml = Builder::XmlMarkup.new

    xml.f_01(payment., :"xsi:type" => 'espp-constraints:PHN_CODE_fmt_01')
    xml.f_02("%.2f" % payment.enrolled_amount)
    xml.f_03(810, :"xsi:type" => 'espp-constraints:CUR_fmt_01')
    xml.f_04(7)
    xml.f_05(terminal(payment))
    xml.f_06(1)
    xml.f_07(@config.setting_agent)
    xml.f_08(@config.setting_contract)
    xml.f_10(payment.gateway_provider_id)

    result = request 'ESPP_0104010', xml.target!

    if !result['ESPP_1204010'].blank?
      return retval(0, result['ESPP_1204010']['f_05'])
    else
      return retval(result['ESPP_2204010']['f_01'])
    end
  rescue Errno::ECONNRESET
    return retval(-1000)
  end
end

#generate_revision(revision) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/payzilla/gateways/mts.rb', line 101

def generate_revision(revision)
  xml = Builder::XmlMarkup.new

  xml.summary do
    xml.contract @config.setting_contract
    xml.comparePeriod do
      xml.from revision.date.to_date.to_datetime
      xml.to DateTime.new(
        revision.date.year,
        revision.date.month,
        revision.date.day,
        23,
        59,
        59
      )
    end
    xml.totalAmountOfPayments revision.payments.count
    xml.currency(810, :"xsi:type" => 'espp-constraints:CUR_fmt_01')
    xml.totalSum revision.payments.map{|x| x.enrolled_amount}.inject(:+)
    xml.totalDebt 0
  end
  xml.payments do
    revision.payments.each_with_index do |p,i|
      row = [
        @config.setting_agent,
        p.gateway_payment_id,
        p.created_at,
        p.id,
        p.terminal_id,
        p.,
        '',
        '',
        "%.2f" % p.enrolled_amount,
        810,
        1,
        0
      ].join(';')

      xml.p(row, :id => i+1)
    end
  end

  [:xml, wrap_xml('comparePacket', xml, revision.id)]
end

#pay(payment) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/payzilla/gateways/mts.rb', line 42

def pay(payment)
  return retval(-1001) if settings_miss?

  begin
    xml = Builder::XmlMarkup.new

    signature = [
      "#{payment.}",
      "%.2f" % payment.enrolled_amount,
      810,
      7,
      "",
      payment.id,
      payment.created_at.strftime("%Y-%m-%dT%H:%M:%S"),
      @config.setting_agent,
      terminal(payment),
      1,
      payment.created_at.to_s,
      "",
      "MTS"
    ].join('&')

    encryptor = OpenSSL::PKey::RSA.new(
      File.open(@config.attachment_signature_key.path).read,
      @config.setting_signature_key_password
    )

    signature = encryptor.sign(OpenSSL::Digest::MD5.new, signature)
    signature = Base64.encode64(signature.force_encoding('UTF-8'))


    xml.f_01(payment., :"xsi:type" => 'espp-constraints:PHN_CODE_fmt_01')
    xml.f_02("%.2f" % payment.enrolled_amount)
    xml.f_03(810, :"xsi:type" => 'espp-constraints:CUR_fmt_01')
    xml.f_04(7)
    xml.f_06(0)
    xml.f_07(payment.id)
    xml.f_08(payment.created_at.strftime("%Y-%m-%dT%H:%M:%S"))
    xml.f_10(payment.gateway_payment_id)
    xml.f_11(@config.setting_agent)
    xml.f_12(terminal(payment))
    xml.f_13(1)
    xml.f_15("138020")
    xml.f_16(payment.created_at.to_s)
    xml.f_18(signature)
    xml.f_19(@config.setting_contract)
    xml.f_21(payment.gateway_provider_id)
    result = request 'ESPP_0104090', xml.target!

    if !result['ESPP_1204090'].blank?
      return retval
    else
      return retval(result['ESPP_2204090']['f_01'])
    end
  rescue Errno::ECONNRESET
    return retval(-1000)
  end
end