diff --git a/android/src/main/java/com/nextar/sumup/RNSumUpModule.java b/android/src/main/java/com/nextar/sumup/RNSumUpModule.java index a855223..8264b6e 100644 --- a/android/src/main/java/com/nextar/sumup/RNSumUpModule.java +++ b/android/src/main/java/com/nextar/sumup/RNSumUpModule.java @@ -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; @@ -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()) @@ -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)); @@ -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)); diff --git a/ios/RNSumUp.m b/ios/RNSumUp.m index d84999f..f9565d5 100644 --- a/ios/RNSumUp.m +++ b/ios/RNSumUp.m @@ -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 }}); } }]; }); @@ -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 }}); + } + }]; }); } @@ -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); + } + }]; }); } diff --git a/ios/RNSumUp.podspec b/ios/RNSumUp.podspec deleted file mode 100644 index 76ba9fa..0000000 --- a/ios/RNSumUp.podspec +++ /dev/null @@ -1,24 +0,0 @@ - -Pod::Spec.new do |s| - s.name = "RNSumUp" - s.version = "1.0.0" - s.summary = "RNSumUp" - s.description = <<-DESC - RNSumUp - DESC - s.homepage = "" - s.license = "MIT" - # s.license = { :type => "MIT", :file => "FILE_LICENSE" } - s.author = { "author" => "author@domain.cn" } - s.platform = :ios, "7.0" - s.source = { :git => "https://github.com/author/RNSumUp.git", :tag => "master" } - s.source_files = "RNSumUp/**/*.{h,m}" - s.requires_arc = true - - - s.dependency "React" - #s.dependency "others" - -end - - \ No newline at end of file