diff --git a/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt b/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt index f8b62c55..977000c5 100644 --- a/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt +++ b/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt @@ -11,6 +11,7 @@ import com.facebook.react.bridge.ReactMethod import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.UiThreadUtil +import com.stripe.stripeterminal.BuildConfig import com.stripe.stripeterminal.Terminal import com.stripe.stripeterminal.TerminalApplicationDelegate.onCreate import com.stripe.stripeterminal.external.CollectData @@ -1122,6 +1123,12 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : terminal.setLocalMobileUxConfiguration(localMobileUxConfigurationBuilder.build()) } + @ReactMethod + @Suppress("unused") + fun getNativeSdkVersion(promise: Promise) { + promise.resolve(BuildConfig.SDK_VERSION_NAME) + } + private fun String?.toLocalMobileColor(): LocalMobileUxConfiguration.Color { return this ?.let { LocalMobileUxConfiguration.Color.Value(hexToArgb(it)) } diff --git a/ios/StripeTerminalReactNative.m b/ios/StripeTerminalReactNative.m index a931f0d4..c0130d93 100644 --- a/ios/StripeTerminalReactNative.m +++ b/ios/StripeTerminalReactNative.m @@ -247,4 +247,9 @@ @interface RCT_EXTERN_MODULE(StripeTerminalReactNative, RCTEventEmitter) resolver: (RCTPromiseResolveBlock)resolve rejecter: (RCTPromiseRejectBlock)reject ) + +RCT_EXTERN_METHOD( + getNativeSdkVersion: (RCTPromiseResolveBlock)resolve + rejecter: (RCTPromiseRejectBlock)reject + ) @end diff --git a/ios/StripeTerminalReactNative.swift b/ios/StripeTerminalReactNative.swift index 976006d0..ad7a2f05 100644 --- a/ios/StripeTerminalReactNative.swift +++ b/ios/StripeTerminalReactNative.swift @@ -1391,6 +1391,11 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe } } + @objc(getNativeSdkVersion:rejecter:) + func getNativeSdkVersion(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) { + resolve(SCPSDKVersion) + } + func reader(_ reader: Reader, didReportAvailableUpdate update: ReaderSoftwareUpdate) { sendEvent(withName: ReactNativeConstants.REPORT_AVAILABLE_UPDATE.rawValue, body: ["result": Mappers.mapFromReaderSoftwareUpdate(update) ?? [:]]) } diff --git a/src/StripeTerminalSdk.tsx b/src/StripeTerminalSdk.tsx index c6afe486..d8bf4744 100644 --- a/src/StripeTerminalSdk.tsx +++ b/src/StripeTerminalSdk.tsx @@ -175,6 +175,7 @@ export interface StripeTerminalSdkType { setLocalMobileUxConfiguration(params: LocalMobileUxConfiguration): Promise<{ error?: StripeError; }>; + getNativeSdkVersion(): Promise; } export default StripeTerminalReactNative as StripeTerminalSdkType; diff --git a/src/__tests__/__snapshots__/functions.test.ts.snap b/src/__tests__/__snapshots__/functions.test.ts.snap index 0a75d109..c1a01497 100644 --- a/src/__tests__/__snapshots__/functions.test.ts.snap +++ b/src/__tests__/__snapshots__/functions.test.ts.snap @@ -33,6 +33,7 @@ Object { "getConnectedReader": [Function], "getConnectionStatus": [Function], "getLocations": [Function], + "getNativeSdkVersion": [Function], "getOfflineStatus": [Function], "getPaymentStatus": [Function], "getReaderSettings": [Function], diff --git a/src/functions.ts b/src/functions.ts index 0d4a2947..7ea5027d 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -971,3 +971,13 @@ export async function setLocalMobileUxConfiguration( } }, 'setLocalMobileUxConfiguration')(); } + +export async function getNativeSdkVersion(): Promise { + return Logger.traceSdkMethod(async () => { + try { + return await StripeTerminalSdk.getNativeSdkVersion(); + } catch (error) { + return ''; + } + }, 'getNativeSdkVersion')(); +} diff --git a/src/hooks/__tests__/__snapshots__/useStripeTerminal.test.tsx.snap b/src/hooks/__tests__/__snapshots__/useStripeTerminal.test.tsx.snap index 0bbdc26d..d04d14aa 100644 --- a/src/hooks/__tests__/__snapshots__/useStripeTerminal.test.tsx.snap +++ b/src/hooks/__tests__/__snapshots__/useStripeTerminal.test.tsx.snap @@ -37,6 +37,7 @@ Object { "getConnectedReader": [Function], "getConnectionStatus": [Function], "getLocations": [Function], + "getNativeSdkVersion": [Function], "getOfflineStatus": [Function], "getPaymentStatus": [Function], "getReaderSettings": [Function], diff --git a/src/hooks/useStripeTerminal.tsx b/src/hooks/useStripeTerminal.tsx index f32a1c81..bf5282d6 100644 --- a/src/hooks/useStripeTerminal.tsx +++ b/src/hooks/useStripeTerminal.tsx @@ -74,6 +74,7 @@ import { getConnectionStatus, getConnectedReader, setLocalMobileUxConfiguration, + getNativeSdkVersion, } from '../functions'; import { StripeTerminalContext } from '../components/StripeTerminalContext'; import { useListener } from './useListener'; @@ -1069,6 +1070,10 @@ export function useStripeTerminal(props?: Props) { [_isInitialized, setLoading] ); + const _getNativeSdkVersion = useCallback(async () => { + return await getNativeSdkVersion(); + }, []); + return { initialize: _initialize, discoverReaders: _discoverReaders, @@ -1115,6 +1120,7 @@ export function useStripeTerminal(props?: Props) { cancelReaderReconnection: _cancelReaderReconnection, supportsReadersOfType: _supportsReadersOfType, setLocalMobileUxConfiguration: _setLocalMobileUxConfiguration, + getNativeSdkVersion: _getNativeSdkVersion, emitter: emitter, discoveredReaders, connectedReader,