Skip to content

Commit

Permalink
Some fixes for Android SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
ital0 committed Sep 16, 2019
1 parent 2881656 commit 2153075
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
13 changes: 4 additions & 9 deletions android/src/main/java/com/nextar/sumup/RNSumUpModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,12 @@ public void preferences(Promise promise) {
}

@ReactMethod
public void isLoggedIn(Promise promise) {
WritableMap map = Arguments.createMap();
if (CoreState.Instance() == null) {
map.putBoolean("isLoggedIn", false);
} else {
map.putBoolean("isLoggedIn", ((UserModel)CoreState.Instance().get(UserModel.class)).isLoggedIn());
public void isLoggedIn(Promise promise) {
WritableMap map = Arguments.createMap();
map.putBoolean("isLoggedIn", SumUpAPI.isLoggedIn());
promise.resolve(map);
}

promise.resolve(map);
}

private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() {

@Override
Expand Down
18 changes: 17 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,23 @@ const RNSumUp = {
return RNSumUpWrapper.prepareForCheckout();
},

checkout(request) {
checkout(request, token = null) {
if (Platform.OS === 'android') {
if (!token)
throw new Error('For Android checkouts you need to provide an OAuth2 token. Please, read: https://github.com/sumup/sumup-android-sdk#5-transparent-authentication');

return this.isLoggedIn().then((result) => {
if (!result.isLoggedIn) {
const authWithToken = new Promise(async resolve => {
await this.authenticateWithToken(token);
resolve();
});

return authWithToken.then(() => RNSumUpWrapper.checkout(request));
}
return RNSumUpWrapper.checkout(request);
});
}
return RNSumUpWrapper.checkout(request);
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rn-sumup",
"version": "1.0.9",
"version": "1.0.10",
"description": "SumUp SDK Wrapper for React Native.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 2153075

Please sign in to comment.