开发者

Rails, How to submit PayPal requests from controller, instead of a form, URL encoding

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


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:

if @project.save!

  # Send to PayPal
  redirect_to URI.encode("https://www.paypal.com/cgi-bin/webscr" + "?cmd=_xclick&business=sales@domain.com&currenct_code=USD&item_name#{@project.name}&amount=#{@project.price}")

else
  # not created
  redirect_to :back, :notice => "Didn't work"
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