Skip to content

Commit 99b1210

Browse files
cleanup
1 parent ca0b1ea commit 99b1210

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentMethodForm.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ import cs from 'classnames'
44
import { z } from 'zod'
55

66
import { AccountDetailsSchema, BillingDetailsSchema } from 'services/account'
7-
import { useUpdatePaymentMethod } from 'services/account/useUpdatePaymentMethod'
7+
import {
8+
MissingAddressError,
9+
MissingEmailError,
10+
MissingNameError,
11+
useUpdatePaymentMethod,
12+
} from 'services/account/useUpdatePaymentMethod'
813
import { Provider } from 'shared/api/helpers'
14+
import A from 'ui/A'
915
import Button from 'ui/Button'
1016

1117
interface PaymentMethodFormProps {
@@ -81,7 +87,7 @@ const PaymentMethodForm = ({
8187
}}
8288
/>
8389
<p className="mt-1 text-ds-primary-red">
84-
{showError && error?.message}
90+
{showError ? getErrorMessage(error) : null}
8591
</p>
8692
<div className="mb-8 mt-4 flex gap-1">
8793
<Button
@@ -150,4 +156,27 @@ export const getName = (
150156
)
151157
}
152158

159+
export const getErrorMessage = (error: Error): JSX.Element => {
160+
switch (error.message) {
161+
case MissingNameError:
162+
return <span>Missing name, please edit Full Name</span>
163+
case MissingEmailError:
164+
return <span>Missing email, please edit Email</span>
165+
case MissingAddressError:
166+
return <span>Missing address, please edit Address</span>
167+
default:
168+
return (
169+
<span>
170+
There&apos;s been an error. Please try refreshing your browser, if
171+
this error persists please{' '}
172+
{/* @ts-expect-error ignore until we can convert A component to ts */}
173+
<A to={{ pageName: 'support' }} variant="link">
174+
contact support
175+
</A>
176+
.
177+
</span>
178+
)
179+
}
180+
}
181+
153182
export default PaymentMethodForm

src/pages/PlanPage/subRoutes/CurrentOrgPlan/CurrentOrgPlan.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ describe('CurrentOrgPlan', () => {
373373
)
374374
expect(paymentFailed).toBeInTheDocument()
375375
const contactSupport = await screen.findByText(
376-
'Please try a different card or contact support at [email protected].'
376+
'Please try a different payment method or contact support at [email protected].'
377377
)
378378
expect(contactSupport).toBeInTheDocument()
379379
})

src/pages/PlanPage/subRoutes/CurrentOrgPlan/CurrentOrgPlan.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ const DelinquentAlert = () => {
147147
<Alert variant={'error'}>
148148
<Alert.Title>Your most recent payment failed</Alert.Title>
149149
<Alert.Description>
150-
Please try a different card or contact support at [email protected].
150+
Please try a different payment method or contact support at
151+
151152
</Alert.Description>
152153
</Alert>
153154
<br />

src/services/account/useUpdatePaymentMethod.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,8 @@ export function useUpdatePaymentMethod({
9494
},
9595
})
9696
}
97+
98+
// Errors from Stripe api confirmSetup() - unfortunately seems to just be by text, no error codes
99+
export const MissingNameError = `You specified "never" for fields.billing_details.name when creating the payment Element, but did not pass confirmParams.payment_method_data.billing_details.name when calling stripe.confirmSetup(). If you opt out of collecting data via the payment Element using the fields option, the data must be passed in when calling stripe.confirmSetup().`
100+
export const MissingEmailError = `You specified "never" for fields.billing_details.email when creating the payment Element, but did not pass confirmParams.payment_method_data.billing_details.email when calling stripe.confirmSetup(). If you opt out of collecting data via the payment Element using the fields option, the data must be passed in when calling stripe.confirmSetup().`
101+
export const MissingAddressError = `You specified "never" for fields.billing_details.address when creating the payment Element, but did not pass confirmParams.payment_method_data.billing_details.address when calling stripe.confirmSetup(). If you opt out of collecting data via the payment Element using the fields option, the data must be passed in when calling stripe.confirmSetup().`

0 commit comments

Comments
 (0)