Webhook with SDK
Use java SDK to handle notification receive on webhook
SDK Usage
Using the NotificationParser Class
The NotificationParser class from the SDK provides an easy way to unmarshal the notification data while validating the signature.
PleenkSignatureService signatureService = new PleenkSignatureService(marketplaceKeyPairPrivateKey);
NotificationParser notificationParser = new NotificationParser(signatureService);
PleenkWebhookPayload notification = notificationParser.extractAndVerify(httpServletRequest);
List<PleenkWebhookEvent<? extends PleenkWebhookData>> events = notification.getEvents();`
PleenkWebhookEvent Instance
A PleenkWebhookEvent instance corresponds to a single notification and holds two properties:
- eventType: An
EventType
enum value depending on the event (USER
,PAYMENT
, etc.). - data: The data for the notification itself. The type of data depends on the event type.
Event Types
- USER_EVENT: Represents user-related events.
- PAYMENT_EVENT: Represents payment-related events.
- APPROVE_EVENT: Represents approval-related events.
Data Types
USER_EVENT
{
"@type": "USER_EVENT",
"ref": "8d1c7d19-7883-4ee6-8e90-f5c4f4fc3957",
"status": "LINKED"
}
PAYMENT_EVENT
{
"@type": "PAYMENT_EVENT",
"transactionRef": "12345",
"paymentId": "abcde",
"privacyScope": "private",
"metadata": "metadata",
"status": "CONFIRMED",
"beneficiaries": [
{
"ref": "beneficiary1",
"amount": 100.00
}
]
}
APPROVE_EVENT
{
"@type": "APPROVE_EVENT",
"userRef": "user123",
"request": "requestId",
"result": {
"age_in_years=": true,
"fiscal=": false
}
}
Verifying Signature
The pleenk-signature
header contains the signature of the notification payload. You should verify this signature to ensure the authenticity and integrity of the notification.
Example: Signature Verification in Java
// Create signature service with your marketplace private key
PleenkSignatureService signatureService = new PleenkSignatureService(marketplaceKeyPairPrivateKey);
// Create the notification parser with the signature service
NotificationParser notificationParser = new NotificationParser(signatureService);
// Extract and verify the notification from the HTTP request
PleenkWebhookPayload notification = notificationParser.extractAndVerify(httpServletRequest);
// Get the list of events from the notification payload
List<PleenkWebhookEvent<? extends PleenkWebhookData>> events = notification.getEvents();
Get more information on Signature verification process.
Updated 4 months ago
What’s Next