sumup / sumup-android-sdk

Sample App for the SumUp Android SDK
Other
100 stars 29 forks source link

ActivityResultContracts / Compose #169

Open YiffyToys opened 2 years ago

YiffyToys commented 2 years ago

The SDK should allow to use the current ActivityResultContracts in addition of the deprecated mechanism in Activity. This is required to use the SDK in Jetpack Compose applications where rememberLauncherForActivityResult() is the prefered way to start other activities when interacting with UI elements and handle the results.

LuK1709 commented 2 years ago

This would also be useful without Compose, as the currently used mechanism is deprecated and ActivityResultsContract would allow for greater flexibility when processing the payment results.

YiffyToys commented 2 years ago

Half a year has passed and nothing happened. This issue hasn't even been triaged yet.

YiffyToys commented 2 years ago

I wonder if something like this may work until SumUp gets their act together:

class SumUpPaymentForResult : ActivityResultContract<SumUpPayment, ActivityResult>() {
        override fun createIntent(context: Context, input: SumUpPayment): Intent {
            class DummyActivity: Activity() {
                var capturedIntent: Intent? = null
                override fun startActivityForResult(intent: Intent?, requestCode: Int) {
                    capturedIntent = intent
                }

                override fun getPackageName(): String {
                    return "myapp.package"
                }
            }

            val dummy = DummyActivity()
            SumUpAPI.checkout(dummy, input, 1)
            return dummy.capturedIntent!!
        }

        override fun parseResult(
            resultCode: Int,
            intent: Intent?
        ): ActivityResult = ActivityResult(resultCode, intent)
    }