| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- import { router } from '@inertiajs/react';
- import { AlertTriangle, Check, Clock, ExternalLink, Link2 } from 'lucide-react';
- import { useState } from 'react';
- import StripeConnectController from '@/actions/App/Http/Controllers/StripeConnectController';
- import { Badge } from '@/components/ui/badge';
- import { Button } from '@/components/ui/button';
- import {
- Card,
- CardContent,
- CardDescription,
- CardHeader,
- CardTitle,
- } from '@/components/ui/card';
- import { Spinner } from '@/components/ui/spinner';
- import type { StoreSummary } from '@/types';
-
- export type PaymentSettings = {
- /** False until the app's own Stripe key is set. */
- available: boolean;
- /** A Stripe account was opened for the store (the form may not be finished). */
- connected: boolean;
- details_submitted: boolean;
- can_take_payments: boolean;
- payouts_enabled: boolean;
- };
-
- const STRIPE_DASHBOARD_URL = 'https://dashboard.stripe.com';
-
- /**
- * Getting paid: the store's own Stripe account, where shoppers' payments go.
- * It sits inside the Settings form, so its buttons never submit that form.
- */
- export function GetPaidSetup({
- store,
- payments,
- }: {
- store: StoreSummary;
- payments: PaymentSettings;
- }) {
- const [busy, setBusy] = useState(false);
-
- const openStripe = () => {
- setBusy(true);
- // Stripe's own sign-up form opens in this tab, then brings the merchant back here.
- router.post(
- StripeConnectController.connect.url(store.slug),
- {},
- { onFinish: () => setBusy(false) },
- );
- };
-
- const stripeButton = (label: string, variant: 'default' | 'outline') => (
- <Button
- type="button"
- variant={variant}
- onClick={openStripe}
- disabled={busy}
- data-test="stripe-connect"
- >
- {busy ? <Spinner /> : <Link2 />}
- {label}
- </Button>
- );
-
- return (
- <Card id="payments" data-test="get-paid">
- <CardHeader>
- <CardTitle className="flex flex-wrap items-center gap-2">
- Get paid
- {payments.can_take_payments && (
- <Badge className="bg-emerald-600 text-white hover:bg-emerald-600">
- <Check className="size-3" />
- Connected
- </Badge>
- )}
- </CardTitle>
- <CardDescription>
- Shoppers pay into your own Stripe account, and Stripe pays
- it into your bank. We take no cut. You only pay Stripe’s
- fees.
- </CardDescription>
- </CardHeader>
- <CardContent>
- {!payments.available ? (
- <p
- className="rounded-md bg-muted p-3 text-xs"
- data-test="stripe-unavailable"
- >
- Stripe is not switched on for this app yet. The app
- owner adds STRIPE_SECRET to .env.local.
- </p>
- ) : payments.can_take_payments ? (
- <div className="space-y-4">
- <ul className="space-y-2 rounded-lg border p-4 text-sm">
- <li className="flex items-center gap-2">
- <Check className="size-4 text-emerald-600" />
- Your store can take payments
- </li>
- <li
- className="flex items-center gap-2"
- data-test="payouts-status"
- >
- {payments.payouts_enabled ? (
- <>
- <Check className="size-4 text-emerald-600" />
- Payouts to your bank are on
- </>
- ) : (
- <>
- <AlertTriangle className="size-4 text-amber-600" />
- Payouts are paused: Stripe needs a few
- more details
- </>
- )}
- </li>
- </ul>
- <div className="flex flex-wrap gap-2">
- <Button type="button" variant="outline" asChild>
- <a
- href={STRIPE_DASHBOARD_URL}
- target="_blank"
- rel="noreferrer"
- >
- <ExternalLink />
- Open Stripe Dashboard
- </a>
- </Button>
- {!payments.payouts_enabled &&
- stripeButton('Update details', 'default')}
- </div>
- <p className="text-xs text-muted-foreground">
- Shoppers can pay by card, FPX online banking or
- GrabPay. Refunds, payouts and payment methods are
- managed in your Stripe Dashboard.
- </p>
- </div>
- ) : payments.details_submitted ? (
- <div className="space-y-4">
- <p
- className="flex items-start gap-2 text-sm"
- data-test="stripe-checking"
- >
- <Clock className="mt-0.5 size-4 shrink-0 text-amber-600" />
- Thank you. Stripe is checking your details. This
- usually takes a few minutes, sometimes a day. Your
- store takes orders as soon as Stripe says yes.
- </p>
- <div className="flex flex-wrap gap-2">
- <Button
- type="button"
- variant="outline"
- onClick={() =>
- router.reload({ only: ['payments'] })
- }
- >
- Check again
- </Button>
- {stripeButton('Update details', 'outline')}
- </div>
- </div>
- ) : payments.connected ? (
- <div className="space-y-4">
- <p
- className="flex items-start gap-2 text-sm text-amber-700 dark:text-amber-400"
- data-test="stripe-unfinished"
- >
- <AlertTriangle className="mt-0.5 size-4 shrink-0" />
- Your Stripe sign-up is not finished. Your store
- cannot take orders until it is.
- </p>
- {stripeButton('Finish setup', 'default')}
- </div>
- ) : (
- <div className="space-y-4 text-sm">
- <p
- className="flex items-start gap-2 text-amber-700 dark:text-amber-400"
- data-test="stripe-not-connected"
- >
- <AlertTriangle className="mt-0.5 size-4 shrink-0" />
- Your store cannot take orders until you connect
- Stripe.
- </p>
- <div className="text-muted-foreground">
- <p className="font-medium text-foreground">
- Have these ready (about 10 minutes):
- </p>
- <ul className="mt-1 list-disc space-y-1 pl-5">
- <li>Your IC or passport</li>
- <li>
- Your SSM registration number, if you have
- one (needed for FPX online banking)
- </li>
- <li>The bank account to receive your money</li>
- </ul>
- </div>
- <p className="text-muted-foreground">
- You fill these in on Stripe’s own page, not ours.
- Already use Stripe? You can sign in there.
- </p>
- {stripeButton('Connect Stripe', 'default')}
- </div>
- )}
- </CardContent>
- </Card>
- );
- }
|