【发布时间】:2021-05-15 06:33:36
【问题描述】:
我需要实现 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 中处理实现相同。以及当控制器被击中时需要哪些参数。
【问题讨论】:
标签: java paypal payment-gateway webhooks paypal-sandbox