Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
sunguroku committed May 8, 2024
1 parent 6ee7546 commit 3bceea2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions dashboard/src/main/home/modals/PaymentSetupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import {
useElements,
useStripe,
} from "@stripe/react-stripe-js";

import {
ClientSecretResponse,
PaymentMethodValidator,
type PaymentMethod,
type PaymentMethodList,
} from "lib/billing/types";

import styled from "styled-components";
import api from "shared/api";

Expand All @@ -14,6 +22,7 @@ import SaveButton from "components/SaveButton";
import {
useCreatePaymentMethod,
useSetDefaultPaymentMethod,
checkIfProjectHasPayment,
} from "lib/hooks/useStripe";

import { Context } from "shared/Context";
Expand Down Expand Up @@ -61,9 +70,12 @@ const PaymentSetupForm = ({ onCreate }: { onCreate: () => Promise<void> }) => {
// Confirm the setup and set as default
if (setupIntent?.payment_method !== null) {
await setDefaultPaymentMethod(setupIntent?.payment_method as string);
}

if (currentProject?.sandbox_enabled) {
const { hasPaymentEnabled, refetchPaymentEnabled } = checkIfProjectHasPayment();

// create cluster on first payment setup for sandbox
if (currentProject?.sandbox_enabled) {
if (!hasPaymentEnabled) {
await api.connectProjectToCluster(
"<token>",
{},
Expand All @@ -75,11 +87,13 @@ const PaymentSetupForm = ({ onCreate }: { onCreate: () => Promise<void> }) => {
{},
{ project_id: currentProject.id }
)
onCreate();
})
.catch((err: any) => {
setErrorMessage(err.message);
setLoading(false);
})
return;
})
}
}

Expand Down

0 comments on commit 3bceea2

Please sign in to comment.