feat: Stripe connect using OAuth

This commit is contained in:
Ahmed Bouhuolia
2024-09-24 14:10:53 +02:00
parent 70bba4a6ed
commit b125e3e58b
26 changed files with 493 additions and 98 deletions

View File

@@ -12,7 +12,6 @@ import { transformToCamelCase, transfromToSnakeCase } from '@/utils';
const PaymentServicesQueryKey = 'PaymentServices';
const PaymentServicesStateQueryKey = 'PaymentServicesState';
// # Get payment services.
// -----------------------------------------
export interface GetPaymentServicesResponse {}
@@ -48,12 +47,15 @@ export const useGetPaymentServices = (
export interface GetPaymentServicesStateResponse {
stripe: {
isStripeAccountCreated: boolean;
isStripePaymentActive: boolean;
isStripePaymentEnabled: boolean;
isStripePayoutEnabled: boolean;
isStripeEnabled: boolean;
isStripeServerConfigured: boolean;
stripeAccountId: string | null;
stripePaymentMethodId: number | null;
stripeCurrencies: string[];
stripePublishableKey: string;
stripeAuthLink: string;
stripeRedirectUrl: string;
};
}

View File

@@ -7,7 +7,6 @@ import {
import useApiRequest from '../useRequest';
import { transformToCamelCase } from '@/utils';
// Create Stripe Account Link.
// ------------------------------------
interface StripeAccountLinkResponse {
@@ -47,7 +46,6 @@ export const useCreateStripeAccountLink = (
);
};
// Create Stripe Account Session.
// ------------------------------------
interface AccountSessionValues {
@@ -149,3 +147,70 @@ export const useCreateStripeCheckoutSession = (
{ ...options },
);
};
// Create Stripe Account OAuth Link.
// ------------------------------------
interface StripeAccountLinkResponse {
clientSecret: {
created: number;
expiresAt: number;
object: string;
url: string;
};
}
interface StripeAccountLinkValues {
stripeAccountId: string;
}
export const useGetStripeAccountLink = (
options?: UseQueryOptions<StripeAccountLinkResponse, Error>,
): UseQueryResult<StripeAccountLinkResponse, Error> => {
const apiRequest = useApiRequest();
return useQuery(
'getStripeAccountLink',
() => {
return apiRequest
.get('/stripe_integration/link')
.then((res) => transformToCamelCase(res.data));
},
{ ...options },
);
};
// Get Stripe Account OAuth Callback Mutation.
// ------------------------------------
interface StripeAccountCallbackMutationValues {
code: string;
}
interface StripeAccountCallbackMutationResponse {
success: boolean;
}
export const useSetStripeAccountCallback = (
options?: UseMutationOptions<
StripeAccountCallbackMutationResponse,
Error,
StripeAccountCallbackMutationValues
>,
): UseMutationResult<
StripeAccountCallbackMutationResponse,
Error,
StripeAccountCallbackMutationValues
> => {
const apiRequest = useApiRequest();
return useMutation(
(values: StripeAccountCallbackMutationValues) => {
return apiRequest
.post(`/stripe_integration/callback`, values)
.then(
(res) =>
transformToCamelCase(
res.data,
) as StripeAccountCallbackMutationResponse,
);
},
{ ...options },
);
};