Skip to content

Commit

Permalink
Sage gateway: Deprecate #credit call
Browse files Browse the repository at this point in the history
Use #refund instead.

Closes #666.
  • Loading branch information
duff authored and ntalbott committed Apr 17, 2013
1 parent 226d41d commit 425ffea
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 38 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -12,6 +12,7 @@
* PayPal Express gateway: Allow an amount of 0 [duff]
* PayPal Express gateway: Reduce parameter requirements [duff]
* Quickpay integration: Update notification parser to handle API v6 [larspind]
* Sage gateway: Deprecate #credit call [duff]

== Version 1.32.1 (April 4, 2013)

Expand Down
15 changes: 10 additions & 5 deletions lib/active_merchant/billing/gateways/sage.rb
Expand Up @@ -119,17 +119,22 @@ def void(reference, options = {})
end
end

# Performs a credit transaction. (Sage +Credit+ transaction).
def credit(money, source, options = {})
deprecated CREDIT_DEPRECATION_MESSAGE
refund(money, source, options)
end

# Performs a refund transaction.
#
# ==== Parameters
#
# * <tt>money</tt> - The amount to be authorized as an integer value in cents.
# * <tt>source</tt> - The CreditCard or Check object to be used as the target for the credit.
def credit(money, source, options = {})
# * <tt>source</tt> - The CreditCard or Check object to be used as the target for the refund.
def refund(money, source, options = {})
if card_brand(source) == "check"
virtual_check.credit(money, source, options)
virtual_check.refund(money, source, options)
else
bankcard.credit(money, source, options)
bankcard.refund(money, source, options)
end
end

Expand Down
27 changes: 16 additions & 11 deletions lib/active_merchant/billing/gateways/sage/sage_bankcard.rb
Expand Up @@ -6,7 +6,7 @@ class SageBankcardGateway < Gateway #:nodoc:
include SageCore
self.live_url = 'https://www.sagepayments.net/cgi-bin/eftBankcard.dll?transaction'
self.source = 'bankcard'

# Credit cards supported by Sage
# * VISA
# * MasterCard
Expand All @@ -17,42 +17,47 @@ class SageBankcardGateway < Gateway #:nodoc:
# * JCB
# * Sears
self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club]

def authorize(money, credit_card, options = {})
post = {}
add_credit_card(post, credit_card)
add_transaction_data(post, money, options)
commit(:authorization, post)
end

def purchase(money, credit_card, options = {})
post = {}
add_credit_card(post, credit_card)
add_transaction_data(post, money, options)
commit(:purchase, post)
end
# The +money+ amount is not used. The entire amount of the
end

# The +money+ amount is not used. The entire amount of the
# initial authorization will be captured.
def capture(money, reference, options = {})
post = {}
add_reference(post, reference)
commit(:capture, post)
end

def void(reference, options = {})
post = {}
add_reference(post, reference)
commit(:void, post)
end

def credit(money, credit_card, options = {})
deprecated CREDIT_DEPRECATION_MESSAGE
refund(money, credit_card, options)
end

def refund(money, credit_card, options = {})
post = {}
add_credit_card(post, credit_card)
add_transaction_data(post, money, options)
commit(:credit, post)
end

private
def exp_date(credit_card)
year = sprintf("%.4i", credit_card.year)
Expand All @@ -67,7 +72,7 @@ def add_credit_card(post, credit_card)
post[:C_exp] = exp_date(credit_card)
post[:C_cvv] = credit_card.verification_value if credit_card.verification_value?
end

def parse(data)
response = {}
response[:success] = data[1,1]
Expand All @@ -78,7 +83,7 @@ def parse(data)
response[:avs_result] = data[43, 1].strip
response[:risk] = data[44, 2]
response[:reference] = data[46, 10]

response[:order_number], response[:recurring] = data[57...-1].split("\034")
response
end
Expand Down
37 changes: 21 additions & 16 deletions lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb
Expand Up @@ -6,29 +6,34 @@ class SageVirtualCheckGateway < Gateway #:nodoc:
include SageCore
self.live_url = 'https://www.sagepayments.net/cgi-bin/eftVirtualCheck.dll?transaction'
self.source = 'virtual_check'

