PayPal Ipn 与 MVC 3 vb.net 状态 200 但根本不记录交易...

发布于 2024-12-11 13:09:00 字数 6041 浏览 4 评论 0原文

将 VB MVC 3 与 Razor 一起使用...我可以在任何控制器中创建 PayPal iPN 吗?假设我把它放在它自己的控制器中,比如 IPN。 URL 不是 http://www.testsite.com/IPN 吗?如果这是正确的。我是否需要创建一个名为 Ipn 的空白视图页面或 Ipn 操作名称是什么?在这个视图中它需要包含任何剃刀语法吗?我在我能找到的关于 IPN 的每一篇文章中都排在第四位,但没有任何 MVC 3 vb.net 的内容。这已被编辑...我得到了 IPN 处理程序 reutrning 状态 200。当我运行它时测试人员我取得了成功...但是实际的测试交易并未输入数据库中...任何人都知道为什么这可能是??? Ipn控制器的功能是这样的:

    End Function
<AcceptVerbs(HttpVerbs.Post)>
Function IPN_Handler(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim strFormValues As String = Request.Form.ToString()
    Dim strNewValue

    Dim Txn_id As String = Request.Form("txn_id")
    Dim mc_gross_1 As String = Request.Form("mc_gross_1")
    Dim mc_gross_2 As String = Request.Form("mc_gross_2")
    Dim mc_gross_3 As String = Request.Form("mc_gross_3")
    Dim mc_gross_4 As String = Request.Form("mc_gross_4")
    Dim num_cart_items As String = Request.Form("num_cart_items")
    Dim Receiver_email As String = Request.Form("receiver_email")
    Dim Item_name1 As String = Request.Form("item_name1")
    Dim Item_name2 As String = Request.Form("item_name2")
    Dim Item_name3 As String = Request.Form("item_name3")
    Dim Item_name4 As String = Request.Form("item_name4")
    Dim Quantity As String = Request.Form("quantity")
    Dim Invoice As String = Request.Form("invoice")
    Dim Custom As Integer = Request.Form("custom")
    Dim transaction_subject As Integer = Request.Form("transaction_subject")
    Dim Payment_status As String = Request.Form("payment_status")
    Dim Pending_reason As String = Request.Form("pending_reason")
    If Payment_status <> "Pending" Then
        Pending_reason = " "
    End If
    Dim Payment_date As String = Request.Form("payment_date")
    Dim Payment_fee As String = Request.Form("payment_fee")
    Dim Payment_gross As String = Request.Form("payment_gross")
    Dim Txn_type As String = Request.Form("txn_type")
    Dim First_name As String = Request.Form("first_name")
    Dim Last_name As String = Request.Form("last_name")
    Dim Address_street As String = Request.Form("address_street")
    Dim Address_city As String = Request.Form("address_city")
    Dim Address_state As String = Request.Form("address_state")
    Dim Address_zip As String = Request.Form("address_zip")
    Dim Address_country As String = Request.Form("address_country")
    Dim Address_status As String = Request.Form("address_status")
    Dim Address_country_code As String = Request.Form("address_country_code")
    Dim Payer_email As String = Request.Form("payer_email")
    Dim Payer_status As String = Request.Form("payer_status")
    Dim Payer_id As Integer = Request.Form("payer_id")
    Dim Payment_type As String = Request.Form("payment_type")
    Dim Notify_version As String = Request.Form("notify_version")
    Dim Verify_sign As String = Request.Form("verify_sign")
    Dim Ipn_Track_Id As String = Request.Form("ipn_track_id")

    Dim req As HttpWebRequest = CType(WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr"),  _
                    HttpWebRequest)

    req.Method = "POST"
    req.ContentType = "application/x-www-form-urlencoded"
    strNewValue = strFormValues + "&cmd=_notify-validate"
    req.ContentLength = strNewValue.Length
    Dim stOut As StreamWriter = New StreamWriter(req.GetRequestStream(), _
                                                 Encoding.ASCII)

    stOut.Write(strNewValue)
    stOut.Close()

    Dim strResponse As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)
    Dim ipnResponseStream As Stream = strResponse.GetResponseStream
    Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
    Dim readStream As New StreamReader(ipnResponseStream, encode)
    Dim read(256) As [Char]
    Dim count As Integer = readStream.Read(read, 0, 256)
    While count > 0
        Dim IpnResponse As New [String](read, 0, count)
        count = readStream.Read(read, 0, 256)

        If IpnResponse = "VERIFIED" Then
            Dim db As New mysql_31309_schoolEntities
            Dim _payment_tracker As New payment_tracker
            _payment_tracker.txn_id = Txn_id
            _payment_tracker.Class_1_ID = Item_name1
            _payment_tracker.Class_2_ID = Item_name2
            _payment_tracker.Class_3_ID = Item_name3
            _payment_tracker.Class_4_ID = Item_name4
            _payment_tracker.num_cart_items = num_cart_items
            _payment_tracker.reciever_email = Receiver_email
            _payment_tracker.payer_id = Custom
            _payment_tracker.payment_status = Payment_status
            _payment_tracker.payment_date = Payment_date
            _payment_tracker.first_name = First_name
            _payment_tracker.last_name = Last_name
            _payment_tracker.address1 = Address_street
            _payment_tracker.city = Address_city
            _payment_tracker.state = Address_state
            _payment_tracker.zipcode = Address_zip
            _payment_tracker.payment_fee = Payment_fee
            _payment_tracker.payment_gross = Payment_gross
            If Payment_status <> "Pending" Then
                _payment_tracker.pending_reason = " "
            Else
                _payment_tracker.payment_status = Payment_status
            End If
            _payment_tracker.ipn_track_id = Ipn_Track_Id
            db.payment_tracker.AddObject(_payment_tracker)
            db.SaveChanges()

        Else
            If Payment_status = "Completed" Then

                Dim reg As reg_info = db.reg_info.Single(Function(f) f.id = Payer_id)
                reg.paid = "Paid"
                reg.date_paid = Payment_date
                reg.payment_method = Payment_type
                db.SaveChanges()


            Else
                If IpnResponse = "INVALID" Then
                    Return Nothing

                End If
            End If

        End If

    End While

    readStream.Close()
    strResponse.Close()


    Return Nothing

