bunq / sdk_java

Java SDK for bunq API
MIT License
47 stars 23 forks source link

No payment details in the result inquiries of a bunq me tab in the api #114

Closed degeusio closed 4 years ago

degeusio commented 5 years ago

Steps to reproduce:

  1. Create a BunqMeTab
  2. Make a payment using the BunqMeTab share url
  3. Get the BunqMeTab again

What should happen:

  1. The response under 3. should contain the payment detail

What happens:

  1. The response under 3. does not contain the payment detail

Traceback

SDK version and environment

Response id

Extra info:

This is exactly the same issue as reported here for the python sdk

https://together.bunq.com/d/4500-no-payment-details-in-the-result-inquiries-of-a-bunq-me-tab-in-the-api/3

Confirmed that the Raw response DOES contain the expected payment detail. The issue is caused by erroneous unmarshalling here:

BunqModel.java:

protected static BunqResponse fromJson(Class classOfObject, BunqResponseRaw responseRaw, String wrapper) { JsonObject responseItemObject = getResponseItemObject(responseRaw); // RAW RESPONSE LOOKS OK, CONTAINS THE PAYMENT DETAIL JsonObject responseItemObjectUnwrapped = getWrappedContent(responseItemObject, wrapper); T responseValue = gson.fromJson(responseItemObjectUnwrapped, classOfObject); // HERE IT GOES WRONG, PAYMENT DETAIL IS EMPTY return new BunqResponse(responseValue, responseRaw.getHeaders()); }

degeusio commented 5 years ago

Update: The bug is caused by a difference between the Java object hierarchy and the hierarchy in the api response. The payment object is nested twice.

Unmarshalling the raw reponse as follows resolves a Payment included in the first 'inquiry_result'.

JsonObject target = jsonObject.getAsJsonArray("Response")
                        .get(0)
                        .getAsJsonObject()
                        .getAsJsonObject("BunqMeTab")
                        .getAsJsonArray("result_inquiries")
                        .get(0)
                        .getAsJsonObject()
                        .getAsJsonObject("payment")
                        .getAsJsonObject("Payment") // this is were the bug caused by mapping error java vs. Json is...
        );
        Payment payment = gson.fromJson(target, Payment.class); //now unmarshals to correct object