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 typed createFetchHttpClient function. #1273

Merged
merged 2 commits into from
Oct 18, 2021
Merged

Add typed createFetchHttpClient function. #1273

merged 2 commits into from
Oct 18, 2021

Conversation

dcr-stripe
Copy link
Contributor

@dcr-stripe dcr-stripe commented Oct 15, 2021

Notify

r? @richardm-stripe

Summary

Adds a createFetchHttpClient function similar to createNodeHttpClient and expose this on the Stripe object. This lets us type the client creation and eliminate an extra import in code while also not forcing all code to require the FetchHttpClient unless needed.

Implementation change

This changes:

const Stripe = require("stripe");
const { FetchHttpClient } = require('stripe/lib/net/FetchHttpClient')

const stripe = Stripe("...", {
  httpClient: new FetchHttpClient()
});

to:

const Stripe = require("stripe");

const stripe = Stripe("...", {
  httpClient: Stripe.createFetchHttpClient(fetch),
});

Test plan

Updated typescript tests. Also confirmed that this doesn't interfere with regular node implementations by cloning https://github.com/stripe-samples/accept-a-payment/tree/main/custom-payment-flow/server/node-typescript, pointing it to this branch, and making sure typescript compiles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants