Nets-mobile-acceptance / Netaxept-Android-SDK

PiA Netaxept Android SDK is a library that provides the native In-App interaction to perform Netaxept payments directly from an app on Android devices while minimizing PCI DSS requirements for you.
31 stars 15 forks source link

registerForActivityResult compiler error in Kotlin #22

Closed ngoclt closed 2 years ago

ngoclt commented 3 years ago

Hi,

I'm developing an Android app in Kotlin, and when I'm trying to registerForActivityResult for CardProcessActivityResultContract the compiler shows this error:

Screenshot 2021-03-04 at 14 38 51

My workaround solution is that writing the card registration in JAVA and import the code to other Kotlin classes to use. :( So I'm wondering if I'm doing anything wrong or the library itself doesn't support Kotlin yet?

Thanks in advance, Ngoc LE

LevonVardanyan commented 3 years ago

I have the same issue

emilfa commented 3 years ago

Also having the same issue, and currently working around it by having a Java helper class for card registration. Would be great with a fix / response

bopmaz commented 3 years ago

@Miss-PiA Do we have any update on this? Not sure if "eu.nets.pia.ResultContract" class (which cause the compiler error) inherited from Google "ActivityResultContract".

Miss-PiA commented 2 years ago

@ngoclt @bopmaz @LevonVardanyan @emilfa Please try our Netxapt Android SDk v2.6.1.

acarlsen commented 2 years ago

I have exactly the same issue in v2.6.1

It seems eu.nets.pia.ResultContract cannot be resolved in Kotlin (but works when referenced in Java). Seems like maybe a packaging issue in the aar file, perhaps caused by obfuscation or incompatible byte code etc.

Miss-PiA commented 2 years ago

Hi @ngoclt @bopmaz @LevonVardanyan @emilfa @acarlsen ,

Thanks for reporting the issue and sharing your findings!

The warning/error can be ignored by casting the insurance to the required type ActivityResultContract<TypeVariable(I)!, TypeVariable(O)!>?. We are developing a new SDK v3.0 which will be rewritten in Kotlin only so that we will find the way to get rid of this type mismatch issue.

acarlsen commented 2 years ago

If I in Kotlin force the cast for CardProcessActivityResultContract like this:

CardProcessActivityResultContract() as ActivityResultContract<CardProcessActivityLauncherInput, ProcessResult<PaymentErrorType>>)

Then I no longer get IDE compile error, but on build this error:

Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath: class eu.nets.pia.card.CardProcessActivityResultContract, unresolved supertypes: eu.nets.pia.ResultContract Adding -Xextended-compiler-checks argument might provide additional information.

So doesn't solve my problem. What does work is wrapping the contract in a Java proxy class, which I guess is good enough for now, although I feel like this should be an easy fix for a 2.6.2 version.

Miss-PiA commented 2 years ago

Hi @acarlsen,

Thanks a lot for your quick input and valuable clarification to allow us to reproduce this issue with Kotlin project. Now, we try to identify the root cause and find the feasible resolution as quick as possible! We will keep you posted once the issue gets fixed and it will be included in the next coming release.

acarlsen commented 2 years ago

With version 2.6.3 the CardProcessActivityResultContract can now compile when using invoke (which seems like a strange way to fix it but ok..). But alas in the result output eu.nets.pia.CardProcessError is not resolvable in Kotlin, so I am unable to parse the result... so we got one step further.

Please refer to this sample project: https://github.com/acarlsen/netaxeptissue22

It shows a very simple example where the compile error is shown. Note the same error is there for eu.nets.pia.PayPalError.

Miss-PiA commented 2 years ago

Hi @acarlsen ,

Thanks for your quick input and example project!

The dev team is looking into the new compile error your reported here. We will keep you posted once the feasible resolution is found to tackle the problem. In the short term, please kindly handle result more generically, i.e. ignoring internal details of an error and merely requesting rollback of transaction upon failure listed the example below.

private fun onTransactionCompletionWithResult(result: ProcessResult<*>) {
    when(result) {
        is ProcessResult.Success ->  TODO("Commit transaction")
        is ProcessResult.Cancellation -> TODO("Rollback transaction")
        is ProcessResult.Failure -> TODO("Rollback transaction and inform user to try different payment method")
    }
}  
Miss-PiA commented 2 years ago

HI @acarlsen ,

The latest SDK v2.6.4 is available to have a try which includes the permanent fix the issue reported here! Please kindly reopen the ticket if the issue is occurred from your end.