From 9956b1c0fb751e625bf299ae1f5a1376bb99b265 Mon Sep 17 00:00:00 2001 From: Robert Field Date: Fri, 12 Jan 2024 14:00:42 +0000 Subject: [PATCH] feat: add order confirm hooks --- packages/react-shopper-hooks/src/index.ts | 1 + .../src/order/hooks/index.ts | 1 + .../src/order/hooks/use-order-confirm.ts | 29 +++++++++++++++++++ .../react-shopper-hooks/src/order/index.ts | 1 + 4 files changed, 32 insertions(+) create mode 100644 packages/react-shopper-hooks/src/order/hooks/index.ts create mode 100644 packages/react-shopper-hooks/src/order/hooks/use-order-confirm.ts create mode 100644 packages/react-shopper-hooks/src/order/index.ts 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"