Skip to content

Commit

Permalink
Add AVS response code to ActiveMerchant responses
Browse files Browse the repository at this point in the history
  • Loading branch information
philbirt committed Dec 2, 2015
1 parent 3df2323 commit 712cc80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/models/solidus/gateway/braintree_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,21 @@ def message_from_result(result)
end
end

def build_results_hash(result)
{}.tap do |results_hash|
results_hash.merge!({
authorization: result.transaction.id,
avs_result: { code: result.transaction.avs_street_address_response_code }
}) if result.success?
end
end

def handle_result(result)
ActiveMerchant::Billing::Response.new(
result.success?,
message_from_result(result),
{},
{ authorization: (result.transaction.id if result.success?) }
build_results_hash(result)
)
end

Expand Down
3 changes: 3 additions & 0 deletions spec/solidus/gateway/braintree_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
capture = payment_method.capture(5000, auth.authorization, {})
expect(capture).to be_success
expect(capture.authorization).to be_present
expect(capture.avs_result["code"]).to eq "M"
end
end

Expand Down Expand Up @@ -151,10 +152,12 @@
auth = payment_method.authorize(5000, card, {})
expect(auth).to be_success
expect(auth.authorization).to be_present
expect(auth.avs_result["code"]).to eq "I"

capture = payment_method.capture(5000, auth.authorization, {})
expect(capture).to be_success
expect(capture.authorization).to be_present
expect(capture.avs_result["code"]).to eq "I"
end

it "succeeds capture on pending settlement" do
Expand Down

0 comments on commit 712cc80

Please sign in to comment.