-
Notifications
You must be signed in to change notification settings - Fork 239
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
move ccp connection to cc link #4616
Changes from all commits
8169bc5
2ec06ab
6ee7546
786af64
3bceea2
bfc4b09
ec7d8ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import React, { useState } from "react"; | ||
import React, { useState, useContext } from "react"; | ||
import { | ||
PaymentElement, | ||
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"; | ||
|
||
import Button from "components/porter/Button"; | ||
import Error from "components/porter/Error"; | ||
|
@@ -13,9 +22,13 @@ import SaveButton from "components/SaveButton"; | |
import { | ||
useCreatePaymentMethod, | ||
useSetDefaultPaymentMethod, | ||
checkIfProjectHasPayment, | ||
} from "lib/hooks/useStripe"; | ||
|
||
import { Context } from "shared/Context"; | ||
|
||
const PaymentSetupForm = ({ onCreate }: { onCreate: () => Promise<void> }) => { | ||
const { currentProject } = useContext(Context); | ||
const stripe = useStripe(); | ||
const elements = useElements(); | ||
|
||
|
@@ -59,6 +72,31 @@ const PaymentSetupForm = ({ onCreate }: { onCreate: () => Promise<void> }) => { | |
await setDefaultPaymentMethod(setupIntent?.payment_method as string); | ||
} | ||
|
||
if (currentProject?.sandbox_enabled) { | ||
const { hasPaymentEnabled, refetchPaymentEnabled } = checkIfProjectHasPayment(); | ||
|
||
if (!hasPaymentEnabled) { | ||
await api.connectProjectToCluster( | ||
"<token>", | ||
{}, | ||
{ id: currentProject.id } | ||
) | ||
.then(() => { | ||
api.inviteAdmin( | ||
"<token>", | ||
{}, | ||
{ project_id: currentProject.id } | ||
) | ||
onCreate(); | ||
}) | ||
.catch((err: any) => { | ||
setErrorMessage(err.message); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The payment method will be added to Stripe even if this call fails, is there another way to create the cluster if that happens? |
||
setLoading(false); | ||
return; | ||
}) | ||
} | ||
} | ||
|
||
onCreate(); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling |
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a user adds another payment method, this will create another cluster connection right? Should we limit to one credit card?