Skip to content

Commit

Permalink
Stripe: Parse EMV ARC from error response
Browse files Browse the repository at this point in the history
Closes #1750.
  • Loading branch information
bizla committed Jun 19, 2015
1 parent a958249 commit 2d6d6a5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
7 changes: 1 addition & 6 deletions CHANGELOG
Expand Up @@ -14,12 +14,7 @@
* Sage: Credit really is credit not refund [duff]
* Sage: Add ability to refund [duff]
* Cardstream: Add scrubbing [anellis]
* Litle: Add debt_repayment_flag [duff]
* Litle: Add debt_repayment_flag [duff]
* iATS: Support ACH [rwdaigle]
* CheckoutV2: Add Gateway [anellis]
* CenPOS: Fix refund amount issue [duff]
* Add error_code mapping and error_code_from to gateway generator [jnormore]

This comment has been minimized.

Copy link
@duff

duff Jun 22, 2015

Contributor

@bizla Not sure you meant to remove all of these or just the duplicated line.

* Stripe: Parse EMV ARC from error response [bizla]


== Version 1.50.0 (June 1, 2015)
Expand Down
14 changes: 12 additions & 2 deletions lib/active_merchant/billing/gateways/stripe.rb
Expand Up @@ -418,7 +418,7 @@ def commit(method, url, parameters = nil, options = {})

success = !response.key?("error")

card = response["card"] || response["active_card"] || response["source"] || {}
card = card_from_response(response)
avs_code = AVS_CODE_TRANSLATOR["line1: #{card["address_line1_check"]}, zip: #{card["address_zip_check"]}"]
cvc_code = CVC_CODE_TRANSLATOR[card["cvc_check"]]

Expand All @@ -429,7 +429,7 @@ def commit(method, url, parameters = nil, options = {})
:authorization => success ? response["id"] : response["error"]["charge"],
:avs_result => { :code => avs_code },
:cvv_result => cvc_code,
:emv_authorization => card["emv_auth_data"],
:emv_authorization => emv_authorization_from_response(response),
:error_code => success ? nil : STANDARD_ERROR_CODE_MAPPING[response["error"]["code"]]
)
end
Expand Down Expand Up @@ -459,6 +459,16 @@ def non_fractional_currency?(currency)
def emv_payment?(payment)
payment.respond_to?(:emv?) && payment.emv?
end

def card_from_response(response)
response["card"] || response["active_card"] || response["source"] || {}
end

def emv_authorization_from_response(response)
return response["error"]["emv_auth_data"] if response["error"]

card_from_response(response)["emv_auth_data"]
end
end
end
end
26 changes: 26 additions & 0 deletions test/unit/gateways/stripe_test.rb
Expand Up @@ -214,6 +214,17 @@ def test_successful_authorization_with_emv_credit_card
assert response.emv_authorization, "Response should include emv_authorization containing the EMV ARPC"
end

def test_declined_authorization_with_emv_credit_card
@gateway.expects(:ssl_request).returns(declined_authorization_response_with_emv_auth_data)

assert response = @gateway.authorize(@amount, @emv_credit_card, @options)
assert_instance_of Response, response
assert_failure response

assert_equal 'ch_declined_auth', response.authorization
assert response.emv_authorization, "Response should include emv_auth_data containing the EMV ARC"
end

def test_successful_capture
@gateway.expects(:ssl_request).returns(successful_capture_response)

Expand Down Expand Up @@ -1305,6 +1316,21 @@ def declined_authorization_response
RESPONSE
end

def declined_authorization_response_with_emv_auth_data
<<-RESPONSE
{
"error": {
"message": "Your card was declined.",
"type": "card_error",
"code": "card_declined",
"decline_code": "generic_decline",
"charge": "ch_declined_auth",
"emv_auth_data": "8A023531910ACD16B371D277FDB90000"
}
}
RESPONSE
end

def successful_update_credit_card_response
<<-RESPONSE
{
Expand Down

0 comments on commit 2d6d6a5

Please sign in to comment.