End Function

Using VB MVC 3 with Razor ... can I create the PayPal ipn in any controller? say I put it in its own controller say IPN. Would the URL not then be http://www.testsite.com/IPN ? and if that is correct. Do I need to create a blank view page named Ipn or what ever the Ipn action name is?? In this view would It need to contain any razor syntax? I have been back and fourth over every single post I could find about IPN but there is nothing for MVC 3 vb.net.. This has been edited... I have got the IPN handler reutrning status 200. And when I run it through the tester I get success... However actual test transactions are not being entered in the database... Anyone know why this might be???? The Ipn Controller function is this:

    End Function
<AcceptVerbs(HttpVerbs.Post)>
Function IPN_Handler(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim strFormValues As String = Request.Form.ToString()
    Dim strNewValue

    Dim Txn_id As String = Request.Form("txn_id")
    Dim mc_gross_1 As String = Request.Form("mc_gross_1")
    Dim mc_gross_2 As String = Request.Form("mc_gross_2")
    Dim mc_gross_3 As String = Request.Form("mc_gross_3")
    Dim mc_gross_4 As String = Request.Form("mc_gross_4")
    Dim num_cart_items As String = Request.Form("num_cart_items")
    Dim Receiver_email As String = Request.Form("receiver_email")
    Dim Item_name1 As String = Request.Form("item_name1")
    Dim Item_name2 As String = Request.Form("item_name2")
    Dim Item_name3 As String = Request.Form("item_name3")
    Dim Item_name4 As String = Request.Form("item_name4")
    Dim Quantity As String = Request.Form("quantity")
    Dim Invoice As String = Request.Form("invoice")
    Dim Custom As Integer = Request.Form("custom")
    Dim transaction_subject As Integer = Request.Form("transaction_subject")
    Dim Payment_status As String = Request.Form("payment_status")
    Dim Pending_reason As String = Request.Form("pending_reason")
    If Payment_status <> "Pending" Then
        Pending_reason = " "
    End If
    Dim Payment_date As String = Request.Form("payment_date")
    Dim Payment_fee As String = Request.Form("payment_fee")
    Dim Payment_gross As String = Request.Form("payment_gross")
    Dim Txn_type As String = Request.Form("txn_type")
    Dim First_name As String = Request.Form("first_name")
    Dim Last_name As String = Request.Form("last_name")
    Dim Address_street As String = Request.Form("address_street")
    Dim Address_city As String = Request.Form("address_city")
    Dim Address_state As String = Request.Form("address_state")
    Dim Address_zip As String = Request.Form("address_zip")
    Dim Address_country As String = Request.Form("address_country")
    Dim Address_status As String = Request.Form("address_status")
    Dim Address_country_code As String = Request.Form("address_country_code")
    Dim Payer_email As String = Request.Form("payer_email")
    Dim Payer_status As String = Request.Form("payer_status")
    Dim Payer_id As Integer = Request.Form("payer_id")
    Dim Payment_type As String = Request.Form("payment_type")
    Dim Notify_version As String = Request.Form("notify_version")
    Dim Verify_sign As String = Request.Form("verify_sign")
    Dim Ipn_Track_Id As String = Request.Form("ipn_track_id")

    Dim req As HttpWebRequest = CType(WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr"),  _
                    HttpWebRequest)

    req.Method = "POST"
    req.ContentType = "application/x-www-form-urlencoded"
    strNewValue = strFormValues + "&cmd=_notify-validate"
    req.ContentLength = strNewValue.Length
    Dim stOut As StreamWriter = New StreamWriter(req.GetRequestStream(), _
                                                 Encoding.ASCII)

    stOut.Write(strNewValue)
    stOut.Close()

    Dim strResponse As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)
    Dim ipnResponseStream As Stream = strResponse.GetResponseStream
    Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
    Dim readStream As New StreamReader(ipnResponseStream, encode)
    Dim read(256) As [Char]
    Dim count As Integer = readStream.Read(read, 0, 256)
    While count > 0
        Dim IpnResponse As New [String](read, 0, count)
        count = readStream.Read(read, 0, 256)

        If IpnResponse = "VERIFIED" Then
            Dim db As New mysql_31309_schoolEntities
            Dim _payment_tracker As New payment_tracker
            _payment_tracker.txn_id = Txn_id
            _payment_tracker.Class_1_ID = Item_name1
            _payment_tracker.Class_2_ID = Item_name2
            _payment_tracker.Class_3_ID = Item_name3
            _payment_tracker.Class_4_ID = Item_name4
            _payment_tracker.num_cart_items = num_cart_items
            _payment_tracker.reciever_email = Receiver_email
            _payment_tracker.payer_id = Custom
            _payment_tracker.payment_status = Payment_status
            _payment_tracker.payment_date = Payment_date
            _payment_tracker.first_name = First_name
            _payment_tracker.last_name = Last_name
            _payment_tracker.address1 = Address_street
            _payment_tracker.city = Address_city
            _payment_tracker.state = Address_state
            _payment_tracker.zipcode = Address_zip
            _payment_tracker.payment_fee = Payment_fee
            _payment_tracker.payment_gross = Payment_gross
            If Payment_status <> "Pending" Then
                _payment_tracker.pending_reason = " "
            Else
                _payment_tracker.payment_status = Payment_status
            End If
            _payment_tracker.ipn_track_id = Ipn_Track_Id
            db.payment_tracker.AddObject(_payment_tracker)
            db.SaveChanges()

        Else
            If Payment_status = "Completed" Then

                Dim reg As reg_info = db.reg_info.Single(Function(f) f.id = Payer_id)
                reg.paid = "Paid"
                reg.date_paid = Payment_date
                reg.payment_method = Payment_type
                db.SaveChanges()


            Else
                If IpnResponse = "INVALID" Then
                    Return Nothing

                End If
            End If

        End If

    End While

    readStream.Close()
    strResponse.Close()


    Return Nothing

