feat(dashboard,js-sdk,types): add ability to capture payment from order page (#8368)
what: - adds ability to capture payment from order page bugs found: - when capturing payment of one order, other orders statuses get affected from "captured" to "partially captured". Will investigate this separately. https://github.com/user-attachments/assets/0a1beac2-74fc-4803-8528-8de5913964d4
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
import { QueryKey, useQuery, UseQueryOptions } from "@tanstack/react-query"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
QueryKey,
|
||||
useMutation,
|
||||
UseMutationOptions,
|
||||
useQuery,
|
||||
UseQueryOptions,
|
||||
} from "@tanstack/react-query"
|
||||
import { client, sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { PaymentProvidersListRes } from "../../types/api-responses"
|
||||
import { client } from "../../lib/client"
|
||||
import { ordersQueryKeys } from "./orders"
|
||||
|
||||
export const usePaymentProviders = (
|
||||
query?: Record<string, any>,
|
||||
@@ -22,3 +31,28 @@ export const usePaymentProviders = (
|
||||
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
export const useCapturePayment = (
|
||||
paymentId: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminPaymentResponse,
|
||||
Error,
|
||||
HttpTypes.AdminCapturePayment
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => sdk.admin.payment.capture(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