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

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, supports?, #test?

Methods included from CreditCardFormatting

#format

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



64
65
66
67
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 64

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.



88
89
90
91
92
93
94
95
96
97
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 88

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



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 106

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



155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 155

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, creditcard, options = {}) ⇒ Object

Make a purchase



70
71
72
73
74
75
76
77
78
79
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 70

def purchase(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(: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.



129
130
131
132
133
134
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 129

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

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

Void a previous transaction

Parameters

  • authorization - The authorization returned from the previous request.



141
142
143
144
145
146
# File 'lib/active_merchant/billing/gateways/elavon.rb', line 141

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