Skip to content

Commit

Permalink
offline transaction limits check
Browse files Browse the repository at this point in the history
  • Loading branch information
nazli-stripe committed Mar 28, 2024
1 parent 04e3e8d commit d55fd20
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions dev-app/src/screens/CollectCardPaymentScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default function CollectCardPaymentScreen() {
retrievePaymentIntent,
cancelCollectPaymentMethod,
setSimulatedCard,
getOfflineStatus,
} = useStripeTerminal({
onDidRequestReaderInput: (input) => {
// @ts-ignore
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d55fd20

Please sign in to comment.