nov / paypal-express

Ruby Gem for PayPal Express Checkout API
MIT License
373 stars 162 forks source link

Getting 'PayPal API Error: 'Version error'' #99

Open krzysztofbialek opened 8 years ago

krzysztofbialek commented 8 years ago

When trying to register transaction I get:

Paypal::Exception::APIError - PayPal API Error: 'Version error'

Full message says that version is not supported. I tried setting Paypal.api_version to latest and different values and it doesn't help.

This started happening suddenly yesterday. It was working fine few days ago.

full code of method

order = @order
    if(APP_CONFIG["paypal"]["sandbox"])
      Paypal.sandbox!
    end

    express_request = Paypal::Express::Request.new(
      :username   => APP_CONFIG["paypal"]["api_username"],
      :password   => APP_CONFIG["paypal"]["api_password"],
      :signature  => APP_CONFIG["paypal"]["api_signature"]
    )

    logger.info "==PPP Express::Request: #{express_request}"

    paypal_options = {
      no_shipping: true, # if you want to disable shipping information
      allow_note: false, # if you want to disable notes
      pay_on_paypal: true # if you don't plan on showing your own confirmation step
    }

    logger.info "==PPP paypal_options: #{paypal_options}"

    payment_request = Paypal::Payment::Request.new(
      :currency_code => "PLN",              # if nil, PayPal use USD as default
      :description   => order.pack.name,    # item description
      :quantity      => 1,                  # item quantity
      :amount        => order.total.round(2).to_f,
      :invoice_number => (order.id + 100000),
      :notify_url => APP_CONFIG["paypal"]["ipn_notify_url"]
    )

    response = express_request.setup(
      payment_request,
      "http://bookrage.org/paypal/success/#{order.return_token}",
      "http://bookrage.org/paypal/cancel/#{order.return_token}",
      paypal_options  # Optional
    )

    logger.info "==PPP response.redirect_uri: #{response.redirect_uri}"

    return response.redirect_uri

Still, example curl from paypal page works on sandbox event with my credentials

curl https://api-3t.sandbox.paypal.com/nvp \
>   -s \
>   --insecure \
>   -d USER=platfo_1255077030_biz_api1.gmail.com \
>   -d PWD=1255077037 \
>   -d SIGNATURE=Abg0gYcQyxQvnf2HDJkKtA-p6pqhA1k-KTYE0Gcy1diujFio4io5Vqjf \
>   -d METHOD=SetExpressCheckout \
>   -d VERSION=78 \
>   -d PAYMENTREQUEST_0_PAYMENTACTION=SALE \
>   -d PAYMENTREQUEST_0_AMT=19 \
>   -d PAYMENTREQUEST_0_CURRENCYCODE=USD \
>   -d cancelUrl=http://www.example.com/cancel.html \
>   -d returnUrl=http://www.example.com/success.html
TOKEN=EC%2d6VH883273N101092R&TIMESTAMP=2016%2d07%2d14T21%3a04%3a57Z&CORRELATIONID=c34496e55ed38&ACK=Success&VERSION=78&BUILD=000000%
fabioglopes commented 7 years ago

Same problem here.

comp615 commented 7 years ago

I think @meal or @ianfleeton seemed to fix it here: https://github.com/ianfleeton/paypal-express/commit/cebd62f02966f74a8aa3ece5d1793be9327048a0

Maybe we can merge that back into the canonical version? @nov are you still maintaining this or is there a new canonical fork?

ianfleeton commented 7 years ago

This was @meal's work - my fork contains two improvements, neither by me. A merge from @meal's would be better.

meal commented 7 years ago

I can create PR for this but I'm not sure if @nov still maintains this repository.

krzysztofbialek commented 7 years ago

There already are pending PR with this change...Looks like this got abandoned

pastullo commented 7 years ago

That's a pity because this gem is very useful and i used it in three projects already!

dgilperez commented 7 years ago

Which fork are you currently using guys?

ianfleeton commented 7 years ago

I've started using my own fork as I need the changes I've pulled in so far, which include changes from more than one other fork.

I am working on a project that depends on this library for the next year. I'm happy to become a maintainer for the next year or so if it helps others, focusing on bug fixes / minor improvements rather than new features. I've not maintained a project before but first time for everything. Unless there are any other takers? @nov?

pastullo commented 7 years ago

