我需要传递 user_id,不是登录用户,而是视图中的 user_id。
我正在写管理部分。
我正在使用用户电子邮件发出发布请求并重定向到适当的页面。所以我想让路线类似于:
/:user_id/pay
为适当的用户调用付费操作。
在我看来,我想显示电子邮件和指向此操作的链接:
<% @users.each do |user| %>
<li>
<%= user.email %>
<%= link_to "Pay", some_controller_pay(user.id) %>
</li>
编辑
def pay
require 'httpclient'
require 'xmlsimple'
clnt = HTTPClient.new
user = User.find(params[:user_id])
credentials = {
'USER' => 'payer_1342623102_biz_api1.gmail.com',
'PWD' => '1342623141',
'SIGNATURE' => 'Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL '
}
header = {"X-PAYPAL-SECURITY-USERID" => "payer_1342623102_biz_api1.gmail.com",
"X-PAYPAL-SECURITY-PASSWORD" => "1342623141",
"X-PAYPAL-SECURITY-SIGNATURE" => "Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL ",
"X-PAYPAL-REQUEST-DATA-FORMAT" => "NV",
"X-PAYPAL-RESPONSE-DATA-FORMAT" => "XML",
"X-PAYPAL-APPLICATION-ID" => "APP-80W284485P519543T"
}
data = {"actionType" => "PAY",
"receiverList.receiver(0).email"=> user.email,
"receiverList.receiver(0).amount" => "10",
"currencyCode" => "USD",
"cancelUrl" => root_path,
"returnUrl" => root_path,
"requestEnvelope.errorLanguage" => "en_US"}
uri = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay"
res = clnt.post(uri, data, header)
@xml = XmlSimple.xml_in(res.content)
@payKey = @xml["payKey"].to_s()
@payKey = @payKey.tr("[]", "")
@payKey = @payKey[1..20]
redirect_to "https://sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=#{@payKey}"
结束 PayPal 说发生了一些错误。
我尝试检查变量,所以我应该考虑:
<%= @xml%>
<%= payKey%>
但我不能工作,我怎么能检查他们?
在开发日志中:
Redirected to https://sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=
Completed 302 Found in 1193ms (ActiveRecord: 1.0ms)
所以它不插入链接,是吗?我如何获得所有响应信息
我怎么能做到这一点?