#jrietz-applepay
1 messages ยท Page 1 of 1 (latest)
heya @timid fable ! could you elaborate on what kind of problem/issue you're facing? Do you get an error message?
I am trying to run this function to just authenticate using the stripe-react-native library.
`import { Alert } from 'react-native';
import { API_URL } from './Config';
export async function fetchPublishableKey(
paymentMethod?: string
): Promise<string | null> {
try {
const response = await fetch(
${API_URL}/stripe-key?paymentMethod=${paymentMethod}
);
const { publishableKey } = await response.json();
return publishableKey;
} catch (e) {
console.warn('Unable to fetch publishable key. Is your server running?');
Alert.alert(
'Error',
'Unable to fetch publishable key. Is your server running?'
);
return null;
}
}`
The error I get is "Unable to fetch publishable key. Is your server running?"
I think the issue is that I am providing the key wrong in some way
But this is basically the underlying error that I get:
{ "error": { "message": "You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY'). See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/.", "type": "invalid_request_error" } }
@timid fable the publishable key is provided as a value in StripeProvider https://github.com/stripe/stripe-react-native#usage-example
i'm baffled as to why you're fetching the publishable key via the API?
or is that a naming issue?
aren't you using the stripe-react-native sdk?
Yes
ah okay, so what's the value of response?
If on local server it's basically only my sk_test
Yes exactly
I know, that's why it is weird
Sorry
Was looking at the wrong print
Yes it is pk_test, my bad
so it's returning pk_test?
Yes
the request to retrieve your publishable key is to your server correct?
Yes
then can you check your server code to see why is it returning the publishable key
if you don't want to retrieve the publishable key from your server, then you can set it
function App() {
// ...
useEffect(() => {
initStripe({
publishableKey: publishableKey
merchantIdentifier: 'merchant.identifier',
});
}, []);
}
Yeah I mean that's probably the only thing I need to do. The goal is to be able to just run the same flow to the remote server as I do in the example with the local server. I just need to initialise it in a good way. I tried the above in the "usage-example" but the "fetchKey()" function wasn't usable as I assume it's a function you create yourself. I just started with this yesterday and am not an app developer so I am still learning the skills. Will try again with the initStripe to just set the publishable key
Thank you for your support so far ๐
feel free to reach out if you have any other questions! ๐