feat: Stripe payment integration

This commit is contained in:
Ahmed Bouhuolia
2024-09-21 16:50:22 +02:00
parent 8de8695b25
commit 7756b5b304
24 changed files with 691 additions and 102 deletions

View 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 },
);
};