2010-03-10 4 views
3

레일과 함께 매우 간단한 페이팔 맞춤형 통합을 만들려고합니다. 나는이 주제에 대해 Ryan Bates Railscast #141을 따르고 있으며, 그것을 더 단순화했습니다. 당신은 슈퍼 간단한 페이팔 통합 경험이 있다면, 어떤 조언을 부탁드립니다!레일스 PayPal 개념 증명

을 내 계정 모델을 통해 전달하려고합니다. 개념 증명.

def paypal_url(return_url) 
    values = { 
    :business => '[email protected]', 
    :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 

물론 내가 링크 생성 :

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

페이팔은 오류를 발견 : "귀하의 쇼핑 카트가 비어이다"내 모델에서 통과 모든 것을 볼 수 있기 때문에 이상하다 URL :

https://www.sandbox.paypal.com/cgi-bin/webscr?amount=7&[email protected]&cmd=_cart&invoice=&item_name=Barcoden+Membership&item_number=1&quantity=1&return=/accounts&upload=1 

답변

2

내가 찾은이 그 빈 카트 오류 메시지의 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> 

작동합니다. 게시 요청을 사용하지 않으면 장바구니가 생성되지 않는 것으로 보입니다.

도우미 link_to에서 :method => :post을 사용하면 작동하지 않습니다.

도우미 button_to을 사용하여 미니 폼을 만들고 railcast에서 link_to를 바꿀 수 있습니다.