Skip to content

Commit 62e2bcf

Browse files
authored
chore: automatically mark default payment method [GEN-12003] (supabase#30707)
When customers go through the upgrade flow via the plan upgrade modal, we want to automatically confirm any newly added payment method as default payment method. We've seen some issues on Orb that customers would upgrade without a default payment method. This change should help mitigate it further.
1 parent 8ece6da commit 62e2bcf

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

apps/studio/components/interfaces/Billing/Payment/AddNewPaymentMethodModal.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface AddNewPaymentMethodModalProps {
1818
onCancel: () => void
1919
onConfirm: () => void
2020
showSetDefaultCheckbox?: boolean
21+
autoMarkAsDefaultPaymentMethod?: boolean
2122
}
2223

2324
const stripePromise = loadStripe(STRIPE_PUBLIC_KEY)
@@ -28,6 +29,7 @@ const AddNewPaymentMethodModal = ({
2829
onCancel,
2930
onConfirm,
3031
showSetDefaultCheckbox,
32+
autoMarkAsDefaultPaymentMethod,
3133
}: AddNewPaymentMethodModalProps) => {
3234
const { resolvedTheme } = useTheme()
3335
const [intent, setIntent] = useState<any>()
@@ -140,6 +142,7 @@ const AddNewPaymentMethodModal = ({
140142
onCancel={onLocalCancel}
141143
onConfirm={onLocalConfirm}
142144
showSetDefaultCheckbox={showSetDefaultCheckbox}
145+
autoMarkAsDefaultPaymentMethod={autoMarkAsDefaultPaymentMethod}
143146
/>
144147
</Elements>
145148
</Modal>

apps/studio/components/interfaces/Billing/Payment/AddPaymentMethodForm.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface AddPaymentMethodFormProps {
1212
onCancel: () => void
1313
onConfirm: () => void
1414
showSetDefaultCheckbox?: boolean
15+
autoMarkAsDefaultPaymentMethod?: boolean
1516
}
1617

1718
// Stripe docs recommend to use the new SetupIntent flow over
@@ -23,6 +24,7 @@ const AddPaymentMethodForm = ({
2324
onCancel,
2425
onConfirm,
2526
showSetDefaultCheckbox = false,
27+
autoMarkAsDefaultPaymentMethod = false,
2628
}: AddPaymentMethodFormProps) => {
2729
const stripe = useStripe()
2830
const elements = useElements()
@@ -59,7 +61,11 @@ const AddPaymentMethodForm = ({
5961
setIsSaving(false)
6062
toast.error(error?.message ?? ' Failed to save card details')
6163
} else {
62-
if (isDefault && selectedOrganization && typeof setupIntent?.payment_method === 'string') {
64+
if (
65+
(isDefault || autoMarkAsDefaultPaymentMethod) &&
66+
selectedOrganization &&
67+
typeof setupIntent?.payment_method === 'string'
68+
) {
6369
try {
6470
await markAsDefault({
6571
slug: selectedOrganization.slug,

apps/studio/components/interfaces/Organization/BillingSettings/Subscription/PaymentMethodSelection.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ const PaymentMethodSelection = ({
150150
visible={showAddNewPaymentMethodModal}
151151
returnUrl={`${getURL()}/org/${selectedOrganization?.slug}/billing?panel=subscriptionPlan`}
152152
onCancel={() => setShowAddNewPaymentMethodModal(false)}
153+
autoMarkAsDefaultPaymentMethod={true}
153154
onConfirm={async () => {
154155
setShowAddNewPaymentMethodModal(false)
155156
toast.success('Successfully added new payment method')

apps/studio/components/interfaces/Organization/BillingSettings/Subscription/Subscription.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ const Subscription = () => {
147147
title="This organization is limited by the included usage"
148148
>
149149
<div className="[&>p]:!leading-normal prose text-sm">
150-
Projects may become unresponsive when this organization exceeds its
150+
Projects may become unresponsive when this organization exceeds its{' '}
151151
<Link href={`/org/${slug}/usage`}>included usage quota</Link>. To scale
152-
seamlessly and pay for over-usage, $
152+
seamlessly and pay for over-usage,{' '}
153153
{currentPlan?.id === 'free'
154154
? 'upgrade to a paid plan.'
155155
: 'you can disable Spend Cap under the Cost Control settings.'}

0 commit comments

Comments
 (0)