Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c5832f
commit 90f5bbd
Showing
7 changed files
with
357 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,3 +112,7 @@ FirstPay (July 24, 2009) | |
Ogone (July 20, 2009) | ||
|
||
* Nicolas Jacobeus | ||
|
||
Elavon (August 09, 2009) | ||
|
||
* Jesse Storimer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
require File.dirname(__FILE__) + '/viaklix' | ||
|
||
module ActiveMerchant #:nodoc: | ||
module Billing #:nodoc: | ||
# = 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 | ||
# | ||
class ElavonGateway < ViaklixGateway | ||
self.test_url = self.live_url = 'https://www.myvirtualmerchant.com/VirtualMerchant/process.do' | ||
|
||
self.display_name = 'Elavon MyVirtualMerchant' | ||
self.supported_countries = ['US', 'CA'] | ||
self.supported_cardtypes = [:visa, :master, :american_express, :discover] | ||
self.homepage_url = 'http://www.elavon.com/' | ||
|
||
self.delimiter = "\n" | ||
self.actions = { | ||
:purchase => 'CCSALE', | ||
:credit => 'CCCREDIT', | ||
:authorize => 'CCAUTHONLY', | ||
:capture => 'CCFORCE' | ||
} | ||
|
||
# Authorize a credit card for a given amount. | ||
# | ||
# ==== Parameters | ||
# * <tt>money</tt> - The amount to be authorized. Either an Integer value in cents or a Money object. | ||
# * <tt>credit_card</tt> - The CreditCard details for the transaction. | ||
# * <tt>options</tt> | ||
# * <tt>:billing_address</tt> - The billing address for the cardholder. | ||
def authorize(money, creditcard, options = {}) | ||
form = {} | ||
add_invoice(form, options) | ||
add_creditcard(form, creditcard) | ||
add_address(form, options) | ||
add_customer_data(form, options) | ||
commit(:authorize, money, form) | ||
end | ||
|
||
# Capture authorized funds from a credit card. | ||
# | ||
# ==== Parameters | ||
# * <tt>money</tt> - The amount to be captured. Either an Integer value in cents or a Money object. | ||
# * <tt>authorization</tt> - The approval code returned from the initial authorization. | ||
# * <tt>options</tt> | ||
# * <tt>:credit_card</tt> - The CreditCard details from the initial transaction (required). | ||
def capture(money, authorization, options = {}) | ||
requires!(options, :credit_card) | ||
|
||
form = {} | ||
add_reference(form, authorization) | ||
add_invoice(form, options) | ||
add_creditcard(form, options[:credit_card]) | ||
add_customer_data(form, options) | ||
commit(:capture, money, form) | ||
end | ||
|
||
private | ||
def add_reference(form, authorization) | ||
form[:approval_code] = authorization | ||
end | ||
|
||
def authorization_from(response) | ||
response['approval_code'] | ||
end | ||
|
||
def add_verification_value(form, creditcard) | ||
form[:cvv2cvc2] = creditcard.verification_value | ||
form[:cvv2cvc2_indicator] = '1' | ||
end | ||
|
||
def message_from(response) | ||
success?(response) ? response['result_message'] : response['errorMessage'] | ||
end | ||
|
||
def success?(response) | ||
!response.has_key?('errorMessage') | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'test_helper' | ||
|
||
class RemoteElavonTest < Test::Unit::TestCase | ||
def setup | ||
@gateway = ElavonGateway.new(fixtures(:elavon)) | ||
|
||
@credit_card = credit_card | ||
@bad_credit_card = credit_card('invalid') | ||
|
||
@options = { | ||
:email => "paul@domain.com", | ||
:description => 'Test Transaction', | ||
:billing_address => address | ||
} | ||
@amount = 100 | ||
end | ||
|
||
def test_successful_purchase | ||
assert response = @gateway.purchase(@amount, @credit_card, @options) | ||
|
||
assert_success response | ||
assert response.test? | ||
assert_equal 'APPROVED', response.message | ||
assert response.authorization | ||
end | ||
|
||
def test_unsuccessful_purchase | ||
assert response = @gateway.purchase(@amount, @bad_credit_card, @options) | ||
|
||
assert_failure response | ||
assert response.test? | ||
assert_equal 'The Credit Card Number supplied in the authorization request appears to be invalid.', response.message | ||
end | ||
|
||
def test_authorize_and_capture | ||
assert auth = @gateway.authorize(@amount, @credit_card, @options) | ||
assert_success auth | ||
assert_equal 'APPROVED', auth.message | ||
assert auth.authorization | ||
assert capture = @gateway.capture(@amount, auth.authorization, :credit_card => @credit_card) | ||
assert_success capture | ||
end | ||
|
||
def test_unsuccessful_capture | ||
assert response = @gateway.capture(@amount, '', :credit_card => @credit_card) | ||
assert_failure response | ||
assert_equal 'The FORCE Approval Code supplied in the authorization request appears to be invalid or blank. The FORCE Approval Code must be 6 or less alphanumeric characters.', response.message | ||
end | ||
|
||
def test_unsuccessful_authorization | ||
@credit_card.number = "1234567890123" | ||
assert response = @gateway.authorize(@amount, @credit_card, @options) | ||
assert_failure response | ||
assert_equal 'The Credit Card Number supplied in the authorization request appears to be invalid.', response.message | ||
end | ||
|
||
def test_purchase_and_credit | ||
assert purchase = @gateway.purchase(@amount, @credit_card, @options) | ||
assert_success purchase | ||
assert purchase.authorization | ||
|
||
assert credit = @gateway.credit(@amount, @credit_card, @options) | ||
assert_success credit | ||
assert credit.authorization | ||
end | ||
end |
Oops, something went wrong.