End Function

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮年慕年 2024-12-18 13:09:00

Paypal IPN 和 MVC 3 VB.NET 与远程托管相结合不仅仅是一个挑战...我终于让它工作了...根本不是通过创建控制器功能...我最终制作了一个 aspx 应用程序。对于 ipn.. 将其扔到根文件夹中。将 paypal 指向 aspx 文件。然后在我的实际家庭控制器中创建一个简短的例程,检查对 ipn 写入的表所做的更改。如果它发现任何新的且已完成的,它就会从那里处理付款。这是我能够不出现 500 错误的唯一方法...为了成功调试 ipn,我实际上从 ipn 的简单 paypal 源代码开始...在 IPN 测试器上得到它说成功,然后从那里我为它要执行的每个任务添加小块代码...然后我将再次通过 paypal ipn 测试器运行它...如果成功,那么我知道我可以继续编写更多代码。 ..如果在任何时候我都失败了500新的,这是我刚刚添加的内容...我知道没有太多帮助,但我认为我从工作到失败的两周时间以及不知道为什么可能会帮助其他人...

我无法强调最后一部分有多么重要那就是。一开始就使用一个非常基本的IPN处理程序,因为调试有点复杂,因为它无法通过VS正常调试。从小处开始,在每次更改后使用 paypal ipn 测试仪逐步测试它,以确保它没有损坏。

