Class: ActiveMerchant::Billing::MPayGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/mpay.rb

Instance Method Summary collapse

Instance Method Details

#authorize(money, options = {}) ⇒ Object



84
85
86
# File 'lib/active_merchant/billing/gateways/mpay.rb', line 84

def authorize(money, options={})
  raise "mpaygateway.authorize called".inspect
end

#gateway_urlObject

move this to the other thing?



15
16
17
# File 'lib/active_merchant/billing/gateways/mpay.rb', line 15

def gateway_url
  self.test_mode == true ? self.test_redirect_url : self.production_redirect_url
end

#merchant_idObject



19
20
21
# File 'lib/active_merchant/billing/gateways/mpay.rb', line 19

def merchant_id
  self.test_mode == true ? self.test_merchant_id : self.production_merchant_id
end

#purchase(money, options = {}) ⇒ Object



88
89
90
# File 'lib/active_merchant/billing/gateways/mpay.rb', line 88

def purchase(money, options={})
  raise "mpaygateway.purchase called".inspect
end

#setup_authorization(money, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/active_merchant/billing/gateways/mpay.rb', line 23

def setup_authorization(money, options = {})
  # TODO: howto use the options infrastructure
  merchant_id = merchant_id
  operation = 'SELECTPAYMENT'

  # TODO: merge options

  # build MDXI XML Block
  xml = Bulder::XmlMarkup.new
  xml.tag! 'order' do
    xml.tag! 'Tid', 'some order identifier'
    xml.tag! 'ShoppingCart' do
      xml.tag! 'Description', 'some description'
    end

    xml.tag! 'price', amount(money)
    xml.tag! 'BillingAddr', :mode => 'ReadWrite' do
      xml.tag! 'Name', options[:shipping_address][:name]
      xml.tag! 'City', options[:shipping_address][:city]
      xml.tag! 'Street', options[:shipping_address][:street]
      #TODO: add more address stuff from options hash
    end

    xml.tag! 'URL' do
      xml.tag! 'Confirmation', 'some-confirmation-url'
      xml.tag! 'Notifcation', mpay_callbacks_url
    end
  end

  cmd = xml.build!

  # build and send the command
  res = Net::HTTP.post_form(URI.parse(self.test_redirect_url),
                        {
                          'operation' => operation,
                          'merchant_id' => merchant_id,
                          'MDXI' => cmd
                        })

  # extract information
  raise res.inspect

    #3: Detailed control
    #url = URI.parse('http://www.example.com/todo.cgi')
    #req = Net::HTTP::Post.new(url.path)
    #req.basic_auth 'jack', 'pass'
    #req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';')
    #res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
    #case res
    #when Net::HTTPSuccess, Net::HTTPRedirection
# OK
    #else
    #  res.error!
    #end
  
  # render the corresponding URL in an IFRAME
  render :partial => 'shared/mpay_confirm',
         :locals => { :iframe_url => "fubar" },
         :layout => true
end