MCPcopy Create free account
hub / github.com/stripe/stripe-react-native / fetchCheckoutSessionParams

Function fetchCheckoutSessionParams

example/src/api/checkoutSession.ts:117–149  ·  view source on GitHub ↗
(
  config: CheckoutPlaygroundConfig
)

Source from the content-addressed store, hash-verified

115}
116
117export async function fetchCheckoutSessionParams(
118 config: CheckoutPlaygroundConfig
119): Promise<CheckoutSessionResponse> {
120 if (normalizePaymentMethodTypes(config.paymentMethodTypes).length === 0) {
121 throw new Error('Select at least one payment method.');
122 }
123
124 const response = await fetch(hostedCheckoutEndpoint, {
125 method: 'POST',
126 headers: {
127 'Content-Type': 'application/json',
128 },
129 body: JSON.stringify(buildCheckoutSessionRequestBody(config)),
130 });
131
132 const responseBody = await parseCheckoutSessionResponseBody(response);
133
134 if (!response.ok) {
135 throw new Error(
136 getCheckoutSessionErrorMessage(responseBody) ||
137 'Failed to create checkout session.'
138 );
139 }
140
141 if (!isCheckoutSessionResponse(responseBody)) {
142 throw new Error('Checkout session response was missing required fields.');
143 }
144
145 return {
146 publishableKey: responseBody.publishableKey,
147 checkoutSessionClientSecret: responseBody.checkoutSessionClientSecret,
148 };
149}

Callers 1

CheckoutScreenFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…