我正在使用沙盒模式。我在沙盒模式下有一个立即购买按钮,链接到我的沙箱企业帐户,该帐户已启用ipn并使用我的网站的网址。 ipn实现与此处的示例代码完全相同:https://cms.paypal.com/cms_content/GB/en_GB/files/developer/IPN_ASP_NET_C.txt
我点击按钮,使用成功的沙盒个人帐户进行购买。它显示为在业务帐户ipn历史记录中使用代码200发送,但在我网站的ipn页面上,响应无效。
现在已经好几天了......不能弄明白:(
答案 0 :(得分:0)
以下是我用于https://ASPSecurityKit.net
的内容 private void ProcessPayment(bool test)
{
try
{
string callbackResponse = null;
string content = null;
string callbackUrl = test ? "https://www.sandbox.paypal.com/cgi-bin/webscr"
: "https://www.paypal.com/cgi-bin/webscr";
var req = (HttpWebRequest) WebRequest.Create(callbackUrl);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
content = Encoding.ASCII.GetString(
Request.BinaryRead(HttpContext.Request.ContentLength)
);
content += "&cmd=_notify-validate";
req.ContentLength = content.Length;
using (var streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))
{
streamOut.Write(content);
}
using (var streamIn = new StreamReader(req.GetResponse().GetResponseStream()))
{
callbackResponse = streamIn.ReadToEnd();
}
if (callbackResponse.Equals("VERIFIED", StringComparison.OrdinalIgnoreCase))
{
// Now validate whether gross_amount is ok, receiver_email is your business acount mail id and so on.
}
}
catch (Exception ex)
{
// Logger.Log(ex); // Uncomment this line if you have a logger
}
}
注意:我存储数据库中的所有事务,无论是变量还是无效。那个逻辑是ASPSecurityKit.net具体的,因此我在这里省略了。