@stripe/stripe-js#loadStripe TypeScript Examples
The following examples show how to use
@stripe/stripe-js#loadStripe.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From livepeer-com with MIT License | 6 votes |
getStripe = () => {
const key = process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY;
if (!key) {
return Promise.resolve(null);
}
if (!stripePromise) {
stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY);
}
return stripePromise;
}
Example #2
Source File: SepaPaymentContainer.tsx From rcvr-app with GNU Affero General Public License v3.0 | 6 votes |
SepaPaymentContainer: React.FC = () => {
const [loading, setLoading] = React.useState(true)
const [stripeSetup, setStripeSetup] = React.useState<StripeSetup>()
const [error, setError] = React.useState()
const initializeStripe = React.useCallback(async () => {
try {
const [stripe, intent] = await Promise.all([
loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY),
postOwnerStripeIntent(),
])
setStripeSetup({ stripe, intent: intent.id })
} catch (e) {
setError(e)
} finally {
setLoading(false)
}
}, [])
React.useEffect(() => {
initializeStripe()
}, [initializeStripe])
return (
<>
{loading && <Loading show />}
{error && <div>{error}</div>}
{stripeSetup && (
<Elements stripe={stripeSetup.stripe}>
<SepaPayment intent={stripeSetup.intent} />
</Elements>
)}
</>
)
}
Example #3
Source File: index.tsx From Demae with MIT License | 5 votes |
stripePromise = loadStripe(STRIPE_API_KEY)
Example #4
Source File: index.tsx From Demae with MIT License | 5 votes |
stripePromise = loadStripe(STRIPE_API_KEY)
Example #5
Source File: App.tsx From platform with MIT License | 5 votes |
stripePromise = loadStripe(STRIPE_KEY)
Example #6
Source File: CheckoutForm.tsx From defund12.org with MIT License | 5 votes |
stripePromise = loadStripe(stripePk)
Example #7
Source File: constants.ts From roamjs-com with MIT License | 5 votes |
stripe = loadStripe(
process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY || ""
)
Example #8
Source File: Billing.tsx From glific-frontend with GNU Affero General Public License v3.0 | 5 votes |
stripePromise = loadStripe(STRIPE_PUBLISH_KEY)
Example #9
Source File: getStripe.ts From ultimate-saas-ts with MIT License | 5 votes |
getStripe = () => {
if (!stripePromise) {
stripePromise = loadStripe(config.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY);
}
return stripePromise;
}
Example #10
Source File: SubscribeModal.tsx From watchparty with MIT License | 5 votes |
stripePromise = process.env.REACT_APP_STRIPE_PUBLIC_KEY
? loadStripe(process.env.REACT_APP_STRIPE_PUBLIC_KEY as string)
: null
Example #11
Source File: constants.ts From app-stormkit-io with GNU General Public License v3.0 | 5 votes |
stripePromise = loadStripe(process.env.STRIPE_API_KEY || "")
Example #12
Source File: get-stripejs.ts From nextjs-typescript-react-stripe-js with MIT License | 5 votes |
getStripe = () => {
if (!stripePromise) {
stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY!);
}
return stripePromise;
}
Example #13
Source File: profile.tsx From rcvr-app with GNU Affero General Public License v3.0 | 4 votes |
ProfilePage: React.FC<WithOwnerProps> = ({ owner }) => {
const { t } = usePageLocale('business/profile')
const [redirecting, setRedirecting] = React.useState(false)
const { data: companies } = useCompanies()
const { query } = useRouter()
const status = React.useMemo(() => {
if (query.success?.toString() === 'true') return 'success'
}, [query])
const didOpenSuccessModal = React.useRef(false)
const { modals, openModal } = useModals({
checkoutSelection: CheckoutSelectionModal,
success: SubscribedModal,
editOwner: OwnerModal,
})
React.useEffect(() => {
if (didOpenSuccessModal.current) return
if (status === 'success') {
didOpenSuccessModal.current = true
openModal('success')
}
}, [status, openModal])
const openStripeCheckout = React.useCallback(async () => {
try {
setRedirecting(true)
const stripe = await loadStripe(
process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
)
const checkout = await postOwnerCheckout()
stripe.redirectToCheckout({ sessionId: checkout.id })
} catch (error) {
setRedirecting(false)
console.error(error)
}
}, [])
const openCheckout = () => {
const props: CheckoutSelectionModalProps = {
locales: {
title: t('checkoutSelectionModalTitle'),
stripeButtonText: t('checkoutSelectionModalStripeButtonText'),
sepaDebitButtonText: t('checkoutSelectionModalSepaButtonText'),
},
openStripeCheckout,
}
openModal('checkoutSelection', props as any)
}
const openEditOwner = () => {
const props: OwnerFormProps = {
owner,
locales: {
nameLabel: t('nameLabel'),
nameRequired: t('nameRequired'),
phoneLabel: t('phoneLabel'),
phoneInvalid: t('phoneInvalid'),
phoneRequired: t('phoneRequired'),
cityLabel: t('cityLabel'),
cityRequired: t('cityRequired'),
streetLabel: t('streetLabel'),
streetRequired: t('streetRequired'),
zipLabel: t('zipLabel'),
zipRequired: t('zipRequired'),
companyNameLabel: t('companyNameLabel'),
companyNameRequired: t('companyNameRequired'),
/**/
editProfile: t('editProfile'),
submitButton: t('ownerModalSubmitButton'),
},
}
openModal('editOwner', props as any)
}
const openSelfService = React.useCallback(async () => {
try {
setRedirecting(true)
const { url } = await postOwnerSubscription()
window.location.href = url
} catch (error) {
setRedirecting(false)
console.error(error)
}
}, [])
const hasCompanies = React.useMemo(() => companies?.length > 0, [companies])
const hasSubscription = React.useMemo(() => {
const states = ['trialing', 'active', 'incomplete']
const isSubscribed = states.includes(owner.stripeSubscriptionStatus)
return isSubscribed || owner.canUseForFree
}, [owner])
return (
<OwnerApp title={t('pageTitle')}>
{modals}
<Loading show={redirecting} />
<Button
onClick={() => openEditOwner()}
right={<ArrowsRight color="green" />}
>
{t('editProfile')}
</Button>
<Divider />
<Text as="h3" variant="h2">
{t('myMembership')}
</Text>
<Box height={4} />
{hasCompanies ? (
<SubscriptionMessage owner={owner} />
) : (
<Callout>
<Text>{t('hasNoCompaniesMessage')}</Text>
</Callout>
)}
<Box height={4} />
{!hasSubscription && hasCompanies && (
<>
<Text>
<PricingInfoDuringTest />
</Text>
<Box height={4} />
{isHealthEnv || isCareEnv ? (
<Text>
<p>{t('writeEmailMessage')}</p>
<p>
<RecoverTeamEmailLink>
<Button right={<ArrowsRight color="pink" />}>
{t('writeEmailButtonText')}
</Button>
</RecoverTeamEmailLink>
</p>
</Text>
) : (
<Button
onClick={() => openCheckout()}
right={<ArrowsRight color="pink" />}
>
{t('upgradeNow')}
</Button>
)}
</>
)}
{hasSubscription && !owner.canUseForFree && (
<>
<ActionList grid>
<ActionCard onClick={() => openCheckout()}>
<ActionCard.Main
title={t('hasSubscriptionNotForFreeCardTitle1')}
icon={Right}
/>
</ActionCard>
</ActionList>
<Divider />
<ActionList grid>
<ActionCard onClick={openSelfService}>
<ActionCard.Main
title={t('hasSubscriptionNotForFreeCardTitle2')}
icon={Right}
/>
</ActionCard>
<div />
</ActionList>
<Box height={4} />
<Text variant="shy">{t('hasSubscriptionNotForFreeMessage')}</Text>
</>
)}
<Box height={10} />
<Text textAlign={['center', 'center', 'left']}>
<Link href="/business/logout" passHref>
<Text variant="h5" as="a" color="bluegrey.400">
{t('logout')}
</Text>
</Link>
</Text>
</OwnerApp>
)
}