feat(medusa,medusa-react): PaymentCollection support (#2659)
* chore: medusa react, order edit complete fix and single payment session
This commit is contained in:
@@ -30,3 +30,5 @@ export * from "./tax-rates"
|
||||
export * from "./uploads"
|
||||
export * from "./users"
|
||||
export * from "./variants"
|
||||
export * from "./payment-collections"
|
||||
export * from "./payments"
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./queries"
|
||||
export * from "./mutations"
|
||||
@@ -0,0 +1,85 @@
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
|
||||
import { Response } from "@medusajs/medusa-js"
|
||||
|
||||
import {
|
||||
AdminPaymentCollectionDeleteRes,
|
||||
AdminPaymentCollectionsRes,
|
||||
AdminUpdatePaymentCollectionsReq,
|
||||
} from "@medusajs/medusa"
|
||||
|
||||
import { buildOptions } from "../../utils/buildOptions"
|
||||
import { useMedusa } from "../../../contexts"
|
||||
import { adminPaymentCollectionQueryKeys } from "."
|
||||
|
||||
export const useAdminDeletePaymentCollection = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
Response<AdminPaymentCollectionDeleteRes>,
|
||||
Error,
|
||||
void
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
() => client.admin.paymentCollections.delete(id),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[
|
||||
adminPaymentCollectionQueryKeys.detail(id),
|
||||
adminPaymentCollectionQueryKeys.lists(),
|
||||
],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export const useAdminUpdatePaymentCollection = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
Response<AdminPaymentCollectionsRes>,
|
||||
Error,
|
||||
AdminUpdatePaymentCollectionsReq
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
(payload: AdminUpdatePaymentCollectionsReq) =>
|
||||
client.admin.paymentCollections.update(id, payload),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[
|
||||
adminPaymentCollectionQueryKeys.detail(id),
|
||||
adminPaymentCollectionQueryKeys.lists(),
|
||||
],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export const useAdminMarkPaymentCollectionAsAuthorized = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
Response<AdminPaymentCollectionsRes>,
|
||||
Error,
|
||||
void
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
() => client.admin.paymentCollections.markAsAuthorized(id),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[
|
||||
adminPaymentCollectionQueryKeys.detail(id),
|
||||
adminPaymentCollectionQueryKeys.lists(),
|
||||
],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { queryKeysFactory } from "../../utils"
|
||||
import { AdminPaymentCollectionsRes } from "@medusajs/medusa"
|
||||
import { useQuery } from "react-query"
|
||||
import { useMedusa } from "../../../contexts"
|
||||
import { UseQueryOptionsWrapper } from "../../../types"
|
||||
import { Response } from "@medusajs/medusa-js"
|
||||
|
||||
const PAYMENT_COLLECTION_QUERY_KEY = `paymentCollection` as const
|
||||
|
||||
export const adminPaymentCollectionQueryKeys = queryKeysFactory<
|
||||
typeof PAYMENT_COLLECTION_QUERY_KEY
|
||||
>(PAYMENT_COLLECTION_QUERY_KEY)
|
||||
|
||||
type AdminPaymentCollectionKey = typeof adminPaymentCollectionQueryKeys
|
||||
|
||||
export const useAdminPaymentCollection = (
|
||||
id: string,
|
||||
options?: UseQueryOptionsWrapper<
|
||||
Response<AdminPaymentCollectionsRes>,
|
||||
Error,
|
||||
ReturnType<AdminPaymentCollectionKey["detail"]>
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const { data, ...rest } = useQuery(
|
||||
adminPaymentCollectionQueryKeys.detail(id),
|
||||
() => client.admin.paymentCollections.retrieve(id),
|
||||
options
|
||||
)
|
||||
|
||||
return { ...data, ...rest } as const
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./queries"
|
||||
export * from "./mutations"
|
||||
@@ -0,0 +1,51 @@
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
|
||||
import { Response } from "@medusajs/medusa-js"
|
||||
|
||||
import {
|
||||
AdminPaymentRes,
|
||||
AdminPostPaymentRefundsReq,
|
||||
AdminRefundRes,
|
||||
} from "@medusajs/medusa"
|
||||
|
||||
import { buildOptions } from "../../utils/buildOptions"
|
||||
import { useMedusa } from "../../../contexts"
|
||||
import { adminPaymentQueryKeys } from "."
|
||||
|
||||
export const useAdminPaymentsCapturePayment = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<Response<AdminPaymentRes>, Error, void>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
() => client.admin.payments.capturePayment(id),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[adminPaymentQueryKeys.detail(id), adminPaymentQueryKeys.lists()],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export const useAdminPaymentsRefundPayment = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
Response<AdminRefundRes>,
|
||||
Error,
|
||||
AdminPostPaymentRefundsReq
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
(payload: AdminPostPaymentRefundsReq) =>
|
||||
client.admin.payments.refundPayment(id, payload),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[adminPaymentQueryKeys.detail(id), adminPaymentQueryKeys.lists()],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { queryKeysFactory } from "../../utils"
|
||||
import { AdminPaymentRes } from "@medusajs/medusa"
|
||||
import { useQuery } from "react-query"
|
||||
import { useMedusa } from "../../../contexts"
|
||||
import { UseQueryOptionsWrapper } from "../../../types"
|
||||
import { Response } from "@medusajs/medusa-js"
|
||||
|
||||
const PAYMENT_QUERY_KEY = `payment` as const
|
||||
|
||||
export const adminPaymentQueryKeys =
|
||||
queryKeysFactory<typeof PAYMENT_QUERY_KEY>(PAYMENT_QUERY_KEY)
|
||||
|
||||
type AdminPaymentKey = typeof adminPaymentQueryKeys
|
||||
|
||||
export const useAdminPayment = (
|
||||
id: string,
|
||||
options?: UseQueryOptionsWrapper<
|
||||
Response<AdminPaymentRes>,
|
||||
Error,
|
||||
ReturnType<AdminPaymentKey["detail"]>
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const { data, ...rest } = useQuery(
|
||||
adminPaymentQueryKeys.detail(id),
|
||||
() => client.admin.payments.retrieve(id),
|
||||
options
|
||||
)
|
||||
|
||||
return { ...data, ...rest } as const
|
||||
}
|
||||
Reference in New Issue
Block a user