From 21530756f858040b0641059a6ca5fb7c6c057400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dtalo=20Menezes?= Date: Mon, 16 Sep 2019 17:27:26 -0300 Subject: [PATCH] Some fixes for Android SDK --- .../java/com/nextar/sumup/RNSumUpModule.java | 13 ++++--------- index.js | 18 +++++++++++++++++- package.json | 2 +- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/com/nextar/sumup/RNSumUpModule.java b/android/src/main/java/com/nextar/sumup/RNSumUpModule.java index c5b8a36..f925438 100644 --- a/android/src/main/java/com/nextar/sumup/RNSumUpModule.java +++ b/android/src/main/java/com/nextar/sumup/RNSumUpModule.java @@ -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 diff --git a/index.js b/index.js index badd282..79d9d7c 100644 --- a/index.js +++ b/index.js @@ -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); }, diff --git a/package.json b/package.json index 1b2fc67..f1cab4f 100644 --- a/package.json +++ b/package.json @@ -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": {