#Kaushal-GooglePay
1 messages · Page 1 of 1 (latest)
hi, pasting your question here
I am calling googlePayLauncher.present to create a payment method and on success of that i get the paymentId, with that paymentId i will call my backend API to get the client secret, once i get the clientSecret i use it to call the googlePayLauncher.presentForPaymentIntent to complete the payment. is this flow correct ?
Please respond in this thread @sterile ingot
ok sure thanks, i am doing this in android
is the above flow correct ?
when i call the second method googlePayLauncher.presentForPaymentIntent i am getting an error : Failed(error=java.lang.IllegalArgumentException: Invalid Payment Intent client secret
Let me get someone with Android experience, thank you for your patience
cool, waiting
and as for "how" you integrate Google Pay, you actually just want either-or approach
if you want to create a PaymentIntent and confirm it with Google Pay:
1/ create a PaymentIntent on your backend
2/ using the PaymentIntent client_secret field, call googlePayLauncher.presentForPaymentIntent('pi_123_secret_456')
so given the error
Failed(error=java.lang.IllegalArgumentException: Invalid Payment Intent client secret
can you log out what you're passing togooglePayLauncher.presentForPaymentIntent(...)??
separately, what ended up being the solution for
but github issues helped me
Hey, the solution was i added existingPaymentMethodRequired = false, to my launcher config property and the sheet appeared, i commented the same in github issues
i saw some one's comment and followed it and luckily it worked
coming to the next issue now, will tell what i have done in steps:
- I am calling the launcher.present("GBP", amount), payment sheet appeared and i pressed on continue
- The payment method creation was successful and i got the paymentMethodId from the callback method result
- I passed this paymentMethodId to get the clientSecret from my backend API
- my API returned the clientSecret
- Now i called the googlePayLauncher.presentForPaymentIntent(clientSecret) but this is giving me the Invalid Payment Intent client secret error
so somewhere i know i am doing this wrong way , not sure what it is
so let's take step by step
ya
- my API returned the clientSecret
now do two things
1/ log it in client-side function that gets the response from your backend HTTP request
2/ log out clientSecret variable before you call presentForPaymentIntent()
could be something as simple as clientSecret not being the PaymentIntent client_secret but something else, say null or some other string
its not null actually, i am logging it, the value is this : pi_3Lfs84Gfgz2J4wP21X7299dZ_secret_Ek7hAQyJIpdMSEDcLTrLJWFyg
looking
yeah I think you're mixing two approaches
do this
- I am calling the launcher.present("GBP", amount), payment sheet appeared and i pressed on continue
- The payment method creation was successful and i got the paymentMethodId from the callback method result
- I passed this paymentMethodId to get the clientSecret from my backend API
remove these steps.
Instead, do
- my API returned the clientSecret
first
then
do what our guide does here: https://stripe.com/docs/google-pay?platform=android#instantiate
notice it does not use the present() function
it only uses
ya i mean its the different launcher actually : GooglePayPaymentMethodLauncher.present()
ok, so the problem for me to call my api to get the clientSecret is , i need to pass the paymentMethodId to the api to get it, so i took this approach
oh yeah you're mixing the two launchers I think, they weren't intended to be used like that
basically,
i need to pass the paymentMethodId to the api to get it
the approach you're using means to create and confirm PaymentIntents on the server, and not usepresentForPaymentIntentwith it. This is a more complex approach basically
I recommend sticking with the doc I linked, since it is a simpler appraoch
you don't need the PaymentMethod ID created first, you can create the PaymentIntent first and pass that to presentForPaymentIntent()
ah ok, so i need to tell my backend guys to change the approach right, clientSecret can be generated even without the PaymentMethod ID ?
ya its simpler, but i didint understand the doc properly, so the gamble
ah ok, so i need to tell my backend guys to change the approach right, clientSecret can be generated even without the PaymentMethod ID ?
correct!
1/ create a PaymentIntent on the server
2/ on the Android app, call presentForPaymentIntent(clientSecret) and that displays the GPay modal and allows paying the PaymentIntent
cool, got it
actually they created the API looking into the apple pay doc, in apple pay they will get the paymentMethod ID before only i guess
Apple Pay on iOS works the same
there's a STPApplePayContext that has a similar thing where you override a delegate method on that class and call completion(clientSecret, error) and STPApplePayContext confirms the PaymentIntent for you
qq why not use PaymentSheet? on both iOS and Android?
I find it much simpler to integrate personally
and it gives me multiple payment methods out of the box, with the integration written once
sorry , i didnt understand this question, can you come again
are you familiar with the PaymentSheet component? it is in the iOS, Android and ReactNative SDKs of Stripe
see this: https://stripe.com/docs/payments/accept-a-payment?platform=android
(or switch to iOS or ReactNative tab)
its a prebuilt UI in the mobile SDKs that gives you card entry UI, Apple Pay, Google Pay and other local payment methods like IDEAL or SEPA or Bancontact etc
so you integrate with PaymentSheet and it supports multiple payment methods out of the box
ah okay , thats nice
need to try once
and going forward more payment methods are added to it, so you don't have to re-write your mobile app to support "one more" PaymentMethod
Great!
But right now, IOS dont need a clientSecret before launching the sheet right, but we do need in android for calling presentForPaymentIntent
to present Apple Pay sheet, technically no but ultimately you do to dismiss the sheet, so really you do need it since you can't dismiss the STPApplePayContext sheet otherwise so really, you need to create the PaymentIntent first anyways to prevent latency in calling completion(clientSecret, ...)
and correct on GPayLauncher
almost all of Stripe's integrations require that you have the PaymentIntent created first
yeah
cool, will discuss with our back end team on generating the clientSecret even without having the paymentMethodId
basically, with my recommended approach, you never need to do anything with a PaymentMethod ID (or even obtain it in your code)
GPayLauncher and STPApplePayContext just handle it for you
but basically basically you ideally use PaymentSheet and never have to think about other payment methods again haha