I need to pass user_id, not logged in user, but user_id from view.
I am writing admin part.
I’m making post request using user email and redirect to appropriate page. so I want to make route something like:
/:user_id/pay
to call pay action for appropriate user.
In my view I want to show email and link to this action:
<% @users.each do |user| %>
<li>
<%= user.email %>
<%= link_to "Pay", some_controller_pay(user.id) %>
</li>
EDIT
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}"
end
PayPal say that some error occured.
I try to inspect variables, so I should put in view:
<%= @xml%>
<%= payKey%>
but id din’t work, how I can inpect them ?
In development log:
Redirected to https://sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=
Completed 302 Found in 1193ms (ActiveRecord: 1.0ms)
So it doesn’t insert link, yes ? How I can get ALL RESPONS info
How I can manage to do this ?
Since you already have a
Usermodel, you can addpayas another RESTful action:This automatically sets up a named route
pay_user:Including a
pay_user_pathhelper for your views:In your
UserControllerthis works like any other action: