Skip to content

Commit

Permalink
CyberSource: Make :ignore_avs and :ignore_cvv settable on a per-trans…
Browse files Browse the repository at this point in the history
…action basis
  • Loading branch information
DarkFox authored and wvanbergen committed Jan 15, 2015
1 parent 215a167 commit 5275200
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/active_merchant/billing/gateways/cyber_source.rb
Expand Up @@ -242,7 +242,7 @@ def build_auth_request(money, creditcard_or_reference, options)
xml = Builder::XmlMarkup.new :indent => 2
add_payment_method_or_subscription(xml, money, creditcard_or_reference, options)
add_auth_service(xml)
add_business_rules_data(xml)
add_business_rules_data(xml, options)
xml.target!
end

Expand All @@ -253,7 +253,7 @@ def build_tax_calculation_request(creditcard, options)
add_line_item_data(xml, options)
add_purchase_data(xml, 0, false, options)
add_tax_service(xml)
add_business_rules_data(xml)
add_business_rules_data(xml, options)
xml.target!
end

Expand All @@ -264,7 +264,7 @@ def build_capture_request(money, authorization, options)
xml = Builder::XmlMarkup.new :indent => 2
add_purchase_data(xml, money, true, options)
add_capture_service(xml, request_id, request_token)
add_business_rules_data(xml)
add_business_rules_data(xml, options)
xml.target!
end

Expand All @@ -275,7 +275,7 @@ def build_purchase_request(money, payment_method_or_reference, options)
add_check_service(xml)
else
add_purchase_service(xml, options)
add_business_rules_data(xml) unless options[:pinless_debit_card]
add_business_rules_data(xml, options) unless options[:pinless_debit_card]
end
xml.target!
end
Expand Down Expand Up @@ -344,7 +344,7 @@ def build_create_subscription_request(payment_method, options)
end
end
add_subscription_create_service(xml, options)
add_business_rules_data(xml)
add_business_rules_data(xml, options)
xml.target!
end

Expand All @@ -356,7 +356,7 @@ def build_update_subscription_request(reference, creditcard, options)
add_creditcard_payment_method(xml) if creditcard
add_subscription(xml, options, reference)
add_subscription_update_service(xml, options)
add_business_rules_data(xml)
add_business_rules_data(xml, options)
xml.target!
end

Expand All @@ -381,11 +381,20 @@ def build_validate_pinless_debit_request(creditcard,options)
xml.target!
end

def add_business_rules_data(xml)
def add_business_rules_data(xml, options)
prioritized_options = [options, @options]

xml.tag! 'businessRules' do
xml.tag!('ignoreAVSResult', 'true') if @options[:ignore_avs]
xml.tag!('ignoreCVResult', 'true') if @options[:ignore_cvv]
xml.tag!('ignoreAVSResult', 'true') if extract_option(prioritized_options, :ignore_avs)
xml.tag!('ignoreCVResult', 'true') if extract_option(prioritized_options, :ignore_cvv)
end
end

def extract_option prioritized_options, option_name
options_matching_key = prioritized_options.detect do |options|
options.has_key? option_name
end
options_matching_key[option_name] if options_matching_key
end

def add_line_item_data(xml, options)
Expand Down
55 changes: 55 additions & 0 deletions test/unit/gateways/cyber_source_test.rb
Expand Up @@ -93,6 +93,61 @@ def test_successful_pinless_debit_card_purchase
assert response.test?
end

def test_successful_credit_cart_purchase_single_request_ignore_avs
@gateway.expects(:ssl_post).with do |host, request_body|
assert_match %r'<ignoreAVSResult>true</ignoreAVSResult>', request_body
assert_not_match %r'<ignoreCVResult>', request_body
true
end.returns(successful_purchase_response)

assert response = @gateway.purchase(@amount, @credit_card, @options.merge(
ignore_avs: true
))
assert_success response
end

def test_successful_credit_cart_purchase_single_request_without_ignore_avs
@gateway.expects(:ssl_post).with do |host, request_body|
assert_not_match %r'<ignoreAVSResult>', request_body
assert_not_match %r'<ignoreCVResult>', request_body
true
end.returns(successful_purchase_response)

# globally ignored AVS for gateway instance:
@gateway.options[:ignore_avs] = true

assert response = @gateway.purchase(@amount, @credit_card, @options.merge(
ignore_avs: false
))
assert_success response
end

def test_successful_credit_cart_purchase_single_request_ignore_ccv
@gateway.expects(:ssl_post).with do |host, request_body|
assert_not_match %r'<ignoreAVSResult>', request_body
assert_match %r'<ignoreCVResult>true</ignoreCVResult>', request_body
true
end.returns(successful_purchase_response)

assert response = @gateway.purchase(@amount, @credit_card, @options.merge(
ignore_cvv: true
))
assert_success response
end

def test_successful_credit_cart_purchase_single_request_without_ignore_ccv
@gateway.expects(:ssl_post).with do |host, request_body|
assert_not_match %r'<ignoreAVSResult>', request_body
assert_not_match %r'<ignoreCVResult>', request_body
true
end.returns(successful_purchase_response)

assert response = @gateway.purchase(@amount, @credit_card, @options.merge(
ignore_cvv: false
))
assert_success response
end

def test_successful_reference_purchase
@gateway.stubs(:ssl_post).returns(successful_create_subscription_response, successful_purchase_response)

Expand Down

0 comments on commit 5275200

Please sign in to comment.