2010-03-10 73 views
3

我正嘗試使用rails創建一個超簡單的paypal自定義集成。我正在關注這個主題的Ryan Bates Railscast #141,我已經進一步簡化了它。如果您有超級簡單的PayPal集成經驗,任何意見將不勝感激!Rails 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) %> 

支付寶檢測到錯誤:「您的購物車是空的」,這很奇怪,因爲我可以看到我的模型經過的一切網址:

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。