From 06f8fae04b835a036d0cf14510bdbd3550571180 Mon Sep 17 00:00:00 2001 From: Alessandro Casazza Date: Thu, 28 Nov 2024 17:28:33 +0100 Subject: [PATCH] Prevent uncorrected place order --- .../src/components/payment_source/AdyenPayment.tsx | 3 +++ .../react-components/src/reducers/PlaceOrderReducer.ts | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/react-components/src/components/payment_source/AdyenPayment.tsx b/packages/react-components/src/components/payment_source/AdyenPayment.tsx index c0a272c8..b434b341 100644 --- a/packages/react-components/src/components/payment_source/AdyenPayment.tsx +++ b/packages/react-components/src/components/payment_source/AdyenPayment.tsx @@ -376,6 +376,9 @@ export function AdyenPayment({ .create(type, { showRemovePaymentMethodButton: showStoredPaymentMethods, instantPaymentTypes: ['applepay', 'googlepay'], + onDisableStoredPaymentMethod: (state) => { + console.log('onDisableStoredPaymentMethod', state) + }, onSelect: (component) => { const id: string = component._id if (id.search('scheme') === -1) { diff --git a/packages/react-components/src/reducers/PlaceOrderReducer.ts b/packages/react-components/src/reducers/PlaceOrderReducer.ts index a7e6ebc9..165be1bc 100644 --- a/packages/react-components/src/reducers/PlaceOrderReducer.ts +++ b/packages/react-components/src/reducers/PlaceOrderReducer.ts @@ -188,6 +188,16 @@ export async function setPlaceOrder({ const sdk = getSdk(config) const { options, paymentType } = state try { + // Prevent extra place order + const lastOrderStatus = await sdk.orders.retrieve(order.id, { + fields: { orders: ['status'] } + }) + if (lastOrderStatus.status === 'placed') { + return { + placed: true, + order + } + } if ( paymentType === 'paypal_payments' && paymentSource?.type === 'paypal_payments'