Class: ActiveMerchant::Billing::MonerisGateway

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

Constant Summary collapse

TEST_URL =
'https://esqa.moneris.com/gateway2/servlet/MpgRequest'
LIVE_URL =
'https://www3.moneris.com/gateway2/servlet/MpgRequest'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Gateway

gateway, supports?, #test?

Methods included from RequiresParameters

#requires!

Methods included from PostsData

#included?, #ssl_post

Constructor Details

#initialize(options = {}) ⇒ MonerisGateway

login is your Store ID password is your API Token



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 16

def initialize(options = {})
  requires!(options, :login, :password)

  @options = {
    :strict_ssl => true,
    :crypt_type => 7
  }.update(options)

  @url = test? ? TEST_URL : LIVE_URL      
  
  super      
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 9

def options
  @options
end

#responseObject (readonly)

Returns the value of attribute response.



8
9
10
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 8

def response
  @response
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 7

def url
  @url
end

Class Method Details

.supported_cardtypesObject

We support visa and master card



90
91
92
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 90

def self.supported_cardtypes
  [:visa, :master]
end

Instance Method Details

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 29

def authorize(money, creditcard, options = {})
  requires!(options, :order_id)

  parameters = {
    :order_id => options[:order_id],
    :cust_id => options[:customer],
    :amount => amount(money),
    :pan => creditcard.number,
    :expdate => expdate(creditcard),
    :crypt_type => options[:crypt_type] || @options[:crypt_type]
  }                                                             

  commit('preauth', parameters)      
end

#capture(money, authorization, options = {}) ⇒ Object

Moneris requires both the order_id and the transaction number of the original authorization. To maintain the same interface as the other gateways the two numbers are concatenated together with an _ separator as the authorization number returned by authorization



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 64

def capture(money, authorization, options = {})
  txn_number, order_id = authorization.split(';')

    parameters = {
      :txn_number => txn_number,
      :order_id => order_id,
      :comp_amount => amount(money),
      :crypt_type => options[:crypt_type] || @options[:crypt_type]
    }

  commit('completion', parameters)      
end

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

Pass in order_id and optionally a customer parameter



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 45

def purchase(money, creditcard, options = {})
  requires!(options, :order_id)

  parameters = {
    :order_id => options[:order_id],
    :cust_id => options[:customer],
    :amount => amount(money),
    :pan => creditcard.number,
    :expdate => expdate(creditcard),
    :crypt_type => options[:crypt_type] || @options[:crypt_type]
  }                                                             

  commit('purchase', parameters)      
end

#void(authorization, options = {}) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 77

def void(authorization, options = {})
  txn_number, order_id = authorization.split(';')

    parameters = {
      :txn_number => txn_number,
      :order_id => order_id,
      :crypt_type => options[:crypt_type] || @options[:crypt_type]
    }

  commit('purchasecorrection', parameters)      
end