How to track error on stripe tap-on-mobile on android device on tap behind device screen?

300 Views Asked by At

I have followed the development from this github repository but I have added only tap on mobile feature with real android device that have NFC support.

Terminal SDK verion used is:

com.stripe:stripeterminal:2.15.0
com.stripe:stripeterminal-localmobile:2.15.0

In my app I have a MainActivity and 2 fragments ( say Fragment1 and Fragment2). Fragment 1 : Selection of amount from a set of values nothing else added here (MainActivity first load this fragment) Fragment 2 : Show selected amount and Connecting reader and Processing Payment is added in this fragment

Issues faced on my Fragment 2 is added with Processing payment is added below.

val config = ConnectionConfiguration.LocalMobileConnectionConfiguration("xxxxxxxxxxxxxxx");
Terminal.getInstance().connectLocalMobileReader(
firstReader,
config,
object : ReaderCallback {

    override fun onSuccess(reader: Reader) {
        Log.d("Custom Log", "Connected to mobile device");
        val params = PaymentIntentParameters.Builder()
                                            .setAmount(30)
                                            .setCurrency("gbp")
                                            .build();

        Terminal.getInstance().createPaymentIntent(params, object: PaymentIntentCallback {

            override fun onSuccess(paymentIntent: PaymentIntent) {
                // Placeholder for collecting a payment method with paymentIntent
                val collectConfig = CollectConfiguration.Builder()
                                                        .updatePaymentIntent(true)
                                                        .build();

                val cancelable = Terminal.getInstance().collectPaymentMethod(paymentIntent,
                    object : PaymentIntentCallback {

                        override fun onSuccess(paymentIntent: PaymentIntent) {
                        val pm = paymentIntent.paymentMethod
                        val card = pm?.cardPresentDetails ?: pm?.interacPresentDetails
                        // Placeholder for business logic on card before processing paymentIntent

                        Terminal.getInstance().processPayment(paymentIntent, object : PaymentIntentCallback {
                            override fun onSuccess(paymentIntent: PaymentIntent) {
                                // Placeholder for notifying your backend to capture paymentIntent.id
                                Log.d("Custom Log","Process Payment : "+paymentIntent.id);

                            }

                            override fun onFailure(exception: TerminalException) {
                                // Placeholder for handling the exception
                                Log.d("Custom Log","Error errorMessage : " + exception.errorMessage);
                            }
                        })

                        }

                        override fun onFailure(exception: TerminalException) {
                        // Placeholder for handling exception
                        }

                    })

            }

            override fun onFailure(exception: TerminalException) {
                Log.d("Custom Log","Error ReaderCallback : " + exception.errorMessage)
            }
        })
    }
    override fun onFailure(e: TerminalException) {
        Log.d("Custom Log","Error ReaderCallback : " + e.errorMessage)
    }
});

In the above code, collectPaymentMethod brings a white screen for tap behind, I think this is a new system activity to handle NFC card reading.I have few questions here regarding customisation

q1: Is it possible to customize this screen view ?

q2: On tapping on this screen with a live card it show success message with green screen, even though the card is invalid for test payment, How can I customise this in error case

q3: Screen automatically closes and goes to MainActivity : Fragment1 , How can I catch the the closing and move to fragment2 insted of fragment1. I could'nt find a callback function to handle such cases

My tapto screen and success case screen is attached below enter image description here

In processPayment of the above code, it fall into onFailure with the error: Your card was declined. Your request was in test mode, but used a non test (live) card. For a list of valid test cards

How can I handle this error with a custom message or info in app.

As a summary, i need to do some customisation with the white screen of the above screenshot, but i couldnt find any documentations or example of that. Someone please help me to sort out these cases

Thanks in advance

0

There are 0 best solutions below