Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] GooglePayPaymentMethodLauncher for compose #5201

Closed
GMetaxakis opened this issue Jun 23, 2022 · 8 comments
Closed

[Feature] GooglePayPaymentMethodLauncher for compose #5201

GMetaxakis opened this issue Jun 23, 2022 · 8 comments
Assignees
Labels

Comments

@GMetaxakis
Copy link

Is your feature request related to a problem? Please describe.

GooglePayPaymentMethodLauncher works without an issue for activities/fragments, but it will be very nice to consider support it an alternative creation method like the PaymentLauncher.Companion.createForCompose for JetpackCompose usage.

Describe the solution you'd like

A way to create the GooglePayPaymentMethodLauncher with just context, without activity/fragment parameter

Describe alternatives you've considered

As I have 1 activity that setups the composable graphs + theme, I can move in that activity the init of the GooglePayPaymentMethodLauncher and keep in the activity a reference to use afterwards with any LocalContext.current with the usage of Context.getActivity(), but I don't like it 😞

fun Context.getActivity(): AppCompatActivity? = when (this) {
    is AppCompatActivity -> this
    is ContextWrapper -> baseContext.getActivity()
    else -> null
}

Note: I don't mind working on it myself if it is possible, shall I fork the project and open a PR ?

@brnunes-stripe
Copy link
Contributor

Hi @GMetaxakis,
Thanks for filing the issue. That's definitely something we want to support better. I'll take a look and test the PR.

@brnunes-stripe brnunes-stripe self-assigned this Jul 1, 2022
@GMetaxakis
Copy link
Author

@brnunes-stripe any luck? I saw a comment on an email on me few days ago but i don't see it here, could i help with anything?

@brnunes-stripe
Copy link
Contributor

Hi @GMetaxakis, yes, I deleted because I figured out the issue. I'll finish woking on this and submit a PR soon.

@GMetaxakis
Copy link
Author

Hi @GMetaxakis, yes, I deleted because I figured out the issue. I'll finish woking on this and submit a PR soon.

Great news 😁 happy to have helped

@brnunes-stripe
Copy link
Contributor

This is implemented in #5274, we're just doing a review and will submit it.

@brnunes-stripe
Copy link
Contributor

Hello,
Version 20.8.0 released today contains the changes mentioned above.
Please try it out and let us know if you have any feedback!

@GMetaxakis
Copy link
Author

Hello, Version 20.8.0 released today contains the changes mentioned above. Please try it out and let us know if you have any feedback!

When I am trying to use it with a wrong clientSecret it crashes the app instead of showing any error, not sure if this is the actual problem to be honest

    java.lang.IllegalStateException: Attempting to launch an unregistered ActivityResultLauncher with 
    contract com.stripe.android.googlepaylauncher.GooglePayLauncherContract@5f9f58c and 
     input PaymentIntentArgs(clientSecret=***, config=Config(environment=Test, merchantCountryCode=**, merchantName=***, isEmailRequired=false, billingAddressConfig=BillingAddressConfig(isRequired=false, format=Min, isPhoneNumberRequired=false), existingPaymentMethodRequired=true, allowCreditCards=true)). You must ensure the ActivityResultLauncher is registered before calling launch().

example of usage

    PaymentConfiguration.init(
        context = LocalContext.current,
        publishableKey = publishableKey,
        stripeAccountId = stripeAccountId,
    )
    paymentLauncherGoogle = GooglePayLauncher.rememberLauncher(
        config = GooglePayLauncher.Config(
            environment = GooglePayEnvironment.Test,
            merchantCountryCode = "GR",
            merchantName = "Any"
        ),
        readyCallback = {
            if (it) {
                paymentLauncherGoogle?.presentForPaymentIntent(paymentIntentSecret)
            } else {
                resultCallback.onPaymentResult(PaymentResult.Failed(Exception("The Gpay isn't ready")))
            }
        },
        resultCallback = { it.mapGoogleResultToGenericResult(resultCallback) }
    )

@brnunes-stripe brnunes-stripe reopened this Aug 5, 2022
@brnunes-stripe
Copy link
Contributor

Hi @GMetaxakis I cannot reproduce the crash you're seeing. Can you share more of your code? The full Activity would be very helpful.
Also take a look at the example in GooglePayLauncherComposeActivity, starting from it might help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants