stripe.tsx 544 B

1234567891011121314151617181920
  1. /**
  2. * Ensures Stripe JS is only loaded once
  3. */
  4. export const loadStripe = (onload?: (stripe: any) => void) => {
  5. // its likely already loaded at this point as its hooked in
  6. // our standard layout.html
  7. if ('Stripe' in window) {
  8. return onload?.(window.Stripe);
  9. }
  10. const script = document.createElement('script');
  11. script.async = true;
  12. script.src = 'https://js.stripe.com/v3/';
  13. script.onload = () => {
  14. document.body.removeChild(script);
  15. onload?.(window.Stripe);
  16. };
  17. return void document.body.appendChild(script);
  18. };