我需要获取交易数据(日期,有价值)和用户adata。我可以使用此gem进行一些修改,如question所示吗?
另外,来自文档:
例如,如果您计划使用getBasicPersonalData和getAdvancedPersonalData查询PayPal,则可能会生成以下商家模型:
rails generate paypal_permissions merchant email:string first_name:string last_name:string full_name:string country:string payer_id:string street1:string street2:string city:string state:string postal_code_string phone:string birth_date:string
bundle exec
rake db:migrate
我应该使用付款数据传输(PDT)还是TRANSACTION_DETAILS? 这是我将写数据的地方,但我如何从PayPal获取数据?
任何人都可以给我一些代码示例吗?
答案 0 :(得分:1)
Paypal Adaptive 似乎是这样做的方法,这里有一些我发现的文档,希望它有所帮助。
像往常一样,PayPal文档非常杂乱无序,因此我想我已经记录了如何在市场风格的网站上设置PayPal Adaptive。
请使用此帖子作为paypal API如何与您的rails应用程序连接的指南。正如Jamesw在下面的评论中指出的那样,我没有创建一个记录每笔交易的所有细节的充分方法;法律无疑要求的东西。所以也许在阅读之后看看他的评论。希望你能找到一种方法来做到这一点
经过一番搜索,我发现现在使用的最好的宝石是paypal_adaptive。 ActiveMerchant目前不支持PayPal Adaptive(有一个gem可以添加它,但它似乎没有被维护。)
# Gemfile
gem 'paypal_adaptive'
PayPal Adaptive相对简单,但凌乱的文档可能会让它看起来令人生畏。简而言之,我就这样做了:
转到here创建沙盒帐户(您将需要它)。登录后,请转到“创建预配置帐户”。创建两个帐户 - 一个买家和一个卖家。如果您使用链式或并行付款(付款分配给多个人),则再创建一些帐户。
单击左侧面板中的Api凭证。
现在使用这些凭据填写你的paypal_adaptive.yml(也使用我在下面提供的application_id - 这是www.x.com提供的测试application_id
development:
environment: "sandbox"
username: "platts_xxxxxxxx_biz_api1.gmail.com"
password: "xxxxxxxxxxxx"
signature: "xxxxxxx"
application_id: "APP-80W284485P519543T"
test:
environment: "sandbox"
username: "platts_xxxxxxxx_biz_api1.gmail.com"
password: "xxxxxxxx"
signature: "xxxxxxxx"
application_id: "APP-80W284485P519543T"
production:
environment: "production"
username: "my_production_username"
password: "my_production_password"
signature: "my_production_signature"
application_id: "my_production_app_id"
在这里,您只需要支付足够的金额以及您希望获得这笔钱的电子邮件列表。所以写下你的逻辑来解决这个问题,然后打电话给PayPal设置购买。
pay_request = PaypalAdaptive::Request.new
data = {
"returnUrl" => return_url,
"requestEnvelope" => {"errorLanguage" => "en_US"},
"currencyCode" => "USD",
"receiverList" =>
{ "receiver" => [
{"email" => "platts_xxxxxxxx_biz@gmail.com", "amount"=> amount}
]},
"cancelUrl" => cancel_url,
"actionType" => "PAY",
"ipnNotificationUrl" => ipn_url
}
#To do chained payments, just add a primary boolean flag:{“receiver”=> [{"email"=>"PRIMARY", "amount"=>"100.00", "primary" => true}, {"email"=>"OTHER", "amount"=>"75.00", "primary" => false}]}
pay_response = pay_request.pay(data)
if pay_response.success?
# Send user to paypal
redirect_to pay_response.approve_paypal_payment_url
else
puts pay_response.errors.first['message']
redirect_to "/", notice: "Something went wrong. Please contact support."
end
我将来自PayPal的IPN呼叫路由到此方法:
def ipn_notification
ipn = PaypalAdaptive::IpnNotification.new
ipn.send_back(request.raw_post)
if ipn.verified?
logger.info "IT WORKED"
else
logger.info "IT DIDNT WORK"
end
render nothing: true
end
不幸的是,如果您使用的是localhost,PayPal无法向您发送IPN,因此测试整个过程存在问题。 Ryan Bates的解决方案是使用curl来模仿IPN请求。但是,正如您在上面的代码中看到的那样,我们向PayPal发出另一个请求,确认IPN是真实的。因此,即使卷发发送假IPN,我们也会遇到问题。我现在要去寻找解决方案,但如果你有任何想法,请发表评论。