Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle ach case #3696

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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