Paypal IPN 400 和 403 错误

如何解决Paypal IPN 400 和 403 错误

Stackoverflow 的各位,大家好,我一直在尝试为我的贝宝支付实现 IPN 功能。我在 localhost 上工作,所以 IPN 不起作用。开始使用 ngrok,现在 IPN 部分正在部分工作。

private class IPNContext
    {
        public HttpRequestBase IPNRequest { get; set; }

        public string RequestBody { get; set; }

        public string Verification { get; set; } 
    }

    [Route("paypalipn")]
    [HttpPost]
    public ActionResult Receive()
    {
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        IPNContext ipnContext = new IPNContext()
        {
            IPNRequest = Request
        };

        using (StreamReader reader = new StreamReader(ipnContext.IPNRequest.InputStream,Encoding.ASCII))
        {
            ipnContext.RequestBody = reader.ReadToEnd();
        }

        //Store the IPN received from 

        LogRequest(ipnContext);

        //Fire and forget verification task
        Task.Run(() => VerifyTask(ipnContext));

        //Reply back a 200 code
        return new HttpStatusCodeResult(HttpStatusCode.OK);
    }

    private void VerifyTask(IPNContext ipnContext)
    {
        try
        {
            var verificationRequest = (HttpWebRequest)WebRequest.Create("https://ipnpb.sandbox.paypal.com/cgi-bin/webscr");

            //Set values for the verification request
            verificationRequest.Method = "POST";
            verificationRequest.ContentType = "application/x-www-form-urlencoded";

            //Add cmd=_notify-validate to the payload
            string strRequest = "cmd=_notify-validate&" + ipnContext.RequestBody;
            verificationRequest.ContentLength = strRequest.Length;

            //verificationRequest.UserAgent = "ASP-IPN-VerificationScript";
            //verificationRequest.KeepAlive = false;

            //Attach payload to the verification request
            using (StreamWriter writer = new StreamWriter(verificationRequest.GetRequestStream(),Encoding.ASCII))
            {
                writer.Write(strRequest);
            }

            //Send the request to PayPal and get the response
            using (StreamReader reader = new StreamReader(verificationRequest.GetResponse().GetResponseStream()))
            {
                ipnContext.Verification = reader.ReadToEnd();
            }
        }
        catch (Exception exception)
        {
            LogErr(exception.ToString());

            //Capture exception for manual investigation
        }

        ProcessVerificationResponse(ipnContext);
    }

上面的代码在 VerifyTask 函数中抛出 403-Forbidden 异常。在 Paypal IPN 文档中,它声明并且我引用了 Please ensure you provide a User-Agent header value that describes your IPN listener,such as,PHP-IPN-VerificationScript.

如果我用 verificationRequest.UserAgent = "ASP-IPN-VerificationScript"; 取消注释行,那么我开始收到 400-Bad Request。以前有人遇到过这个问题吗?我将非常感谢任何帮助,感谢您阅读到目前为止。

对于 403-禁止:

POST https://ipnpb.sandbox.paypal.com/cgi-bin/webscr HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: ipnpb.sandbox.paypal.com
Content-Length: 1245

cmd=_notify-validate&mc_gross=10.00&invoice=4967920&protection_eligibility=Eligible&address_status=confirmed&item_number1=sku&payer_id=UG9FLUCH489QQ&tax=0.00&address_street=asfasdgdsgsd&payment_date=00%3A36%3A22+Jun+28%2C+2021+PDT&payment_status=Completed&charset=KOI8_R&address_zip=365555&mc_shipping=0.00&first_name=%E1%CC%C5%CB%D3%C1%CE%C4%D2&mc_fee=10.00&address_country_code=RU&address_name=%E4%CF%D3%D4%CF%C5%D7%D3%CB%C9%CA+%E1%CC%C5%CB%D3%C1%CE%C4%D2&notify_version=3.9&custom=latios%3A1000001&payer_status=verified&business=sb-fyb3f6626939%40business.example.com&address_country=Russia&num_cart_items=1&address_city=sggdsgdsgsdgf&verify_sign=As7YjUf-EtwWTklniO1RIaVMU-GLAbAN64Awhlx16OwPRDGAMxNV1f-B&payer_email=sb-mjmkt6611016%40personal.example.com&txn_id=4RF57039YW521103B&payment_type=instant&last_name=%E4%CF%D3%D4%CF%C5%D7%D3%CB%C9%CA&address_state=fhdhfdhfdh&item_name1=TestPayment&receiver_email=sb-fyb3f6626939%40business.example.com&payment_fee=&shipping_discount=0.00&quantity1=1&insurance_amount=0.00&receiver_id=7W727DS9L36YE&txn_type=cart&discount=0.00&mc_gross_1=10.00&mc_currency=RUB&residence_country=RU&test_ipn=1&shipping_method=Default&transaction_subject=Test+Payment&payment_gross=&ipn_track_id=4d1fa1b02fc27

