Skip to content

Commit

Permalink
fix: Handle ach case (#3696)
Browse files Browse the repository at this point in the history
  • Loading branch information
suejung-sentry authored Feb 3, 2025
1 parent 2a51004 commit 4ec0d14
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ function CurrentOrgPlan() {
/>
) : null}
<InfoMessageStripeCallback
hasUnverifiedPaymentMethods={hasUnverifiedPaymentMethods}
awaitingInitialPaymentMethodVerification={
awaitingInitialPaymentMethodVerification
}
/>
{isDelinquent ? <DelinquentAlert /> : null}
{data?.plan ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const wrapper =
describe('InfoMessageStripeCallback', () => {
describe('when rendering without success or cancel in the url', () => {
const { container } = render(
<InfoMessageStripeCallback hasUnverifiedPaymentMethods={false} />,
<InfoMessageStripeCallback
awaitingInitialPaymentMethodVerification={false}
/>,
{
wrapper: wrapper('/account/gh/codecov'),
}
Expand All @@ -27,7 +29,9 @@ describe('InfoMessageStripeCallback', () => {
describe('when rendering with success in the url', () => {
it('renders a success message', async () => {
render(
<InfoMessageStripeCallback hasUnverifiedPaymentMethods={false} />,
<InfoMessageStripeCallback
awaitingInitialPaymentMethodVerification={false}
/>,
{
wrapper: wrapper('/account/gh/codecov?success'),
}
Expand All @@ -39,10 +43,12 @@ describe('InfoMessageStripeCallback', () => {
})
})

describe('when hasUnverifiedPaymentMethods is true', () => {
describe('when awaitingInitialPaymentMethodVerification is true', () => {
it('does not enders a success message even at ?success', async () => {
const { container } = render(
<InfoMessageStripeCallback hasUnverifiedPaymentMethods={true} />,
<InfoMessageStripeCallback
awaitingInitialPaymentMethodVerification={true}
/>,
{
wrapper: wrapper('/account/gh/codecov?success'),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import Message from 'old_ui/Message'
// Stripe redirects to this page with ?success or ?cancel in the URL
// this component takes care of rendering a message if it is successful
function InfoMessageStripeCallback({
hasUnverifiedPaymentMethods,
awaitingInitialPaymentMethodVerification,
}: {
hasUnverifiedPaymentMethods: boolean
awaitingInitialPaymentMethodVerification: boolean
}) {
const urlParams = qs.parse(useLocation().search, {
ignoreQueryPrefix: true,
})

if ('success' in urlParams && !hasUnverifiedPaymentMethods)
if ('success' in urlParams && !awaitingInitialPaymentMethodVerification)
return (
<div className="col-start-1 col-end-13 mb-4">
<Message variant="success">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ type SetupArgs = {
hasSentryPlans?: boolean
monthlyPlan?: boolean
planUserCount?: number
hasUnverifiedPaymentMethod?: boolean
hasUnverifiedPaymentMethods?: boolean
subscriptionHasDefaultPaymentMethod?: boolean
}

describe('UpgradeForm', () => {
Expand All @@ -310,7 +311,8 @@ describe('UpgradeForm', () => {
hasSentryPlans = false,
monthlyPlan = true,
planUserCount = 1,
hasUnverifiedPaymentMethod = false,
hasUnverifiedPaymentMethods = false,
subscriptionHasDefaultPaymentMethod = true,
}: SetupArgs) {
const addNotification = vi.fn()
const user = userEvent.setup()
Expand All @@ -319,6 +321,16 @@ describe('UpgradeForm', () => {

server.use(
http.get(`/internal/:provider/:owner/account-details/`, () => {
if (!subscriptionHasDefaultPaymentMethod) {
return HttpResponse.json({
...mockAccountDetailsBasic,
subscriptionDetail: {
...mockAccountDetailsBasic.subscriptionDetail,
defaultPaymentMethod: null,
},
})
}

if (planValue === Plans.USERS_BASIC) {
return HttpResponse.json(mockAccountDetailsBasic)
} else if (planValue === Plans.USERS_PR_INAPPM) {
Expand Down Expand Up @@ -408,7 +420,7 @@ describe('UpgradeForm', () => {
data: {
owner: {
billing: {
unverifiedPaymentMethods: hasUnverifiedPaymentMethod
unverifiedPaymentMethods: hasUnverifiedPaymentMethods
? [
{
paymentMethodId: 'asdf',
Expand Down Expand Up @@ -436,7 +448,8 @@ describe('UpgradeForm', () => {
it('shows modal when form is submitted', async () => {
const { user } = setup({
planValue: Plans.USERS_BASIC,
hasUnverifiedPaymentMethod: true,
hasUnverifiedPaymentMethods: true,
subscriptionHasDefaultPaymentMethod: false,
})
render(<UpgradeForm {...props} />, { wrapper: wrapper() })

Expand All @@ -457,7 +470,7 @@ describe('UpgradeForm', () => {
it('does not show modal when no unverified payment methods', async () => {
const { user } = setup({
planValue: Plans.USERS_BASIC,
hasUnverifiedPaymentMethod: false,
hasUnverifiedPaymentMethods: false,
})
render(<UpgradeForm {...props} />, { wrapper: wrapper() })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,17 @@ function UpgradeForm({ selectedPlan, setSelectedPlan }: UpgradeFormProps) {
const newPlan = watch('newPlan')
const seats = watch('seats')

const awaitingInitialPaymentMethodVerification =
!!unverifiedPaymentMethods?.length &&
!accountDetails?.subscriptionDetail?.defaultPaymentMethod

useEffect(() => {
// This is necessary because the validity of seats depends on the value of newPlan
trigger('seats')
}, [newPlan, trigger])

const onSubmit = handleSubmit((data) => {
if (unverifiedPaymentMethods?.length) {
if (awaitingInitialPaymentMethodVerification) {
setFormData(data)
setShowModal(true)
} else {
Expand Down

0 comments on commit 4ec0d14

Please sign in to comment.