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
4 changes: 4 additions & 0 deletions apps/backend/src/auto-migrations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ export async function applyMigrations(options: {
//
// if you have a migration that's slower, consider using CONDITIONALLY_REPEAT_MIGRATION_SENTINEL
timeout: 80_000,
// Allow waiting longer to acquire a connection so bursts of concurrent migration attempts don't
// immediately fail with P2028 ("Unable to start a transaction in the given time"). This keeps the
// migration logic resilient under high contention, which can happen in CI where many workers race at once.
maxWait: 30_000,
});
}
}
Expand Down
27 changes: 2 additions & 25 deletions apps/dashboard/src/app/(main)/purchase/[code]/page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import { CheckoutForm } from "@/components/payments/checkout";
import { StripeElementsProvider } from "@/components/payments/stripe-elements-provider";
import { getPublicEnvVar } from "@/lib/env";
import { StackAdminApp, useUser } from "@stackframe/stack";
import { inlineProductSchema } from "@stackframe/stack-shared/dist/schema-fields";
import { throwErr } from "@stackframe/stack-shared/dist/utils/errors";
import { typedEntries } from "@stackframe/stack-shared/dist/utils/objects";
import { runAsynchronouslyWithAlert } from "@stackframe/stack-shared/dist/utils/promises";
import { Alert, AlertDescription, AlertTitle, Button, Card, CardContent, Input, Skeleton, Typography } from "@stackframe/stack-ui";
import { ArrowRight, Minus, Plus } from "lucide-react";
import { Minus, Plus } from "lucide-react";
import { useSearchParams } from "next/navigation";
import { useCallback, useEffect, useMemo, useState } from "react";
import * as yup from "yup";
Expand Down Expand Up @@ -272,11 +270,6 @@ export default function PageClient({ code }: { code: string }) {
)}
</div>
<div className="grow relative flex justify-center items-center bg-primary/5">
{data?.test_mode && (
<div className="absolute top-4 right-4 max-w-xs">
<BypassInfo handleBypass={handleBypass} disabled={!selectedPriceId || quantityNumber < 1 || isTooLarge} />
</div>
)}
{data && (
<StripeElementsProvider
stripeAccountId={data.stripe_account_id}
Expand All @@ -289,27 +282,11 @@ export default function PageClient({ code }: { code: string }) {
setupSubscription={setupSubscription}
returnUrl={returnUrl ?? undefined}
disabled={quantityNumber < 1 || isTooLarge || data.already_bought_non_stackable === true}
onTestModeBypass={data.test_mode ? handleBypass : undefined}
/>
</StripeElementsProvider>
)}
</div>
</div>
);
}

function BypassInfo({ handleBypass, disabled }: { handleBypass: () => Promise<void>, disabled: boolean }) {
return (
<Card className="border-primary/30 bg-secondary animate-fade-in">
<CardContent className="p-3">
<div className="flex items-center justify-between gap-3">
<div className="flex flex-col">
<Typography type="label">Test mode bypass</Typography>
</div>
<Button onClick={handleBypass} size="icon" variant="ghost" disabled={disabled}>
<ArrowRight className="w-4 h-4" />
</Button>
</div>
</CardContent>
</Card>
);
}
35 changes: 33 additions & 2 deletions apps/dashboard/src/components/payments/checkout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button } from "@stackframe/stack-ui";
import { Button, Typography } from "@stackframe/stack-ui";
import {
PaymentElement,
useElements,
Expand All @@ -23,9 +23,17 @@ type Props = {
fullCode: string,
returnUrl?: string,
disabled?: boolean,
onTestModeBypass?: () => Promise<void>,
};

export function CheckoutForm({ setupSubscription, stripeAccountId, fullCode, returnUrl, disabled }: Props) {
export function CheckoutForm({
setupSubscription,
stripeAccountId,
fullCode,
returnUrl,
disabled,
onTestModeBypass,
}: Props) {
const stripe = useStripe();
const elements = useElements();
const [message, setMessage] = useState<string | null>(null);
Expand Down Expand Up @@ -65,6 +73,29 @@ export function CheckoutForm({ setupSubscription, stripeAccountId, fullCode, ret
}
};

if (onTestModeBypass) {
return (
<div className="flex flex-col gap-4 max-w-md w-full p-6 rounded-md bg-background">
<div className="space-y-1">
<Typography type="h3">Test mode active</Typography>
<p className="text-sm text-muted-foreground">
This project is in test mode. Use the bypass button to simulate a purchase.
</p>
</div>
<Button
disabled={disabled}
onClick={onTestModeBypass}
className="mt-2"
>
Complete test purchase
</Button>
{message && (
<div className="text-destructive text-sm">{message}</div>
)}
</div>
);
}

return (
<div className="flex flex-col gap-6 max-w-md w-full p-6 rounded-md bg-background">
<PaymentElement options={paymentElementOptions} />
Expand Down
1 change: 1 addition & 0 deletions apps/e2e/tests/backend/backend-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,7 @@ export namespace Payments {
await Payments.setup();
await Project.updateConfig({
payments: {
testMode: false,
products: {
"test-product": {
displayName: "Test Product",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ it("should reject untrusted return_url and accept trusted return_url", async ({
},
"project_id": "<stripped UUID>",
"stripe_account_id": <stripped field 'stripe_account_id'>,
"test_mode": false,
"test_mode": true,
},
"headers": Headers { <some fields may have been hidden> },
}
Expand Down
2 changes: 1 addition & 1 deletion packages/stack-shared/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ const organizationConfigDefaults = {
},

payments: {
testMode: false,
testMode: true,
autoPay: undefined,
catalogs: (key: string) => ({
displayName: undefined,
Expand Down