Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions ios/SmallcaseGateway.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion react-native-smallcase-gateway.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 26 additions & 8 deletions src/ScLoan.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const setup = async (config) => {
* @param {ScLoanInfo} loanInfo
* @returns {Promise<ScLoanSuccess>}
* @throws {ScLoanError}
* @deprecated This method is deprecated use triggerInteraction() instead.
*/
const apply = async (loanInfo) => {
const safeLoanInfo = safeObject(loanInfo);
Expand All @@ -56,6 +57,7 @@ const apply = async (loanInfo) => {
* @param {ScLoanInfo} loanInfo
* @returns {Promise<ScLoanSuccess>}
* @throws {ScLoanError}
* @deprecated This method is deprecated use triggerInteraction() instead.
*/
const pay = async (loanInfo) => {
const safeLoanInfo = safeObject(loanInfo);
Expand All @@ -69,6 +71,7 @@ const pay = async (loanInfo) => {
* @param {ScLoanInfo} loanInfo
* @returns {Promise<ScLoanSuccess>}
* @throws {ScLoanError}
* @deprecated This method is deprecated use triggerInteraction() instead.
*/
const withdraw = async (loanInfo) => {
const safeLoanInfo = safeObject(loanInfo);
Expand All @@ -82,19 +85,34 @@ const withdraw = async (loanInfo) => {
* @param {ScLoanInfo} loanInfo
* @returns {Promise<ScLoanSuccess>}
* @throws {ScLoanError}
* @deprecated This method is deprecated use triggerInteraction() instead.
*/
const service = async (loanInfo) => {
const safeLoanInfo = safeObject(loanInfo);

return SmallcaseGatewayNative.service(safeLoanInfo);
};

/**
* Triggers the triggerInteraction function
*
* @param {ScLoanInfo} loanInfo
* @returns {Promise<ScLoanSuccess>}
* @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;
10 changes: 10 additions & 0 deletions types/ScLoan.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ declare namespace ScLoan {
export { pay };
export { withdraw };
export { service };
export { triggerInteraction };
}
/**
* @typedef {Object} ScLoanConfig
Expand Down Expand Up @@ -84,3 +85,12 @@ declare function withdraw(loanInfo: ScLoanInfo): Promise<ScLoanSuccess>;
* @throws {ScLoanError}
*/
declare function service(loanInfo: ScLoanInfo): Promise<ScLoanSuccess>;

/**
* Triggers the triggerInteraction Journey
*
* @param {ScLoanInfo} loanInfo
* @returns {Promise<ScLoanSuccess>}
* @throws {ScLoanError}
*/
declare function triggerInteraction(loanInfo: ScLoanInfo): Promise<ScLoanSuccess>;
Loading