feat(medusa,medusa-react): PaymentCollection support (#2659)
* chore: medusa react, order edit complete fix and single payment session
This commit is contained in:
1 parent
42d9c7222b
commit
15c667fbd3
54 files changed
+2001
-261
No files matched your search
@@ -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
|
||||
}
|
||||
@@ -13,3 +13,4 @@ export * from "./returns/"
|
||||
export * from "./gift-cards/"
|
||||
export * from "./line-items/"
|
||||
export * from "./collections"
|
||||
export * from "./payment-collections"
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./queries"
|
||||
export * from "./mutations"
|
||||
@@ -0,0 +1,139 @@
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
|
||||
import { Response } from "@medusajs/medusa-js"
|
||||
|
||||
import {
|
||||
StorePaymentCollectionsRes,
|
||||
StorePostPaymentCollectionsBatchSessionsReq,
|
||||
StorePostPaymentCollectionsBatchSessionsAuthorizeReq,
|
||||
StorePaymentCollectionSessionsReq,
|
||||
StorePaymentCollectionsSessionRes,
|
||||
} from "@medusajs/medusa"
|
||||
|
||||
import { buildOptions } from "../../utils/buildOptions"
|
||||
import { useMedusa } from "../../../contexts"
|
||||
import { paymentCollectionQueryKeys } from "."
|
||||
|
||||
export const useManageMultiplePaymentSessions = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
Response<StorePaymentCollectionsRes>,
|
||||
Error,
|
||||
StorePostPaymentCollectionsBatchSessionsReq
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
(payload: StorePostPaymentCollectionsBatchSessionsReq) =>
|
||||
client.paymentCollections.managePaymentSessionsBatch(id, payload),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[
|
||||
paymentCollectionQueryKeys.lists(),
|
||||
paymentCollectionQueryKeys.detail(id),
|
||||
],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export const useManagePaymentSession = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
Response<StorePaymentCollectionsRes>,
|
||||
Error,
|
||||
StorePaymentCollectionSessionsReq
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
(payload: StorePaymentCollectionSessionsReq) =>
|
||||
client.paymentCollections.managePaymentSession(id, payload),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[
|
||||
paymentCollectionQueryKeys.lists(),
|
||||
paymentCollectionQueryKeys.detail(id),
|
||||
],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export const useAuthorizePaymentSession = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
Response<StorePaymentCollectionsRes>,
|
||||
Error,
|
||||
string
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
(session_id: string) =>
|
||||
client.paymentCollections.authorizePaymentSession(id, session_id),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[
|
||||
paymentCollectionQueryKeys.lists(),
|
||||
paymentCollectionQueryKeys.detail(id),
|
||||
],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export const useAuthorizePaymentSessionsBatch = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
Response<StorePaymentCollectionsRes>,
|
||||
Error,
|
||||
StorePostPaymentCollectionsBatchSessionsAuthorizeReq
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
(payload) =>
|
||||
client.paymentCollections.authorizePaymentSessionsBatch(id, payload),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[
|
||||
paymentCollectionQueryKeys.lists(),
|
||||
paymentCollectionQueryKeys.detail(id),
|
||||
],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export const usePaymentCollectionRefreshPaymentSession = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
Response<StorePaymentCollectionsSessionRes>,
|
||||
Error,
|
||||
string
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
(session_id: string) =>
|
||||
client.paymentCollections.refreshPaymentSession(id, session_id),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[
|
||||
paymentCollectionQueryKeys.lists(),
|
||||
paymentCollectionQueryKeys.detail(id),
|
||||
],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { queryKeysFactory } from "../../utils"
|
||||
import { StorePaymentCollectionsRes } 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 paymentCollectionQueryKeys = queryKeysFactory<
|
||||
typeof PAYMENT_COLLECTION_QUERY_KEY
|
||||
>(PAYMENT_COLLECTION_QUERY_KEY)
|
||||
|
||||
type PaymentCollectionKey = typeof paymentCollectionQueryKeys
|
||||
|
||||
export const usePaymentCollection = (
|
||||
id: string,
|
||||
options?: UseQueryOptionsWrapper<
|
||||
Response<StorePaymentCollectionsRes>,
|
||||
Error,
|
||||
ReturnType<PaymentCollectionKey["detail"]>
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const { data, ...rest } = useQuery(
|
||||
paymentCollectionQueryKeys.detail(id),
|
||||
() => client.paymentCollections.retrieve(id),
|
||||
options
|
||||
)
|
||||
|
||||
return { ...data, ...rest } as const
|
||||
}
|
||||
Reference in new issue
Block a user