mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: use stripe connect for payments
This commit is contained in:
parent
cdd893ca6f
commit
a8ba053447
17 changed files with 835 additions and 364 deletions
26
apps/web/components/Hooks/usePaymentsEnabled.tsx
Normal file
26
apps/web/components/Hooks/usePaymentsEnabled.tsx
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// hooks/usePaymentsEnabled.ts
|
||||
import { useOrg } from '@components/Contexts/OrgContext';
|
||||
import { useLHSession } from '@components/Contexts/LHSessionContext';
|
||||
import useSWR from 'swr';
|
||||
import { getPaymentConfigs } from '@services/payments/payments';
|
||||
|
||||
export function usePaymentsEnabled() {
|
||||
const org = useOrg() as any;
|
||||
const session = useLHSession() as any;
|
||||
const access_token = session?.data?.tokens?.access_token;
|
||||
|
||||
const { data: paymentConfigs, error, isLoading } = useSWR(
|
||||
org && access_token ? [`/payments/${org.id}/config`, access_token] : null,
|
||||
([url, token]) => getPaymentConfigs(org.id, token)
|
||||
);
|
||||
|
||||
const isStripeEnabled = paymentConfigs?.some(
|
||||
(config: any) => config.provider === 'stripe' && config.active
|
||||
);
|
||||
|
||||
return {
|
||||
isEnabled: !!isStripeEnabled,
|
||||
isLoading,
|
||||
error
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue