簡體   English   中英

Rails PayPal概念證明

[英]Rails PayPal proof of concept

我正在嘗試用rails創建一個超簡單的paypal自定義集成。 我正在關注這個主題的Ryan Bates Railscast#141 ,我進一步簡化了它。 如果您有超級簡單的paypal集成經驗,任何建議將不勝感激!

我試圖通過我的帳戶模型傳遞所有內容 概念驗證。

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 

當然我創建了一個鏈接:

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

Paypal檢測到錯誤:“ 您的購物車是空的 ”,這很奇怪,因為我可以看到我的模型在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

我發現跟蹤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 helper中的:method => :post不起作用。

您可以使用button_to幫助程序創建迷你表單並替換railcast中的link_to。

要回答我們需要仔細查看您的代碼。

但也許這可以幫助你: 一個帶有Rails 2.3的可測試的PayPal IPN

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM