Class: Payzilla::Gateways::Megafon

Inherits:
Gateway
  • Object
show all
Includes:
Transports::HTTP
Defined in:
lib/payzilla/gateways/megafon.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



15
16
17
18
19
20
# File 'lib/payzilla/gateways/megafon.rb', line 15

def check(payment)
  result = request 'HTTP_ADD_PAYMENT', :get,
    :P_MSISDN => payment.

  return retval(result)
end

#check_revision(revision) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/payzilla/gateways/megafon.rb', line 62

def check_revision(revision)
  result = request 'HTTP_GET_REESTR_STATUS', :get,
    :LOGIN     => @config.setting_client,
    :PASSWORD  => @config.setting_password,
    :P_DATE    => revision.date.strftime('%d.%m.%Y')
  return retval(result)
end

#generate_revision(revision) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/payzilla/gateways/megafon.rb', line 35

def generate_revision(revision)
  builder = Builder::XmlMarkup.new
  count   = 0
  sum     = 0

  builder.instruct! :xml, version: "1.0", encoding: "WINDOWS-1251"
  data = builder.reestr do
    totals = paginate_payments(revision.payments, builder) do |slice, builder|
      generate_revision_page(slice, builder)
    end

    builder.pay_sum totals[:enrolled_sum]
    builder.pay_count totals[:count]
  end

  [:xml, data]
end

#pay(payment) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/payzilla/gateways/megafon.rb', line 22

def pay(payment)
  begin
    result = request 'HTTP_ADD_PAYMENT', :get,
      :P_MSISDN      => payment.,
      :P_PAY_AMOUNT  => payment.enrolled_amount,
      :P_RECEIPT_NUM => payment.id
  ensure
    pay(payment) if result == "100"
  end

  return retval(result)
end

#send_revision(revision, data) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/payzilla/gateways/megafon.rb', line 53

def send_revision(revision, data)
  result = request 'HTTP_LOAD_REESTR', :post,
    :LOGIN     => @config.setting_client,
    :PASSWORD  => @config.setting_password,
    :P_DATE    => revision.date.strftime('%d.%m.%Y'),
    :FILE_DATA => Payzilla::Utils::StringFile.new('data.xml', data)
  return retval(result)
end