#greatBear-keys

1 messages · Page 1 of 1 (latest)

golden otter
#

hi! validate them how exactly? Generally this is just static configuration you set once, you'd know if the keys are wrong as you'll get errors calling functions in our library and customers won't be able to pay

feral dagger
#

new \Stripe\StripeClient([
"api_key" => $api_key,
"stripe_version" => self::STRIPE_VERSION,
]);
this code does not validate the api key

#

Sure the function checks if the api key is not an empty string. But does not make a call to stripe server to validate its existance

golden otter
#

yep!

feral dagger
#

Only when use of the API for example creating a product or retrieving etc would you get an error

golden otter
#

yep! so you probably want to try/catch those calls to robustly handle errors like logging them and alerting you

feral dagger
#

here is the use case. My site fetches all payment gateways of Download Monitor - a e-commerce plugin for software.

#

I created a Stripe extension for it. On the checkout page Download Monitor creates a html element for each payment gateway.

#

It is no use rendering Stripe if the api keys are invalid

golden otter
#

not sure what else I can add really to what I already answered

feral dagger
#

So I was wondering if there is a way to validate the keys. If they are incorrect Download Monitor would skip rendering

golden otter
#

why would you have invalid keys in the first place?

#

it's a plugin where your user pastes their API key into it? and they might get it wrong?

feral dagger
#

human error

golden otter
#

if so then ok, do something simple like call GET /v1/customers with the key and see if it errors really

#

lots of options

feral dagger
#

Yeah that would work. I just wanted to know if there was exclusively a function that validates the api keys.

#

But that doesnt seem to be the case.

#

One more thing concerning error handling

#

Why dont errors have unique codes to identify them by?

#

It would be very handy if a code # is given to identify which error it is. This helps with my selection of localized error messages to display

#

There is a code property in the Event object. But its almost always empty

golden otter
#

they do have codes, that's what the code field of the error object is

feral dagger
#

like I said they are almost always empty

golden otter
#

yep, you are right there

#

that's feedback we raise to the product teams often but a lot of APIs get built without having proper codes returned

#

I agree with you and wish every single error returned a code consistently and all codes were documented with explicit "this is how you should react" steps, that's not the case today but is a work in progress

feral dagger
#

In other words I have to check the HTTP header response

golden otter
#

not really, all the information is in the PHP exception object as the docs describe

feral dagger
#

Well as a coder you should be able to figure out stuff on your own. But some details on the type of errors makes it easier to work with. Now Im not sure what errors each API generates (read error string). Hanling errors is now a it harder in relation to what localized string to display to the admin. I cant just use the error message generated by the API, since sometimes it contains unneccesary/unwanted details.