为什么我在asp.net中使用c#收到贝宝无效的回复?

时间:2022-10-14 14:18:27

I have a sandbox account for paypal for trial purpose An aspx page:sampleprocess.aspx

我有一个关于paypal的沙盒账户,用于测试的一个aspx页面:sampleprocess.aspx。

In Merchant A/c the page is Redirected to http://www.Hostsite.com/member/samplepaypal.aspx after completion of payment.

在商户A/c中,完成付款后,页面被重定向到http://www.Hostsite.com/member/samplepaypal.aspx。

In samplepaypal.aspx.cs Page Load:

在samplepaypal.aspx。cs页面加载:

protected void Page_Load(object sender, EventArgs e)
    {
        //string tx = Request.QueryString["tx"];
        //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")
        {
            lblmsg.Text = "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
        }
        else if (strResponse == "INVALID")
        {
            lblmsg.Text = "Not Verified";
            //log for manual investigation
        }
        else
        {
            lblmsg.Text = "IPN Logged";
            //log response/ipn data for manual investigation
        }
    }

here i get the result "INVALID"! whats wrong plz rectify the error. after post back to http://www.Hostsite.com/member/samplepaypal.aspx page from paypal it shows :

这里我得到的结果是“无效”!什么地方出错了?在从paypal返回到http://www.Hostsite.com/member/samplepaypal.aspx页面后显示:

http://111.111.111.111/member/samplepaypal.aspx?tx=8L903541KW5338647&st=Pending&amt=100.00&cc=USD&**cm=&item_number=&**sig=QRmNHFf5%2fAH3io9Tn2kj%2fuicu3gpAuMew701OvazfkCdN3jSR5tmFoX3OUPbQlZGoj2PY7vI%2fP1dH84g1CEzSG9NhjnLbjuAFFHyENVsBjKb1dVvK1nZe3FJfElZt11qPfggMOPu8%2bUhDwHekJvNAcXkjLQV01vAjN1y%2fZs1rJw%3d

what are these cm & item_number are blank! what to do to get "VALID" response.

这些cm和item_number是什么?如何获得“有效”的响应。

help appreciated..!

帮助感激. . !

1 个解决方案

#1


1  

Using Postbacks for Validation:

使用回发进行验证:

If you cannot use shared secrets for notification validation, you can use postbacks to PayPal, instead. Your postback must include exactly the same variables and values that you receive in the IPN posted to your server by PayPal, and they must be in the same order.

如果您不能使用共享的秘密进行通知验证,您可以使用postback到PayPal。您的回发必须包含与您在IPN中收到的由PayPal发送到您的服务器的变量和值完全相同的值,并且它们必须以相同的顺序。

Constructing Your Postback

构建你的回发

Use these guidelines for constructing your postback to PayPal:.

使用这些指导原则来构建您对PayPal的回发:。

  1. Your postback must be sent to https://www.paypal.com/cgi-bin/webscr. NOTE:You can implement IPN without SSL, including your postbacks for validation, but PayPal recommends against doing so.

    您的回发必须发送到https://www.paypal.com/cgi-bin/webscr。注意:您可以在没有SSL的情况下实现IPN,包括用于验证的回发,但是贝宝建议不要这样做。

  2. Your postback must include the variable cmd with the value _notify-validate: cmd=_notify-validate

    您的回发必须包含变量cmd和值_notify-validate: cmd=_notify-validate

  3. Your postback must include exactly the same variables and values that you receive in the IPN from PayPal, and they must be in the same order.

    您的回发必须包含与您从PayPal在IPN中收到的变量和值完全相同的值,并且它们必须按照相同的顺序。

Processing the PayPal Response to Your Postback PayPal responds to your postbacks with a single word in the body of the response: VERIFIED or INVALID. When you receive a VERIFIED postback response, perform the following checks on data in the IPN:

处理贝宝对您的回邮的响应,贝宝对您的回邮的响应只有一个词:已验证或无效。当您收到一个经过验证的回发响应时,对IPN中的数据执行以下检查:

  1. Check that the payment_status is Completed.

    检查payment_status是否已完成。

  2. If the payment_status is Completed, check the txn_id against the previous PayPal transaction that you processed to ensure it is not a duplicate.

    如果payment_status已完成,则将txn_id与之前处理的PayPal事务进行检查,以确保它不是副本。

  3. Check that the receiver_email is an email address registered in your PayPal account.

    检查receiver_email是否是在您的PayPal帐户中注册的电子邮件地址。

  4. Check that the price, carried in mc_gross, and the currency, carried in mc_currency, are correct for the item, carried in item_name or item_number. After you complete the above checks, notification validation is complete. You can update your database with the information provided, and you can initiate other appropriate automated back-end processing.

    检查在mc_gross中携带的价格和在mc_currency中携带的货币对项目是否正确(在item_name或item_number中携带)。完成上述检查后,通知验证完成。您可以使用提供的信息更新数据库,还可以启动其他适当的自动后端处理。

#1


1  

Using Postbacks for Validation:

使用回发进行验证:

If you cannot use shared secrets for notification validation, you can use postbacks to PayPal, instead. Your postback must include exactly the same variables and values that you receive in the IPN posted to your server by PayPal, and they must be in the same order.

如果您不能使用共享的秘密进行通知验证,您可以使用postback到PayPal。您的回发必须包含与您在IPN中收到的由PayPal发送到您的服务器的变量和值完全相同的值,并且它们必须以相同的顺序。

Constructing Your Postback

构建你的回发

Use these guidelines for constructing your postback to PayPal:.

使用这些指导原则来构建您对PayPal的回发:。

  1. Your postback must be sent to https://www.paypal.com/cgi-bin/webscr. NOTE:You can implement IPN without SSL, including your postbacks for validation, but PayPal recommends against doing so.

    您的回发必须发送到https://www.paypal.com/cgi-bin/webscr。注意:您可以在没有SSL的情况下实现IPN,包括用于验证的回发,但是贝宝建议不要这样做。

  2. Your postback must include the variable cmd with the value _notify-validate: cmd=_notify-validate

    您的回发必须包含变量cmd和值_notify-validate: cmd=_notify-validate

  3. Your postback must include exactly the same variables and values that you receive in the IPN from PayPal, and they must be in the same order.

    您的回发必须包含与您从PayPal在IPN中收到的变量和值完全相同的值,并且它们必须按照相同的顺序。

Processing the PayPal Response to Your Postback PayPal responds to your postbacks with a single word in the body of the response: VERIFIED or INVALID. When you receive a VERIFIED postback response, perform the following checks on data in the IPN:

处理贝宝对您的回邮的响应,贝宝对您的回邮的响应只有一个词:已验证或无效。当您收到一个经过验证的回发响应时,对IPN中的数据执行以下检查:

  1. Check that the payment_status is Completed.

    检查payment_status是否已完成。

  2. If the payment_status is Completed, check the txn_id against the previous PayPal transaction that you processed to ensure it is not a duplicate.

    如果payment_status已完成,则将txn_id与之前处理的PayPal事务进行检查,以确保它不是副本。

  3. Check that the receiver_email is an email address registered in your PayPal account.

    检查receiver_email是否是在您的PayPal帐户中注册的电子邮件地址。

  4. Check that the price, carried in mc_gross, and the currency, carried in mc_currency, are correct for the item, carried in item_name or item_number. After you complete the above checks, notification validation is complete. You can update your database with the information provided, and you can initiate other appropriate automated back-end processing.

    检查在mc_gross中携带的价格和在mc_currency中携带的货币对项目是否正确(在item_name或item_number中携带)。完成上述检查后,通知验证完成。您可以使用提供的信息更新数据库,还可以启动其他适当的自动后端处理。