#jrietz-applepay

1 messages ยท Page 1 of 1 (latest)

devout violet
#

heya @timid fable ! could you elaborate on what kind of problem/issue you're facing? Do you get an error message?

timid fable
#

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" } }

devout violet
#

i'm baffled as to why you're fetching the publishable key via the API?

#

or is that a naming issue?

timid fable
#

Are you referring to the code above?

#

Because that's how that example is coded

devout violet
#

aren't you using the stripe-react-native sdk?

timid fable
#

Yes

devout violet
#

which documentation is this example from?

#

could you point me to that page?

timid fable
devout violet
#

ah okay, so what's the value of response?

timid fable
#

If on local server it's basically only my sk_test

devout violet
#

the publishable key starts with pk_test

#

sk_test is the secret key

timid fable
#

Yes exactly

#

I know, that's why it is weird

#

Sorry

#

Was looking at the wrong print

#

Yes it is pk_test, my bad

devout violet
#

so it's returning pk_test?

timid fable
#

Yes

devout violet
#

the request to retrieve your publishable key is to your server correct?

timid fable
#

Yes

devout violet
#

then can you check your server code to see why is it returning the publishable key

timid fable
#

So I am wondering if it's possible to just point the URL to a remote one

#

One sec

devout violet
#

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',
    });
  }, []);
}
timid fable
#

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 ๐Ÿ™‚

devout violet
#

feel free to reach out if you have any other questions! ๐Ÿ˜„