bunq / sdk_java

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

Cannot list draft payments for monetary account #46

Closed robinkanters closed 6 years ago

robinkanters commented 6 years ago

Steps to reproduce:

  1. Make a draft payment for monetary account X
  2. List draft payments for monetary account X

What should happen:

  1. Draft payments are retrieved and deserialized into DraftPayment instances

What happens:

  1. Gson Error is thrown

Logs

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected NULL but was NUMBER at path $.object.Payment.geolocation.latitude
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224)
        at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:63)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
        at com.google.gson.Gson.fromJson(Gson.java:887)
        at com.google.gson.Gson.fromJson(Gson.java:952)
        at com.google.gson.Gson.fromJson(Gson.java:925)
        at com.bunq.sdk.model.core.BunqModel.fromJsonList(BunqModel.java:104)
        at com.bunq.sdk.model.generated.endpoint.DraftPayment.list(DraftPayment.java:151)
        at com.bunq.sdk.model.generated.endpoint.DraftPayment.list(DraftPayment.java:141)
        at com.bunq.sdk.model.generated.endpoint.DraftPayment.list(DraftPayment.java:137)
OGKevin commented 6 years ago

Hey @robinkanters,

Thanks for reporting. I have a felling this has to do with 1 or multiple payments inside the LIST where $.object.Payment.geolocation.latitude is actually populated with data while the deserialiser expects nothing. Which doesn't make sense to me yet :thinking: Ill see if i can reproduce and find a fix :thumbsup:.

robinkanters commented 6 years ago

@OGKevin that sounds correct, that is what the error says haha!

OGKevin commented 6 years ago

@robinkanters btw, how did you make the draft payment ? Via API or inside the bunq app ? Save's me some time finding out how to get $.object.Payment.geolocation.latitude populated with data :grin:

robinkanters commented 6 years ago

@OGKevin via the api

robinkanters commented 6 years ago

@OGKevin it's just this, nothing special

return DraftPayment.create(apiContext, mapOf(
        "status" to "PENDING",
        "entries" to listOf(mapOf(
                "amount" to Amount(paymentOrder.amount.toString(), paymentOrder.currency),
                "counterparty_alias" to makePointer(paymentOrder.to, paymentOrder.name),
                "description" to paymentOrder.description,
                "merchant_reference" to paymentOrder.uniqueKey
        )),
        "number_of_required_accepts" to 1
), userId, from).value
OGKevin commented 6 years ago

@robinkanters I could not reproduce with the following snippet:

    List<DraftPaymentEntry> entries = new ArrayList<>();
    entries.add(new DraftPaymentEntry(
        new Amount("0.01", "EUR"),
        new MonetaryAccountReference(counterPartyAliasOther),
        "Test"
    ));

    HashMap<String, Object> requestMap = new HashMap<>();
    requestMap.put(DraftPayment.FIELD_NUMBER_OF_REQUIRED_ACCEPTS, 1);
    requestMap.put(DraftPayment.FIELD_STATUS, "PENDING");
    requestMap.put(DraftPayment.FIELD_ENTRIES, entries);

    int draftPaymentId = DraftPayment.create(getApiContext(), requestMap, userId, monetaryAccountId).getValue();
    DraftPayment.list(getApiContext(), userId, monetaryAccountId);
    DraftPayment.get(getApiContext(), userId, monetaryAccountId, draftPaymentId);

:thinking: Later today ill try reproducing with a manually made json with the field $.object.Payment.geolocation.latitude populated and deserialise the object then.

robinkanters commented 6 years ago

@OGKevin maybe it's choking on another payment on my MA, don't know how to figure out which though

robinkanters commented 6 years ago

@OGKevin try accepting the draft payment (in the app) and then listing them for that MA.

It seems to choke on the geolocation on the linked payment instance for some reason. (edit: duh, that's what the error says haha)

If you want to dive into the database, it's payment id removed for draft payment id removed.

Edit: removed ids for privacy reasons.

robinkanters commented 6 years ago

I found a workaround for my personal situation, but it still seems like an important issue to me.

never mind, that also doesn't work

OGKevin commented 6 years ago

@robinkanters I think that might be it indeed.

I removed the payment ids for privacy reasons. I did write them down so I’ll have a look indeed 👍.

Once I’ve found a way to reproduce, I should be able to fix it and provide a test so that it doesn’t come back later on 😄. I’ll try your accept in bunq app suggestion as well, if this doesn’t work neither then I’ll try with a manual made raw json.

robinkanters commented 6 years ago

I removed the payment ids for privacy reasons

who cares 😉 wouldn't have posted them if I'd have been concerned about that

robinkanters commented 6 years ago

manual made raw json

~yeah so I'm building the request data with a java Map (not by setting properties on a DraftPayment instance), so that might be different from what you're doing. try my snippet 👍~

oh wait that is actually what you're doing. no idea what the difference is then

OGKevin commented 6 years ago

@robinkanters reproduced :thumbsup:.

Ill plan to fix this in 0.12.5.

robinkanters commented 6 years ago

@OGKevin no doubt you noticed, but just for completeness: this also happens for listing Payments 😉

OGKevin commented 6 years ago

@robinkanters yes your indeed correct! It was due to a silly miss type 🤦‍♂️