diff --git a/android/build.gradle b/android/build.gradle index 2055921f..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:3.0.3' + 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/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/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 0a252df8..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', '3.0.0' + s.dependency 'SCLoans', '3.1.0' end diff --git a/src/ScLoan.js b/src/ScLoan.js index 788551ce..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); @@ -89,12 +93,26 @@ const service = async (loanInfo) => { 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 -} - -export default ScLoan; + setup, + apply, + pay, + withdraw, + service, + triggerInteraction, +}; + +export default ScLoan; \ No newline at end of file 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