Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook processing #441

Open
andreaskraschitzer opened this issue Sep 27, 2024 · 1 comment
Open

Webhook processing #441

andreaskraschitzer opened this issue Sep 27, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@andreaskraschitzer
Copy link

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?

@armando-rodriguez-cko armando-rodriguez-cko self-assigned this Sep 27, 2024
@armando-rodriguez-cko
Copy link
Contributor

Hi @andreaskraschitzer, sorry for the delay, here you have:

https://github.com/checkout/checkout-sdk-java/blob/master/src/main/java/com/checkout/payments/response/source/AlternativePaymentSourceResponse.java

And here:

.registerTypeAdapterFactory(RuntimeTypeAdapterFactory.of(com.checkout.payments.response.source.ResponseSource.class, CheckoutUtils.TYPE, true, com.checkout.payments.response.source.AlternativePaymentSourceResponse.class)

For the correct deserialisation

@armando-rodriguez-cko armando-rodriguez-cko added the question Further information is requested label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

2 participants