Closed PiDyGB closed 5 years ago
That's weird. Doesn't the compiler throw you an error?
It seems like you are passing the whole API response to the component, when it should be just the PaymentMethod for the Card, which is called 'scheme'.
Something like this:
for (pm in response.paymentMethods!!) {
if (pm.type == PaymentMethodTypes.SCHEME) {
val cardComponent = CardComponent.PROVIDER.get(this@MainActivity, pm, cardConfiguration)
}
}
Other than that, can you try to attach before adding the observer and see if that fixes it? If it does, we will work on a fix for the next release.
Sorry @caiofaustino , I missed a piece of code, I report here the complete one:
val cardConfiguration = CardConfiguration.Builder(
Locale.getDefault(),
resources.displayMetrics,
Environment.TEST,
"<publicKey>"
).build()
val response = PaymentMethodsApiResponse.SERIALIZER.deserialize(JSONObject(res))
//when res is the /paymentMethods POST response
response.paymentMethods?.firstOrNull { it.type == PaymentMethodTypes.SCHEME }?.let {
val cardComponent = CardComponent.PROVIDER.get(this@MainActivity, it, cardConfiguration)
adyenCardComponent.attach(cardComponent, this@MainActivity)
cardComponent.observe(this@MainActivity, Observer { state ->
Log.d(MainActivity::class.java.simpleName, "CardComponent data: $state")
})
}
This is why the compiler doesn't report an error, but, unfortunately, an NPE runtime exception is raised instead, also if I move the attach method before observe.
I don't know if this can help, but, decompiling the SDK, I noticed that into the attach method this
this.mComponent.observeOutputData(lifecycleOwner, this);
is called before this
this.mCardListAdapter = new CardListAdapter(this.mComponent);
but the first one will immediately deliver an onChanged(@NonNull CardOutputData cardOutputData)
event and here the exception in raised (onChanged -> updateNumber -> this.mCardListAdapter.setCards).
Ah ok, that's right this was a stupid mistake, thanks for the catch. We are creating the view programmatically on our test so this issue didn't show up. We will fix this for the next release.
Also, the code is open source here, you don't need to decompile to look at it :)
Should be fixed on rc02, @PiDyGB can you check?
Hi @caiofaustino ,
I can confirm that now seems working as expected.
This is my demo implementation:
but the CardView class raises an exception during the execution of the attach method.
Seems that the CardListAdapter is used before have been initialized.