Skip to content
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 @@ -11,8 +11,12 @@ import { useEffect } from "react";

export function StripeCheckout() {
const { clearError, starterpackDetails } = useStarterpackContext();
const { stripePromise, clientSecret, costDetails } =
useCreditPurchaseContext();
const {
stripePromise,
clientSecret,
customerSessionClientSecret,
costDetails,
} = useCreditPurchaseContext();
const { navigate, setOnBackCallback } = useNavigation();
const isOnchainStarterpackCheckout =
!!starterpackDetails && isOnchainStarterpack(starterpackDetails);
Expand Down Expand Up @@ -60,7 +64,14 @@ export function StripeCheckout() {

return (
<Elements
options={{ clientSecret, appearance, loader: "auto" }}
options={{
clientSecret,
appearance,
loader: "auto",
...(customerSessionClientSecret && {
customerSessionClientSecret,
}),
}}
stripe={stripePromise}
>
<CheckoutForm
Expand Down
8 changes: 8 additions & 0 deletions packages/keychain/src/context/starterpack/credit-purchase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface CreditPurchaseContextType {
// Stripe state
stripePaymentId: string | undefined;
clientSecret: string | undefined;
customerSessionClientSecret: string | undefined;
costDetails: CostDetails | undefined;
stripePromise: Promise<Stripe | null>;
isStripeLoading: boolean;
Expand Down Expand Up @@ -67,6 +68,8 @@ export const CreditPurchaseProvider = ({
const [usdAmount, setUsdAmount] = useState<number>(USD_AMOUNTS[0]);
const [stripePaymentId, setStripePaymentId] = useState<string | undefined>();
const [clientSecret, setClientSecret] = useState<string | undefined>();
const [customerSessionClientSecret, setCustomerSessionClientSecret] =
useState<string | undefined>();
const [costDetails, setCostDetails] = useState<CostDetails | undefined>();

const {
Expand Down Expand Up @@ -127,6 +130,9 @@ export const CreditPurchaseProvider = ({

setStripePaymentId(paymentIntent.id);
setClientSecret(paymentIntent.clientSecret);
setCustomerSessionClientSecret(
paymentIntent.customerSessionClientSecret ?? undefined,
);
setCostDetails(
starterpackDetails && isOnchainStarterpack(starterpackDetails)
? getStarterpackStripeCostDetails(starterpackDetails.quote!, quantity)
Expand All @@ -153,6 +159,7 @@ export const CreditPurchaseProvider = ({
useEffect(() => {
setStripePaymentId(undefined);
setClientSecret(undefined);
setCustomerSessionClientSecret(undefined);
setCostDetails(undefined);
}, [starterpackId]);

Expand All @@ -161,6 +168,7 @@ export const CreditPurchaseProvider = ({
setUsdAmount,
stripePaymentId,
clientSecret,
customerSessionClientSecret,
costDetails,
stripePromise,
isStripeLoading,
Expand Down
5 changes: 5 additions & 0 deletions packages/keychain/src/utils/api/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6360,6 +6360,7 @@ export type StripePayment = {
export type StripePaymentIntent = {
__typename?: "StripePaymentIntent";
clientSecret: Scalars["String"];
customerSessionClientSecret?: Maybe<Scalars["String"]>;
id: Scalars["ID"];
pricing: StripePricingDetails;
};
Expand Down Expand Up @@ -7236,6 +7237,7 @@ export type CreateStripePaymentIntentMutation = {
__typename?: "StripePaymentIntent";
id: string;
clientSecret: string;
customerSessionClientSecret?: string | null;
pricing: {
__typename?: "StripePricingDetails";
baseCostInCents: number;
Expand All @@ -7255,6 +7257,7 @@ export type CreateStripeStarterpackIntentMutation = {
__typename?: "StripePaymentIntent";
id: string;
clientSecret: string;
customerSessionClientSecret?: string | null;
pricing: {
__typename?: "StripePricingDetails";
baseCostInCents: number;
Expand Down Expand Up @@ -7964,6 +7967,7 @@ export const CreateStripePaymentIntentDocument = `
createStripePaymentIntent(input: $input) {
id
clientSecret
customerSessionClientSecret
pricing {
baseCostInCents
processingFeeInCents
Expand Down Expand Up @@ -8001,6 +8005,7 @@ export const CreateStripeStarterpackIntentDocument = `
createStripeStarterpackIntent(input: $input) {
id
clientSecret
customerSessionClientSecret
pricing {
baseCostInCents
processingFeeInCents
Expand Down
2 changes: 2 additions & 0 deletions packages/keychain/src/utils/api/payment.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ mutation CreateStripePaymentIntent($input: CreateStripePaymentIntentInput!) {
createStripePaymentIntent(input: $input) {
id
clientSecret
customerSessionClientSecret
pricing {
baseCostInCents
processingFeeInCents
Expand All @@ -59,6 +60,7 @@ mutation CreateStripeStarterpackIntent(
createStripeStarterpackIntent(input: $input) {
id
clientSecret
customerSessionClientSecret
pricing {
baseCostInCents
processingFeeInCents
Expand Down
Loading