checkout / frames-android

Frames Android: making native card payments simple
https://www.checkout.com/docs/integrate/sdks/android-sdk
MIT License
47 stars 32 forks source link

Error codes for the CardTokenRequest #206

Open september669 opened 1 year ago

september669 commented 1 year ago

Hello We are using version 3.x.x And we don't use your UI, but only API part. So we are processing error: CardTokenisationFail to show error messages to our users.

api.setTokenListener(
                object : CheckoutAPIClient.OnTokenGenerated {
                    override fun onNetworkError(error: NetworkError) {
                        Timber.e(error)
                        deferred.completeExceptionally(error)
                    }

                    override fun onTokenGenerated(response: CardTokenisationResponse) {
                        deferred.complete(response.token)
                    }

                    override fun onError(error: CardTokenisationFail) {
                        Timber.e("request_id: ${error.requestId}\nerror_type: ${error.errorType}\nerror_codes: ${Arrays.toString(error.errorCodes)}")
                        deferred.completeExceptionally(CardTokenisationException(error.requestId, error.errorType, error.errorCodes))
                    }
                }
            )

Now we are going to update lib version to 4.x.x But in CardTokenRequest (as I understand it is a replacement for the CheckoutAPIClient.OnTokenGenerated) there is no error code and error.errorType, only errorMessage. We can't use errorMessage for mapping to the our messages, it is highly unreliable.

public data class CardTokenRequest(
    val card: Card,
    val onSuccess: (tokenDetails: TokenDetails) -> Unit,
    val onFailure: (errorMessage: String) -> Unit
)
https://github.com/checkout/frames-android/blob/fc90c00c05ac76e77d148935a1b02023f14aad0a/checkout/src/main/java/com/checkout/tokenization/model/CardTokenRequest.kt#L9

Is it possible to add an error code and error type to CardTokenRequest? Or is there another way to create a card token?