Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
suejung-sentry committed Jan 30, 2025
1 parent ca0b1ea commit 2902a3d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,15 @@ const mocks = {
useUpdatePaymentMethod: vi.fn(),
}

vi.mock('services/account/useUpdatePaymentMethod', () => ({
useUpdatePaymentMethod: () => mocks.useUpdatePaymentMethod(),
}))
vi.mock('services/account/useUpdatePaymentMethod', async () => {
const original = await vi.importActual(
'services/account/useUpdatePaymentMethod'
)
return {
...original,
useUpdatePaymentMethod: () => mocks.useUpdatePaymentMethod(),
}
})

afterEach(() => {
vi.clearAllMocks()
Expand Down Expand Up @@ -214,7 +220,13 @@ describe('PaymentMethodForm', () => {

await user.click(screen.getByTestId('save-payment-method'))

expect(screen.getByText(randomError)).toBeInTheDocument()
expect(
screen.getByText((content) =>
content.includes(
"There's been an error. Please try refreshing your browser"
)
)
).toBeInTheDocument()
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import cs from 'classnames'
import { z } from 'zod'

import { AccountDetailsSchema, BillingDetailsSchema } from 'services/account'
import { useUpdatePaymentMethod } from 'services/account/useUpdatePaymentMethod'
import {
MissingAddressError,
MissingEmailError,
MissingNameError,
useUpdatePaymentMethod,
} from 'services/account/useUpdatePaymentMethod'
import { Provider } from 'shared/api/helpers'
import A from 'ui/A'
import Button from 'ui/Button'

interface PaymentMethodFormProps {
Expand Down Expand Up @@ -81,7 +87,7 @@ const PaymentMethodForm = ({
}}
/>
<p className="mt-1 text-ds-primary-red">
{showError && error?.message}
{showError ? getErrorMessage(error) : null}
</p>
<div className="mb-8 mt-4 flex gap-1">
<Button
Expand Down Expand Up @@ -150,4 +156,27 @@ export const getName = (
)
}

export const getErrorMessage = (error: Error): JSX.Element => {
switch (error.message) {
case MissingNameError:
return <span>Missing name, please edit Full Name</span>
case MissingEmailError:
return <span>Missing email, please edit Email</span>
case MissingAddressError:
return <span>Missing address, please edit Address</span>
default:
return (
<span>
There&apos;s been an error. Please try refreshing your browser, if
this error persists please{' '}
{/* @ts-expect-error ignore until we can convert A component to ts */}
<A to={{ pageName: 'support' }} variant="link">
contact support
</A>
.
</span>
)
}
}

export default PaymentMethodForm
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ describe('CurrentOrgPlan', () => {
)
expect(paymentFailed).toBeInTheDocument()
const contactSupport = await screen.findByText(
'Please try a different card or contact support at [email protected].'
'Please try a different payment method or contact support at [email protected].'
)
expect(contactSupport).toBeInTheDocument()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ const DelinquentAlert = () => {
<Alert variant={'error'}>
<Alert.Title>Your most recent payment failed</Alert.Title>
<Alert.Description>
Please try a different card or contact support at [email protected].
Please try a different payment method or contact support at
[email protected].
</Alert.Description>
</Alert>
<br />
Expand Down
5 changes: 5 additions & 0 deletions src/services/account/useUpdatePaymentMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,8 @@ export function useUpdatePaymentMethod({
},
})
}

// Errors from Stripe api confirmSetup() - unfortunately seems to just be by text, no error codes
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().`
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().`
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 comments on commit 2902a3d

Please sign in to comment.