nyartech / hyperpay

A Flutter plugin to wrap HyperPay SDK for iOS and Android.
MIT License
15 stars 34 forks source link

Android CustomTabs crash on API 30 and above #19

Closed AbdrahumanFikry closed 2 years ago

AbdrahumanFikry commented 2 years ago

` private fun bindCustomTabsService() { if (mClient != null) return try { val mConnection = object : CustomTabsServiceConnection() { override fun onCustomTabsServiceConnected(name: ComponentName, client: CustomTabsClient) { Log.d(TAG, "onCustomTabsServiceConnected CustomTabsClient = $mClient"); mClient = client mClient!!.warmup(0L); }

            override fun onServiceDisconnected(name: ComponentName?) {
                mClient = null
            }

        }
        Log.d(TAG, "mConnection =  $mConnection");

        val ok = CustomTabsClient.bindCustomTabsService(mActivity!!, CUSTOM_TAB_PACKAGE_NAME, mConnection);

        Log.d(TAG, "bindCustomTabsService : ,ok = $ok ,CustomTabsClient = $mClient");
    } catch (e: Exception) {
        Log.e(TAG, "bindCustomTabsService = $e ");
    }
}`

bindCustomTabsServiceis always False !!

@pr-Mais

pr-Mais commented 2 years ago

Without additional information and a minimum reproducible code I cannot guess where's your problem. Here're some steps to do before filing an issue:

  1. Make sure your server endpoints are correctly setup by following the official docs here.
  2. To test your endpoints, use Postman with the testing environment and configurations, make sure you're receiving a correct and valid JSON response.
  3. Clone this repository, then paste the configurations you received from HyperPay here.
  4. Run the example app and do a transaction using test cards.

If you followed the above steps and the example app is crashing, let me know.

AbdrahumanFikry commented 2 years ago

I followed the above steps and the example app is crashing. End points are working fine

the problem with the native code specially the function I have attached to the pervious comment . The When Card is validated the app should open a web activity But this line : CustomTabsClient.bindCustomTabsService(mActivity!!, CUSTOM_TAB_PACKAGE_NAME, mConnection);

is Always false and no web vies or callBack

@pr-Mais

pr-Mais commented 2 years ago

It's crashing in the example app?

pr-Mais commented 2 years ago

The code snippet you attached is not from this plugin.

AbdrahumanFikry commented 2 years ago

line 172 HyperPayPlugin.kt CustomTabsClient.bindCustomTabsService(mActivity!!, CUSTOM_TAB_PACKAGE_NAME, cctConnection);

@pr-Mais

pr-Mais commented 2 years ago

I pushed a small fix in the example app, could you please pull and try again. Additionally, the crash I got was caused by an error with the example app package name, couldn't reproduce the case you're facing.

AbdrahumanFikry commented 2 years ago

Didn't fix my problem I debugged the problem many Times and the problem with the function I sent you earlier it always return false so the callBack isn't working and I don't Know if the payment succussed or not

@pr-Mais

AbdrahumanFikry commented 2 years ago

I fixed this issue https://github.com/AbdrahumanFikry/hyperpayPlugin/blob/main/android/src/main/kotlin/com/nyartech/hyperpay/HyperpayPlugin.kt

@pr-Mais

pr-Mais commented 2 years ago

Could you please answer this question: the issue happens in the example app?

pr-Mais commented 2 years ago

Pull and try from the original repository. You seem to have pushed many changes on your fork.

AbdrahumanFikry commented 2 years ago

Could you please answer this question: the issue happens in the example app?

Pull and try from the original repository. You seem to have pushed many changes on your fork.

pr-Mais commented 2 years ago

Get back to the steps I mentioned in my first comment, try running a test transaction with your configurations on the example app in this repository, not your fork, purely without changing anything else.

Once you do that, write the exact steps you followed that caused the crash.

Also, what's the version of the HyperPay Android SDK you have?

salahamassi commented 2 years ago

I have the same issue after calling

hyperpay.pay(card);

the plugin throws this exception

