From d55fd207ea87b2ddb8f420215eec84166ec72b8b Mon Sep 17 00:00:00 2001 From: Nazli Yurdakul Date: Thu, 28 Mar 2024 15:57:06 -0400 Subject: [PATCH] offline transaction limits check --- .../src/screens/CollectCardPaymentScreen.tsx | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/dev-app/src/screens/CollectCardPaymentScreen.tsx b/dev-app/src/screens/CollectCardPaymentScreen.tsx index 44f6ae96..b1da8b3f 100644 --- a/dev-app/src/screens/CollectCardPaymentScreen.tsx +++ b/dev-app/src/screens/CollectCardPaymentScreen.tsx @@ -96,6 +96,7 @@ export default function CollectCardPaymentScreen() { retrievePaymentIntent, cancelCollectPaymentMethod, setSimulatedCard, + getOfflineStatus, } = useStripeTerminal({ onDidRequestReaderInput: (input) => { // @ts-ignore @@ -203,6 +204,35 @@ export default function CollectCardPaymentScreen() { paymentIntent = response.paymentIntent; paymentIntentError = response.error; } else { + const offlineStatus = await getOfflineStatus(); + let sdkStoredPaymentAmount = 0; + for (let currency in offlineStatus.sdk.offlinePaymentAmountsByCurrency) { + if (currency === inputValues.currency) { + sdkStoredPaymentAmount = + offlineStatus.sdk.offlinePaymentAmountsByCurrency[currency]; + } + } + let readerStoredPaymentAmount = 0; + if (offlineStatus.reader) { + for (let currency in offlineStatus.reader + .offlinePaymentAmountsByCurrency) { + if (currency === inputValues.currency) { + readerStoredPaymentAmount = + offlineStatus.reader.offlinePaymentAmountsByCurrency[currency]; + } + } + } + if ( + Number(inputValues.amount) > + Number(inputValues.offlineModeTransactionLimit) || + sdkStoredPaymentAmount > + Number(inputValues.offlineModeStoredTransactionLimit) || + readerStoredPaymentAmount > + Number(inputValues.offlineModeStoredTransactionLimit) + ) { + inputValues.offlineBehavior = 'require_online'; + } + const response = await createPaymentIntent({ amount: Number(inputValues.amount), currency: inputValues.currency,