38 lines
762 B
TypeScript
38 lines
762 B
TypeScript
// imports
|
|
|
|
import { useMutation } from "@tanstack/vue-query";
|
|
import { API_ENDPOINTS } from "~/constants";
|
|
|
|
// types
|
|
|
|
export type PayOrderRequest = {
|
|
gateway_type: Pick<PaymentGateway, "type">;
|
|
};
|
|
|
|
export type PayOrderResponse = {
|
|
url: string;
|
|
};
|
|
|
|
const usePayOrder = () => {
|
|
// state
|
|
|
|
const { $axios: axios } = useNuxtApp();
|
|
|
|
// methods
|
|
|
|
const handlePayOrder = async (params: PayOrderRequest) => {
|
|
const { data } = await axios.post<PayOrderResponse>(
|
|
API_ENDPOINTS.orders.checkout.payment,
|
|
{ ...params }
|
|
);
|
|
return data;
|
|
};
|
|
|
|
return useMutation({
|
|
mutationFn: (PaymentData: PayOrderRequest) =>
|
|
handlePayOrder(PaymentData),
|
|
});
|
|
};
|
|
|
|
export default usePayOrder;
|