为了帮助其他发现文档过于贫乏的人。以下是 paypal IPN 处理程序的工作示例。

asp.net 视图只是一个空白的 asp.net 服务器页面,为此示例命名为 IPN_Handler.ascx 。并且如下:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Ipn_Handler.aspx.vb" Inherits="yourNamespace.Ipn_Handler" %>

<!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 runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <div>

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

隐藏文件的代码示例如下。请注意,这来自一个正在运行的 IPN 处理程序,因此有几个您可能不需要的引用。

  Imports System.Net
  Imports System.IO
  Imports System.Text
  Imports System.Collections.Specialized
  Imports System.Web.Mail
  Imports MySql.Data.MySqlClient
  Imports System.Security.Principal
  Imports System.Data
  Imports System.Linq
  Imports System.Web.Mvc
  Imports System.Reflection
  Imports System.Data.OleDb
  Imports System.ComponentModel

Public Class Ipn_Handler
 Inherits System.Web.UI.Page

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim strFormValues As String = Request.Form.ToString()
    Dim strNewValue

    Dim Txn_id As String = Request.Form("txn_id")
    Dim mc_gross_1 As String = Request.Form("mc_gross_1")
    Dim mc_gross_2 As String = Request.Form("mc_gross_2")
    Dim mc_gross_3 As String = Request.Form("mc_gross_3")
    Dim mc_gross_4 As String = Request.Form("mc_gross_4")
    Dim num_cart_items As String = Request.Form("num_cart_items")
    Dim Receiver_email As String = Request.Form("receiver_email")
    Dim Item_name1 As String = Request.Form("item_name1")
    Dim Item_name2 As String = Request.Form("item_name2")
    Dim Item_name3 As String = Request.Form("item_name3")
    Dim Item_name4 As String = Request.Form("item_name4")
    Dim Quantity As String = Request.Form("quantity")
    Dim Invoice As String = Request.Form("invoice")
    Dim Custom As Integer = Request.Form("custom")
    Dim transaction_subject As Integer = Request.Form("transaction_subject")
    Dim Payment_status As String = Request.Form("payment_status")
    Dim Pending_reason As String = Request.Form("pending_reason")
    If Payment_status <> "Pending" Then
        Pending_reason = " "
    End If
    Dim Payment_date As String = Request.Form("payment_date")
    Dim Payment_fee As String = Request.Form("payment_fee")
    Dim Payment_gross As String = Request.Form("payment_gross")
    Dim Txn_type As String = Request.Form("txn_type")
    Dim First_name As String = Request.Form("first_name")
    Dim Last_name As String = Request.Form("last_name")
    Dim Address_street As String = Request.Form("address_street")
    Dim Address_city As String = Request.Form("address_city")
    Dim Address_state As String = Request.Form("address_state")
    Dim Address_zip As String = Request.Form("address_zip")
    Dim Address_country As String = Request.Form("address_country")
    Dim Address_status As String = Request.Form("address_status")
    Dim Address_country_code As String = Request.Form("address_country_code")
    Dim Payer_email As String = Request.Form("payer_email")
    Dim Payer_status As String = Request.Form("payer_status")
    Dim Payer_id As Integer = Request.Form("payer_id")
    Dim Payment_type As String = Request.Form("payment_type")
    Dim Notify_version As String = Request.Form("notify_version")
    Dim Verify_sign As String = Request.Form("verify_sign")
    Dim Ipn_Track_Id As String = Request.Form("ipn_track_id")

    Dim req As HttpWebRequest = CType(WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr"),  _
                    HttpWebRequest)

    req.Method = "POST"
    req.ContentType = "application/x-www-form-urlencoded"
    strNewValue = strFormValues + "&cmd=_notify-validate"
    req.ContentLength = strNewValue.Length
    Dim stOut As StreamWriter = New StreamWriter(req.GetRequestStream(), _
                                                 Encoding.ASCII)

    stOut.Write(strNewValue)
    stOut.Close()

    Dim strResponse As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)
    Dim ipnResponseStream As Stream = strResponse.GetResponseStream
    Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
    Dim readStream As New StreamReader(ipnResponseStream, encode)
    Dim read(256) As [Char]
    Dim count As Integer = readStream.Read(read, 0, 256)
    While count > 0
        Dim IpnResponse As New [String](read, 0, count)
        count = readStream.Read(read, 0, 256)

        If IpnResponse = "VERIFIED" Then
            '//Logic to handle what to do on Verified response.

            If Payment_status = "Completed" Then

                '// The Payment_status variable can be used to trap a completed payment response and do work.

                End If


            ElseIf IpnResponse = "INVALID" Then
            '// This is where possible hacking attempts will be caught by paypal and returned as invalid.
            Else


            End If

    End While

    readStream.Close()
    strResponse.Close()




