Skip to content

Commit

Permalink
Add getNativeSdkVersion to get native sdk version (#790)
Browse files Browse the repository at this point in the history
* get native sdk version

* expose getNativeSdkVersion api

* Add try catch
  • Loading branch information
tim-lin-bbpos authored Sep 5, 2024
1 parent e6de527 commit e3dbcf6
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) }
Expand Down
5 changes: 5 additions & 0 deletions ios/StripeTerminalReactNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions ios/StripeTerminalReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?? [:]])
}
Expand Down
1 change: 1 addition & 0 deletions src/StripeTerminalSdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export interface StripeTerminalSdkType {
setLocalMobileUxConfiguration(params: LocalMobileUxConfiguration): Promise<{
error?: StripeError;
}>;
getNativeSdkVersion(): Promise<string>;
}

export default StripeTerminalReactNative as StripeTerminalSdkType;
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/functions.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Object {
"getConnectedReader": [Function],
"getConnectionStatus": [Function],
"getLocations": [Function],
"getNativeSdkVersion": [Function],
"getOfflineStatus": [Function],
"getPaymentStatus": [Function],
"getReaderSettings": [Function],
Expand Down
10 changes: 10 additions & 0 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,3 +971,13 @@ export async function setLocalMobileUxConfiguration(
}
}, 'setLocalMobileUxConfiguration')();
}

export async function getNativeSdkVersion(): Promise<string> {
return Logger.traceSdkMethod(async () => {
try {
return await StripeTerminalSdk.getNativeSdkVersion();
} catch (error) {
return '';
}
}, 'getNativeSdkVersion')();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"getConnectedReader": [Function],
"getConnectionStatus": [Function],
"getLocations": [Function],
"getNativeSdkVersion": [Function],
"getOfflineStatus": [Function],
"getPaymentStatus": [Function],
"getReaderSettings": [Function],
Expand Down
6 changes: 6 additions & 0 deletions src/hooks/useStripeTerminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {
getConnectionStatus,
getConnectedReader,
setLocalMobileUxConfiguration,
getNativeSdkVersion,
} from '../functions';
import { StripeTerminalContext } from '../components/StripeTerminalContext';
import { useListener } from './useListener';
Expand Down Expand Up @@ -1069,6 +1070,10 @@ export function useStripeTerminal(props?: Props) {
[_isInitialized, setLoading]
);

const _getNativeSdkVersion = useCallback(async () => {
return await getNativeSdkVersion();
}, []);

return {
initialize: _initialize,
discoverReaders: _discoverReaders,
Expand Down Expand Up @@ -1115,6 +1120,7 @@ export function useStripeTerminal(props?: Props) {
cancelReaderReconnection: _cancelReaderReconnection,
supportsReadersOfType: _supportsReadersOfType,
setLocalMobileUxConfiguration: _setLocalMobileUxConfiguration,
getNativeSdkVersion: _getNativeSdkVersion,
emitter: emitter,
discoveredReaders,
connectedReader,
Expand Down

0 comments on commit e3dbcf6

Please sign in to comment.