我收到:

HTTP/1.1 403 Forbidden
Connection: close
Content-Length: 419
Server: Varnish
Retry-After: 0
Content-Type: text/html
Accept-Ranges: bytes
Via: 1.1 varnish,1.1 varnish
Date: Mon,28 Jun 2021 07:36:31 GMT
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Served-By: cache-hhn11549-HHN,cache-ams21035-AMS
X-Cache: MISS,MISS
X-Cache-Hits: 0,0
X-Timer: S1624865791.439206,VS0,VE12
Set-Cookie: x-cdn=fastly:AMS; Domain=paypal.com; Path=/; Secure


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Paypal Error</title>
</head>
<body>
<h1>Access Denied.</h1>
<p>You don't have permission to access "/cgi-bin/webscr" on this server.
<br/>
<p>Reference #16248657919b384e2feca947c115f57
<br/>
<p> Timestamp: 1624865791
</body>
</html>

对于 400 错误请求错误:

POST https://ipnpb.sandbox.paypal.com/cgi-bin/webscr HTTP/1.1
Content-Type: application/x-www-form-urlencoded
User-Agent: ASP-IPN-VerificationScript
Host: ipnpb.sandbox.paypal.com
Content-Length: 1245

cmd=_notify-validate&mc_gross=10.00&invoice=6419605&protection_eligibility=Eligible&address_status=confirmed&item_number1=sku&payer_id=UG9FLUCH489QQ&tax=0.00&address_street=asfasdgdsgsd&payment_date=00%3A31%3A25+Jun+28%2C+2021+PDT&payment_status=Completed&charset=KOI8_R&address_zip=365555&mc_shipping=0.00&first_name=%E1%CC%C5%CB%D3%C1%CE%C4%D2&mc_fee=10.00&address_country_code=RU&address_name=%E4%CF%D3%D4%CF%C5%D7%D3%CB%C9%CA+%E1%CC%C5%CB%D3%C1%CE%C4%D2&notify_version=3.9&custom=latios%3A1000001&payer_status=verified&business=sb-fyb3f6626939%40business.example.com&address_country=Russia&num_cart_items=1&address_city=sggdsgdsgsdgf&verify_sign=AX8Qhp1KduwF1PenaWfGM32xmlvMAhGJ2G8kcZxf1Y2LyqJwTyF9J-zn&payer_email=sb-mjmkt6611016%40personal.example.com&txn_id=4H0466721N516441A&payment_type=instant&last_name=%E4%CF%D3%D4%CF%C5%D7%D3%CB%C9%CA&address_state=fhdhfdhfdh&item_name1=TestPayment&receiver_email=sb-fyb3f6626939%40business.example.com&payment_fee=&shipping_discount=0.00&quantity1=1&insurance_amount=0.00&receiver_id=7W727DS9L36YE&txn_type=cart&discount=0.00&mc_gross_1=10.00&mc_currency=RUB&residence_country=RU&test_ipn=1&shipping_method=Default&transaction_subject=Test+Payment&payment_gross=&ipn_track_id=38f99419954c7

我收到:

HTTP/1.1 400 Bad Request
Connection: close
Content-Length: 226
Content-Type: text/html; charset=iso-8859-1
Cache-Control: max-age=0,no-cache,no-store,must-revalidate
Paypal-Debug-Id: 1dc58fdccb02b
Set-Cookie: Cookie 1
Set-Cookie: Cookie 2
Accept-Ranges: bytes
Via: 1.1 varnish,28 Jun 2021 07:31:39 GMT
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Served-By: cache-hhn11528-HHN,cache-ams21054-AMS
X-Cache: MISS,0
X-Timer: S1624865500.675648,VE150
Set-Cookie: x-cdn=fastly:AMS; Domain=paypal.com; Path=/; Secure

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>

针对将来会发现此主题的人的解决方案:

我的问题是,我的两个测试帐户都有西里尔文名称。为了解决这个问题,我需要登录我的企业帐户(将接受付款的帐户)

  • 帐户设置
  • 网站付款
  • PayPal 付款按钮的语言编码
  • 附加功能
  • 将编码更改为“UTF-8”。

现在它可以正常工作了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res