Skip to content

Backmerge/4.2.0 #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 22, 2024
Merged
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
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions ios/SmallcaseGateway.m
Original file line number Diff line number Diff line change
@@ -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);
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": [
2 changes: 1 addition & 1 deletion react-native-smallcase-gateway.podspec
Original file line number Diff line number Diff line change
@@ -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
@@ -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);
@@ -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);
@@ -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);
@@ -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
@@ -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<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>;