From 8008e67fc744bc4f5517fa190096ad2edc559e58 Mon Sep 17 00:00:00 2001 From: aaditya singh Date: Thu, 22 Aug 2024 11:56:08 +0530 Subject: [PATCH 1/6] feat(loans): handle all intents with Trigger Interaction on bridge --- .../SmallcaseGatewayModule.kt | 21 +++++++ ios/SmallcaseGateway.m | 28 +++++++++ src/ScLoan.js | 59 ++++++++++++------- types/ScLoan.d.ts | 10 ++++ 4 files changed, 96 insertions(+), 22 deletions(-) diff --git a/android/src/main/java/com/reactnativesmallcasegateway/SmallcaseGatewayModule.kt b/android/src/main/java/com/reactnativesmallcasegateway/SmallcaseGatewayModule.kt index 689c074c..7794d099 100644 --- a/android/src/main/java/com/reactnativesmallcasegateway/SmallcaseGatewayModule.kt +++ b/android/src/main/java/com/reactnativesmallcasegateway/SmallcaseGatewayModule.kt @@ -407,6 +407,27 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte }) } + @ReactMethod + fun triggerInteraction(loanConfig: ReadableMap, promise: Promise) { + val appCompatActivity = currentActivity as? AppCompatActivity ?: return + val hashMap = readableMapToStrHashMap(loanConfig) + val interactionToken = hashMap["interactionToken"] + if(interactionToken == null) { + promise.reject(Throwable("Interaction token is null")) + return + } + val loanConfigObj = ScLoanInfo(interactionToken) + ScLoan.triggerInteraction(appCompatActivity, loanConfigObj, object : ScLoanResult { + override fun onFailure(error: ScLoanError) { + promise.reject("${error.code}", scLoanResponseToWritableMap(error) ?: return) + } + + override fun onSuccess(response: ScLoanSuccess) { + promise.resolve(scLoanResponseToWritableMap(response) ?: return) + } + }) + } + private fun getProtocol(envName: String): Environment.PROTOCOL { return when (envName) { "production" -> Environment.PROTOCOL.PRODUCTION diff --git a/ios/SmallcaseGateway.m b/ios/SmallcaseGateway.m index 5e62b08f..11627054 100644 --- a/ios/SmallcaseGateway.m +++ b/ios/SmallcaseGateway.m @@ -661,6 +661,34 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject) }); } +RCT_REMAP_METHOD(triggerInteraction, + loanInfo: (NSDictionary *)loanInfo + triggerInteractionWithResolver:(RCTPromiseResolveBlock)resolve + rejecter:(RCTPromiseRejectBlock)reject + ) { + dispatch_async(dispatch_get_main_queue(), ^(void) { + + if(loanInfo != nil && loanInfo[@"interactionToken"] != nil) { + + NSString *interactionToken = loanInfo[@"interactionToken"]; + NSLog(@" ----------- Interaction Token: %@", interactionToken); + + ScLoanInfo *gatewayLoanInfo = [[ScLoanInfo alloc] initWithInteractionToken:interactionToken]; + + [ScLoan.instance triggerInteractionWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController] loanInfo:gatewayLoanInfo completion:^(ScLoanSuccess * success, ScLoanError * error) { + + if(error != nil) { + reject([NSString stringWithFormat:@"%li", (long)error.errorCode], error.errorMessage, [self scLoanErrorToDict:error]); + return; + } + resolve([self scLoanSuccessToDict:success]); + + }]; + } + + }); +} + - (NSDictionary *)scLoanSuccessToDict:(ScLoanSuccess *)success { NSMutableDictionary *successDict = [NSMutableDictionary dictionary]; successDict[@"isSuccess"] = @(success.isSuccess); diff --git a/src/ScLoan.js b/src/ScLoan.js index 788551ce..f043f6e9 100644 --- a/src/ScLoan.js +++ b/src/ScLoan.js @@ -31,11 +31,12 @@ const { SmallcaseGateway: SmallcaseGatewayNative } = NativeModules; * @throws {ScLoanError} */ const setup = async (config) => { - const safeConfig = safeObject(config); - if(safeConfig.environment === undefined || safeConfig.environment === null) safeConfig.environment = ENV.PROD + const safeConfig = safeObject(config); + if (safeConfig.environment === undefined || safeConfig.environment === null) + safeConfig.environment = ENV.PROD; - return SmallcaseGatewayNative.setupLoans(safeConfig); - }; + return SmallcaseGatewayNative.setupLoans(safeConfig); +}; /** * Triggers the LOS Journey @@ -45,10 +46,10 @@ const setup = async (config) => { * @throws {ScLoanError} */ const apply = async (loanInfo) => { - const safeLoanInfo = safeObject(loanInfo); + const safeLoanInfo = safeObject(loanInfo); - return SmallcaseGatewayNative.apply(safeLoanInfo); - }; + return SmallcaseGatewayNative.apply(safeLoanInfo); +}; /** * Triggers the Repayment Journey @@ -58,10 +59,10 @@ const apply = async (loanInfo) => { * @throws {ScLoanError} */ const pay = async (loanInfo) => { - const safeLoanInfo = safeObject(loanInfo); + const safeLoanInfo = safeObject(loanInfo); - return SmallcaseGatewayNative.pay(safeLoanInfo); - }; + return SmallcaseGatewayNative.pay(safeLoanInfo); +}; /** * Triggers the Withdraw Journey @@ -71,10 +72,10 @@ const pay = async (loanInfo) => { * @throws {ScLoanError} */ const withdraw = async (loanInfo) => { - const safeLoanInfo = safeObject(loanInfo); + const safeLoanInfo = safeObject(loanInfo); - return SmallcaseGatewayNative.withdraw(safeLoanInfo); - }; + return SmallcaseGatewayNative.withdraw(safeLoanInfo); +}; /** * Triggers the Servicing Journey @@ -84,17 +85,31 @@ const withdraw = async (loanInfo) => { * @throws {ScLoanError} */ const service = async (loanInfo) => { - const safeLoanInfo = safeObject(loanInfo); + const safeLoanInfo = safeObject(loanInfo); - return SmallcaseGatewayNative.service(safeLoanInfo); - }; + return SmallcaseGatewayNative.service(safeLoanInfo); +}; + +/** + * Triggers the triggerInteraction function + * + * @param {ScLoanInfo} loanInfo + * @returns {Promise} + * @throws {ScLoanError} + */ +const triggerInteraction = async (loanInfo) => { + const safeLoanInfo = safeObject(loanInfo); + + return SmallcaseGatewayNative.triggerInteraction(safeLoanInfo); +}; const ScLoan = { - setup, - apply, - pay, - withdraw, - service -} + setup, + apply, + pay, + withdraw, + service, + triggerInteraction, +}; export default ScLoan; diff --git a/types/ScLoan.d.ts b/types/ScLoan.d.ts index 88a1b2fa..3d0a4723 100644 --- a/types/ScLoan.d.ts +++ b/types/ScLoan.d.ts @@ -25,6 +25,7 @@ declare namespace ScLoan { export { pay }; export { withdraw }; export { service }; + export { triggerInteraction }; } /** * @typedef {Object} ScLoanConfig @@ -84,3 +85,12 @@ declare function withdraw(loanInfo: ScLoanInfo): Promise; * @throws {ScLoanError} */ declare function service(loanInfo: ScLoanInfo): Promise; + +/** + * Triggers the triggerInteraction Journey + * + * @param {ScLoanInfo} loanInfo + * @returns {Promise} + * @throws {ScLoanError} + */ +declare function triggerInteraction(loanInfo: ScLoanInfo): Promise; \ No newline at end of file From 6a2abba62f355db642fd5227257bb815aade3b97 Mon Sep 17 00:00:00 2001 From: aaditya singh Date: Thu, 22 Aug 2024 11:57:48 +0530 Subject: [PATCH 2/6] build(android): v+ scg:4.1.0_loans:3.0.3-62-release --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index 2055921f..85fdcd8a 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -150,7 +150,7 @@ dependencies { //noinspection GradleDynamicVersion implementation 'com.facebook.react:react-native:+' // From node_modules implementation 'com.smallcase.gateway:sdk:4.1.0' - implementation 'com.smallcase.loans:sdk:3.0.3' + implementation 'com.smallcase.loans:sdk-internal:3.0.3-62-release' implementation "androidx.core:core-ktx:1.3.1" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } From ec8d6addeb9aba916671856d6b81f772ce752495 Mon Sep 17 00:00:00 2001 From: aaditya singh Date: Thu, 22 Aug 2024 11:58:17 +0530 Subject: [PATCH 3/6] build(ios): v+ scg:4.0.1_loans:3.0.0-24-release --- react-native-smallcase-gateway.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-native-smallcase-gateway.podspec b/react-native-smallcase-gateway.podspec index 0a252df8..f317b822 100644 --- a/react-native-smallcase-gateway.podspec +++ b/react-native-smallcase-gateway.podspec @@ -34,5 +34,5 @@ Pod::Spec.new do |s| end s.dependency 'SCGateway', '4.0.1' - s.dependency 'SCLoans', '3.0.0' + s.dependency 'SCLoans-internal', '3.0.0-24-release' end From 85fa7e897b0103667d396df0eb9165d127d0359d Mon Sep 17 00:00:00 2001 From: aaditya singh Date: Thu, 22 Aug 2024 12:22:12 +0530 Subject: [PATCH 4/6] fix: fixed formatting inside ScLoan.js --- src/ScLoan.js | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/ScLoan.js b/src/ScLoan.js index f043f6e9..8045d221 100644 --- a/src/ScLoan.js +++ b/src/ScLoan.js @@ -31,12 +31,11 @@ const { SmallcaseGateway: SmallcaseGatewayNative } = NativeModules; * @throws {ScLoanError} */ const setup = async (config) => { - const safeConfig = safeObject(config); - if (safeConfig.environment === undefined || safeConfig.environment === null) - safeConfig.environment = ENV.PROD; + const safeConfig = safeObject(config); + if(safeConfig.environment === undefined || safeConfig.environment === null) safeConfig.environment = ENV.PROD - return SmallcaseGatewayNative.setupLoans(safeConfig); -}; + return SmallcaseGatewayNative.setupLoans(safeConfig); + }; /** * Triggers the LOS Journey @@ -46,10 +45,10 @@ const setup = async (config) => { * @throws {ScLoanError} */ const apply = async (loanInfo) => { - const safeLoanInfo = safeObject(loanInfo); + const safeLoanInfo = safeObject(loanInfo); - return SmallcaseGatewayNative.apply(safeLoanInfo); -}; + return SmallcaseGatewayNative.apply(safeLoanInfo); + }; /** * Triggers the Repayment Journey @@ -59,10 +58,10 @@ const apply = async (loanInfo) => { * @throws {ScLoanError} */ const pay = async (loanInfo) => { - const safeLoanInfo = safeObject(loanInfo); + const safeLoanInfo = safeObject(loanInfo); - return SmallcaseGatewayNative.pay(safeLoanInfo); -}; + return SmallcaseGatewayNative.pay(safeLoanInfo); + }; /** * Triggers the Withdraw Journey @@ -72,10 +71,10 @@ const pay = async (loanInfo) => { * @throws {ScLoanError} */ const withdraw = async (loanInfo) => { - const safeLoanInfo = safeObject(loanInfo); + const safeLoanInfo = safeObject(loanInfo); - return SmallcaseGatewayNative.withdraw(safeLoanInfo); -}; + return SmallcaseGatewayNative.withdraw(safeLoanInfo); + }; /** * Triggers the Servicing Journey @@ -85,10 +84,10 @@ const withdraw = async (loanInfo) => { * @throws {ScLoanError} */ const service = async (loanInfo) => { - const safeLoanInfo = safeObject(loanInfo); + const safeLoanInfo = safeObject(loanInfo); - return SmallcaseGatewayNative.service(safeLoanInfo); -}; + return SmallcaseGatewayNative.service(safeLoanInfo); + }; /** * Triggers the triggerInteraction function @@ -112,4 +111,4 @@ const ScLoan = { triggerInteraction, }; -export default ScLoan; +export default ScLoan; \ No newline at end of file From a03f21aff36f4d559dd0e7ed71b08e00c8482dd3 Mon Sep 17 00:00:00 2001 From: aaditya singh Date: Thu, 22 Aug 2024 20:03:15 +0530 Subject: [PATCH 5/6] fix: mark old loans functions as deprecated --- src/ScLoan.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ScLoan.js b/src/ScLoan.js index 8045d221..3a51804c 100644 --- a/src/ScLoan.js +++ b/src/ScLoan.js @@ -43,6 +43,7 @@ const setup = async (config) => { * @param {ScLoanInfo} loanInfo * @returns {Promise} * @throws {ScLoanError} + * @deprecated This method is deprecated use triggerInteraction() instead. */ const apply = async (loanInfo) => { const safeLoanInfo = safeObject(loanInfo); @@ -56,6 +57,7 @@ const apply = async (loanInfo) => { * @param {ScLoanInfo} loanInfo * @returns {Promise} * @throws {ScLoanError} + * @deprecated This method is deprecated use triggerInteraction() instead. */ const pay = async (loanInfo) => { const safeLoanInfo = safeObject(loanInfo); @@ -69,6 +71,7 @@ const pay = async (loanInfo) => { * @param {ScLoanInfo} loanInfo * @returns {Promise} * @throws {ScLoanError} + * @deprecated This method is deprecated use triggerInteraction() instead. */ const withdraw = async (loanInfo) => { const safeLoanInfo = safeObject(loanInfo); @@ -82,6 +85,7 @@ const withdraw = async (loanInfo) => { * @param {ScLoanInfo} loanInfo * @returns {Promise} * @throws {ScLoanError} + * @deprecated This method is deprecated use triggerInteraction() instead. */ const service = async (loanInfo) => { const safeLoanInfo = safeObject(loanInfo); From 812e2d8b6b0c3207770972fa7bbe46779b3c31fc Mon Sep 17 00:00:00 2001 From: aaditya singh Date: Thu, 22 Aug 2024 20:57:52 +0530 Subject: [PATCH 6/6] chore(prod): 4.2.0 --- android/build.gradle | 2 +- package.json | 2 +- react-native-smallcase-gateway.podspec | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 85fdcd8a..3ead979f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -150,7 +150,7 @@ dependencies { //noinspection GradleDynamicVersion implementation 'com.facebook.react:react-native:+' // From node_modules implementation 'com.smallcase.gateway:sdk:4.1.0' - implementation 'com.smallcase.loans:sdk-internal:3.0.3-62-release' + implementation 'com.smallcase.loans:sdk:3.1.0' implementation "androidx.core:core-ktx:1.3.1" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } diff --git a/package.json b/package.json index 14aeb252..8ddefb74 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-smallcase-gateway", "title": "React Native Smallcase Gateway", - "version": "4.1.0", + "version": "4.2.0", "description": "smallcase gateway bindings for react native", "main": "src/index.js", "files": [ diff --git a/react-native-smallcase-gateway.podspec b/react-native-smallcase-gateway.podspec index f317b822..08e63188 100644 --- a/react-native-smallcase-gateway.podspec +++ b/react-native-smallcase-gateway.podspec @@ -34,5 +34,5 @@ Pod::Spec.new do |s| end s.dependency 'SCGateway', '4.0.1' - s.dependency 'SCLoans-internal', '3.0.0-24-release' + s.dependency 'SCLoans', '3.1.0' end