繁体   English   中英

使用PayPal红宝石gem获取用户的PayPal付款

[英]Get User's PayPal Payments using PayPal ruby gem

我正在尝试使用PayPal的ruby gem来完成一个简单的任务,如下所示:

1-用户使用PayPal OAuth登录到我的应用程序。

2-用户授权我的应用访问他的帐户。

3-我的应用发出了一个简单请求,要求列出该用户的10笔交易。

我正在按照官方PayPal的github存储库( https://github.com/paypal/PayPal-Ruby-SDK )中的说明进行操作

require 'paypal-sdk-rest'
include PayPal::SDK::REST
include PayPal::SDK::OpenIDConnect

# Update client_id, client_secret and redirect_uri
PayPal::SDK.configure({
  :openid_client_id     => "client_id",
  :openid_client_secret => "client_secret",
  :openid_redirect_uri  => "http://google.com"
})

# Generate URL to Get Authorize code
puts Tokeninfo.authorize_url( :scope => "openid profile" )

# Create tokeninfo by using AuthorizeCode from redirect_uri
tokeninfo = Tokeninfo.create("Replace with Authorize Code received on redirect_uri")
puts tokeninfo.to_hash

# Refresh tokeninfo object
tokeninfo = tokeninfo.refresh
puts tokeninfo.to_hash

经过这个简单的设置代码,我试图获取用户的交易,但是我不能仅使用如下代码的Payment实体来做到这一点:

Payment.all(count: 10)

它返回一个错误:

PayPal::SDK::Core::Exceptions::UnauthorizedAccess: Failed.  Response code = 401.  Response message = Unauthorized.  Response debug ID = 409003e14dd9a, 409003e14dd9a.

那么,如何验证用户的身份,然后使用其令牌进行API操作?

我不确定您是否需要所有这些。

这是我所做的:

include PayPal::SDK::REST

PayPal::SDK.configure({ 
  openid_client_id: "client_id",
  openid_client_secret: "client_secret",
  openid_redirect_uri: "http://google.com"
})

Payment.all
=>

Request[get]: https://api.sandbox.paypal.com/v1/payments/payment
Request.body=null   request.header={"X-PAYPAL-SANDBOX-EMAIL-ADDRESS"=>"Platform.sdk.sell@gmail.com", "Authorization"=>"Bearer A101.CLf7NBF8CWMt0Lt4tc9OzrKs9RmGB8wuDBw11n1Ucn8DWTyws8A-nM5b68NYpn8F.qiud2q4fOpca2RSfhZElDV4fzLm", "Content-Type"=>"application/json", "User-Agent"=>"PayPalSDK/PayPal-Ruby-SDK 1.4.4 (paypal-sdk-core 1.4.4; ruby 2.3.0p0-x86_64-linux;OpenSSL 1.0.1f 6 Jan 2014)"}
Response[200]: OK, Duration: 30.002s
Response.body={"payments":[{"id":"PAY-
...etcetc

值得注意的是,目前它仅显示通过REST API创建的付款。

尽管401是未经授权的,所以很可能您得到的信息不正确。 确保您的client_id和client_secret是正确的-您可以在开发人员信息中心下找到此信息。

现在,它使用Transactions API支持此功能。

https://developer.paypal.com/docs/api/sync/v1/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM