2012-12-04 40 views
2

我有,有一個訂閱PayPal按鈕一個asp.net MVC4動作:如何在付款獲得批准後從貝寶獲取信息?

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="payPalForm"> 
       <input type="hidden" name="item_number" value="@item.Id"> 
       <input type="hidden" name="item_name" value="@item.Name"> 
       <input type="hidden" name="src" value="1">@*Recurring until user cancels*@ 
       <input type="hidden" name="cmd" value="_xclick"> 
       <input type="hidden" name="p3" value="1"> @*Billing cycle amount*@ 
       <input type="hidden" name="t3" value="M"> @*billing cycle period - Month*@ 
       <input type="hidden" name="no_note" value="1"> 
       <input type="hidden" name="business" value="[email protected]">@*Hiva's paypal account*@ 
       <input type="hidden" name="currency_code" value="USD"> 
       <input type="hidden" name="return" value="@returnUrl"> 
       <input type="hidden" name="amount" id="amount" value="@item.Price"> 
       <input type="submit" name="Submit" value="Subscribe"> 
      </form> 

在它擊中,我希望能夠看到形式的詳情以及是否付款通過一個動作的返回URL,和所有的好東西。這是我的:

 public ActionResult PaymentConfirm(FormCollection form) 
    { 
     //if successful, blah blah 
     var user = User.Identity.Name; 
     //Merchant merch = ctx.Merchants.Single(x => x.User.UserName == user); 
     //merch.Plan = plan; 

     return RedirectToAction("Index", "Merchant"); 
    } 

我怎樣才能得到這些數據!

+1

查看PayPal IPN? https://www.paypal.com/ipn – IrishChieftain

+0

我手邊沒有這方面的信息,但IPN Docs覆蓋了它的相當好。基本上,您會在返回的查詢字符串中獲得交易號碼,然後您可以將其提交回PayPal以確認用戶尚未完成交易。 – Greg

回答

2

如上所述,解決方案是IPN。基本上,IPN是您在商家帳戶下使用銷售工具設置的網址。

  1. 你想創建一個指向你的行爲的URL。 (要在本地執行此操作,您需要執行端口轉發以使您的網站公開可用)

  2. IPN包含您需要的所有信息。只要付款已完成,它就會收到付款通知,並且付款狀態也會成功或失敗。

這裏是你可以參照有代碼樣本的鏈接。

https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623

更新:有關詳細信息,IPN如何工作在幕後,參考以下鏈接

https://www.paypal.com/cgi-bin/webscr?cmd=p/acc/ipn-info-outside

+0

好吧,我看了一下,並實現了代碼,但我仍然不理解一些事情。這是我應該把我的網頁上,我已經重定向到貝寶後,直接給我的東西?目前我有一個付款頁面,其中有提交付款的表單,然後我將它放到我放置代碼示例的頁面中,它路由正常,但我沒有看到任何可用的數據。 – ledgeJumper

+0

當你說「它路由好」,你是說它調用你的幕後IPN網址? – Jack

+0

是的,上面的表格,當你點擊提交時,它會帶你到PayPal沙箱網站登錄和批准付款。在貝寶網站上的流程結束時,我點擊說回到我的網站的鏈接。然後它會轉到我的付款確認頁面(我有示例代碼)。 – ledgeJumper

0

如果使用PayPal REST API,那麼你可以這樣做:

 // You create the ProcessPayment() method 
     string jsonResponse = ProcessPayment(model); 

     var jss = new JavaScriptSerializer(); 
     Payment payment = jss.Deserialize<Payment>(jsonResponse); 

     APIContext apiContext = Configuration.GetAPIContext(); 
     Payment originalPayment = Payment.Get(apiContext, payment.id);