Closed dorianmariecom closed 2 years ago
Excellent work, please merge it!
thanks, but maybe using activesupport's Hash#to_query
would be better, or not doing the gsub
or using CGI.escape
Also it needs to be tested on a full set of endpoints, I only tested for fetching an order and creating an order
Thanks for taking the time to create this. It seems like the gem authors won't be merging these anytime soon.
How would I do a monkey patch to included these changes?? Not done one before and I'm having trouble
@GregSmith92 You would add this in an initializer:
module PayPalHttp
class FormEncoded
def encode(request)
encoded_params = []
request.body.each do |k, v|
encoded_params.push("#{escape(k)}=#{escape(v)}")
end
encoded_params.join("&")
end
def decode(body)
raise UnsupportedEncodingError.new("FormEncoded does not support deserialization")
end
def content_type
/^application\/x-www-form-urlencoded/
end
private
def escape(value)
URI.encode_www_form_component(value.to_s).gsub('+', '%20')
end
end
end
@dorianmariefr Thanks for responding 🙏.
This works perfectly, much appreciated.
An issue with this approach might come up when the original "key" that gets encoded contains a + within its value, as that will be translated into %2b with cgi escape, but will it be able to be properly decoded if the space values are replaced from + to %20?
ruby 3.1:
> URI.encode_www_form_component("Hello world").gsub('+', '%20')
=> "Hello%20world"
ruby 2.7.6
> URI.escape("Hello world")
(irb):3: warning: URI.escape is obsolete
=> "Hello%20world"
I don't know how PayPal's backend handles spacing but at least it's sending the same payload as before
This is fixed in v2.0.0, which was just released.
Otherwise I get: