Ruby PayPal SDK,从授权代码获取令牌信息会引发400错误

时间:2016-07-21 09:14:20

标签: ruby-on-rails ruby paypal

我创建了PayPal商家帐户,并且我已在sandbox模式下创建了应用程序。

使用PayPal-Ruby-SDK我已将client_idclient_secretusernamepasswordsignature添加到paypal.yml文件。

我也使用PayPal-Android-SDK,其中有client_id此应用,当我的手机应用程序通过PayPal登录时,它会创建这种响应:

"response": { 
    "code":"mock_code_EJhi9jOPswug9TDOv93qg4Y28xIlqPDpAoqd7biDLpeGCPvORHjP1Fh4CbFPgKMGCHejdDwe9w1uDWnjPCp1lkaFBjVmjvjpFtnr6z1YeBbmfZYqa9faQT_71dmgZhMIFVkbi4yO7hk0LBHXt_wtdsw"
  },
"client": {
    "platform": "Android",
    "paypal_sdk_version": "2.14.4",
    "product_name": "PayPal-Android-SDK",
    "environment": "mock"
  },
 "response_type": "authorization_code"
}

现在我想从此refresh token字段生成code。我把这个code输入我的ruby控制台:

tokeninfo = Tokeninfo.create('mock_code_EJhi9jOPswug9TDOv93qg4Y28xIlqPDpAoqd7biDLpeGCPvORHjP1Fh4CbFPgKMGCHejdDwe9w1uDWnjPCp1lkaFBjVmjvjpFtnr6z1YeBbmfZYqa9faQT_71dmgZhMIFVkbi4yO7hk0LBHXt_wtdsw')

然而,这引发了我的错误:

PayPal::SDK::Core::Exceptions::BadRequest: Failed.  Response code = 400.  Response message = Bad Request.  Response debug ID = 93403fd3eb431, 1998e13f9d984.
from D:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/paypal-sdk-rest-1.4.8/lib/paypal-sdk/core/util/http_helper.rb:135:in `handle_response'
from D:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/paypal-sdk-rest-1.4.8/lib/paypal-sdk/core/util/http_helper.rb:78:in `http_call'
from D:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/paypal-sdk-rest-1.4.8/lib/paypal-sdk/core/api/base.rb:86:in `api_call'
from D:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/paypal-sdk-rest-1.4.8/lib/paypal-sdk/core/api/base.rb:98:in `post'
from D:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/paypal-sdk-rest-1.4.8/lib/paypal-sdk/core/openid_connect.rb:71:in `create_from_authorization_code'
from (irb):3
from D:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.2.7/lib/rails/commands/console.rb:110:in `start'
from D:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.2.7/lib/rails/commands/console.rb:9:in `start'
from D:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.2.7/lib/rails/commands/commands_tasks.rb:68:in `console'
from D:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.2.7/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from D:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-4.2.7/lib/rails/commands.rb:17:in `<top (required)>'

我在信息中心选中了使用PayPal登录选项。为什么会这样?

此外,我注意到每当我从不同的帐户登录时,此mock_code_都是相同的。

1 个答案:

答案 0 :(得分:0)

我会回答我自己的问题。这对未来的其他人有帮助。

Tokeninfo.create方法失败的主要原因是从Android应用程序收到的授权代码是模拟模式

每个具有 mock_code _ 前缀的授权代码都不适用于沙箱(和实时)。这仅适用于设备测试。

在Android SDK中,您必须设置ENVIRONMENT_SANDBOXENVIRONMENT_PRODUCTION而不是ENVIRONMENT_NO_NETWORK