diff --git a/android/src/main/java/com/nextar/sumup/RNSumUpModule.java b/android/src/main/java/com/nextar/sumup/RNSumUpModule.java index 8264b6e..d56d968 100644 --- a/android/src/main/java/com/nextar/sumup/RNSumUpModule.java +++ b/android/src/main/java/com/nextar/sumup/RNSumUpModule.java @@ -54,6 +54,13 @@ public void authenticate(String affiliateKey, Promise promise) { SumUpAPI.openLoginActivity(getCurrentActivity(), sumupLogin, REQUEST_CODE_LOGIN); } + @ReactMethod + public void authenticateWithToken(String affiliateKey, String token, Promise promise) { + mSumUpPromise = promise; + SumUpLogin sumupLogin = SumUpLogin.builder(affiliateKey).accessToken(token).build(); + SumUpAPI.openLoginActivity(getCurrentActivity(), sumupLogin, REQUEST_CODE_LOGIN); + } + @ReactMethod public void prepareForCheckout(Promise promise) { mSumUpPromise = promise; diff --git a/index.js b/index.js index 99e860e..71055ff 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,10 @@ const RNSumUp = { return (Platform.OS === 'ios') ? RNSumUpWrapper.authenticate() : RNSumUpWrapper.authenticate(this.apiKey); }, + authenticateWithToken(token) { + return (Platform.OS === 'ios') ? RNSumUpWrapper.authenticate(token) : RNSumUpWrapper.authenticate(this.apiKey, token); + }, + logout() { this.isLoggedIn = false; return RNSumUpWrapper.logout(); diff --git a/ios/RNSumUp.m b/ios/RNSumUp.m index f9565d5..e9525a0 100644 --- a/ios/RNSumUp.m +++ b/ios/RNSumUp.m @@ -58,6 +58,17 @@ - (NSDictionary *)constantsToExport }); } +RCT_EXPORT_METHOD(authenticateWithToken:(NSString *)token resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) +{ + [SMPSumUpSDK loginWithToken:token completion:^(BOOL success, NSError * _Nullable error) { + if (!success) { + reject(@"004", @"It was not possible to login with SumUp using a token. Please, try again.", nil); + } else { + resolve(nil); + } + }]; +} + RCT_EXPORT_METHOD(logout:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { [SMPSumUpSDK logoutWithCompletionBlock:^(BOOL success, NSError * _Nullable error) {