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:
Riqwan Thamir
2024-08-01 06:46:03 +00:00
committed by GitHub
parent 4a7b2fd625
commit 3169543d56
10 changed files with 160 additions and 30 deletions
@@ -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,
})
}