【问题标题】:java paypal webhook controller to handle event of paymentjava paypal webhook控制器处理支付事件
【发布时间】: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


    【解决方案1】:

    对于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

    【讨论】:

    • 当时我需要收到付款(即收到付款)我需要收到通知,并且该捕获事件可用对吗?我需要那个付款对象。
    猜你喜欢
    • 2017-08-20
    • 2020-06-02
    • 2014-12-20
    • 2011-03-21
    • 2018-06-11
    • 2016-07-17
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    相关资源
    最近更新 更多