Skip to content

Commit

Permalink
Exposes isAuthorizationInProgress (#72)
Browse files Browse the repository at this point in the history
* Exposes isAuthorizationInProgress

* Now using RCT_REMAP_METHOD instead of RCT_EXPORT_METHOD for parity reasons

* Added change in docs
  • Loading branch information
SudoPlz authored and hukid committed Aug 21, 2019
1 parent 6ee985b commit 98e75a0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
26 changes: 26 additions & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions ios/RNReaderSDKAuthorization.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 98e75a0

Please sign in to comment.