Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing key warning to README #2238

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,39 @@ const customer = await stripe.customers.create({
console.log(customer.id);
```

> [!WARNING]
> If you're using `v17.x.x` or later and getting an error about a missing API key despite being sure it's available, it's likely you're importing the file that instantiates `Stripe` while the key isn't present (for instance, during a build step).
> If that's the case, consider instantiating the client lazily:
>
> ```ts
> import Stripe from 'stripe';
>
> let _stripe: Stripe | null = null;
> const getStripe = (): Stripe => {
> if (!_stripe) {
> _stripe = new Stripe(process.env.STRIPE_SECRET_KEY as string, {
> // ...
> });
> }
> return _stripe;
> };
>
> const getCustomers = () => getStripe().customers.list();
> ```
>
> Alternatively, you can provide a placeholder for the real key (which will be enough to get the code through a build step):
>
> ```ts
> import Stripe from 'stripe';
>
> export const stripe = new Stripe(
> process.env.STRIPE_SECRET_KEY || 'api_key_placeholder',
> {
> // ...
> }
> );
> ```

### Usage with TypeScript

As of 8.0.1, Stripe maintains types for the latest [API version][api-versions].
Expand Down Expand Up @@ -197,7 +230,7 @@ const stripe = Stripe('sk_test_...', {
| `host` | `'api.stripe.com'` | Host that requests are made to. |
| `port` | 443 | Port that requests are made to. |
| `protocol` | `'https'` | `'https'` or `'http'`. `http` is never appropriate for sending requests to Stripe servers, and we strongly discourage `http`, even in local testing scenarios, as this can result in your credentials being transmitted over an insecure channel. |
| `telemetry` | `true` | Allow Stripe to send [telemetry](#telemetry). |
| `telemetry` | `true` | Allow Stripe to send [telemetry](#telemetry). |

> **Note**
> Both `maxNetworkRetries` and `timeout` can be overridden on a per-request basis.
Expand Down Expand Up @@ -543,14 +576,13 @@ const stripe = new Stripe('sk_test_...');
const response = await stripe.rawRequest(
'POST',
'/v1/beta_endpoint',
{ param: 123 },
{ apiVersion: '2022-11-15; feature_beta=v3' }
{param: 123},
{apiVersion: '2022-11-15; feature_beta=v3'}
);

// handle response
```


## Support

New features and bug fixes are released on the latest major version of the `stripe` package. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.
Expand Down
Loading