java - java paypal webhook控制器处理支付事件
问题描述
我需要实现 webhook 控制器来处理完整的支付事件,所以我该如何处理或订阅。`public IActionResult Webhook() { // APIContext 对象可以包含可信证书的可选覆盖。var apiContext = PayPalConfiguration.GetAPIContext();
// Get the received request's headers
var requestheaders = HttpContext.Request.Headers;
// Get the received request's body
var requestBody = string.Empty;
using (var reader = new System.IO.StreamReader(HttpContext.Request.Body))
{
requestBody = reader.ReadToEnd();
}
dynamic jsonBody = JObject.Parse(requestBody);
string webhookId = jsonBody.id;
var ev = WebhookEvent.Get(apiContext, webhookId);
// We have all the information the SDK needs, so perform the validation.
// Note: at least on Sandbox environment this returns false.
// var isValid = WebhookEvent.ValidateReceivedEvent(apiContext, ToNameValueCollection(requestheaders), requestBody, webhookId);
switch (ev.event_type)
{
case "PAYMENT.CAPTURE.COMPLETED":
// Handle payment completed
break;
case "PAYMENT.CAPTURE.DENIED":
// Handle payment denied
break;
// Handle other webhooks
default:
break;
}
return new HttpStatusCodeResult(200);
}
这是我得到的javascript示例,但与我想在java中处理实现相同。以及当控制器被击中时需要哪些参数。
解决方案
对于PayPal Subscriptions,Webhook 事件名称列表在这里:https ://developer.paypal.com/docs/api-basics/notifications/webhooks/event-names/#subscriptions ,特别是您想要的是PAYMENT.SALE.COMPLETED
(不是“.CAPTURE.”)
您可能会发现此处的信息很有帮助:https ://stackoverflow.com/a/65139331/2069605
推荐阅读
- django - 从 Django 的 ArrayAgg 中排除空值
- java - 当我尝试使用 btrace 跟踪 spring 项目时,出现错误(“处理程序调度失败;嵌套异常是 java.lang.NoSuchFieldError: runtime”)
- go - 为什么gccgo会报这么奇怪的错误信息?
- github - Github:如何列出问题的里程碑更新
- file - 使用 Rest API 将数据附加到 Azure Datalake Storage Gen2 中的现有文件
- javascript - 来自 Promise Async 的带有 puppeteer 错误的 NodeJS
- javascript - JavaScript 和 HTML 中带有滑动动画的模态框
- javascript - 如何在反应中通过按钮打开新页面?
- c++ - 全局命名空间前缀的规则和实践?
- python - 如何更正不完整的多边形几何并在 MySQL 中插入?