awesome @ianfleeton do that! we need somebody to take over. A quick paypal integration gem is quite useful and we can't let it die.

I tried to contact @nov multiple times on email, twitter and github, but no answer. Let's move on!

dgilperez commented 7 years ago

@nov what about creating an organization for the gem? Time for this useful child to fly away?

If @nov doesn't reply, we may well create the org and move on. @ianfleeton if you need some help, I may find some time here and there.

ianfleeton commented 7 years ago

Excellent, I'll wait to see if anything happens by Sunday and if no news I'll start reviewing the current open issues and pull requests with a view to moving things forward. Any and all help welcome :)

pastullo commented 7 years ago

@ianfleeton @dgilperez shall we? 👍

ianfleeton commented 7 years ago

I've made a few commits and pulled in some others' changes into https://github.com/ianfleeton/paypal-express by making pull requests from their forks and merging them.

Fixed:

  1. PayPal API version, including with refunds (thanks @meal @netjungle)
  2. Travis build with ActiveSupport 5.x (thanks @ursm)
  3. Phone number included (thanks @fny)

The next two items to look at:

  1. Gem releases
  2. Organization

Is it time to move the discussion over to ianfleeton/paypal-express?

Cheers!

tansaku commented 7 years ago

if you guys want help and support from an organisation - AgileVentures is a charity that could help - we were just thinking about integrating paypal

Happy to provide a home for the project at https://github.com/AgileVentures/ if that's any help

tansaku commented 7 years ago

I see that Paypal also has their own ruby gem https://github.com/paypal/PayPal-Ruby-SDK - is that any relation?

ianfleeton commented 7 years ago

PayPal Express uses the NVP / SOAP APIs instead of the REST APIs provided by that library. I don't think they overlap, but I'm not 100%.

ktopping commented 7 years ago

I encountered this same problem and it turns out that the issue was that, although the paypal-express gem hadn't changed, I had upgraded the rest-client gem from 1.8.2 to 2.0.0. The slight change between the versions is that they serialize querystring parameters slightly differently. Where 1.8.2 would emit: &SUBJECT=&VERSION=0.88 2.0.0 emits: &SUBJECT&VERSION=0.88 Although many servers understand this, seemingly Paypal's doesn't. (I'm guessing it sees one parameter named "SUBJECT&VERSION" with value "0.88" - and then complains that there's no VERSION in the request). I have implemented a horrible workaround for now (evilly monkey-patching RestClient::Utils#encode_query_string). Although fixing to 1.8.2 of the rest-client gem works, too.

ianfleeton commented 7 years ago

@ktopping have you tried using a later API version -- e.g., 204.0 to see if that helps? The fork over at https://github.com/ianfleeton/paypal-express uses that. If you find the same problem with that fork I'd be interested to know. Also, this fork includes the required version parameter in many more places.

I have that running with rest-client 2.0.0 no problems, though I haven't dug in to see whether the SUBJECT param is or isn't set in my usage.

(I find it interesting that your monkey patching did make a difference.. hmm)

pastullo commented 7 years ago

Quick solution: using the fork from Ian Fleeton

gem 'paypal-express', github: 'ianfleeton/paypal-express'

ianfleeton commented 7 years ago

I've pulled into the above PR #98 from @ursm (thanks!) which hopefully addresses this problem by explicitly setting a blank string for the subject parameter if it's nil.

ktopping commented 7 years ago

Thanks for the replies. I have it working at the moment but will try upgrading to ianfleeton's fork next time I rebundle.

leandro commented 7 years ago

Following @pastullo's suggestion worked for me. Thank you. Too bad that this repo doesn't seem to be receiving any attention from the creator anymore.

henrik commented 6 years ago

We just upgraded rest-client from 1.8.0 to 2.0.2 and started getting this "Version error". Changing to ianfleeton's fork as mentioned by @pastullo above fixed it. Thank you!

luismiv85 commented 2 years ago

Hi! If you want not change of repository you can use monkey patching. This is the code:

File: config/initializers/paypal.rb

....

Paypal::NVP::Request.class_eval do
  def common_params
    {
      USER: self.username,
      PWD: self.password,
      SIGNATURE: self.signature,
      SUBJECT: self.subject,
      VERSION: self.version,
      version: self.version # This is necessary
    }
  end
end

A little bit late, but I hoppe help some one.

This solution was taking from ianfleeton/paypal-express repository, so thanks a lot ianfleeton