#JRietz-client-secret

1 messages ยท Page 1 of 1 (latest)

ashen moon
#

"I am currently creating a payment_intent in the stripe-react-native SDK using a PK" -> can you speak a little more on this? You should only be able to create Payment Intents with a secret key?

radiant crown
#

So maybe that is the issue then? If I just provide my sk instead of pk it will give me the correct response as it will be secret and not publishable?

ashen moon
#

That could be the issue, but do you have a request ID I could take a look at?

radiant crown
#

You mean in the Dashboard logs?

#

req_dQEcuAV1O0yu24

#

This one

ashen moon
#

๐Ÿ‘ thank you!

radiant crown
#

That was for the payment_method

#

This one is for payment_intent: req_OkgIiawWEhCXmC

#

But I should always initialise Stripe with the PK right?

ashen moon
#

For your client-side requests, yes, you should be using the PK!

#

req_OkgIiawWEhCXmC is a request to list Payment Intents for a particular customer, it's not actually creating any payment intent

radiant crown
#

ahaaa

ashen moon
#

Out of curiousity, have you logged what the secret is before whatever line in your code is hitting the error?

radiant crown
#

Nope I haven't, but I was about to actually

radiant crown
ashen moon
radiant crown
#

I get the assert in the swift code but I think the reason it fails is because the client secret isn't valid

#

It happens here in the else statement:
if publishableKeyIsUserKey { assert( secret.hasPrefix("pi_"), "secret format does not match expected identifer formatting.") endpoint = "\(APIEndpointPaymentIntents)/\(secret)" } else { assert( STPPaymentIntentParams.isClientSecretValid(secret), "secret format does not match expected client secret formatting.") let identifier = STPPaymentIntent.id(fromClientSecret: secret) ?? "" endpoint = "\(APIEndpointPaymentIntents)/\(identifier)" parameters["client_secret"] = secret }

ashen moon
#

And what did you see when you printed it out?

radiant crown
#

undefined

#

Where would it be suitable to provide the SK?

#

I can obviously do it when using curl but it's a bit different when using TypeScript

#

Would I provide it in the Header?

ashen moon
#

The SK is something you should only be using from your server, not client-side at all.

radiant crown
#

Yeah

#

Thought so

#

`const fetchPaymentIntentClientSecret = async () => {
const response = await fetch('https://api.stripe.com/v1/payment_intents', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
currency: 'sek',
items: cart,
force3dSecure: true,
}),
});
const { clientSecret } = await response.json();
console.log(clientSecret);

return clientSecret;

};`

#

This is what triggers the issue, I am afraid the response is incorrect

ashen moon
radiant crown
#

Got it, mainly for security reasons eh?

ashen moon
#

yeah... you don't want folks to be able to just take your publishable key and use it to create payments on your account

radiant crown
#

Yeah that makes sense of course, I just started developing on Stripe yesterday so still learning a bit. But then I basically keep the server as it is in the example and just provide my secret key and it should be alright

ashen moon
#

Very understandable - all this can get very confusing! Are you looking at the example in the docs I linked, or a different one?

radiant crown
#

I am looking at the stripe-reaact-native-sdk example

ashen moon
#

๐Ÿ‘ Gotcha, then yes that server example should be a great starting point to get the basic flow working for you

radiant crown
#

Yupp I got it working with complete payments on my simulator but got some issues on my real device, thought it had something to do with my server request to the API so I started to experiment a bit there and ended up here ๐Ÿ˜„

#

But I think my issue was something else, going back to the local server configuration now and testing it again.

#

But when running this on production, do I have to spin up my local server on some service, hosting it on firebase for example? We already have stripe payments integrated but I wanted to add Apple Pay to our offering

ashen moon
#

Yes, when you run this in production you need some kind of server to get this whole flow working (firebase should work fine!)

radiant crown
#

Yeah, on my real device I still don't manage to connect to the server though. I only get through to initialising Apple Pay if I provide the PK manually

ashen moon
#

I need to head out, but @sacred salmon can help you out!

#

@radiant crown can you clarify - is your current issue that Apple Pay isn't working on a real device? are you hitting the same errors (bad client secret format) that you mentioned before?

radiant crown
#

Yes it is not working on a real device but since I went back to trying to connect to my local server, I am getting socket issues instead. Seems like it's my server that is not accepting connections.

#

I think this issue is mainly because my phone does not have access to my local host. Which makes sense

sacred salmon
#

Yes that will do it

#

Apple Pay doesn't play nice with local host anyways

radiant crown
#

Yeah because I assume that my example server just automatically utilises localhost as it intends to just work with the simulator anyways?

#

Nice, trying it out now. Forwarded my localhost to a public web interface

sacred salmon
#

Sounds good let me know how it goes!

radiant crown
#

It worked ๐Ÿ˜„

sacred salmon
#

Awesome!

radiant crown
#

Thanks for the help!

sacred salmon
#

Of course! Always happy to help