AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

get-paid-setup.tsx 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import { router } from '@inertiajs/react';
  2. import { AlertTriangle, Check, Clock, ExternalLink, Link2 } from 'lucide-react';
  3. import { useState } from 'react';
  4. import StripeConnectController from '@/actions/App/Http/Controllers/StripeConnectController';
  5. import { Badge } from '@/components/ui/badge';
  6. import { Button } from '@/components/ui/button';
  7. import {
  8. Card,
  9. CardContent,
  10. CardDescription,
  11. CardHeader,
  12. CardTitle,
  13. } from '@/components/ui/card';
  14. import { Spinner } from '@/components/ui/spinner';
  15. import type { StoreSummary } from '@/types';
  16. export type PaymentSettings = {
  17. /** False until the app's own Stripe key is set. */
  18. available: boolean;
  19. /** A Stripe account was opened for the store (the form may not be finished). */
  20. connected: boolean;
  21. details_submitted: boolean;
  22. can_take_payments: boolean;
  23. payouts_enabled: boolean;
  24. };
  25. const STRIPE_DASHBOARD_URL = 'https://dashboard.stripe.com';
  26. /**
  27. * Getting paid: the store's own Stripe account, where shoppers' payments go.
  28. * It sits inside the Settings form, so its buttons never submit that form.
  29. */
  30. export function GetPaidSetup({
  31. store,
  32. payments,
  33. }: {
  34. store: StoreSummary;
  35. payments: PaymentSettings;
  36. }) {
  37. const [busy, setBusy] = useState(false);
  38. const openStripe = () => {
  39. setBusy(true);
  40. // Stripe's own sign-up form opens in this tab, then brings the merchant back here.
  41. router.post(
  42. StripeConnectController.connect.url(store.slug),
  43. {},
  44. { onFinish: () => setBusy(false) },
  45. );
  46. };
  47. const stripeButton = (label: string, variant: 'default' | 'outline') => (
  48. <Button
  49. type="button"
  50. variant={variant}
  51. onClick={openStripe}
  52. disabled={busy}
  53. data-test="stripe-connect"
  54. >
  55. {busy ? <Spinner /> : <Link2 />}
  56. {label}
  57. </Button>
  58. );
  59. return (
  60. <Card id="payments" data-test="get-paid">
  61. <CardHeader>
  62. <CardTitle className="flex flex-wrap items-center gap-2">
  63. Get paid
  64. {payments.can_take_payments && (
  65. <Badge className="bg-emerald-600 text-white hover:bg-emerald-600">
  66. <Check className="size-3" />
  67. Connected
  68. </Badge>
  69. )}
  70. </CardTitle>
  71. <CardDescription>
  72. Shoppers pay into your own Stripe account, and Stripe pays
  73. it into your bank. We take no cut. You only pay Stripe’s
  74. fees.
  75. </CardDescription>
  76. </CardHeader>
  77. <CardContent>
  78. {!payments.available ? (
  79. <p
  80. className="rounded-md bg-muted p-3 text-xs"
  81. data-test="stripe-unavailable"
  82. >
  83. Stripe is not switched on for this app yet. The app
  84. owner adds STRIPE_SECRET to .env.local.
  85. </p>
  86. ) : payments.can_take_payments ? (
  87. <div className="space-y-4">
  88. <ul className="space-y-2 rounded-lg border p-4 text-sm">
  89. <li className="flex items-center gap-2">
  90. <Check className="size-4 text-emerald-600" />
  91. Your store can take payments
  92. </li>
  93. <li
  94. className="flex items-center gap-2"
  95. data-test="payouts-status"
  96. >
  97. {payments.payouts_enabled ? (
  98. <>
  99. <Check className="size-4 text-emerald-600" />
  100. Payouts to your bank are on
  101. </>
  102. ) : (
  103. <>
  104. <AlertTriangle className="size-4 text-amber-600" />
  105. Payouts are paused: Stripe needs a few
  106. more details
  107. </>
  108. )}
  109. </li>
  110. </ul>
  111. <div className="flex flex-wrap gap-2">
  112. <Button type="button" variant="outline" asChild>
  113. <a
  114. href={STRIPE_DASHBOARD_URL}
  115. target="_blank"
  116. rel="noreferrer"
  117. >
  118. <ExternalLink />
  119. Open Stripe Dashboard
  120. </a>
  121. </Button>
  122. {!payments.payouts_enabled &&
  123. stripeButton('Update details', 'default')}
  124. </div>
  125. <p className="text-xs text-muted-foreground">
  126. Shoppers can pay by card, FPX online banking or
  127. GrabPay. Refunds, payouts and payment methods are
  128. managed in your Stripe Dashboard.
  129. </p>
  130. </div>
  131. ) : payments.details_submitted ? (
  132. <div className="space-y-4">
  133. <p
  134. className="flex items-start gap-2 text-sm"
  135. data-test="stripe-checking"
  136. >
  137. <Clock className="mt-0.5 size-4 shrink-0 text-amber-600" />
  138. Thank you. Stripe is checking your details. This
  139. usually takes a few minutes, sometimes a day. Your
  140. store takes orders as soon as Stripe says yes.
  141. </p>
  142. <div className="flex flex-wrap gap-2">
  143. <Button
  144. type="button"
  145. variant="outline"
  146. onClick={() =>
  147. router.reload({ only: ['payments'] })
  148. }
  149. >
  150. Check again
  151. </Button>
  152. {stripeButton('Update details', 'outline')}
  153. </div>
  154. </div>
  155. ) : payments.connected ? (
  156. <div className="space-y-4">
  157. <p
  158. className="flex items-start gap-2 text-sm text-amber-700 dark:text-amber-400"
  159. data-test="stripe-unfinished"
  160. >
  161. <AlertTriangle className="mt-0.5 size-4 shrink-0" />
  162. Your Stripe sign-up is not finished. Your store
  163. cannot take orders until it is.
  164. </p>
  165. {stripeButton('Finish setup', 'default')}
  166. </div>
  167. ) : (
  168. <div className="space-y-4 text-sm">
  169. <p
  170. className="flex items-start gap-2 text-amber-700 dark:text-amber-400"
  171. data-test="stripe-not-connected"
  172. >
  173. <AlertTriangle className="mt-0.5 size-4 shrink-0" />
  174. Your store cannot take orders until you connect
  175. Stripe.
  176. </p>
  177. <div className="text-muted-foreground">
  178. <p className="font-medium text-foreground">
  179. Have these ready (about 10 minutes):
  180. </p>
  181. <ul className="mt-1 list-disc space-y-1 pl-5">
  182. <li>Your IC or passport</li>
  183. <li>
  184. Your SSM registration number, if you have
  185. one (needed for FPX online banking)
  186. </li>
  187. <li>The bank account to receive your money</li>
  188. </ul>
  189. </div>
  190. <p className="text-muted-foreground">
  191. You fill these in on Stripe’s own page, not ours.
  192. Already use Stripe? You can sign in there.
  193. </p>
  194. {stripeButton('Connect Stripe', 'default')}
  195. </div>
  196. )}
  197. </CardContent>
  198. </Card>
  199. );
  200. }