feat: clean up the stripe payment integration

This commit is contained in:
Ahmed Bouhuolia
2024-09-21 09:18:39 +02:00
parent f5a1d68c52
commit 11c56c75a4
18 changed files with 3144 additions and 484 deletions

View File

@@ -10,17 +10,17 @@ import {
import useApiRequest from '../useRequest';
import { transformToCamelCase, transfromToSnakeCase } from '@/utils';
// Create Payment Link
// ------------------------------------
interface CreatePaymentLinkValues {
publicity: string;
transactionType: string;
transactionId: number | string;
expiryDate: string;
}
interface CreatePaymentLinkResponse {
link: string;
}
/**
* Creates a new payment link.
* @param {UseMutationOptions<CreatePaymentLinkResponse, Error, CreatePaymentLinkValues>} options
@@ -50,7 +50,10 @@ export function useCreatePaymentLink(
);
}
export interface GetSharableLinkMetaResponse {
// Get Invoice Payment Link
// -----------------------------------------
export interface GetInvoicePaymentLinkResponse {
dueAmount: number;
dueAmountFormatted: string;
dueDate: string;
@@ -80,20 +83,19 @@ export interface GetSharableLinkMetaResponse {
totalFormatted: string;
}>;
}
/**
* Fetches the sharable link metadata for a given link ID.
* Fetches the sharable invoice link metadata for a given link ID.
* @param {string} linkId - The ID of the link to fetch metadata for.
* @param {UseQueryOptions<GetSharableLinkMetaResponse, Error>} options - Optional query options.
* @returns {UseQueryResult<GetSharableLinkMetaResponse, Error>} The query result.
* @param {UseQueryOptions<GetInvoicePaymentLinkResponse, Error>} options - Optional query options.
* @returns {UseQueryResult<GetInvoicePaymentLinkResponse, Error>} The query result.
*/
export function useGetSharableLinkMeta(
export function useGetInvoicePaymentLink(
linkId: string,
options?: UseQueryOptions<GetSharableLinkMetaResponse, Error>,
): UseQueryResult<GetSharableLinkMetaResponse, Error> {
options?: UseQueryOptions<GetInvoicePaymentLinkResponse, Error>,
): UseQueryResult<GetInvoicePaymentLinkResponse, Error> {
const apiRequest = useApiRequest();
return useQuery<GetSharableLinkMetaResponse, Error>(
return useQuery<GetInvoicePaymentLinkResponse, Error>(
['sharable-link-meta', linkId],
() =>
apiRequest

View File

@@ -5,10 +5,13 @@ import { transformToCamelCase } from '@/utils';
const PaymentServicesQueryKey = 'PaymentServices';
export interface GetPaymentServicesResponse {
}
export interface GetPaymentServicesResponse {}
/**
* Retrieves the integrated payment services.
* @param {UseQueryOptions<GetPaymentServicesResponse, Error>} options
* @returns {UseQueryResult<GetPaymentServicesResponse, Error>}
*/
export const useGetPaymentServices = (
options?: UseQueryOptions<GetPaymentServicesResponse, Error>,
): UseQueryResult<GetPaymentServicesResponse, Error> => {

View File

@@ -14,6 +14,11 @@ interface AccountSessionResponse {
client_secret: string;
}
/**
* Generates a new Stripe checkout session for the provided link ID.
* @param {CreateCheckoutSessionValues} values - The values required to create a checkout session.
* @returns {Promise<CreateCheckoutSessionResponse>} The response containing the checkout session details.
*/
export const useCreateStripeAccountSession = (
options?: UseMutationOptions<
AccountSessionResponse,