End Sub

End Class

测试是否已将此示例放置在适合您的设置的正确位置的一个简单方法是浏览到 IPN 本身。也许可以在 IPN_Handler.ascx 页面的视图标记中放置一条简单的消息。无论您用来浏览的 URL 是什么,您都需要在 Paypal 的 IPN URL 地址设置中输入该 URL。不要向我发送有关本地主机问题的消息。这需要在远程可访问的服务器上进行测试。

Paypal IPN and MVC 3 VB.NET when combined with remote hosting can be more than a challenge... I finally got it working... Not by creating a controller function at all... I ended up making a aspx app. for the ipn.. Throwing it in the root folder. Pointing paypal to the aspx file. And then making a short routine in my actual home controller that checks for changes made to the table that the ipn writes to. If it finds any that are new and completed it processes the payment from there. That is the only way I have been able to not get a 500 error... To debug the ipn successfully I actually started with the plain paypal source code for a ipn... Got it saying successful on the IPN tester then from there I added small blocks of code to it for each of the tasks it is to do... Then I would run it through the paypal ipn tester again... If It was successful then I knew I could carry on with a little more code... If it failed with 500 at anytime I new that it was something in what I just added... Not much help I know but I figure my 2 weeks of going from working to failing and not knowing why might help someone else out...

I cannot stress how important the last part of that is. Just use a very basic IPN handler at first because debugging is kind of complicated as it is not able to be debugged normally through VS. Start out small and work your way up testing it with the paypal ipn tester after each change to make sure that it is not broken.

In the interest of helping others out who find the documentation to be overly poor. The below is a working example of a paypal IPN handler.

The asp.net view is just a blank asp.net server page named for this example IPN_Handler.ascx . And is as follows:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Ipn_Handler.aspx.vb" Inherits="yourNamespace.Ipn_Handler" %>

<!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 runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <div>

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

And example for the code behind file is as follows. Please note that this came from a working IPN handler so there are SEVERAL references that you may not need..

  Imports System.Net
  Imports System.IO
  Imports System.Text
  Imports System.Collections.Specialized
  Imports System.Web.Mail
  Imports MySql.Data.MySqlClient
  Imports System.Security.Principal
  Imports System.Data
  Imports System.Linq
  Imports System.Web.Mvc
  Imports System.Reflection
  Imports System.Data.OleDb
  Imports System.ComponentModel

