经典 ASP Paypal IPN 退款

问题描述

尝试对一些旧的经典 ASP Paypal IPN 代码进行故障排除。遗留代码非常适合销售产品。但是,处理来自 Paypal 帐户的退款似乎会导致 Paypal IPN 出现一些问题。 IPN 监听器接收到 refund IPN 消息并正确处理业务逻辑,将交易标记refunded。但是,由于某种原因,Paypal 仍将交易 IPN 历史标记为“正在重试”。下面是来自 GitHub 的示例代码,用于创建我们正在排除故障的 IPN 侦听器。

对于“销售”和“退款”,发回 Paypal 的帖子是否需要不同?

非常感谢任何帮助。干杯

<%@LANGUAGE="VBScript"%>
<%
Dim Item_name,Item_number,Payment_status,Payment_amount
Dim Txn_id,Receiver_email,Payer_email
Dim objHttp,str
' read post from PayPal system and add 'cmd'
str = Request.Form & "&cmd=_notify-validate"
' post back to PayPal system to validate
set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
' set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
' set objHttp = Server.CreateObject("Microsoft.XMLHTTP")
objHttp.open "POST","https://www.paypal.com/cgi-bin/webscr",false
objHttp.setRequestHeader "Content-type","application/x-www-form-urlencoded"
objHttp.Send str
' assign posted variables to local variables
Item_name = Request.Form("item_name")
Item_number = Request.Form("item_number")
Payment_status = Request.Form("payment_status")
Payment_amount = Request.Form("mc_gross")
Payment_currency = Request.Form("mc_currency")
Txn_id = Request.Form("txn_id")
Receiver_email = Request.Form("receiver_email")
Payer_email = Request.Form("payer_email")
' Check notification validation
if (objHttp.status <> 200 ) then
' HTTP error handling
elseif (objHttp.responseText = "VERIFIED") then
' check that Payment_status=Completed and other variables
Execute business process code,mark transaction Completed or refunded from payment_status works successfully
elseif (objHttp.responseText = "INVALID") then
' log for manual investigation
else
' error
end if
set objHttp = nothing%>

解决方法

回发到 PayPal 不会影响 IPN 是否被标记为成功接收。回发步骤用于您自己验证 IPN 来自 PayPal。

要成功接收 IPN,HTTP 响应状态必须为 200 OK。