feat: Delete Stripe payment method

This commit is contained in:
Ahmed Bouhuolia
2024-09-22 14:30:47 +02:00
parent c0a4c965f0
commit 3129c76c30
12 changed files with 262 additions and 14 deletions

View File

@@ -1,7 +1,12 @@
// @ts-nocheck
import { useQuery, UseQueryOptions, UseQueryResult } from 'react-query';
import {
useMutation,
useQuery,
UseQueryOptions,
UseQueryResult,
} from 'react-query';
import useApiRequest from '../useRequest';
import { transformToCamelCase } from '@/utils';
import { transformToCamelCase, transfromToSnakeCase } from '@/utils';
const PaymentServicesQueryKey = 'PaymentServices';
@@ -37,7 +42,8 @@ export interface GetPaymentServicesStateResponse {
stripe: {
isStripeAccountCreated: boolean;
isStripePaymentActive: boolean;
stripeAccountId: string;
stripeAccountId: string | null;
stripePaymentMethodId: number | null;
stripeCurrencies: string[];
stripePublishableKey: string;
stripeRedirectUrl: string;
@@ -69,3 +75,42 @@ export const useGetPaymentServicesState = (
},
);
};
interface UpdatePaymentMethodResponse {
id: number;
message: string;
}
interface UpdatePaymentMethodValues {
paymentMethodId: string | number;
values: {
name: string;
bankAccountId: number;
clearingAccountId: number;
};
}
/**
* Updates a payment method.
* @returns {UseMutationResult<UpdatePaymentMethodResponse, Error, UpdatePaymentMethodValues, unknown>}
*/
export const useUpdatePaymentMethod = (): UseMutationResult<
UpdatePaymentMethodResponse,
Error,
UpdatePaymentMethodValues,
unknown
> => {
const apiRequest = useApiRequest();
return useMutation<
UpdatePaymentMethodResponse,
Error,
UpdatePaymentMethodValues,
unknown
>((data: UpdatePaymentMethodValues) =>
apiRequest
.post(
`/payment-services/${data.paymentMethodId}`,
transfromToSnakeCase(data.values),
)
.then((response) => response.data),
);
};