feat(dashboard,types,js-sdk,payment): ability to refund payment in order page (#8385)
* feat(dashboard,types,js-sdk,payment): ability to refund payment in order page * chore: use confirmation variant for capture payment * chore: change refund design accords to figma * chore: move to js-sdk + currency input
This commit is contained in:
@@ -8,9 +8,13 @@ import {
|
||||
} from "@tanstack/react-query"
|
||||
import { client, sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { PaymentProvidersListRes } from "../../types/api-responses"
|
||||
import { ordersQueryKeys } from "./orders"
|
||||
|
||||
const PAYMENT_QUERY_KEY = "payment" as const
|
||||
export const paymentQueryKeys = queryKeysFactory(PAYMENT_QUERY_KEY)
|
||||
|
||||
export const usePaymentProviders = (
|
||||
query?: Record<string, any>,
|
||||
options?: Omit<
|
||||
@@ -32,6 +36,28 @@ export const usePaymentProviders = (
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
export const usePayment = (
|
||||
id: string,
|
||||
query?: HttpTypes.AdminPaymentFilters,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminPaymentResponse,
|
||||
Error,
|
||||
HttpTypes.AdminPaymentResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => sdk.admin.payment.retrieve(id, query),
|
||||
queryKey: paymentQueryKeys.detail(id),
|
||||
...options,
|
||||
})
|
||||
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
export const useCapturePayment = (
|
||||
paymentId: string,
|
||||
options?: UseMutationOptions<
|
||||
@@ -56,3 +82,28 @@ export const useCapturePayment = (
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useRefundPayment = (
|
||||
paymentId: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminPaymentResponse,
|
||||
Error,
|
||||
HttpTypes.AdminRefundPayment
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => sdk.admin.payment.refund(paymentId, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.lists(),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user