2014-03-05 84 views
0

我的問題是Notify_url不會在數據庫中插入任何值。任何人都可以告訴我我錯在哪裏。我有以下可用Paypal的notify_url沒有返回一個值,也沒有插入數據庫

代碼的網頁我有三個頁面:1)的Default.aspx 2)sendpayment.aspx 3)PAypal.aspx

Default.aspx中, 我有兩個文本框。我得到了會議這兩個值和提交我重定向頁面Sendpayment.aspx

在sendpayment.aspx,我有以下代碼

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Sendpayment.aspx.vb" Inherits="Sendpayment" Debug="true" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
<title>Untitled Page</title> 
</head> 
<body> 

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="form1" 
    name="form1"> 
    <input type="hidden" name="cmd" value="_xclick"/> 
    <input type="hidden" name="business" value="[email protected]"/><!--Paypal or sandbox Merchant account --> 

    <input type="hidden" name="custom" value="<%=Session("regemail")%>"/><!--Custom Field for payer email --> 
    <input type="hidden" name="item_number" value="1"/> 
    <input type="hidden" name="amount" value="<%=Session("totalShoppingAmt")%>"/> 
    <input type="hidden" name="notify_url" value="http://www.abc.com/paypal.aspx"/><!--this should be your domain web page where you going to receive all your transaction variables --> 
    <input type="hidden" name="return" value="http://www.abc.com/thankyou.html"/><!--this page will be your redirection page --> 
    <input type="hidden" name="cancel_return" value="http://www.abc.com"/> 
    <input type="hidden" name="currency_code" value="USD"/> 

</form> 

<script type="text/jscript"> 
    document.form1.submit(); 
</script> 

我必須在指定通知http://www.abc.com/paypal.aspx網址

在Paypal.aspx,

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Paypal.aspx.vb" Inherits="Paypal" Debug="true" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head id="Head1" runat="server"> 
<title>Untitled Page</title> 
</head> 
<body> 
<form id="form1" runat="server"> 
<div> 

</div> 
</form> 
</body> 
</html 

和VB頁是這樣的:

Imports System.Data 
Imports System.Configuration 
Imports System.Collections 
Imports System.Web 
Imports System.Web.Security 
Imports System.Web.UI 
Imports System.Web.UI.WebControls 
Imports System.Web.UI.WebControls.WebParts 
Imports System.Web.UI.HtmlControls 
Imports System.Data.SqlClient 
Imports System.IO 
Imports System.Text 
Imports System.Threading 
Imports System.Net 


Partial Public Class paypal 
Inherits System.Web.UI.Page 
Protected Sub Page_Load(sender As Object, e As EventArgs) 
    'Post back to either sandbox or live 
    Dim strSandbox As String = "https://www.sandbox.paypal.com/cgi-bin/webscr" 
    ' string strLive = "https://www.paypal.com/cgi-bin/webscr"; 
    Dim req As HttpWebRequest = DirectCast(WebRequest.Create(strSandbox), HttpWebRequest) 

    'Set values for the request back 
    req.Method = "POST" 
    req.ContentType = "application/x-www-form-urlencoded" 
    Dim param As Byte() = Request.BinaryRead(HttpContext.Current.Request.ContentLength) 
    Dim strRequest As String = Encoding.ASCII.GetString(param) 
    strRequest += "&cmd=_notify-validate" 
    req.ContentLength = strRequest.Length 

    'for proxy 
    'WebProxy proxy = new WebProxy(new Uri("http://url:port#")); 
    'req.Proxy = proxy; 

    'Send the request to PayPal and get the response 

    Dim txnid As String = Server.HtmlEncode(Request.Form("txn_id")) 
    Dim receiv_email As String = Server.HtmlEncode(Request.Form("receiver_email")) 
    Dim business As String = Server.HtmlEncode(Request.Form("business")) 
    Dim payer_email As String = Server.HtmlEncode(Request.Form("payer_email")) 
    Dim tnx_type As String = Server.HtmlEncode(Request.Form("txn_Type")) 
    Dim payment_type As String = Server.HtmlEncode(Request.Form("payment_type")) 
    Dim payment_stat As String = Server.HtmlEncode(Request.Form("payment_status")) 
    Dim regemail As String = Server.HtmlEncode(Request.Form("custom")) 
    ' this is where i get my member's email adress 
    Dim constr As String = "data source=activehost.com;initial catalog=demo;password=R12ComSQ;persist security info=True;user id=demo_sa" 
    Dim insertsql As String = "INSERT INTO NOTIFICATION_PAYPAL_TRANSACTION (txn_id,receiver_email,business,payer_email,tnx_type,payment_status,LocalDate,payment_type,regemail) values('" & txnid & "','" & receiv_email & "','" & business & "','" & payer_email & "','" & tnx_type & "','" & payment_stat & "','" & DateTime.Now.ToString() & "','" & payment_type & "','" & regemail & "')" 
    Using myConnection As New SqlConnection(constr) 
     myConnection.Open() 
     Dim mycommand As New SqlCommand(insertsql, myConnection) 

     mycommand.ExecuteNonQuery() 
     myConnection.Close() 
    End Using 

    ' for testing purposes i did not create any ipn status actions as i wanted to record every paypal status. 
    'If strResponse = "VERIFIED" Then 
    ' 'UPDATE YOUR DATABASE 



    ' 'check the payment_status is Completed 
    ' 'check that txn_id has not been previously processed 
    ' 'check that receiver_email is your Primary PayPal email 
    ' 'check that payment_amount/payment_currency are correct 
    ' 'process payment 


    ' 'UPDATE YOUR DATABASE 


    'ElseIf strResponse = "INVALID" Then 
    ' 'UPDATE YOUR DATABASE 
    'Else 
    'End If 
End Sub 
End Class 

回答

1

檢查IPN歷史在您的支付寶,看看什麼是越來越發送與否。您可能會發現它正在顯示它正在發送數據,但卻收到了不好的迴應。

如果顯示它正在發送數據,但獲取200響應以外的任何內容,那麼需要修復的腳本有問題。你可以檢查你的Web服務器日誌尋求幫助,或者我想要做的是構建一個HTML表單,其中的動作設置爲我的IPN腳本以及一些與我期望從IPN獲得的隱藏字段相匹配的隱藏字段。然後我在瀏覽器中提交,並實際在屏幕上看到可幫助解決問題的結果。

一旦它的工作方式,你知道你很好。請記住,當您這樣做時,數據不會來自PayPal,因此無法成功驗證。您需要確保您的代碼邏輯可以處理該問題。

如果您的IPN歷史記錄沒有顯示任何內容正在發送,那麼我會質疑您是否正在查看正確的沙盒帳戶。很容易讓他們感到困惑,並且看錯了一個。

+0

正如您所說的YE IPN歷史顯示爲每筆交易發送。但我沒有得到任何東西。 我正在使用沙箱帳戶從https://developer.paypal.com/webapps/developer/applications/accounts 我使用正確的沙箱帳戶?如果不是,我應該使用哪個? –