Rocky_Mountain_Vending/.pnpm-store/v10/files/4e/0027365ba98d32aec1979983c07127719b5670860d1d77c90dac79e30a3ffbe430496c656db4079f6dda5429a9c57222313a13fb326e596c7a4efc398711d0
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

54 lines
1.2 KiB
Text

import {
validateLoadParams,
loadScript,
initStripe,
LoadStripe,
LoadParams,
} from './shared';
type SetLoadParams = (params: LoadParams) => void;
let loadParams: null | LoadParams;
let loadStripeCalled = false;
export const loadStripe: LoadStripe & {setLoadParameters: SetLoadParams} = (
...args
) => {
loadStripeCalled = true;
const startTime = Date.now();
return loadScript(loadParams).then((maybeStripe) =>
initStripe(maybeStripe, args, startTime)
);
};
loadStripe.setLoadParameters = (params): void => {
// we won't throw an error if setLoadParameters is called with the same values as before
if (loadStripeCalled && loadParams) {
const validatedParams = validateLoadParams(params);
const parameterKeys = Object.keys(validatedParams) as Array<
keyof LoadParams
>;
const sameParameters = parameterKeys.reduce(
(previousValue, currentValue) => {
return (
previousValue && params[currentValue] === loadParams?.[currentValue]
);
},
true
);
if (sameParameters) {
return;
}
}
if (loadStripeCalled) {
throw new Error(
'You cannot change load parameters after calling loadStripe'
);
}
loadParams = validateLoadParams(params);
};