Skip to content

Commit 02d5b6b

Browse files
feat: Cut over to Stripe PaymentElement (#3665)
1 parent 371a218 commit 02d5b6b

File tree

17 files changed

+629
-86
lines changed

17 files changed

+629
-86
lines changed

src/assets/billing/bank.svg

Lines changed: 10 additions & 0 deletions
Loading

src/pages/PlanPage/PlanPage.jsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ import config from 'config'
88

99
import { SentryRoute } from 'sentry'
1010

11+
import { Theme, useThemeContext } from 'shared/ThemeContext'
1112
import LoadingLogo from 'ui/LoadingLogo'
1213

1314
import { PlanProvider } from './context'
1415
import PlanBreadcrumb from './PlanBreadcrumb'
1516
import { PlanPageDataQueryOpts } from './queries/PlanPageDataQueryOpts'
1617
import Tabs from './Tabs'
1718

19+
import { StripeAppearance } from '../../stripe'
20+
1821
const CancelPlanPage = lazy(() => import('./subRoutes/CancelPlanPage'))
1922
const CurrentOrgPlan = lazy(() => import('./subRoutes/CurrentOrgPlan'))
2023
const InvoicesPage = lazy(() => import('./subRoutes/InvoicesPage'))
@@ -37,6 +40,8 @@ function PlanPage() {
3740
const { data: ownerData } = useSuspenseQueryV5(
3841
PlanPageDataQueryOpts({ owner, provider })
3942
)
43+
const { theme } = useThemeContext()
44+
const isDarkMode = theme !== Theme.LIGHT
4045

4146
if (config.IS_SELF_HOSTED || !ownerData?.isCurrentUserPartOfOrg) {
4247
return <Redirect to={`/${provider}/${owner}`} />
@@ -45,7 +50,15 @@ function PlanPage() {
4550
return (
4651
<div className="flex flex-col gap-4">
4752
<Tabs />
48-
<Elements stripe={stripePromise}>
53+
<Elements
54+
stripe={stripePromise}
55+
options={{
56+
...StripeAppearance(isDarkMode),
57+
// mode and currency are required for the PaymentElement
58+
mode: 'setup',
59+
currency: 'usd',
60+
}}
61+
>
4962
<PlanProvider>
5063
<PlanBreadcrumb />
5164
<Suspense fallback={<Loader />}>

src/pages/PlanPage/PlanPage.test.jsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { MemoryRouter, Route } from 'react-router-dom'
1111

1212
import config from 'config'
1313

14+
import { ThemeContextProvider } from 'shared/ThemeContext'
15+
1416
import PlanPage from './PlanPage'
1517

1618
vi.mock('config')
@@ -44,18 +46,20 @@ const wrapper =
4446
({ children }) => (
4547
<QueryClientProviderV5 client={queryClientV5}>
4648
<QueryClientProvider client={queryClient}>
47-
<Suspense fallback={null}>
48-
<MemoryRouter initialEntries={[initialEntries]}>
49-
<Route path="/plan/:provider/:owner">{children}</Route>
50-
<Route
51-
path="*"
52-
render={({ location }) => {
53-
testLocation = location
54-
return null
55-
}}
56-
/>
57-
</MemoryRouter>
58-
</Suspense>
49+
<ThemeContextProvider>
50+
<Suspense fallback={null}>
51+
<MemoryRouter initialEntries={[initialEntries]}>
52+
<Route path="/plan/:provider/:owner">{children}</Route>
53+
<Route
54+
path="*"
55+
render={({ location }) => {
56+
testLocation = location
57+
return null
58+
}}
59+
/>
60+
</MemoryRouter>
61+
</Suspense>
62+
</ThemeContextProvider>
5963
</QueryClientProvider>
6064
</QueryClientProviderV5>
6165
)

src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/Address/AddressCard.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ describe('AddressCard', () => {
224224
{ wrapper }
225225
)
226226

227-
expect(screen.getByText('Cardholder name')).toBeInTheDocument()
227+
expect(screen.getByText('Full name')).toBeInTheDocument()
228228
expect(screen.getByText('N/A')).toBeInTheDocument()
229229
expect(screen.getByText('Billing address')).toBeInTheDocument()
230230
expect(screen.queryByText(/null/)).not.toBeInTheDocument()
@@ -241,7 +241,7 @@ describe('AddressCard', () => {
241241
{ wrapper }
242242
)
243243

244-
expect(screen.getByText(/Cardholder name/)).toBeInTheDocument()
244+
expect(screen.getByText(/Full name/)).toBeInTheDocument()
245245
expect(screen.getByText(/Bob Smith/)).toBeInTheDocument()
246246
})
247247
})

src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/Address/AddressCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function AddressCard({
4040
{!isFormOpen && (
4141
<>
4242
<div className="flex justify-between">
43-
<h4 className="font-semibold">Cardholder name</h4>
43+
<h4 className="font-semibold">Full name</h4>
4444
<A
4545
variant="semibold"
4646
onClick={() => setIsFormOpen(true)}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { z } from 'zod'
2+
3+
import bankLogo from 'assets/billing/bank.svg'
4+
import { USBankAccountSchema } from 'services/account'
5+
6+
interface BankInformationProps {
7+
usBankAccount: z.infer<typeof USBankAccountSchema>
8+
nextBillingDisplayDate: string | null
9+
}
10+
11+
function BankInformation({
12+
usBankAccount,
13+
nextBillingDisplayDate,
14+
}: BankInformationProps) {
15+
return (
16+
<div className="flex flex-col gap-3">
17+
<div className="flex gap-2">
18+
<img src={bankLogo} alt="bank logo" />
19+
<div className="ml-1 flex flex-col self-center">
20+
<b>
21+
{usBankAccount?.bankName}
22+
&nbsp;••••&nbsp;
23+
{usBankAccount?.last4}
24+
</b>
25+
</div>
26+
</div>
27+
{nextBillingDisplayDate && (
28+
<p className="text-sm text-ds-gray-quinary">
29+
Your next billing date is{' '}
30+
<span className="text-ds-gray-octonary">
31+
{nextBillingDisplayDate}
32+
</span>
33+
.
34+
</p>
35+
)}
36+
</div>
37+
)
38+
}
39+
40+
export default BankInformation

src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/CardInformation.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ CardInformation.propTypes = {
7676
expMonth: PropTypes.number.isRequired,
7777
expYear: PropTypes.number.isRequired,
7878
}).isRequired,
79-
openForm: PropTypes.func.isRequired,
8079
}
8180

8281
export default CardInformation

src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentCard.jsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,59 @@ import PropTypes from 'prop-types'
22
import { useState } from 'react'
33

44
import { subscriptionDetailType } from 'services/account'
5+
import { formatTimestampToCalendarDate } from 'shared/utils/billing'
56
import A from 'ui/A'
67
import Button from 'ui/Button'
78
import Icon from 'ui/Icon'
89

10+
import BankInformation from './BankInformation'
911
import CardInformation from './CardInformation'
10-
import CreditCardForm from './CreditCardForm'
12+
import PaymentMethodForm from './PaymentMethodForm'
1113
function PaymentCard({ subscriptionDetail, provider, owner }) {
1214
const [isFormOpen, setIsFormOpen] = useState(false)
1315
const card = subscriptionDetail?.defaultPaymentMethod?.card
16+
const usBankAccount = subscriptionDetail?.defaultPaymentMethod?.usBankAccount
17+
18+
let nextBillingDisplayDate = null
19+
if (!subscriptionDetail?.cancelAtPeriodEnd) {
20+
nextBillingDisplayDate = formatTimestampToCalendarDate(
21+
subscriptionDetail?.currentPeriodEnd
22+
)
23+
}
1424

1525
return (
16-
<div className="flex flex-col gap-2 border-t p-4">
26+
<div className="flex flex-col gap-3 border-t p-4">
1727
<div className="flex justify-between">
1828
<h4 className="font-semibold">Payment method</h4>
1929
{!isFormOpen && (
2030
<A
2131
variant="semibold"
2232
onClick={() => setIsFormOpen(true)}
23-
hook="edit-card"
33+
hook="edit-payment-method"
2434
>
2535
Edit <Icon name="chevronRight" size="sm" variant="solid" />
2636
</A>
2737
)}
2838
</div>
2939
{isFormOpen ? (
30-
<CreditCardForm
40+
<PaymentMethodForm
3141
provider={provider}
3242
owner={owner}
3343
closeForm={() => setIsFormOpen(false)}
44+
subscriptionDetail={subscriptionDetail}
3445
/>
3546
) : card ? (
3647
<CardInformation card={card} subscriptionDetail={subscriptionDetail} />
48+
) : usBankAccount ? (
49+
<BankInformation
50+
usBankAccount={usBankAccount}
51+
nextBillingDisplayDate={nextBillingDisplayDate}
52+
/>
3753
) : (
3854
<div className="flex flex-col gap-4 text-ds-gray-quinary">
3955
<p className="mt-4">
40-
No credit card set. Please contact support if you think it’s an
41-
error or set it yourself.
56+
No payment method set. Please contact support if you think it&apos;s
57+
an error or set it yourself.
4258
</p>
4359
<div className="flex self-start">
4460
<Button
@@ -56,7 +72,7 @@ function PaymentCard({ subscriptionDetail, provider, owner }) {
5672
}
5773

5874
PaymentCard.propTypes = {
59-
subscriptionDetail: PropTypes.oneOf([subscriptionDetailType, null]),
75+
subscriptionDetail: subscriptionDetailType,
6076
provider: PropTypes.string.isRequired,
6177
owner: PropTypes.string.isRequired,
6278
}

0 commit comments

Comments
 (0)