From 8d446a8aae7d4609db52f09a686dd31c11604aa9 Mon Sep 17 00:00:00 2001 From: Nazli Yurdakul Date: Mon, 4 Dec 2023 14:54:59 -0500 Subject: [PATCH 1/9] fix offline status returns for ios --- dev-app/src/screens/DatabaseScreen.tsx | 4 ++-- dev-app/src/screens/HomeScreen.tsx | 9 +++++---- ios/Mappers.swift | 17 +++++++++++++---- ios/StripeTerminalReactNative.swift | 16 ++++------------ src/StripeTerminalSdk.tsx | 4 ++-- src/functions.ts | 4 ++-- src/types/index.ts | 14 ++++---------- 7 files changed, 32 insertions(+), 36 deletions(-) diff --git a/dev-app/src/screens/DatabaseScreen.tsx b/dev-app/src/screens/DatabaseScreen.tsx index 686e60af..b11f0a5f 100644 --- a/dev-app/src/screens/DatabaseScreen.tsx +++ b/dev-app/src/screens/DatabaseScreen.tsx @@ -1,6 +1,6 @@ import React, { useContext, useEffect, useState } from 'react'; import { ScrollView, StyleSheet, Text } from 'react-native'; -import type { OfflinePaymentStatus } from 'src/types'; +import type { OfflineStatus } from 'src/types'; import { colors } from '../colors'; import List from '../components/List'; import ListItem from '../components/ListItem'; @@ -10,7 +10,7 @@ import { useStripeTerminal } from '@stripe/stripe-terminal-react-native'; export default function DatabaseScreen() { const { account } = useContext(AppContext); const [offlinePaymentStatus, setOfflinePaymentStatus] = - useState(null); + useState(null); const currencySymbols = [ { value: 'usd', label: '$' }, { value: 'gbp', label: '£' }, diff --git a/dev-app/src/screens/HomeScreen.tsx b/dev-app/src/screens/HomeScreen.tsx index 0255a3df..44f5a31b 100644 --- a/dev-app/src/screens/HomeScreen.tsx +++ b/dev-app/src/screens/HomeScreen.tsx @@ -33,8 +33,9 @@ export default function HomeScreen() { useState('bluetoothScan'); const { disconnectReader, connectedReader } = useStripeTerminal({ onDidChangeOfflineStatus(status: OfflineStatus) { - console.log('offline status = ' + status.networkStatus); - setOnline(status.networkStatus == 'online' ? true : false); + console.log('offline status = ' + status.sdk.networkStatus); + console.log(status); + setOnline(status.sdk.networkStatus === 'online' ? true : false); }, onDidForwardingFailure(error) { console.log('onDidForwardingFailure ' + error?.message); @@ -56,9 +57,9 @@ export default function HomeScreen() { 'Payment Intent ' + paymentIntent.id + ' forwarded. ErrorCode' + - error.code + + error?.code + '. ErrorMsg = ' + - error.message; + error?.message; let toast = Toast.show(toastMsg, { duration: Toast.durations.LONG, position: Toast.positions.BOTTOM, diff --git a/ios/Mappers.swift b/ios/Mappers.swift index cd4a3793..9d4c0a25 100644 --- a/ios/Mappers.swift +++ b/ios/Mappers.swift @@ -518,10 +518,19 @@ class Mappers { } class func mapFromOfflineStatus(_ offlineStatus: OfflineStatus) -> NSDictionary { - let result: NSDictionary = [ - "networkStatus": mapFromNetworkStatus(offlineStatus.sdk.networkStatus) - ] - return result + let sdkDic: NSDictionary = [ + "networkStatus": Mappers.mapFromNetworkStatus(offlineStatus.sdk.networkStatus), + "offlinePaymentsCount": offlineStatus.sdk.paymentsCount ?? 0, + "offlinePaymentAmountsByCurrency": offlineStatus.sdk.paymentAmountsByCurrency + ] + + let readDic: NSDictionary = [ + "networkStatus": Mappers.mapFromNetworkStatus(offlineStatus.reader?.networkStatus ?? NetworkStatus.unknown), + "offlinePaymentsCount": offlineStatus.reader?.paymentsCount ?? 0, + "offlinePaymentAmountsByCurrency": offlineStatus.reader?.paymentAmountsByCurrency ?? {} + ] + + return(["sdk": sdkDic, "reader": readDic]) } } diff --git a/ios/StripeTerminalReactNative.swift b/ios/StripeTerminalReactNative.swift index b92970cd..1172b4a5 100644 --- a/ios/StripeTerminalReactNative.swift +++ b/ios/StripeTerminalReactNative.swift @@ -915,17 +915,9 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe @objc(getOfflineStatus:rejecter:) func getOfflineStatus(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) { - let sdkDic: NSDictionary = [ - "offlinePaymentsCount": Terminal.shared.offlineStatus.sdk.paymentsCount ?? 0, - "offlinePaymentAmountsByCurrency": Terminal.shared.offlineStatus.sdk.paymentAmountsByCurrency - ] - - let readDic: NSDictionary = [ - "offlinePaymentsCount": Terminal.shared.offlineStatus.reader?.paymentsCount ?? 0, - "offlinePaymentAmountsByCurrency": Terminal.shared.offlineStatus.reader?.paymentAmountsByCurrency ?? {} - ] + let result = Mappers.mapFromOfflineStatus(Terminal.shared.offlineStatus) - resolve(["sdk": sdkDic, "reader": readDic]) + resolve(result) } func reader(_ reader: Reader, didReportAvailableUpdate update: ReaderSoftwareUpdate) { @@ -1003,8 +995,8 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe } func terminal(_ terminal: Terminal, didChange offlineStatus: OfflineStatus) { - let offlineStatus = Mappers.mapFromOfflineStatus(offlineStatus) - sendEvent(withName: ReactNativeConstants.CHANGE_OFFLINE_STATUS.rawValue, body: ["result": offlineStatus]) + let result = Mappers.mapFromOfflineStatus(offlineStatus) + sendEvent(withName: ReactNativeConstants.CHANGE_OFFLINE_STATUS.rawValue, body: ["result": result]) } func terminal(_ terminal: Terminal, didForwardPaymentIntent intent: PaymentIntent, error: Error?) { diff --git a/src/StripeTerminalSdk.tsx b/src/StripeTerminalSdk.tsx index 5de1280c..e0d98c77 100644 --- a/src/StripeTerminalSdk.tsx +++ b/src/StripeTerminalSdk.tsx @@ -29,7 +29,7 @@ import type { CollectPaymentMethodParams, PaymentIntent, SetupIntent, - OfflinePaymentStatus, + OfflineStatus, } from './types'; const { StripeTerminalReactNative } = NativeModules; @@ -139,7 +139,7 @@ export interface StripeTerminalSdkType { setSimulatedCard(cardNumber: string): Promise<{ error?: StripeError; }>; - getOfflineStatus(): Promise; + getOfflineStatus(): Promise; } export default StripeTerminalReactNative as StripeTerminalSdkType; diff --git a/src/functions.ts b/src/functions.ts index a26b8bd9..2062adcc 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -30,7 +30,7 @@ import type { CollectPaymentMethodParams, PaymentIntent, SetupIntent, - OfflinePaymentStatus, + OfflineStatus, } from './types'; export async function initialize( @@ -742,7 +742,7 @@ export async function cancelCollectSetupIntent(): Promise<{ }, 'cancelCollectSetupIntent')(); } -export async function getOfflineStatus(): Promise { +export async function getOfflineStatus(): Promise { return Logger.traceSdkMethod(async () => { try { const offlineStatus = await StripeTerminalSdk.getOfflineStatus(); diff --git a/src/types/index.ts b/src/types/index.ts index 4de5c295..9979e36b 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -272,21 +272,15 @@ export type ConfirmRefundResultType = { error?: StripeError; }; -export type OfflineStatus = { +export type OfflineStatusDetails = { networkStatus: 'online' | 'offline' | 'unknown'; offlinePaymentsCount: number; offlinePaymentAmountsByCurrency: { [key: string]: number }; }; -export type OfflinePaymentStatus = { - sdk: { - offlinePaymentsCount: number; - offlinePaymentAmountsByCurrency: { [key: string]: number }; - }; - reader: { - offlinePaymentsCount: number; - offlinePaymentAmountsByCurrency: { [key: string]: number }; - }; +export type OfflineStatus = { + sdk: OfflineStatusDetails; + reader: OfflineStatusDetails; }; type CardDetails = { From 5296a74770ac81788a7787bc3295348711a7026b Mon Sep 17 00:00:00 2001 From: Nazli Yurdakul Date: Mon, 4 Dec 2023 16:01:35 -0500 Subject: [PATCH 2/9] return empty dict for reader --- ios/Mappers.swift | 13 ++++++++----- src/types/index.ts | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ios/Mappers.swift b/ios/Mappers.swift index 9d4c0a25..f88846b7 100644 --- a/ios/Mappers.swift +++ b/ios/Mappers.swift @@ -524,11 +524,14 @@ class Mappers { "offlinePaymentAmountsByCurrency": offlineStatus.sdk.paymentAmountsByCurrency ] - let readDic: NSDictionary = [ - "networkStatus": Mappers.mapFromNetworkStatus(offlineStatus.reader?.networkStatus ?? NetworkStatus.unknown), - "offlinePaymentsCount": offlineStatus.reader?.paymentsCount ?? 0, - "offlinePaymentAmountsByCurrency": offlineStatus.reader?.paymentAmountsByCurrency ?? {} - ] + var readDic: NSDictionary = [:] + if let reader = offlineStatus.reader { + readDic = [ + "networkStatus": Mappers.mapFromNetworkStatus(reader.networkStatus), + "offlinePaymentsCount": reader.paymentsCount ?? 0, + "offlinePaymentAmountsByCurrency": reader.paymentAmountsByCurrency + ] + } return(["sdk": sdkDic, "reader": readDic]) } diff --git a/src/types/index.ts b/src/types/index.ts index 9979e36b..2f5f15e1 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -280,7 +280,7 @@ export type OfflineStatusDetails = { export type OfflineStatus = { sdk: OfflineStatusDetails; - reader: OfflineStatusDetails; + reader?: OfflineStatusDetails; }; type CardDetails = { From f502877a0ebe3885a6f5a7bb1773b37f46d17535 Mon Sep 17 00:00:00 2001 From: Nazli Yurdakul Date: Mon, 4 Dec 2023 16:11:57 -0500 Subject: [PATCH 3/9] fix android --- .../com/stripeterminalreactnative/Mappers.kt | 27 +++++++++++++++-- .../StripeTerminalReactNativeModule.kt | 29 +------------------ 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/android/src/main/java/com/stripeterminalreactnative/Mappers.kt b/android/src/main/java/com/stripeterminalreactnative/Mappers.kt index 99a40648..60a0844e 100644 --- a/android/src/main/java/com/stripeterminalreactnative/Mappers.kt +++ b/android/src/main/java/com/stripeterminalreactnative/Mappers.kt @@ -499,8 +499,8 @@ internal fun mapFromNetworkStatus(status: NetworkStatus): String { } } -fun mapFromOfflineStatus(offlineStatus: OfflineStatus): ReadableMap = - nativeMapOf { +fun mapFromOfflineStatus(offlineStatus: OfflineStatus): ReadableMap { + val sdkMap = nativeMapOf { putString("networkStatus", mapFromNetworkStatus(offlineStatus.sdk.networkStatus)) putInt("offlinePaymentsCount", offlineStatus.sdk.offlinePaymentsCount) @@ -512,3 +512,26 @@ fun mapFromOfflineStatus(offlineStatus: OfflineStatus): ReadableMap = putMap("offlinePaymentAmountsByCurrency", map) } + val readerMap = nativeMapOf { + offlineStatus.reader?.also { reader -> + putString("networkStatus", mapFromNetworkStatus(reader.networkStatus)) + putInt("offlinePaymentsCount", reader.offlinePaymentsCount) + + val map = nativeMapOf { + reader.offlinePaymentAmountsByCurrency.forEach { + putInt(it.key, it.value.toInt()) + } + } + putMap("offlinePaymentAmountsByCurrency", map) + } + + } + + return nativeMapOf { + putMap("sdk", sdkMap) + putMap("reader", readerMap) + } +} + + + diff --git a/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt b/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt index f1bd6b2e..cf4c8e4a 100644 --- a/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt +++ b/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt @@ -696,34 +696,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : @ReactMethod @Suppress("unused") fun getOfflineStatus(promise: Promise) { - promise.resolve( - nativeMapOf { - val sdkMap = nativeMapOf { - putInt("offlinePaymentsCount", terminal.offlineStatus.sdk.offlinePaymentsCount) - - val map = nativeMapOf { - terminal.offlineStatus.sdk.offlinePaymentAmountsByCurrency.forEach { - putInt(it.key, it.value.toInt()) - } - } - putMap("offlinePaymentAmountsByCurrency", map) - } - - val readerMap = nativeMapOf { - putInt("offlinePaymentsCount", terminal.offlineStatus.reader?.offlinePaymentsCount?:0) - - val map = nativeMapOf { - terminal.offlineStatus.reader?.offlinePaymentAmountsByCurrency?.forEach { - putInt(it.key, it.value.toInt()) - } - } - putMap("offlinePaymentAmountsByCurrency", map) - } - - putMap("sdk", sdkMap) - putMap("reader", readerMap) - } - ) + promise.resolve(mapFromOfflineStatus(terminal.offlineStatus)) } private fun cancelOperation( From 4cb53101c42cb7444584e97da7cfe42a0b95f008 Mon Sep 17 00:00:00 2001 From: Nazli Yurdakul Date: Mon, 4 Dec 2023 16:48:06 -0500 Subject: [PATCH 4/9] improve logs --- dev-app/src/screens/HomeScreen.tsx | 1 + ios/StripeTerminalReactNative.swift | 6 +++++- src/components/StripeTerminalProvider.tsx | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dev-app/src/screens/HomeScreen.tsx b/dev-app/src/screens/HomeScreen.tsx index 44f5a31b..8014dcde 100644 --- a/dev-app/src/screens/HomeScreen.tsx +++ b/dev-app/src/screens/HomeScreen.tsx @@ -53,6 +53,7 @@ export default function HomeScreen() { }, 3000); }, onDidForwardPaymentIntent(paymentIntent, error) { + console.log(error); let toastMsg = 'Payment Intent ' + paymentIntent.id + diff --git a/ios/StripeTerminalReactNative.swift b/ios/StripeTerminalReactNative.swift index 1172b4a5..ecb59094 100644 --- a/ios/StripeTerminalReactNative.swift +++ b/ios/StripeTerminalReactNative.swift @@ -1001,7 +1001,11 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe func terminal(_ terminal: Terminal, didForwardPaymentIntent intent: PaymentIntent, error: Error?) { let result = Mappers.mapFromPaymentIntent(intent, uuid: "") - sendEvent(withName: ReactNativeConstants.FORWARD_PAYMENT_INTENT.rawValue, body: ["result": result]) + var errorAsDictionary: [String: Any?] = [:] + if let nsError = error as NSError? { + errorAsDictionary = Errors.createError(nsError: nsError) + } + sendEvent(withName: ReactNativeConstants.FORWARD_PAYMENT_INTENT.rawValue, body: ["result": result, "error": errorAsDictionary]) } func terminal(_ terminal: Terminal, didReportForwardingError error: Error) { diff --git a/src/components/StripeTerminalProvider.tsx b/src/components/StripeTerminalProvider.tsx index 71db1c6a..7250bffd 100644 --- a/src/components/StripeTerminalProvider.tsx +++ b/src/components/StripeTerminalProvider.tsx @@ -210,7 +210,7 @@ export function StripeTerminalProvider({ const didChangeOfflineStatus = useCallback( ({ result }: { result?: OfflineStatus }) => { - log('didChangeOfflineStatus'); + log('didChangeOfflineStatus', result); emitter?.emit(CHANGE_OFFLINE_STATUS, result); }, [log] @@ -218,7 +218,7 @@ export function StripeTerminalProvider({ const didForwardPaymentIntent = useCallback( ({ result, error }: { result: PaymentIntent.Type; error: StripeError }) => { - log('didForwardPaymentIntent'); + log('didForwardPaymentIntent', { ...result, ...error }); emitter?.emit(FORWARD_PAYMENT_INTENT, result, error); }, [log] @@ -226,7 +226,7 @@ export function StripeTerminalProvider({ const didReportForwardingError = useCallback( ({ error }: { error?: StripeError }) => { - log('didReportForwardingError'); + log('didReportForwardingError', error); emitter?.emit(REPORT_FORWARDING_ERROR, error); }, [log] From 321167a48fd11cfaaa5b72dcd1f9850a8a33c1ad Mon Sep 17 00:00:00 2001 From: Nazli Yurdakul Date: Mon, 4 Dec 2023 16:52:15 -0500 Subject: [PATCH 5/9] report android error only if exists --- .../listener/RNOfflineListener.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/stripeterminalreactnative/listener/RNOfflineListener.kt b/android/src/main/java/com/stripeterminalreactnative/listener/RNOfflineListener.kt index 4e52fbca..07f15191 100644 --- a/android/src/main/java/com/stripeterminalreactnative/listener/RNOfflineListener.kt +++ b/android/src/main/java/com/stripeterminalreactnative/listener/RNOfflineListener.kt @@ -26,10 +26,12 @@ class RNOfflineListener( override fun onPaymentIntentForwarded(paymentIntent: PaymentIntent, e: TerminalException?) { context.sendEvent(ReactNativeConstants.FORWARD_PAYMENT_INTENT.listenerName) { putMap("result", mapFromPaymentIntent(paymentIntent, "")) - putMap("error", nativeMapOf { - putString("code", e?.errorCode.toString()) - putString("message", e?.errorMessage) - }) + if (e != null) { + putMap("error", nativeMapOf { + putString("code", e.errorCode.toString()) + putString("message", e.errorMessage) + }) + } } } From 00f3e3cc03314edaad4f86929ac3d6d338081724 Mon Sep 17 00:00:00 2001 From: Nazli Yurdakul Date: Mon, 4 Dec 2023 17:27:42 -0500 Subject: [PATCH 6/9] fix ios error --- ios/StripeTerminalReactNative.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ios/StripeTerminalReactNative.swift b/ios/StripeTerminalReactNative.swift index ecb59094..6cb02729 100644 --- a/ios/StripeTerminalReactNative.swift +++ b/ios/StripeTerminalReactNative.swift @@ -1001,11 +1001,20 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe func terminal(_ terminal: Terminal, didForwardPaymentIntent intent: PaymentIntent, error: Error?) { let result = Mappers.mapFromPaymentIntent(intent, uuid: "") - var errorAsDictionary: [String: Any?] = [:] + var body: [String: Any] = ["result": result] + if let nsError = error as NSError? { - errorAsDictionary = Errors.createError(nsError: nsError) + let errorAsDictionary = Errors.createError(nsError: nsError) + // createError will return a dictionary of ["error": {the error}] + // so merge that with the result so we have [result:, error:] + body = body.merging(errorAsDictionary, uniquingKeysWith: { _, error in + error + }) } - sendEvent(withName: ReactNativeConstants.FORWARD_PAYMENT_INTENT.rawValue, body: ["result": result, "error": errorAsDictionary]) + + + + sendEvent(withName: ReactNativeConstants.FORWARD_PAYMENT_INTENT.rawValue, body: body) } func terminal(_ terminal: Terminal, didReportForwardingError error: Error) { From ea11f4742488eb5c73a5816d3c7f15351c183108 Mon Sep 17 00:00:00 2001 From: Nazli Yurdakul Date: Tue, 5 Dec 2023 10:58:50 -0500 Subject: [PATCH 7/9] fix createError type --- ios/Errors.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Errors.swift b/ios/Errors.swift index b46d7566..169a881a 100644 --- a/ios/Errors.swift +++ b/ios/Errors.swift @@ -26,7 +26,7 @@ class Errors { return createError(errorCode: code.rawValue, message: message) } - class func createError(nsError: NSError) -> [String: Any?] { + class func createError(nsError: NSError) -> [String: Any] { return createError(code: ErrorCode.Code.init(rawValue: nsError.code) ?? ErrorCode.unexpectedSdkError, message: nsError.localizedDescription) } From 0abfaa347f9417ee09c5a7505e1db55197ebd922 Mon Sep 17 00:00:00 2001 From: Nazli Yurdakul Date: Tue, 5 Dec 2023 11:47:06 -0500 Subject: [PATCH 8/9] code improvements --- .../main/java/com/stripeterminalreactnative/Mappers.kt | 3 --- dev-app/src/screens/HomeScreen.tsx | 2 -- ios/Mappers.swift | 8 ++++---- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/android/src/main/java/com/stripeterminalreactnative/Mappers.kt b/android/src/main/java/com/stripeterminalreactnative/Mappers.kt index 60a0844e..71a88865 100644 --- a/android/src/main/java/com/stripeterminalreactnative/Mappers.kt +++ b/android/src/main/java/com/stripeterminalreactnative/Mappers.kt @@ -532,6 +532,3 @@ fun mapFromOfflineStatus(offlineStatus: OfflineStatus): ReadableMap { putMap("reader", readerMap) } } - - - diff --git a/dev-app/src/screens/HomeScreen.tsx b/dev-app/src/screens/HomeScreen.tsx index 8014dcde..415ffeba 100644 --- a/dev-app/src/screens/HomeScreen.tsx +++ b/dev-app/src/screens/HomeScreen.tsx @@ -33,7 +33,6 @@ export default function HomeScreen() { useState('bluetoothScan'); const { disconnectReader, connectedReader } = useStripeTerminal({ onDidChangeOfflineStatus(status: OfflineStatus) { - console.log('offline status = ' + status.sdk.networkStatus); console.log(status); setOnline(status.sdk.networkStatus === 'online' ? true : false); }, @@ -53,7 +52,6 @@ export default function HomeScreen() { }, 3000); }, onDidForwardPaymentIntent(paymentIntent, error) { - console.log(error); let toastMsg = 'Payment Intent ' + paymentIntent.id + diff --git a/ios/Mappers.swift b/ios/Mappers.swift index f88846b7..7e049f22 100644 --- a/ios/Mappers.swift +++ b/ios/Mappers.swift @@ -518,22 +518,22 @@ class Mappers { } class func mapFromOfflineStatus(_ offlineStatus: OfflineStatus) -> NSDictionary { - let sdkDic: NSDictionary = [ + let sdkDict: NSDictionary = [ "networkStatus": Mappers.mapFromNetworkStatus(offlineStatus.sdk.networkStatus), "offlinePaymentsCount": offlineStatus.sdk.paymentsCount ?? 0, "offlinePaymentAmountsByCurrency": offlineStatus.sdk.paymentAmountsByCurrency ] - var readDic: NSDictionary = [:] + var readerDict: NSDictionary = [:] if let reader = offlineStatus.reader { - readDic = [ + readerDict = [ "networkStatus": Mappers.mapFromNetworkStatus(reader.networkStatus), "offlinePaymentsCount": reader.paymentsCount ?? 0, "offlinePaymentAmountsByCurrency": reader.paymentAmountsByCurrency ] } - return(["sdk": sdkDic, "reader": readDic]) + return(["sdk": sdkDict, "reader": readerDict]) } } From fcd5faf832da51e7b590785a0e39fd97daef0643 Mon Sep 17 00:00:00 2001 From: Nazli Yurdakul Date: Tue, 5 Dec 2023 12:44:01 -0500 Subject: [PATCH 9/9] reader undefined --- ios/StripeTerminalReactNative.swift | 2 -- src/hooks/useStripeTerminal.tsx | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ios/StripeTerminalReactNative.swift b/ios/StripeTerminalReactNative.swift index 6cb02729..3c2ac28e 100644 --- a/ios/StripeTerminalReactNative.swift +++ b/ios/StripeTerminalReactNative.swift @@ -1012,8 +1012,6 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe }) } - - sendEvent(withName: ReactNativeConstants.FORWARD_PAYMENT_INTENT.rawValue, body: body) } diff --git a/src/hooks/useStripeTerminal.tsx b/src/hooks/useStripeTerminal.tsx index 5d761488..8043fa92 100644 --- a/src/hooks/useStripeTerminal.tsx +++ b/src/hooks/useStripeTerminal.tsx @@ -275,6 +275,9 @@ export function useStripeTerminal(props?: Props) { const didChangeOfflineStatus = useCallback( ({ result }: { result: OfflineStatus }) => { + if (!result.reader?.networkStatus) { + result.reader = undefined; + } onDidChangeOfflineStatus?.(result); }, [onDidChangeOfflineStatus] @@ -835,6 +838,9 @@ export function useStripeTerminal(props?: Props) { throw Error(NOT_INITIALIZED_ERROR_MESSAGE); } const response = await getOfflineStatus(); + if (response.reader?.networkStatus) { + response.reader = undefined; + } return response; }, [_isInitialized]);