我一直在尝试设置PayPal Webhooks(在沙盒模式下)以接收有关拒绝和成功付款的通知。我的问题是我无法进行验证工作。关于我的尝试的一些细节:
我尝试了两种方式来监听Webhook调用:
[HttpPost]
public async Task<IHttpActionResult> PaymentCaptureCompleted()
{
// Get the received request's headers
NameValueCollection nvc = new NameValueCollection();
foreach (var item in Request.Headers)
{
nvc.Add(item.Key, string.Join(",", item.Value));
}
// Get the received request's body
var requestBody = await Request.Content.ReadAsStringAsync();
var isValid = WebhookEvent.ValidateReceivedEvent(Api, nvc, requestBody, ConfigurationManager.AppSettings["paypal.webhook.id"]);
if (isValid)
{
return Ok();
}
else
{
return BadRequest("Could not validate request");
}
}
当然还有很多细节,但我不确定回答我的问题需要多少信息。只是让我知道你需要什么,我会编辑这个问题。
有关代码示例,请参阅PayPal Dot Net SDK。 https://github.com/paypal/PayPal-NET-SDK
此外,如果您的模拟器不工作,要排除webhook或azure配置有问题,您可能需要使用Runscope。 Ypu可以将Runscope存储桶配置为webhook端点,如果您在此处收到webhook通知,则可能需要在Azure配置中进行更改。
真的没有去文档。它虽然陈旧,但物体仍然很好。您可以使用WebhookEvent类。只需在控制器中使用此操作即可。
public JsonResult Index(WebhookEvent event)
{
// event has all the data
return Json(new { success = true });
}
验证不适用于模拟中的IPN沙箱和Webhook事件。它在PayPal文档中说明。验证仅适用于PayPal的生产环境。