Skip to content

Commit

Permalink
Exposing authetication via token
Browse files Browse the repository at this point in the history
  • Loading branch information
ital0 committed Mar 13, 2018
1 parent 5722583 commit 843d00e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions android/src/main/java/com/nextar/sumup/RNSumUpModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions ios/RNSumUp.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 843d00e

Please sign in to comment.