diff --git a/packages/react-shopper-hooks/src/index.ts b/packages/react-shopper-hooks/src/index.ts index 755fe624..b15d0e94 100644 --- a/packages/react-shopper-hooks/src/index.ts +++ b/packages/react-shopper-hooks/src/index.ts @@ -8,4 +8,5 @@ export * from "./account" export * from "./elasticpath" export * from "./payments" export * from "./currency" +export * from "./order" export * from "@elasticpath/shopper-common" diff --git a/packages/react-shopper-hooks/src/order/hooks/index.ts b/packages/react-shopper-hooks/src/order/hooks/index.ts new file mode 100644 index 00000000..be069fed --- /dev/null +++ b/packages/react-shopper-hooks/src/order/hooks/index.ts @@ -0,0 +1 @@ +export * from "./use-order-confirm" diff --git a/packages/react-shopper-hooks/src/order/hooks/use-order-confirm.ts b/packages/react-shopper-hooks/src/order/hooks/use-order-confirm.ts new file mode 100644 index 00000000..f4e9e059 --- /dev/null +++ b/packages/react-shopper-hooks/src/order/hooks/use-order-confirm.ts @@ -0,0 +1,29 @@ +import { useMutation, UseMutationOptions } from "@tanstack/react-query" +import { useElasticPath } from "../../elasticpath" +import { ConfirmPaymentResponse, ConfirmPaymentBody } from "@moltin/sdk" + +export type UseOrderConfirmReq = { + orderId: string + transactionId: string + options: ConfirmPaymentBody +} + +export const useOrderConfirm = ( + options?: UseMutationOptions< + ConfirmPaymentResponse, + Error, + UseOrderConfirmReq + >, +) => { + const { client } = useElasticPath() + return useMutation({ + mutationFn: async ({ + orderId, + transactionId, + options, + }: UseOrderConfirmReq) => { + return client.Orders.Confirm(orderId, transactionId, options) + }, + ...options, + }) +} diff --git a/packages/react-shopper-hooks/src/order/index.ts b/packages/react-shopper-hooks/src/order/index.ts new file mode 100644 index 00000000..351e313d --- /dev/null +++ b/packages/react-shopper-hooks/src/order/index.ts @@ -0,0 +1 @@ +export * from "./hooks"