Skip to content

Commit

Permalink
Experiment with headers in response params
Browse files Browse the repository at this point in the history
  • Loading branch information
aenand committed Jul 12, 2024
1 parent f270a60 commit bc815c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/active_merchant/billing/gateways/adyen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -755,18 +755,28 @@ def add_metadata(post, options = {})
post[:metadata].merge!(options[:metadata]) if options[:metadata]
end

def parse(body)
def parse(response)
body = response.body
return {} if body.blank?

JSON.parse(body)
JSON.parse(body).merge(response.each_header.to_h)
end

def handle_response(response)
case response.code.to_i
when 200...300
response
else
raise ResponseError.new(response)
end
end

def commit(action, parameters, options)
begin
raw_response = ssl_post(url(action), post_data(action, parameters), request_headers(options))
response = parse(raw_response)
rescue ResponseError => e
raw_response = e.response.body
raw_response = e.response
response = parse(raw_response)
end

Expand Down
7 changes: 7 additions & 0 deletions test/remote/gateways/remote_adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ def test_successful_authorize
assert_equal 'Authorised', response.message
end

def test_headers_in_response
response = @gateway.authorize(@amount, @credit_card, @options)
assert_success response
assert_equal 'Authorised', response.message
refute response.params['content-type'].blank?
end

def test_successful_authorize_with_bank_account
response = @gateway.authorize(@amount, @bank_account, @options)
assert_success response
Expand Down

0 comments on commit bc815c9

Please sign in to comment.