Class: ActiveMerchant::Billing::ElavonGateway

Inherits:
Gateway
  • Object
show all
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::CURRENCIES_WITHOUT_FRACTIONS, 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, non_fractional_currency?, #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



66
67
68
69
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 66

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.



94
95
96
97
98
99
100
101
102
103
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 94

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)
  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).



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 112

def capture(money, authorization, options = {})
  requires!(options, :credit_card)

  form = {}
  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)
  commit(:capture, 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



161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 161

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



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 72

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)
  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.



135
136
137
138
139
140
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 135

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



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

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



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

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



175
176
177
178
179
180
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 175

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.



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

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