def purchase(money, credit_card, options = {})
post = {}
add_check(post, credit_card)
add_check_customer_data(post, options)
add_transaction_data(post, money, options)
commit(:purchase, post)
end

def void(reference, options = {})
post = {}
add_reference(post, reference)
commit(:void, post)
end

def credit(money, credit_card, options = {})
deprecated CREDIT_DEPRECATION_MESSAGE
refund(money, source, options)
end

def refund(money, credit_card, options = {})
post = {}
add_check(post, credit_card)
add_check_customer_data(post, options)
add_transaction_data(post, money, options)
commit(:credit, post)
end

private
def add_check(post, check)
post[:C_first_name] = check.first_name
Expand All @@ -38,53 +43,53 @@ def add_check(post, check)
post[:C_check_number] = check.number
post[:C_acct_type] = account_type(check)
end

def add_check_customer_data(post, options)
# Required  Customer Type – (NACHA Transaction Class)
# CCD for Commercial, Merchant Initiated
# CCD for Commercial, Merchant Initiated
# PPD for Personal, Merchant Initiated
# WEB for Internet, Consumer Initiated
# RCK for Returned Checks
# ARC for Account Receivable Entry
# WEB for Internet, Consumer Initiated
# RCK for Returned Checks
# ARC for Account Receivable Entry
# TEL for TelephoneInitiated
post[:C_customer_type] = "WEB"

# Optional  10  Digit Originator  ID – Assigned  By for  each transaction  class  or  business  purpose. If  not provided, the default Originator ID for the specific  Customer Type will be applied. 
# Optional  10  Digit Originator  ID – Assigned  By for  each transaction  class  or  business  purpose. If  not provided, the default Originator ID for the specific  Customer Type will be applied. 
post[:C_originator_id] = options[:originator_id]

# Optional  Transaction Addenda
post[:T_addenda] = options[:addenda]

# Required  Check  Writer  Social  Security  Number  (  Numbers Only, No Dashes ) 
# Required  Check  Writer  Social  Security  Number  (  Numbers Only, No Dashes ) 
post[:C_ssn] = options[:ssn].to_s.gsub(/[^\d]/, '')

post[:C_dl_state_code] = options[:drivers_license_state]
post[:C_dl_number] = options[:drivers_license_number]
post[:C_dob] = format_birth_date(options[:date_of_birth])
end

def format_birth_date(date)
date.respond_to?(:strftime) ? date.strftime("%m/%d/%Y") : date
end

# DDA for Checking
# SAV for Savings 
# DDA for Checking
# SAV for Savings 
def account_type(check)
case check.account_type
when 'checking' then 'DDA'
when 'savings' then 'SAV'
else raise ArgumentError, "Unknown account type #{check.account_type}"
end
end

def parse(data)
response = {}
response[:success] = data[1,1]
response[:code] = data[2,6].strip
response[:message] = data[8,32].strip
response[:risk] = data[40, 2]
response[:reference] = data[42, 10]

extra_data = data[53...-1].split("\034")
response[:order_number] = extra_data[0]
response[:authentication_indicator] = extra_data[1]
Expand Down
4 changes: 2 additions & 2 deletions test/remote/gateways/remote_sage_bankcard_test.rb
Expand Up @@ -91,8 +91,8 @@ def test_failed_void
assert_equal 'INVALID T_REFERENCE', response.message
end

def test_successful_credit
assert response = @gateway.credit(@amount, @visa, @options)
def test_successful_refund
assert response = @gateway.refund(@amount, @visa, @options)
assert_success response
assert response.test?
end
Expand Down
8 changes: 4 additions & 4 deletions test/remote/gateways/remote_sage_test.rb
Expand Up @@ -63,14 +63,14 @@ def test_check_purchase_and_void
assert_success void
end

def test_visa_credit
assert response = @gateway.credit(@amount, @visa, @options)
def test_visa_refund
assert response = @gateway.refund(@amount, @visa, @options)
assert_success response
assert response.test?
end

def test_check_credit
assert response = @gateway.credit(@amount, @check, @options)
def test_check_refund
assert response = @gateway.refund(@amount, @check, @options)
assert_success response
assert response.test?
end
Expand Down

0 comments on commit 425ffea

Please sign in to comment.