#A-I-nstein-stripe-java

1 messages · Page 1 of 1 (latest)

versed timber
sleek gate
#

Also can I directly pass the token returned by the google pay api to the 'source' parameter in the charge function or do I have to parse it ?

#

something like this ( token = paymentResult['paymentMethodData']['tokenizationData']['token'];) maybe ?

versed timber
#

By google pay API do you mean google's API or our something that our APi gives you for google pay?

sleek gate
#

google's API

versed timber
sleek gate
#

what about the Charge.create? what package am I supposed to import?

sleek gate
# versed timber You won't be able to use their API token with our API. You will want to use this...

https://stackoverflow.com/questions/68659908/use-google-pay-response-token-in-stripe-api?rq=1

but in this discussion, the user seems to think that that we could directly send the api to the 'source parameter'?

versed timber
#

Looking in to these...

#

You are right on the second one. With that setup you can use that token.

#

And can you use other stripe methods with java at all? Is it just Charge related things that you can't see?

sleek gate
#

When I call the Charge.create function, an error is thrown. I don't know how to import the Charge class.

sleek gate
chrome thorn
#

What error is thrown?

sleek gate
chrome thorn
#

And you've already installed the Stripe-java library? A direct copy-paste of the exact error message you're seeing would be helpful!

sleek gate
#

MainActivity.java:42: error: cannot find symbol
Charge charge = Charge.create(params);
^
symbol: class Charge
location: class MainActivity

#

import com.stripe.Stripe;
import java.util.HashMap;
import java.util.Map;

those are my imports

#

implementation "com.stripe:stripe-java:20.75.0"

the dependency in my build.gradle

chrome thorn
#

and what happens if you also import the following:

import com.stripe.model.*;
import com.stripe.param.*;
sleek gate
#

error: unreported exception StripeException; must be caught or declared to be thrown
Charge charge = Charge.create(params);
^
1 error

chrome thorn
#

So that tells you you need to catch the exception

sleek gate
#

So I simply need to work out the usual error handling? Oh Thank you.

chrome thorn
#

Yes, it wasn't working earlier since you didn't have the correct imports.

sleek gate
#

@chrome thorn @versed timber thank you for helping me out.

chrome thorn
#

Now that you have them, you just need to fix your error handling and make sure you keep the imports up to date

sleek gate
#

Really appreciate your time.

sleek gate
chrome thorn
#

Is there a specific reason you're trying to integrate directly with Google Pay? I only ask because this is a MUCH more complicated integration path

chrome thorn
#

You haven't responded for a while so I'm going to archive this thread - if you come back later and need help please ask for someone to reopen your thread in the main channel and we can continue from there!!

sleek gate
drifting coral
#

Hey @sleek gate karbi is offline so I will try to catch up. Please wait for a wile

sleek gate
#

Sure. No problem.

drifting coral
#

Okie I think I got it from here. Yes you now can use that token to Charge create method

#

Just to be sure, does your token start with "tok_"?

sleek gate
drifting coral
#

Sure

drifting coral
#

I think the token is a string already? Then you should be good to directly use it. The ideal way to confirm if it is a correct token, is checking if it starts by "tok_"

sleek gate
#

Okay. Makes sense. I'll do that. Thank you so much for the support. Appreciate your time.

drifting coral
#

Oh but if it is something like ('examplePaymentToken'), then you may want to strip out that ( or '. Just make sure the check the value you got