Class: ActiveMerchant::Billing::ElavonGateway

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

Overview

Elavon Virtual Merchant Gateway

Example use:

gateway = ActiveMerchant::Billing::ElavonGateway.new(
            :login     => "my_virtual_merchant_id",
            :password  => "my_virtual_merchant_pin",
            :user      => "my_virtual_merchant_user_id" # optional
         )

# set up credit card obj as in main ActiveMerchant example
creditcard = ActiveMerchant::Billing::CreditCard.new(
  :type       => 'visa',
  :number     => '41111111111111111',
  :month      => 10,
  :year       => 2011,
  :first_name => 'Bob',
  :last_name  => 'Bobsen'
)

# run request
response = gateway.purchase(1000, creditcard) # authorize and capture 10 USD

puts response.success?      # Check whether the transaction was successful
puts response.message       # Retrieve the message returned by Elavon
puts response.authorization # Retrieve the unique transaction ID returned by Elavon

Constant Summary

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, #generate_unique_id, inherited, #scrub, supported_countries, #supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #supports_scrubbing?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ ElavonGateway

Initialize the Gateway

The gateway requires that a valid login and password be passed in the options hash.

Options

  • :login – Merchant ID

  • :password – PIN

  • :user – Specify a subuser of the account (optional)

  • :test => true or false – Force test transactions



69
70
71
72
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 69

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

Instance Method Details

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

Authorize a credit card for a given amount.

Parameters

  • money - The amount to be authorized as an Integer value in cents.

  • credit_card - The CreditCard details for the transaction.

  • options

    • :billing_address - The billing address for the cardholder.



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 98

def authorize(money, creditcard, options = {})
  form = {}
  add_salestax(form, options)
  add_invoice(form, options)
  add_creditcard(form, creditcard)
  add_address(form, options)
  add_customer_data(form, options)
  add_test_mode(form, options)
  add_ip(form, options)
  commit(:authorize, money, form)
end

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

Capture authorized funds from a credit card.

Parameters

  • money - The amount to be captured as an Integer value in cents.

  • authorization - The approval code returned from the initial authorization.

  • options

    • :credit_card - The CreditCard details from the initial transaction (required).



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 117

def capture(money, authorization, options = {})
  form = {}
  if options[:credit_card]
    action = :capture
    add_salestax(form, options)
    add_approval_code(form, authorization)
    add_invoice(form, options)
    add_creditcard(form, options[:credit_card])
    add_customer_data(form, options)
    add_test_mode(form, options)
  else
    action = :capture_complete
    add_txn_id(form, authorization)
    add_partial_shipment_flag(form, options)
    add_test_mode(form, options)
  end
  commit(action, money, form)
end

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

Make a credit to a card. Use the refund method if you’d like to credit using previous transaction

Parameters

  • money - The amount to be credited as an Integer value in cents.

  • creditcard - The credit card to be credited.

  • options



172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 172

def credit(money, creditcard, options = {})
  if creditcard.is_a?(String)
    raise ArgumentError, "Reference credits are not supported. Please supply the original credit card or use the #refund method."
  end

  form = {}
  add_invoice(form, options)
  add_creditcard(form, creditcard)
  add_address(form, options)
  add_customer_data(form, options)
  add_test_mode(form, options)
  commit(:credit, money, form)
end

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

Make a purchase



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 75

def purchase(money, payment_method, options = {})
  form = {}
  add_salestax(form, options)
  add_invoice(form, options)
  if payment_method.is_a?(String)
    add_token(form, payment_method)
  else
    add_creditcard(form, payment_method)
  end
  add_address(form, options)
  add_customer_data(form, options)
  add_test_mode(form, options)
  add_ip(form, options)
  commit(:purchase, money, form)
end

#refund(money, identification, options = {}) ⇒ Object

Refund a transaction.

This transaction indicates to the gateway that money should flow from the merchant to the customer.

Parameters

  • money – The amount to be credited to the customer as an Integer value in cents.

  • identification – The ID of the original transaction against which the refund is being issued.

  • options – A hash of parameters.



146
147
148
149
150
151
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 146

def refund(money, identification, options = {})
  form = {}
  add_txn_id(form, identification)
  add_test_mode(form, options)
  commit(:refund, money, form)
end

#store(creditcard, options = {}) ⇒ Object



193
194
195
196
197
198
199
200
201
202
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 193

def store(creditcard, options = {})
  form = {}
  add_creditcard(form, creditcard)
  add_address(form, options)
  add_customer_data(form, options)
  add_test_mode(form, options)
  add_verification(form, options)
  form[:add_token] = 'Y'
  commit(:store, nil, form)
end

#update(token, creditcard, options = {}) ⇒ Object



204
205
206
207
208
209
210
211
212
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 204

def update(token, creditcard, options = {})
  form = {}
  add_token(form, token)
  add_creditcard(form, creditcard)
  add_address(form, options)
  add_customer_data(form, options)
  add_test_mode(form, options)
  commit(:update, nil, form)
end

#verify(credit_card, options = {}) ⇒ Object



186
187
188
189
190
191
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 186

def verify(credit_card, options = {})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, credit_card, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end

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

Void a previous transaction

Parameters

  • authorization - The authorization returned from the previous request.



158
159
160
161
162
163
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 158

def void(identification, options = {})
  form = {}
  add_txn_id(form, identification)
  add_test_mode(form, options)
  commit(:void, nil, form)
end