This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plg): Add new Checkout flow that uses Stripe's
createToken
API (…
- Loading branch information
Showing
17 changed files
with
625 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
client/web/src/cody/management/subscription/StripeAddressElement.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { useMemo } from 'react' | ||
|
||
import { AddressElement } from '@stripe/react-stripe-js' | ||
import type { StripeAddressElementOptions } from '@stripe/stripe-js' | ||
|
||
import type { Subscription } from '../api/types' | ||
|
||
interface StripeAddressElementProps { | ||
subscription?: Subscription | ||
onFocus?: () => void | ||
} | ||
|
||
export const StripeAddressElement: React.FC<StripeAddressElementProps> = ({ subscription, onFocus }) => { | ||
const options = useMemo( | ||
(): StripeAddressElementOptions => ({ | ||
mode: 'billing', | ||
display: { name: 'full' }, | ||
...(subscription | ||
? { | ||
defaultValues: { | ||
name: subscription.name, | ||
address: { | ||
...subscription.address, | ||
postal_code: subscription.address.postalCode, | ||
}, | ||
}, | ||
} | ||
: {}), | ||
autocomplete: { mode: 'automatic' }, | ||
}), | ||
[subscription] | ||
) | ||
|
||
return <AddressElement options={options} onFocus={onFocus} /> | ||
} |
62 changes: 62 additions & 0 deletions
62
client/web/src/cody/management/subscription/StripeCardDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { useCallback } from 'react' | ||
|
||
import { CardNumberElement, CardExpiryElement, CardCvcElement } from '@stripe/react-stripe-js' | ||
import type { StripeCardElementOptions } from '@stripe/stripe-js' | ||
|
||
import { useTheme, Theme } from '@sourcegraph/shared/src/theme' | ||
import { Label, Text, Grid } from '@sourcegraph/wildcard' | ||
|
||
const useCardElementOptions = (): ((type: 'number' | 'expiry' | 'cvc') => StripeCardElementOptions) => { | ||
const { theme } = useTheme() | ||
|
||
return useCallback( | ||
(type: 'number' | 'expiry' | 'cvc') => ({ | ||
...(type === 'number' ? { disableLink: true } : {}), | ||
|
||
classes: { | ||
base: 'form-control py-2', | ||
focus: 'focus-visible', | ||
invalid: 'is-invalid', | ||
}, | ||
|
||
style: { | ||
base: { | ||
color: theme === Theme.Light ? '#262b38' : '#dbe2f0', | ||
}, | ||
}, | ||
}), | ||
[theme] | ||
) | ||
} | ||
|
||
interface StripeCardDetailsProps { | ||
onFocus?: () => void | ||
className?: string | ||
} | ||
|
||
export const StripeCardDetails: React.FC<StripeCardDetailsProps> = ({ onFocus, className }) => { | ||
const getOptions = useCardElementOptions() | ||
|
||
return ( | ||
<div className={className}> | ||
<div> | ||
<Label className="d-block"> | ||
<Text className="mb-2">Card number</Text> | ||
<CardNumberElement options={getOptions('number')} onFocus={onFocus} /> | ||
</Label> | ||
</div> | ||
|
||
<Grid columnCount={2} className="mt-3 mb-0 pb-3"> | ||
<Label className="d-block"> | ||
<Text className="mb-2">Expiry date</Text> | ||
<CardExpiryElement options={getOptions('expiry')} onFocus={onFocus} /> | ||
</Label> | ||
|
||
<Label className="d-block"> | ||
<Text className="mb-2">CVC</Text> | ||
<CardCvcElement options={getOptions('cvc')} onFocus={onFocus} /> | ||
</Label> | ||
</Grid> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.