Skip to content

Commit

Permalink
finansbank_gateway adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scamurcuoglu committed Feb 17, 2013
1 parent 7f33fd9 commit eb8657c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 13 deletions.
40 changes: 30 additions & 10 deletions lib/active_merchant/billing/gateways/cc5.rb
Expand Up @@ -32,29 +32,28 @@ def authorize(money, creditcard, options = {})
end

def capture(money, authorization, options = {})
# PostAuth
commit('capture', money, post)
request = build_capture_request(money, authorization, options)
commit(request)
end

protected

def build_sale_request(type, money, creditcard, options = {})
requires!(options, :order_id)

xml = Builder::XmlMarkup.new :indent => 2

xml.tag! 'CC5Request' do
xml.tag! 'Name', options[:login]
xml.tag! 'Password', options[:password]
xml.tag! 'ClientId', options[:client_id]
add_login_tags(xml)
xml.tag! 'OrderId', options[:order_id]
xml.tag! 'Type', type
xml.tag! 'Number', creditcard.number
xml.tag! 'Expires', [two_digits(creditcard.month), two_digits(creditcard.year)].join('/')
xml.tag! 'Cvv2Val', creditcard.verification_value
xml.tag! 'Total', amount(money)
xml.tag! 'Currency', currency_code(options[:currency] || currency(money))
add_amount_tags(money, options, xml)
xml.tag! 'Email', options[:email]

if address = options[:address]
if address = options[:billing_address] || options[:address]
xml.tag! 'BillTo' do
add_address(xml, address)
end
Expand All @@ -68,6 +67,17 @@ def build_sale_request(type, money, creditcard, options = {})
xml.target!
end

def build_capture_request(money, authorization, options = {})
xml = Builder::XmlMarkup.new :indent => 2

xml.tag! 'CC5Request' do
add_login_tags(xml)
xml.tag! 'OrderId', authorization
xml.tag! 'Type', 'PostAuth'
add_amount_tags(money, options, xml)
end
end

def add_address(xml, address)
xml.tag! 'Name', normalize(address[:name])
xml.tag! 'Street1', normalize(address[:address1])
Expand All @@ -79,6 +89,17 @@ def add_address(xml, address)
xml.tag! 'TelVoice', address[:phone].to_s.gsub(/[^0-9]/, '') if address[:phone]
end

def add_login_tags(xml)
xml.tag! 'Name', @options[:login]
xml.tag! 'Password', @options[:password]
xml.tag! 'ClientId', @options[:client_id]
end

def add_amount_tags(money, options, xml)
xml.tag! 'Total', amount(money)
xml.tag! 'Currency', currency_code(options[:currency] || currency(money))
end

def currency_code(currency)
CURRENCY_CODES[currency] || CURRENCY_CODES[default_currency]
end
Expand Down Expand Up @@ -115,7 +136,7 @@ def parse_element(response, node)
end

def success?(response)
response[:message] == "Approved"
response[:response] == "Approved"
end

def message_from(response)
Expand Down Expand Up @@ -143,4 +164,3 @@ def two_digits(value)
end
end
end

2 changes: 2 additions & 0 deletions lib/active_merchant/billing/gateways/finansbank.rb
@@ -1,3 +1,5 @@
require File.dirname(__FILE__) + '/cc5'

module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class FinansbankGateway < CC5Gateway
Expand Down
31 changes: 28 additions & 3 deletions test/unit/gateways/finansbank_test.rb
Expand Up @@ -4,7 +4,8 @@ class FinansbankTest < Test::Unit::TestCase
def setup
@gateway = FinansbankGateway.new(
:login => 'login',
:password => 'password'
:password => 'password',
:client_id => 'client_id'
)

@credit_card = credit_card
Expand All @@ -21,11 +22,11 @@ def test_successful_purchase
@gateway.expects(:ssl_post).returns(successful_purchase_response)

assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_instance_of
assert_instance_of Response, response
assert_success response

# Replace with authorization number from the successful response
assert_equal '', response.authorization
assert_equal '1', response.authorization
assert response.test?
end

Expand All @@ -41,9 +42,33 @@ def test_unsuccessful_request

# Place raw successful response from gateway here
def successful_purchase_response
<<-EOF
<CC5Response>
<OrderId>1</OrderId>
<GroupId>2</GroupId>
<Response>Approved</Response>
<AuthCode>123456</AuthCode>
<HostRefNum>123456</HostRefNum>
<ProcReturnCode>00</ProcReturnCode>
<TransId>123456</TransId>
<ErrMsg></ErrMsg>
</CC5Response>
EOF
end

# Place raw failed response from gateway here
def failed_purchase_response
<<-EOF
<CC5Response>
<OrderId>1</OrderId>
<GroupId>2</GroupId>
<Response>Declined</Response>
<AuthCode></AuthCode>
<HostRefNum>123456</HostRefNum>
<ProcReturnCode>17</ProcReturnCode>
<TransId>123456</TransId>
<ErrMsg>Not enough credit</ErrMsg>
</CC5Response>
EOF
end
end

0 comments on commit eb8657c

Please sign in to comment.