paypal-checkout-sdk breaks in ruby 3.0.1

Viewed 225

Ruby 3.0.1

Rails 6.1.3.2

Executing a Paypal OrdersCreateRequest fails with this error

NoMethodError (undefined method `escape' for URI:Module):

The backtrace points to .rvm/gems/ruby-3.0.1/gems/paypalhttp-1.0.0/lib/paypalhttp/serializers/form_encoded.rb:8:in `block in encode' which contains this line as of paypalhttp v1.0.0

encoded_params.push("#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}")

Apparently the URI.escape method was removed in ruby 3 as stated here https://github.com/ruby/uri/issues/14

Is there a workaround for this or I have to just wait for Paypal to update the gem? I do not want to downgrade to ruby 2.x

1 Answers

You could monkeypatch it:

module URI
  def self.escape(*args)
    URI.encode_www_form_component(*args)
  end
end
Related