简体   繁体   中英

java paypal webhook controller to handle event of payment

i need to implement webhook controller to handle complete payment event so how can i handle or subscribe. `public IActionResult Webhook() { // The APIContext object can contain an optional override for the trusted certificate. 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);

}

this is javascript example i got but same as i want to handler implementation in java.and which parameters are needed when controller getting hit.

For PayPal Subscriptions , the list of Webhook event names is here: https://developer.paypal.com/docs/api-basics/notifications/webhooks/event-names/#subscriptions , and in particular the one you would want is PAYMENT.SALE.COMPLETED (not ".CAPTURE.")

You may find the information here helpful: https://stackoverflow.com/a/65139331/2069605

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM