mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
feat: Stripe payment integration
This commit is contained in:
69
packages/webapp/src/hooks/query/payment-methods.ts
Normal file
69
packages/webapp/src/hooks/query/payment-methods.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
// @ts-nocheck
|
||||
import {
|
||||
useMutation,
|
||||
UseMutationOptions,
|
||||
UseMutationResult,
|
||||
} from 'react-query';
|
||||
import useApiRequest from '../useRequest';
|
||||
|
||||
|
||||
// # Delete payment method
|
||||
// -----------------------------------------
|
||||
interface DeletePaymentMethodValues {
|
||||
paymentMethodId: number;
|
||||
}
|
||||
export const useDeletePaymentMethod = (
|
||||
options?: UseMutationOptions<void, Error, DeletePaymentMethodValues>,
|
||||
): UseMutationResult<void, Error, DeletePaymentMethodValues> => {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation<void, Error, DeletePaymentMethodValues>(
|
||||
({ paymentMethodId }) => {
|
||||
return apiRequest
|
||||
.delete(`/payment-methods/${paymentMethodId}`)
|
||||
.then((res) => res.data);
|
||||
},
|
||||
{ ...options },
|
||||
);
|
||||
};
|
||||
|
||||
// # Edit payment method
|
||||
// -----------------------------------------
|
||||
interface EditPaymentMethodValues {
|
||||
paymentMethodId: number;
|
||||
name?: string;
|
||||
bankAccountId?: number;
|
||||
clearningAccountId?: number;
|
||||
showVisa?: boolean;
|
||||
showMasterCard?: boolean;
|
||||
showDiscover?: boolean;
|
||||
showAmer?: boolean;
|
||||
showJcb?: boolean;
|
||||
showDiners?: boolean;
|
||||
}
|
||||
interface EditPaymentMethodResponse {
|
||||
id: number;
|
||||
message: string;
|
||||
}
|
||||
export const useEditPaymentMethod = (
|
||||
options?: UseMutationOptions<
|
||||
EditPaymentMethodResponse,
|
||||
Error,
|
||||
EditPaymentMethodValues
|
||||
>,
|
||||
): UseMutationResult<
|
||||
EditPaymentMethodResponse,
|
||||
Error,
|
||||
EditPaymentMethodValues
|
||||
> => {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation<EditPaymentMethodResponse, Error, EditPaymentMethodValues>(
|
||||
({ paymentMethodId, ...editData }) => {
|
||||
return apiRequest
|
||||
.put(`/payment-methods/${paymentMethodId}`, editData)
|
||||
.then((res) => res.data);
|
||||
},
|
||||
{ ...options },
|
||||
);
|
||||
};
|
||||
@@ -6,7 +6,6 @@ import { transformToCamelCase } from '@/utils';
|
||||
const PaymentServicesQueryKey = 'PaymentServices';
|
||||
|
||||
export interface GetPaymentServicesResponse {}
|
||||
|
||||
/**
|
||||
* Retrieves the integrated payment services.
|
||||
* @param {UseQueryOptions<GetPaymentServicesResponse, Error>} options
|
||||
@@ -33,3 +32,31 @@ export const useGetPaymentServices = (
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export interface GetPaymentServicesStateResponse {}
|
||||
/**
|
||||
* Retrieves the state of payment services.
|
||||
* @param {UseQueryOptions<GetPaymentServicesStateResponse, Error>} options
|
||||
* @returns {UseQueryResult<GetPaymentServicesStateResponse, Error>}
|
||||
*/
|
||||
export const useGetPaymentServicesState = (
|
||||
options?: UseQueryOptions<GetPaymentServicesStateResponse, Error>,
|
||||
): UseQueryResult<GetPaymentServicesStateResponse, Error> => {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useQuery<GetPaymentServicesStateResponse, Error>(
|
||||
['PaymentServicesState'],
|
||||
() =>
|
||||
apiRequest
|
||||
.get('/payment-services/state')
|
||||
.then(
|
||||
(response) =>
|
||||
transformToCamelCase(
|
||||
response.data?.paymentServicesState,
|
||||
) as GetPaymentServicesStateResponse,
|
||||
),
|
||||
{
|
||||
...options,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -7,6 +7,49 @@ import {
|
||||
import useApiRequest from '../useRequest';
|
||||
import { transformToCamelCase } from '@/utils';
|
||||
|
||||
|
||||
// Create Stripe Account Link.
|
||||
// ------------------------------------
|
||||
interface StripeAccountLinkResponse {
|
||||
clientSecret: {
|
||||
created: number;
|
||||
expiresAt: number;
|
||||
object: string;
|
||||
url: string;
|
||||
};
|
||||
}
|
||||
interface StripeAccountLinkValues {
|
||||
stripeAccountId: string;
|
||||
}
|
||||
|
||||
export const useCreateStripeAccountLink = (
|
||||
options?: UseMutationOptions<
|
||||
StripeAccountLinkResponse,
|
||||
Error,
|
||||
StripeAccountLinkValues
|
||||
>,
|
||||
): UseMutationResult<
|
||||
StripeAccountLinkResponse,
|
||||
Error,
|
||||
StripeAccountLinkValues
|
||||
> => {
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
(values: StripeAccountLinkValues) => {
|
||||
return apiRequest
|
||||
.post('/stripe_integration/account_link', {
|
||||
stripe_account_id: values?.stripeAccountId,
|
||||
})
|
||||
.then((res) => transformToCamelCase(res.data));
|
||||
},
|
||||
{ ...options },
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// Create Stripe Account Session.
|
||||
// ------------------------------------
|
||||
interface AccountSessionValues {
|
||||
connectedAccountId?: string;
|
||||
}
|
||||
@@ -40,6 +83,8 @@ export const useCreateStripeAccountSession = (
|
||||
);
|
||||
};
|
||||
|
||||
// Create Stripe Account.
|
||||
// ------------------------------------
|
||||
interface CreateStripeAccountValues {}
|
||||
interface CreateStripeAccountResponse {
|
||||
account_id: string;
|
||||
@@ -64,6 +109,8 @@ export const useCreateStripeAccount = (
|
||||
);
|
||||
};
|
||||
|
||||
// Create Stripe Checkout Session.
|
||||
// ------------------------------------
|
||||
interface CreateCheckoutSessionValues {
|
||||
linkId: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user