W/System.err(13521): java.lang.NullPointerException W/System.err(13521): at com.nyartech.hyperpay.HyperpayPlugin.transactionCompleted(HyperpayPlugin.kt:291) W/System.err(13521): at com.oppwa.mobile.connect.service.ConnectService.transactionCompleted(ConnectService.java:2) W/System.err(13521): at com.oppwa.mobile.connect.provider.OppPaymentProvider.a(OppPaymentProvider.java:64) W/System.err(13521): at com.oppwa.mobile.connect.provider.OppPaymentProvider.lambda$Z7rpKa2phFQX0DRjHjS8RQqzthY(Unknown Source:0) W/System.err(13521): at com.oppwa.mobile.connect.provider.-$$Lambda$OppPaymentProvider$Z7rpKa2phFQX0DRjHjS8RQqzthY.run(Unknown Source:8) W/System.err(13521): at java.lang.Thread.run(Thread.java:1012) E/AndroidRuntime(13521): FATAL EXCEPTION: Thread-4 E/AndroidRuntime(13521): Process: sa.example.fixit.staging, PID: 13521 E/AndroidRuntime(13521): java.lang.IllegalStateException: null️ E/AndroidRuntime(13521): at com.nyartech.hyperpay.HyperpayPlugin.transactionCompleted(HyperpayPlugin.kt:320) E/AndroidRuntime(13521): at com.oppwa.mobile.connect.service.ConnectService.transactionCompleted(ConnectService.java:2) E/AndroidRuntime(13521): at com.oppwa.mobile.connect.provider.OppPaymentProvider.a(OppPaymentProvider.java:64) E/AndroidRuntime(13521): at com.oppwa.mobile.connect.provider.OppPaymentProvider.lambda$Z7rpKa2phFQX0DRjHjS8RQqzthY(Unknown Source:0) E/AndroidRuntime(13521): at com.oppwa.mobile.connect.provider.-$$Lambda$OppPaymentProvider$Z7rpKa2phFQX0DRjHjS8RQqzthY.run(Unknown Source:8) E/AndroidRuntime(13521): at java.lang.Thread.run(Thread.java:1012) I/Process (13521): Sending signal. PID: 13521 SIG: 9 Lost connection to device. Failed to send request: {"jsonrpc":"2.0","id":"58","method":"getMemoryUsage","params":{"isolateId":"isolates/791169051683579"}}

AbdrahumanFikry commented 2 years ago

@salahamassi I solved this Issue at https://github.com/AbdrahumanFikry/hyperpayPlugin

pr-Mais commented 2 years ago

Unless you provide the exact steps you followed and a minimal reproducible code, we're unable to help you. I tried running a transaction in the example app on both platforms and it was successful.

I'll close the issue, feel free to comment if you have any helpful details.

AbdrahumanFikry commented 2 years ago

@pr-Mais Please use the package in a new flutter app and not the example and you well get it

pr-Mais commented 2 years ago

I'm using the package in an app that is running in production for a year now and I had no issues on both Android and iOS.

I cannot help you unless you tell me what exactly you did that led to this exception.

AbdrahumanFikry commented 2 years ago

@pr-Mais I did exactly what I found in the package documentation and led to this exception!!

Please try it your self on a new flutter project with the newest version of every thing and you will get it!

@salahamassi this man had the same Issue and you don't even try what we told you, what do you need to believe us the whole flutter community !!

pr-Mais commented 2 years ago

Create a repo with a minimal code that produces this exception for you and share it here please

AbdrahumanFikry commented 2 years ago

@pr-Mais Please create a new flutter app and use the package and follow the package documentation and

YOU WELL GET IT

pr-Mais commented 2 years ago

What's the version of the Android HyperPay SDK you are using?

AbdrahumanFikry commented 2 years ago

@pr-Mais 3.10.0

pr-Mais commented 2 years ago

Just tried a new Flutter project and it's working as expected.

Worth noting that the plugin is tested against version 3.6.0 of the SDK (check here). I had to make some changes in the Android files to compile with v3.10.0, will update the docs shortly.

Here're the changes I did:

  1. In settings.gradle:
    configurations.maybeCreate("default")
    artifacts.add("default", file('oppwa.mobile-3.10.0-release.aar'))
  2. In app/build.gradle: set the compileSdkVersion to 31

Looking closely at the exception you're getting, I can see java.lang.NullPointerException, which indicates a required value by the pay method is being passed as null. Have you tried printing the checkoutID and made sure it's not null?

AbdrahumanFikry commented 2 years ago

Dear Mais , Please talk to the Android Developer Who coded this file and let him fix this issue java.lang.NullPointerException

I already solved here [https://github.com/AbdrahumanFikry/hyperpayPlugin/blob/main/android/src/main/kotlin/com/nyartech/hyperpay/HyperpayPlugin.kt](https://github.com/nyartech/hyperpay/issues/url)

and here too https://github.com/AbdrahumanFikry/hyperpayPlugin/blob/main/android/src/main/AndroidManifest.xml

pr-Mais commented 2 years ago

The issue is caused by Browser 1.3.0 on Android API 30 and above. A fix will be published soon.

@AbdrahumanFikry thanks for reporting, such detail about the environment that produced the issue could have helped much earlier.