Skip to content

Instantly share code, notes, and snippets.

@kernow
Created May 9, 2011 15:51
Show Gist options
  • Save kernow/962764 to your computer and use it in GitHub Desktop.
Save kernow/962764 to your computer and use it in GitHub Desktop.
# create a worldpay response object that acts like a string but has the each_header method
# so that we can access the headers that worldpay returns
class WorldPayResponse < String
def initialize(resp)
@resp = resp
super(resp.body)
end
def each_header(&block)
@resp.each_header &block
end
end
# overwrite the handle_response method so that it returns a WorldPayResponse object rather
# than the response.body string, this acts the same as a string but includes the each_header
# method for accessing the returned headers
module ActiveMerchant
class Connection
private
def handle_response(response)
case response.code.to_i
when 200...300
WorldPayResponse.new(response)
else
raise ResponseError.new(response)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment