Paypal Sandbox IPN始终响应无效。 [英] Paypal Sandbox IPN always response Invalid.

查看:446
本文介绍了Paypal Sandbox IPN始终响应无效。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我使用过Paypal沙盒IPN,但我总是得到无效回复,请帮我,我已经在下面发布了我的代码。



 使用系统; 
使用 System.Data;
使用 System.Configuration;
使用 System.Collections;
使用 System.Web;
使用 System.Web.Security;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Web.UI.WebControls.WebParts;
使用 System.Web.UI.HtmlControls;
使用 System.Data.SqlClient;
使用 System.IO;
使用 System.Text;
使用 System.Threading;
使用 System.Net;
使用 System.Net.Mail;


public partial class Paypal:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{

// 回发到沙箱或实时
string strSandbox = https://www.sandbox.paypal.com/cgi-bin/webscr;
string strLive = https:// www.paypal.com/cgi-bin/webscr;
HttpWebRequest req =(HttpWebRequest)WebRequest.Create(strSandbox);

// 设置请求的值
req。方法= POST;
req.ContentType = application / x-www-form-urlencoded;
byte [] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
strRequest + = & cmd = _notify-validate;
req.ContentLength = strRequest.Length;

// 代理
// WebProxy proxy = new WebProxy(new Uri(http:// url:port#));
// req.Proxy = proxy;

// 将请求发送到PayPal并获得响应
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(),System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse()。GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();

if (strResponse == 已验证
{
// 检查payment_status是否已完成
// 检查先前是否处理过txn_id
< span class =code-comment> //
检查receiver_email是您的主要PayPal电子邮件
// 检查payment_amount / payment_currency是否正确
// 流程付款

Response.Write(strResponse);
}
else if (strResponse == INVALID
{
// 手动调查日志
Response.Write(strResponse);
}
其他
{
// < span class =code-comment>用于手动调查的日志响应/ ipn数据
Response.Write( 无法获得响应);
}
}
}

解决方案

嘿大家我得到了解决方案.....



您应该使用任何其他选项,例如发送邮件或运行插入查询....



基本概念是你不需要运行你的notify_url......它会运行当paypal响应时自动...(如果你手动运行...它将永远返回无效)



感谢All帮助我.....

Hello There, I have used Paypal sandbox IPN but I always get Invalid response, please help me i have posted my code below.

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


public partial class Paypal : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

  //Post back to either sandbox or live
        string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
        string strLive = "https://www.paypal.com/cgi-bin/webscr";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
 
        //Set values for the request back
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
        string strRequest = 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
        StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
        streamOut.Write(strRequest);
        streamOut.Close();
        StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
        string strResponse = streamIn.ReadToEnd();
        streamIn.Close();
 
        if (strResponse == "VERIFIED")
        {
            //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

               Response.Write(strResponse);
        }
        else if (strResponse == "INVALID")
        {
            //log for manual investigation
                 Response.Write(strResponse);
        }
        else
        {
            //log response/ipn data for manual investigation
             Response.Write("Cant Get Response");
        }
    }
}

解决方案

Hey Guys I got the solution.....

Instead of checking the response by Response.write() you should use any other option like send mail or run insert query ....

the basic concept is you dont need to run your "notify_url" ... it will run automatically when paypal respond ... (if you run it manually ... it will always return invalid)

Thanks to All to help me.....


这篇关于Paypal Sandbox IPN始终响应无效。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