#Kaushal-GooglePay

1 messages · Page 1 of 1 (latest)

quaint matrix
#

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

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

quaint matrix
#

Let me get someone with Android experience, thank you for your patience

sterile ingot
#

cool, waiting

alpine surge
#

hello again

#

was wondering, did the adb logs reveal anything?

sterile ingot
#

Hey @alpine surge

#

no adb didnt help me, but github issues helped me🙂

alpine surge
#

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 to googlePayLauncher.presentForPaymentIntent(...) ??

#

separately, what ended up being the solution for

but github issues helped me

sterile ingot
#

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:

  1. I am calling the launcher.present("GBP", amount), payment sheet appeared and i pressed on continue
  2. The payment method creation was successful and i got the paymentMethodId from the callback method result
  3. I passed this paymentMethodId to get the clientSecret from my backend API
  4. my API returned the clientSecret
  5. 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

alpine surge
#

so let's take step by step

sterile ingot
#

ya

alpine surge
#
  1. 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

sterile ingot
#

its not null actually, i am logging it, the value is this : pi_3Lfs84Gfgz2J4wP21X7299dZ_secret_Ek7hAQyJIpdMSEDcLTrLJWFyg

alpine surge
#

looking

#

yeah I think you're mixing two approaches

#

do this

#
  1. I am calling the launcher.present("GBP", amount), payment sheet appeared and i pressed on continue
  2. The payment method creation was successful and i got the paymentMethodId from the callback method result
  3. I passed this paymentMethodId to get the clientSecret from my backend API
    remove these steps.

Instead, do

  1. 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

sterile ingot
#

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

alpine surge
#

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 use presentForPaymentIntent with 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()

sterile ingot
#

ah ok, so i need to tell my backend guys to change the approach right, clientSecret can be generated even without the PaymentMethod ID ?

sterile ingot
alpine surge
#

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

sterile ingot
#

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

alpine surge
#

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

sterile ingot
alpine surge
#

are you familiar with the PaymentSheet component? it is in the iOS, Android and ReactNative SDKs of Stripe

sterile ingot
#

nope, no idea about that actually

#

Its my first ever payment integration🙂

alpine surge
#

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

sterile ingot
#

need to try once

alpine surge
#

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

sterile ingot
#

Great!

#

But right now, IOS dont need a clientSecret before launching the sheet right, but we do need in android for calling presentForPaymentIntent

alpine surge
#

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

sterile ingot
#

yeah

#

cool, will discuss with our back end team on generating the clientSecret even without having the paymentMethodId

alpine surge
#

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