paypal / paypalhttp_ruby

MIT License
6 stars 38 forks source link

Replaces URI.escape to fix Ruby 2.7 deprecation warning #4

Closed alg closed 2 years ago

alg commented 4 years ago

Using URI.encode_www_form_component instead.

davidalejandroaguilar commented 3 years ago

Any chance we can merge this? PayPal SDK breaks with Ruby 3.0.0. This fixes it.

smirceal commented 3 years ago

Can this be merged? it's broken in ruby 3.0

rbclark commented 3 years ago

Running into this issue as well, causing a lot of warnings on Ruby 2.7 and blocking upgrade to 3.0.

sweetppro commented 3 years ago

Merge please

cristi commented 3 years ago

can this be merged please?

dabrorius commented 3 years ago

This is blocking us from upgrading to Ruby 3.0, can you please merge it?

otikev commented 3 years ago

Please merge this. I've been forced to downgrade to ruby 2.7.3 because of this bug

jclarke commented 3 years ago

Another vote to please merge this so we can upgrade to Ruby 3! Thank you!

thushw commented 3 years ago

I hit this with the paypal payout api as well.

teddydjiomou commented 3 years ago

Please merge this, it's very annoying. Do anyone solved this in any other way?

rbclark commented 3 years ago

@HDLahlou Please address one of the PRs on this issue, it is blocking everyone from having the ability to use ruby 3.0.

khannotations commented 2 years ago

Please merge! Our business cannot operate without this, we process our payments through paypal!

estafaa commented 2 years ago

Merge, please!

shanecav84 commented 2 years ago

Wow. This is a simple fix that could have been done in 2020.

dechimp commented 2 years ago

@HDLahlou Can this be merged please?

rbclark commented 2 years ago

I did some more digging on this, and this solution doesn't actually work for all use cases. This encodes URLs as

http%3A%2F%2Flocalhost%3A3001%2F

instead of

http://localhost:3001/

as it did previously which breaks the RETURNURL in Paypal Payflow. I ended up monkeypatching with:

      encoded_params = []
      p = URI::Parser.new
      request.body.each do |k, v|
        encoded_params.push("#{p.escape(k.to_s)}=#{p.escape(v.to_s)}")
      end

in order to unblock the upgrade to Ruby 3.1.

PeaceS commented 2 years ago

The most wanted PR to be merge is right here!!!

mkroszka commented 2 years ago

When can we expect to merge?

smirceal commented 2 years ago

When can we expect to merge?

we know for sure it's going to be 20xx :(

JulienSansot commented 2 years ago

This monkey patch works:

module URI
  def self.escape(*args)
    URI.encode_www_form_component(*args)
  end
end
davidalejandroaguilar commented 2 years ago

@JulienSansot Wouldn't recommend monkey patching URI. Instead, just put this PR's code on an initializer and be done with it 🤷🏼‍♂️ :

# config/initializers/paypal.rb

# Monkeypatch to work with Ruby 3.0
#
# https://github.com/paypal/paypalhttp_ruby/pull/4

require "uri"

module PayPalHttp
  class FormEncoded
    def encode(request)
      encoded_params = []
      request.body.each do |k, v|
        encoded_params.push("#{encode_part(k)}=#{encode_part(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 encode_part(part)
      URI.encode_www_form_component(part.to_s)
    end
  end
end
mecampbellsoup commented 2 years ago

@JulienSansot Wouldn't recommend monkey patching URI.

I actually think this is a perfect candidate for a global monkeypatch considering Ruby deprecated the method and explicitly recommend using URI.encode_www_form_component.

https://ruby-doc.org/stdlib-2.7.3/libdoc/uri/rdoc/URI/Escape.html#method-i-escape

magni- commented 2 years ago

@HDLahlou Is this repo actively maintained?

crookedneighbor commented 2 years ago

This is fixed in v2.0.0, which was just released.

sedubois commented 2 years ago

@crookedneighbor but the PayPal Ruby SDK has been deprecated and archived, and is locked on PayPal HTTP v1. So this PR can't be used.

crookedneighbor commented 2 years ago

@sedubois you are welcome to fork the Ruby Checkout SDK and update it.