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

PIMOB:2138 - CVV Tokenization was implemented #243

Closed chintan-soni-cko closed 8 months ago

chintan-soni-cko commented 8 months ago

Issue

PIMOB-2138

Proposed changes

   cvvComponentMediator.createToken { result ->
                when (result) {
                    is CVVTokenizationResultHandler.Success -> {
                        val tokenDetails = result.tokenDetails
                        context.showAlertDialog(
                            title = context.getString(R.string.token_generated), message = tokenDetails.token
                        )
                    }

                    is CVVTokenizationResultHandler.Failure -> {
                        val errorMessage = result.errorMessage
                        context.showAlertDialog(
                            title = context.getString(R.string.token_generated_failed), message = errorMessage
                        )
                    }
                }
            }
  1. CVV Tokenisation implementation high-level explanation:
    • Created CVVTokenizationUseCase from Frames to hit the createToken from Checkout module (reusing the existing implementation)
    • Injected CardScheme from CVVComponentMediator in tokenization to handle the CVV validation from the SDK side and then call the tokenization endpoint
    • On failure of CVV Validation, SDK returns a common error message as "Please enter a valid security code"

Note: Currently tokenisation error handling is part of the existing implementation and we are returning only an error message with "error_type": "request_invalid" and an error response code. We need to improve this error handling and it is in backlog for us. Reference Github issue

Test Steps

  1. Open the kotlin sample app and navigate to CVVComponent screen
  2. Test all 4 cvv components for tokenisation

What to test:

  1. The first 3 CVV components are handled with pay button validation where the merchant will know whether the entered cvv is valid or not and based on it they can handle the pay button
  2. If the merchant applies a card scheme, the CVV field will have the typing length validation. For instance, if cvv is visa type, the user can type only 3 characters and if it is AMEX, the user can add up to 4 values
  3. For Tokenisation error handling testing, the last CVV component does not have the pay button validation. So,
    • When the merchant does not handle the pay button, SDK will do the CVV validation first. For instance, Visa scheme. if without entering CVV or entering an invalid CVV results in displaying an error message from the client side.
    • When a user enters the valid cvv, SDK will call the tokenisation endpoint and return a tokenisation response from the server side to the application layer

video.webm

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you choose the solution you did and what alternatives you considered, etc...

jheng-hao-lin-cko commented 8 months ago

Shall we wait a bit and merge #242 & #240 first? So that we could have ktlint to check and ktlintFormat to auto-format the coding style?