Public Class Ipn_Handler
 Inherits System.Web.UI.Page

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim strFormValues As String = Request.Form.ToString()
    Dim strNewValue

    Dim Txn_id As String = Request.Form("txn_id")
    Dim mc_gross_1 As String = Request.Form("mc_gross_1")
    Dim mc_gross_2 As String = Request.Form("mc_gross_2")
    Dim mc_gross_3 As String = Request.Form("mc_gross_3")
    Dim mc_gross_4 As String = Request.Form("mc_gross_4")
    Dim num_cart_items As String = Request.Form("num_cart_items")
    Dim Receiver_email As String = Request.Form("receiver_email")
    Dim Item_name1 As String = Request.Form("item_name1")
    Dim Item_name2 As String = Request.Form("item_name2")
    Dim Item_name3 As String = Request.Form("item_name3")
    Dim Item_name4 As String = Request.Form("item_name4")
    Dim Quantity As String = Request.Form("quantity")
    Dim Invoice As String = Request.Form("invoice")
    Dim Custom As Integer = Request.Form("custom")
    Dim transaction_subject As Integer = Request.Form("transaction_subject")
    Dim Payment_status As String = Request.Form("payment_status")
    Dim Pending_reason As String = Request.Form("pending_reason")
    If Payment_status <> "Pending" Then
        Pending_reason = " "
    End If
    Dim Payment_date As String = Request.Form("payment_date")
    Dim Payment_fee As String = Request.Form("payment_fee")
    Dim Payment_gross As String = Request.Form("payment_gross")
    Dim Txn_type As String = Request.Form("txn_type")
    Dim First_name As String = Request.Form("first_name")
    Dim Last_name As String = Request.Form("last_name")
    Dim Address_street As String = Request.Form("address_street")
    Dim Address_city As String = Request.Form("address_city")
    Dim Address_state As String = Request.Form("address_state")
    Dim Address_zip As String = Request.Form("address_zip")
    Dim Address_country As String = Request.Form("address_country")
    Dim Address_status As String = Request.Form("address_status")
    Dim Address_country_code As String = Request.Form("address_country_code")
    Dim Payer_email As String = Request.Form("payer_email")
    Dim Payer_status As String = Request.Form("payer_status")
    Dim Payer_id As Integer = Request.Form("payer_id")
    Dim Payment_type As String = Request.Form("payment_type")
    Dim Notify_version As String = Request.Form("notify_version")
    Dim Verify_sign As String = Request.Form("verify_sign")
    Dim Ipn_Track_Id As String = Request.Form("ipn_track_id")

    Dim req As HttpWebRequest = CType(WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr"),  _
                    HttpWebRequest)

    req.Method = "POST"
    req.ContentType = "application/x-www-form-urlencoded"
    strNewValue = strFormValues + "&cmd=_notify-validate"
    req.ContentLength = strNewValue.Length
    Dim stOut As StreamWriter = New StreamWriter(req.GetRequestStream(), _
                                                 Encoding.ASCII)

    stOut.Write(strNewValue)
    stOut.Close()

    Dim strResponse As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)
    Dim ipnResponseStream As Stream = strResponse.GetResponseStream
    Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
    Dim readStream As New StreamReader(ipnResponseStream, encode)
    Dim read(256) As [Char]
    Dim count As Integer = readStream.Read(read, 0, 256)
    While count > 0
        Dim IpnResponse As New [String](read, 0, count)
        count = readStream.Read(read, 0, 256)

        If IpnResponse = "VERIFIED" Then
            '//Logic to handle what to do on Verified response.

            If Payment_status = "Completed" Then

                '// The Payment_status variable can be used to trap a completed payment response and do work.

                End If


            ElseIf IpnResponse = "INVALID" Then
            '// This is where possible hacking attempts will be caught by paypal and returned as invalid.
            Else


            End If

    End While

    readStream.Close()
    strResponse.Close()




End Sub

End Class

A simple way to test if you have placed this example in the proper location for your setup is to browse to the IPN itself. Maybe placing a simple message in the view markup of the IPN_Handler.ascx page. Whatever url you use to browse to it is the one that you will need to enter at paypal in the setup for IPN URL address. Don't message me about Localhost issues. This needs to be tested on a remote accessible server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文