我的问题是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="naveed.mansuri@abc.com"/><!--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分配了通知URL

在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

最佳答案

检查您的贝宝(PayPal)中的IPN历史记录,以查看是否发送了任何内容。您可能会发现它正在显示正在发送数据,但返回的响应很差。

如果显示正在发送数据,但得到的响应不是200,则说明该脚本有问题,需要修复。您可以检查您的Web服务器日志以寻求帮助,或者我想做的是构建一个HTML表单,将操作设置为我的IPN脚本,并添加一堆与我期望从IPN获得的内容相匹配的隐藏字段。然后,我将其提交到浏览器中,然后在屏幕上实际看到可以帮助解决问题的结果。

一旦以这种方式工作,您就会知道自己很好。请记住,当您这样做时数据不是来自PayPal,因此不会成功验证。您需要确保您的代码逻辑可以处理该问题。

如果您的IPN历史记录没有显示任何内容正在发送,那么我会怀疑您是否在寻找正确的沙箱帐户。很容易让他们感到困惑,并且看错了。

关于asp.net - Paypal notify_url不返回值,数据库中未插入任何内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22193294/

10-17 02:00