0
{Following is the vb.net code for IPN listener:
    If Me.TestMode = True Then
            Me.RequestUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr"
        Else
            Me.RequestUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr" '"https://www.paypal.com/cgi-bin/webscr"
        End If



        '====================================Test======================================'
        Dim startTime As String = String.Format("{0:MM-dd-yyyy hh:mm:ss:tt}", Now)
        '=============================================================================='

        Dim req As HttpWebRequest = CType(WebRequest.Create(Me.RequestUrl), HttpWebRequest)
        req.Method = "POST"
        req.ContentType = "application/x-www-form-urlencoded"
        Dim Param() As Byte = HttpContext.Current.Request.BinaryRead(HttpContext.Current.Request.ContentLength)
        Dim strRequest As String = Encoding.ASCII.GetString(Param)
        strRequest = strRequest & "&cmd=_notify-validate"
        req.ContentLength = strRequest.Length
        ' Dim pairs() As String = strRecieved.Split("&")
        Using streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
            streamOut.Write(strRequest.ToString)
            streamOut.Close()
        End Using
        Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
        Dim strResponse As String = streamIn.ReadToEnd()
        streamIn.Close()
        WriteLog(strResponse)

vb.net でペイパル IPN リスナーのコードを作成しました。その URL をペイパル サンドボックス アカウントでテストすると、「IPN が正常に送信されました」というメッセージが表示されます。しかし、サーバー上のログ ファイルを確認すると、paypal サンドボックス URL からの無効な応答が表示されます。VALID 応答がないと、他のコードは機能しません。助けてください!!

4

1 に答える 1

0

Generate paypal transaction like e.g buy now button via vb.net

Public Shared Function GetPayPalPaymentUrl(item_name As String, item_number As String, amount As String, quantity As String, username As String) As String
Dim strURL As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
If PaypalBLL.Paypal_Live_Status() = 1 Then
    strURL = "https://www.paypal.com/cgi-bin/webscr"
End If
Dim BaseUrl As String = Config.GetUrl()
Dim cancel_url As String = BaseUrl + "paypal/cancel.aspx"
Dim return_url As String = BaseUrl + "paypal/confirmation.aspx"
Dim notifyUrl As String = BaseUrl + "paypal/ipn.aspx"
'string image_url = ""
Dim image_url As String = ""
' paypal header url
Dim paypal_logo As String = HttpUtility.UrlEncode(BaseUrl + "images/logo.png")
Dim Url As New StringBuilder()
Dim CustomFieldValue As String = username
'User-defined field which PayPal passes through the system and returns to you in your merchant payment notification email. Subscribers do not see this field.
Url.Append(strURL + "?cmd=_xclick&upload=1&rm=2&no_shipping=1&no_note=1&currency_code=USD&business=" + PaypalBLL.Paypal_Receiver_Email() + "&item_number=" + item_number + "&item_name=" + item_name + "&amount=" + amount + "&quantity=" + quantity + "&undefined_quantity=0&notify_url=" + notifyUrl + "&return=" + return_url + "&cancel_return=" + cancel_url + "&cpp_header_Image=" + image_url + "&cpp_headerback_color=ECDFDF&cpp_headerborder_color=A02626&cpp_payflow_color=ECDFDF&image_url=" + paypal_logo + "&custom=" + CustomFieldValue + "")
Return Url.ToString()
End Function

Generate paypal link, when you click on link, you will be redirect to paypal sandbox or live link. once you complete transaction, you will be redirected to website back and within background paypal will send transaction event via ipn.

Hope you will receive proper ipn response.

于 2012-04-14T06:09:43.313 に答える