Rails,如何从控制器提交 PayPal 请求,而不是表单,URL 编码
我们正在尝试从控制器而不是表单向 PayPal 提交请求。当我们使用表单版本时,一切正常,但是当我们在控制器中使用重定向时,无论我们做什么都会出错。看来存在某种 URL 编码问题。
表单:
<% form_tag Paypal_URL do %> <%= hide_field_tag :cmd, "_s-xclick" %> <%=hidden_field_tag:加密,@paypal_link%> <%=submit_tag“完成购买”%> <%结束%>
控制器: 我们已经尝试了以下所有方法,但都导致错误。
redirect_to Paypal_URL + "?cmd=_s-xclick:encrypted=" + @paypal_link 并返回 => Rails 给我们 URI 错误
redirect_to URI.encode(Paypal_URL + "?cmd=_s-xclick:encrypted=" + @paypal_link) 并返回 =>我们从 paypal 收到 500 错误。看起来链接编码错误
We are trying to submit requests to PayPal from a controller instead of from a form. When we use the form version everything works correctly, but when we use redirect in the controller, we get errors no matter what we do. It appears that there is some sort of URL encoding problem.
Form:
<% form_tag Paypal_URL do %>
<%= hidden_field_tag :cmd, "_s-xclick" %>
<%= hidden_field_tag :encrypted, @paypal_link %>
<%= submit_tag "Complete Purchase" %>
<% end %>
Controller:
We've tried all the following, but all result in errors.
redirect_to Paypal_URL + "?cmd=_s-xclick:encrypted=" + @paypal_link and return
=> Rails give us URI errors
redirect_to URI.encode(Paypal_URL + "?cmd=_s-xclick:encrypted=" + @paypal_link) and return
=> We get a 500 error from paypal. Looks like the link is encoding wrong
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
迈克,
这可能不是问题的最佳解决方案,但我还需要从控制器重定向到 Paypal 付款网址。以下对我来说效果很好:
Mike,
This might not be the best solution to the problem but I also needed to redirect to a Paypal payment url after from a controller. The following worked fine for me: