Description
It would be great if you could pass a webhook to the library, and it would take care of the key / signature validation and parsing the payload into POJOs.
It seems to me that the SDK doesn't support any webhook processing.
Environment
- Checkout SDK version: 6.3.5
- Platform and version: Java 21 - Spring Boot 3.2.5
Description
I had a look around the sdk and also the official Checkout documentation but could not find any details about what Webhooks look like or how they should be processed. This leads me to
- setting up a webhook.site url
- triggering all my expected flows
- building processing logic based on the data captured on webhook.site
I found the EventResponse
object closely aligns with the structure of the webhook payload so used it for an initial parsing.
This then allows me to determine how the data
should be further parsed based on the type
field.
My usecase is card and payment processing, so based on the event type "card_verified" I went ahead and tried to parse the data
field to the PaymentResponse
which fails at PaymentResponse.source
because com.checkout.payments.response.source.ResponseSource
is just an interface and jackson doesn't know at this time which impelemtation should be used.
Example code
public HttpStatus handlePspHook(final Configuration configuration, final String path, final Map<String, String> headers, final String data) {
// authentication check
final EventResponse event = objectMapper.readValue(data, EventResponse.class);
switch (event.getType()) {
case "card_verified" -> {
final PaymentResponse payment = objectMapper.convertValue(event.getData(), PaymentResponse.class);
...
I also just now realized that EventResponse
is from the previous
package which use I tried to avoid so far.
Question
Do I have to build my own POJOs based on the structure of EventResponse
and PaymentResponse
to process the webhook data or is there a better way which I have missed?