Rails PayPal proof of concept

I am trying to create an extremely simple Paypal user integration with rails. I am following Ryan Bates Railscast # 141 on this, and I have simplified it even further. If you have experience with simple, easy integration with PayPal, any advice would be appreciated!

I am trying to transfer everything through my account model. Proof of concept.

def paypal_url(return_url)
  values = {
    :business => 'jwade_1268181180_biz@gmail.com',
    :cmd => '_cart',
    :upload => 1,
    :return => return_url,
    :invoice => 2,
    :amount => 7,
    :item_name => 'Membership',
    :item_number => 1,
    :quantity => 1 
  }

  "https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.to_query
end 

and, of course, create a link:

<%= link_to "Checkout", @account.paypal_url(accounts_path) %>

Paypal detects an error: " Your shopping cart is empty ", which is strange because I see everything that my model sends in the URL:

https://www.sandbox.paypal.com/cgi-bin/webscr?amount=7&business=jwade_1268181180_biz@gmail.com&cmd=_cart&invoice=&item_name=Barcoden+Membership&item_number=1&quantity=1&return=/accounts&upload=1
+3
source share
2 answers

, railscast . , :

<div>
  <%= form_tag 'https://www.sandbox.paypal.com/cgi-bin/webscr' do %>
  <input type="hidden" name="cmd" value="_cart"> 
  <input type="hidden" name="upload" value="1"> 
  <input type="hidden" name="business" value="Your sandbox biz Account"> 
  <input type="hidden" name="item_name_1" value="Some Name"> 
  <input type="hidden" name="amount_1" value="100"> 
  <input type="submit" value="PayPal">
  <% end %>
</div>

. , , .

:method => :post link_to .

button_to, - link_to .

+2

Source: https://habr.com/ru/post/1736245/


All Articles