diff --git a/android/src/main/java/com/squareup/sdk/reader/react/AuthorizationModule.java b/android/src/main/java/com/squareup/sdk/reader/react/AuthorizationModule.java index 38b0fa91..fc5640b8 100644 --- a/android/src/main/java/com/squareup/sdk/reader/react/AuthorizationModule.java +++ b/android/src/main/java/com/squareup/sdk/reader/react/AuthorizationModule.java @@ -71,6 +71,11 @@ public void isAuthorized(Promise promise) { promise.resolve(ReaderSdk.authorizationManager().getAuthorizationState().isAuthorized()); } + @ReactMethod + public void isAuthorizationInProgress(Promise promise) { + promise.resolve(ReaderSdk.authorizationManager().getAuthorizationState().isAuthorizationInProgress()); + } + @ReactMethod public void authorizedLocation(Promise promise) { if (ReaderSdk.authorizationManager().getAuthorizationState().isAuthorized()) { diff --git a/docs/reference.md b/docs/reference.md index 09553cc8..ace86043 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -25,6 +25,7 @@ Method | Return Object [deauthorizeAsync](#deauthorizeasync) | void | Deauthorizes Reader SDK. [getAuthorizedLocationAsync](#getauthorizedlocationasync) | [Location](#location) | Returns the currently authorized location [isAuthorizedAsync](#isauthorizedasync) | boolean | Verifies Reader SDK is currently authorized for payment collection. +[isAuthorizationInProgressAsync](#isAuthorizationInProgressAsync) | boolean | Verifies Reader SDK is currently authorizing. [startCheckoutAsync](#startcheckoutasync) | [CheckoutResult](#checkoutresult) | Begins the checkout workflow. [startReaderSettingsAsync](#startreadersettingsasync) | void | Starts the Reader settings flow for connecting Square Reader @@ -186,6 +187,31 @@ if (await isAuthorizedAsync()) { ``` +--- + +### isAuthorizationInProgressAsync + +Used to determine if Reader SDK is currently authorizing. + +* **On success**: returns `true` if the sdk is currently authorizing, `false` otherwise. +* **On failure**: throws [`USAGE_ERROR`](#e1). + + +#### Example usage + +```javascript +import { isAuthorizationInProgressAsync } from 'react-native-square-reader-sdk'; +... +if (await isAuthorizationInProgressAsync()) { + + // The reader is currently authorizing, don't try to authorize again + +} else { + Alert.alert('Unable to authorize again', 'Reader SDK is already authorizing.'); +} +``` + + --- ### startCheckoutAsync diff --git a/index.js b/index.js index a4f0bc9d..5042f9fb 100644 --- a/index.js +++ b/index.js @@ -31,6 +31,14 @@ export async function isAuthorizedAsync() { } } +export async function isAuthorizationInProgressAsync() { + try { + return await RNReaderSDKAuthorization.isAuthorizationInProgress(); + } catch (ex) { + throw createReaderSDKError(ex); + } +} + export async function canDeauthorizeAsync() { try { return await RNReaderSDKAuthorization.canDeauthorize(); diff --git a/ios/RNReaderSDKAuthorization.m b/ios/RNReaderSDKAuthorization.m index ef5ba542..839b7f20 100644 --- a/ios/RNReaderSDKAuthorization.m +++ b/ios/RNReaderSDKAuthorization.m @@ -94,6 +94,17 @@ @implementation RNReaderSDKAuthorization }); } +RCT_REMAP_METHOD(isAuthorizationInProgress, + isAuthorizationInProgressWithResolver + : (RCTPromiseResolveBlock)resolve + rejecter + : (RCTPromiseRejectBlock)reject) +{ + dispatch_async(dispatch_get_main_queue(), ^{ + resolve(@(SQRDReaderSDK.sharedSDK.isAuthorizationInProgress)); + }); +} + RCT_REMAP_METHOD(authorizedLocation, authorizedLocationWithResolver : (RCTPromiseResolveBlock)resolve