Skip to content

Commit 8eaa2c1

Browse files
committed
Consider "incomplete" subscription status as invalid
1 parent 3948b93 commit 8eaa2c1

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

landing/src/components/sections/subscribe/SubscribeForm.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
import {
2+
constants,
3+
formatPriceAndInterval,
4+
Plan,
5+
UserPlan,
6+
isPlanStatusValid,
7+
} from '@brunolemos/devhub-core'
8+
import classNames from 'classnames'
19
import React, { useEffect, useRef, useState } from 'react'
210
import { CardElement, injectStripe } from 'react-stripe-elements'
311

@@ -166,7 +174,10 @@ export const SubscribeForm = injectStripe<SubscribeFormProps>(
166174

167175
mergeAuthData({ plan: data.subscribeToPlan })
168176

169-
if (data.subscribeToPlan.status === 'incomplete') {
177+
if (
178+
!isPlanStatusValid(data.subscribeToPlan) ||
179+
data.subscribeToPlan.status === 'incomplete'
180+
) {
170181
throw new Error('Please try a different credit card.')
171182
}
172183

packages/components/src/components/modals/partials/SubscribeForm.web.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
constants,
44
formatPriceAndInterval,
55
freePlan,
6+
isPlanStatusValid,
67
UserPlan,
78
} from '@devhub/core'
89
import axios from 'axios'
@@ -257,7 +258,10 @@ const SubscribeFormWithStripe = React.memo(
257258

258259
dispatch(actions.updateUserData({ plan: data.subscribeToPlan }))
259260

260-
if (data.subscribeToPlan.status === 'incomplete') {
261+
if (
262+
!isPlanStatusValid(data.subscribeToPlan) ||
263+
data.subscribeToPlan.status === 'incomplete'
264+
) {
261265
throw new Error('Please try a different credit card.')
262266
}
263267

packages/core/src/helpers/plans.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ export function isPlanStatusValid(
8484
): boolean {
8585
if (!plan) return false
8686

87-
return !!(
88-
plan.status === 'active' ||
89-
plan.status === 'trialing' ||
90-
plan.status === 'incomplete'
91-
)
87+
return !!(plan.status === 'active' || plan.status === 'trialing')
9288
}
9389

9490
export function isPlanExpired(

0 commit comments

Comments
 (0)