Skip to content

Commit

Permalink
Added some responses to checkout and autheticate
Browse files Browse the repository at this point in the history
  • Loading branch information
ital0 committed Mar 8, 2018
1 parent 36835fd commit 5722583
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
20 changes: 18 additions & 2 deletions android/src/main/java/com/nextar/sumup/RNSumUpModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;
import com.sumup.merchant.Models.TransactionInfo;
import com.sumup.merchant.api.SumUpAPI;
import com.sumup.merchant.api.SumUpLogin;
import com.sumup.merchant.api.SumUpPayment;
Expand Down Expand Up @@ -67,14 +68,14 @@ public void logout(Promise promise) {
}

@ReactMethod
public void checkout(String affiliateKey, Double value, String name, Promise promise) {
public void checkout(String affiliateKey, String value, String name, Promise promise) {
// TODO: replace foreignTransactionId to transaction UUID sent by user.
mSumUpPromise = promise;
try {

SumUpPayment payment = SumUpPayment.builder()
.affiliateKey(affiliateKey)
.total(new BigDecimal(value))
.total(new BigDecimal(Double.parseDouble(value)))
.currency(SumUpPayment.Currency.BRL)
.title(name)
.foreignTransactionId(UUID.randomUUID().toString())
Expand Down Expand Up @@ -111,6 +112,13 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,
if (extra.getInt(SumUpAPI.Response.RESULT_CODE) == REQUEST_CODE_LOGIN) {
WritableMap map = Arguments.createMap();
map.putBoolean("success", true);

UserModel userInfo = CoreState.Instance().get(UserModel.class);
WritableMap userAdditionalInfo = Arguments.createMap();
userAdditionalInfo.putString("merchantCode", userInfo.getBusiness().getMerchantCode());
userAdditionalInfo.putString("currencyCode", userInfo.getBusiness().getCountry().getCurrency().getCode());
map.putMap("userAdditionalInfo", userAdditionalInfo);

mSumUpPromise.resolve(map);
} else {
mSumUpPromise.reject(extra.getString(SumUpAPI.Response.RESULT_CODE), extra.getString(SumUpAPI.Response.MESSAGE));
Expand All @@ -126,6 +134,14 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,
WritableMap map = Arguments.createMap();
map.putBoolean("success", true);
map.putString("transactionCode", extra.getString(SumUpAPI.Response.TX_CODE));

TransactionInfo transactionInfo = extra.getParcelable(SumUpAPI.Response.TX_INFO);
WritableMap additionalInfo = Arguments.createMap();
additionalInfo.putString("cardType", transactionInfo.getCard().getType());
additionalInfo.putString("cardLast4Digits", transactionInfo.getCard().getLast4Digits());
additionalInfo.putInt("installments", transactionInfo.getInstallments());
map.putMap("additionalInfo", additionalInfo);

mSumUpPromise.resolve(map);
}else
mSumUpPromise.reject(extra.getString(SumUpAPI.Response.RESULT_CODE), extra.getString(SumUpAPI.Response.MESSAGE));
Expand Down
40 changes: 24 additions & 16 deletions ios/RNSumUp.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ - (NSDictionary *)constantsToExport
[rootViewController dismissViewControllerAnimated:YES completion:nil];
reject(@"000", @"It was not possible to auth with SumUp. Please, check the username and password provided.", error);
} else {
resolve(@{@"success": @(success)});
SMPMerchant *merchantInfo = [SMPSumUpSDK currentMerchant];
NSString *merchantCode = [merchantInfo merchantCode];
NSString *currencyCode = [merchantInfo currencyCode];
resolve(@{@"success": @(success), @"userAdditionalInfo": @{ @"merchantCode": merchantCode, @"currencyCode": currencyCode }});
}
}];
});
Expand Down Expand Up @@ -91,13 +94,18 @@ - (NSDictionary *)constantsToExport
UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController;
[SMPSumUpSDK checkoutWithRequest:checkoutRequest
fromViewController:rootViewController
completion:^(SMPCheckoutResult *result, NSError *error) {
if (error) {
reject(@"001", @"It was not possible to perform checkout with SumUp. Please, try again.", error);
} else {
resolve(@{@"success": @([result success]), @"transactionCode": [result transactionCode]});
}
}];
completion:^(SMPCheckoutResult *result, NSError *error) {
if (error) {
reject(@"001", @"It was not possible to perform checkout with SumUp. Please, try again.", error);
} else {
NSDictionary *additionalInformation = [result additionalInfo];
NSString *cardType = [additionalInformation valueForKeyPath:@"card.type"];
NSString *cardLast4Digits = [additionalInformation valueForKeyPath:@"card.last_4_digits"];
NSString *installments = [additionalInformation valueForKeyPath:@"installments"];

resolve(@{@"success": @([result success]), @"transactionCode": [result transactionCode], @"additionalInfo": @{ @"cardType": cardType, @"cardLast4Digits": cardLast4Digits, @"installments": installments }});
}
}];
});
}

Expand All @@ -106,14 +114,14 @@ - (NSDictionary *)constantsToExport
dispatch_sync(dispatch_get_main_queue(), ^{
UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController;
[SMPSumUpSDK presentCheckoutPreferencesFromViewController:rootViewController
animated:YES
completion:^(BOOL success, NSError * _Nullable error) {
if (!success) {
resolve(nil);
} else {
reject(@"002", @"It was not possible to open Preferences window. Please, try again.", nil);
}
}];
animated:YES
completion:^(BOOL success, NSError * _Nullable error) {
if (success) {
resolve(nil);
} else {
reject(@"002", @"It was not possible to open Preferences window. Please, try again.", nil);
}
}];
});
}

Expand Down
24 changes: 0 additions & 24 deletions ios/RNSumUp.podspec

This file was deleted.

0 comments on commit 5722583

Please sign in to comment.