How to switch back from the payment app back to my app?

1 week ago 5
ARTICLE AD BOX

I have an issue on a SUNMI P2 terminal that has integrated NEXO protocol and Besteron for payment. To process the payment a HTTP request is sent from my app to the NEXO API which then displays the Besteron's UI that tells the user to use a card. When the the card is read, this Besteron UI stays in the front instead of redirecting the user back to my app.

Android version 11

I send a HTTP request to the NEXO protocol and when I get the response the paymentResult.collect triggers. Inside the collect I try to bring my app back to the front using Intent.FLAG_ACTIVITY_REORDER_TO_FRONT, but it does not work. Then I call the doTransactionTickets which calls my API which then triggers the transactionResult.collect which just navigates to another page.

The app has one MainActivity and multiple fragments, the following code is inside CheckoutFragment.kt

viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.CREATED) { viewModel.paymentResult.collect { Log.d("paymentTest", "The payment response has been received: $it") val intent = Intent(requireActivity(), MainActivity::class.java).apply { flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT } requireActivity().startActivity(intent) viewModel.doTransactionTickets ( binding.noteText.editText?.text.toString(), args.itemType, args.itemId, args.selectedTickets!!.tickets, totalPrice.formatWithDecimalPlaces(), args.date, args.packItems?.result, args.itemSeats, client ) } } } viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.CREATED) { viewModel.transactionResult.collect { item -> val receipt = viewModel.receiptPdf.value?.let { PdfDocument(it) } val ticket = viewModel.ticketPdf.value?.let { PdfDocument(it) } Log.d("paymentTest", "Transaction done") requireActivity().runOnUiThread { findNavController().navigate( R.id.action_checkoutFragment_to_confirmationFragment, Bundle().apply { putString("name", args.name) putFloat("totalPrice", totalPrice.toFloat()) putString( "ticketsDescription", binding.summaryTicketBreakdown.text.toString() ) putString("eventDateTime", args.date) putString("orderNumber", item.toString()) putInt("itemType", args.itemType) putBoolean("hasTimetable", args.hasTimetable) putSerializable("receipt", receipt) putSerializable("ticket", ticket) } ) } } } }

What else can I do here, I am open to ideas.

Read Entire Article