Skip to content

Commit

Permalink
Merge pull request #53 from smallcase/prod
Browse files Browse the repository at this point in the history
Back merge 3.0.0 to development
  • Loading branch information
indrajit-roy-sc authored Jan 19, 2024
2 parents 8739805 + f5b1266 commit 9880943
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 78 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [3.0.0](https://github.com/smallcase/react-native-smallcase-gateway/compare/v2.3.1...v3.0.0) (2024-01-19)


### Features

* loans ([1ac32dc](https://github.com/smallcase/react-native-smallcase-gateway/commit/1ac32dc1506b5511ab7924a73bfd2b31d471fe8a))


### Bug Fixes

* **native:** changed Bridge method responses to conform to ScLoanResponse ([6f1a2b6](https://github.com/smallcase/react-native-smallcase-gateway/commit/6f1a2b621f90b7677d37e6dd2150487f46e3d5a7))

### [2.3.1](https://github.com/smallcase/react-native-smallcase-gateway/compare/v2.3.0...v2.3.1) (2023-12-08)

## [2.3.0](https://github.com/smallcase/react-native-smallcase-gateway/compare/v2.2.2...v2.3.0) (2023-10-17)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,18 +315,13 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte
val scGatewayConfig = ScLoanConfig(gateway, scEnvironment)
val setupResponse = ScLoan.setup(scGatewayConfig, object : ScLoanResult {
override fun onFailure(error: ScLoanError) {
val errorWritableMap = createErrorJSON(error.code, error.message, error.data)
promise.reject("error", errorWritableMap)
}

override fun onSuccess(response: ScLoanSuccess) {
promise.resolve(response.toString())
}
promise.reject("${error.code}", scLoanResponseToWritableMap(error) ?: return)
}

override fun onSuccess(response: ScLoanSuccess) {
promise.resolve(scLoanResponseToWritableMap(response) ?: return)
}
})
// val writableMap: WritableMap = Arguments.createMap()
// writableMap.putString("version", setupResponse.version)
// writableMap.putInt("versionCode", setupResponse.versionCode.toInt())
// promise.resolve(Gson().toJson(writableMap.toHashMap()))
}

@ReactMethod
Expand All @@ -341,12 +336,11 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte
val loanConfigObj = ScLoanInfo(interactionToken)
ScLoan.apply(appCompatActivity, loanConfigObj, object : ScLoanResult {
override fun onFailure(error: ScLoanError) {
val errorWritableMap = createErrorJSON(error.code, error.message, error.data)
promise.reject("error", errorWritableMap)
promise.reject("${error.code}", scLoanResponseToWritableMap(error) ?: return)
}

override fun onSuccess(response: ScLoanSuccess) {
promise.resolve(response.toString())
promise.resolve(scLoanResponseToWritableMap(response) ?: return)
}
})
}
Expand All @@ -363,12 +357,11 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte
val loanConfigObj = ScLoanInfo(interactionToken)
ScLoan.pay(appCompatActivity, loanConfigObj, object : ScLoanResult {
override fun onFailure(error: ScLoanError) {
val errorWritableMap = createErrorJSON(error.code, error.message, error.data)
promise.reject("error", errorWritableMap)
promise.reject("${error.code}", scLoanResponseToWritableMap(error) ?: return)
}

override fun onSuccess(response: ScLoanSuccess) {
promise.resolve(response.toString())
promise.resolve(scLoanResponseToWritableMap(response) ?: return)
}
})
}
Expand All @@ -385,16 +378,15 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte
val loanConfigObj = ScLoanInfo(interactionToken)
ScLoan.withdraw(appCompatActivity, loanConfigObj, object : ScLoanResult {
override fun onFailure(error: ScLoanError) {
val errorWritableMap = createErrorJSON(error.code, error.message, error.data)
promise.reject("error", errorWritableMap)
promise.reject("${error.code}", scLoanResponseToWritableMap(error) ?: return)
}

override fun onSuccess(response: ScLoanSuccess) {
promise.resolve(response.toString())
promise.resolve(scLoanResponseToWritableMap(response) ?: return)
}
})
}

@ReactMethod
fun service(loanConfig: ReadableMap, promise: Promise) {
val appCompatActivity = currentActivity as? AppCompatActivity ?: return
Expand All @@ -407,12 +399,11 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte
val loanConfigObj = ScLoanInfo(interactionToken)
ScLoan.service(appCompatActivity, loanConfigObj, object : ScLoanResult {
override fun onFailure(error: ScLoanError) {
val errorWritableMap = createErrorJSON(error.code, error.message, error.data)
promise.reject("error", errorWritableMap)
promise.reject("${error.code}", scLoanResponseToWritableMap(error) ?: return)
}

override fun onSuccess(response: ScLoanSuccess) {
promise.resolve(response.toString())
promise.resolve(scLoanResponseToWritableMap(response) ?: return)
}
})
}
Expand Down Expand Up @@ -472,5 +463,20 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte
return errObj
}

private fun scLoanResponseToWritableMap(response: ScLoansResponse?): WritableMap? {
val map = Arguments.createMap()
response?.also {
map.putBoolean("isSuccess", it.isSuccess)
map.putString("data", it.data)
}
if(response is ScLoanError) {
map.apply {
putInt("code", response.code)
putString("message", response.message)
}
}
return map
}

}

85 changes: 37 additions & 48 deletions ios/SmallcaseGateway.m
Original file line number Diff line number Diff line change
Expand Up @@ -518,19 +518,10 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)
[ScLoan.instance setupWithConfig:gatewayLoanConfig completion:^(ScLoanSuccess * success, ScLoanError * error) {

if(error != nil) {
if(error != nil) {
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
[responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
[responseDict setValue:error.domain forKey:@"errorMessage"];

NSError *err = [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:responseDict];

reject(@"apply", @"Error while applying for Loan", err);
return;
}
reject([NSString stringWithFormat:@"%li", (long)error.errorCode], error.errorMessage, [self scLoanErrorToDict:error]);
return;
}

resolve(@(YES));
resolve([self scLoanSuccessToDict:success]);
}];
}

Expand All @@ -554,17 +545,10 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)
[ScLoan.instance applyWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController] loanInfo:gatewayLoanInfo completion:^(ScLoanSuccess * success, ScLoanError * error) {

if(error != nil) {
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
[responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
[responseDict setValue:error.domain forKey:@"errorMessage"];

NSError *err = [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:responseDict];

reject(@"apply", @"Error while applying for Loan", err);
reject([NSString stringWithFormat:@"%li", (long)error.errorCode], error.errorMessage, [self scLoanErrorToDict:error]);
return;
}

resolve(success.data);
resolve([self scLoanSuccessToDict:success]);
}];
}

Expand All @@ -588,17 +572,10 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)
[ScLoan.instance payWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController] loanInfo:gatewayLoanInfo completion:^(ScLoanSuccess * success, ScLoanError * error) {

if(error != nil) {
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
[responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
[responseDict setValue:error.domain forKey:@"errorMessage"];

NSError *err = [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:responseDict];

reject(@"apply", @"Error while applying for Loan", err);
reject([NSString stringWithFormat:@"%li", (long)error.errorCode], error.errorMessage, [self scLoanErrorToDict:error]);
return;
}

resolve(success.data);
resolve([self scLoanSuccessToDict:success]);
}];
}

Expand All @@ -622,17 +599,10 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)
[ScLoan.instance withdrawWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController] loanInfo:gatewayLoanInfo completion:^(ScLoanSuccess * success, ScLoanError * error) {

if(error != nil) {
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
[responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
[responseDict setValue:error.domain forKey:@"errorMessage"];

NSError *err = [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:responseDict];

reject(@"apply", @"Error while applying for Loan", err);
reject([NSString stringWithFormat:@"%li", (long)error.errorCode], error.errorMessage, [self scLoanErrorToDict:error]);
return;
}

resolve(success.data);
resolve([self scLoanSuccessToDict:success]);
}];
}

Expand All @@ -656,22 +626,41 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)
[ScLoan.instance serviceWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController] loanInfo:gatewayLoanInfo completion:^(ScLoanSuccess * success, ScLoanError * error) {

if(error != nil) {
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
[responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
[responseDict setValue:error.domain forKey:@"errorMessage"];

NSError *err = [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:responseDict];

reject(@"apply", @"Error while applying for Loan", err);
reject([NSString stringWithFormat:@"%li", (long)error.errorCode], error.errorMessage, [self scLoanErrorToDict:error]);
return;
}

resolve(success.data);
resolve([self scLoanSuccessToDict:success]);

}];
}

});
}

- (NSDictionary *)scLoanSuccessToDict:(ScLoanSuccess *)success {
NSMutableDictionary *successDict = [NSMutableDictionary dictionary];
successDict[@"isSuccess"] = @(success.isSuccess);

id data = success.data;
if (data && ![data isKindOfClass:[NSNull class]]) {
successDict[@"data"] = data;
}

return successDict;
}

- (NSError *)scLoanErrorToDict:(ScLoanError *)error {

NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
[responseDict setValue:[NSNumber numberWithInteger:error.errorCode] forKey:@"code"];
[responseDict setValue:error.errorMessage forKey:@"message"];
[responseDict setValue:error.data forKey:@"data"];
[responseDict setValue:@NO forKey:@"isSuccess"];

NSError *err = [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:responseDict];
return err;

}

@end

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": "2.3.1",
"version": "3.0.0",
"description": "smallcase gateway bindings for react native",
"main": "src/index.js",
"files": [
Expand Down
25 changes: 20 additions & 5 deletions src/ScLoan.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@ const { SmallcaseGateway: SmallcaseGatewayNative } = NativeModules;
*
* @typedef {Object} ScLoanInfo
* @property {String} interactionToken
*
* @typedef {Object} ScLoanSuccess
* @property {boolean} isSuccess
* @property {string} data
*
* @typedef {Object} ScLoanError
* @property {boolean} isSuccess
* @property {number} code
* @property {string} message
* @property {string} data
*/

/**
* Setup ScLoans
*
* @param {ScLoanConfig} config
* @returns {Promise<String>}
* @returns {Promise<ScLoanSuccess>}
* @throws {ScLoanError}
*/
const setup = async (config) => {
const safeConfig = safeObject(config);
Expand All @@ -30,7 +41,8 @@ const setup = async (config) => {
* Triggers the LOS Journey
*
* @param {ScLoanInfo} loanInfo
* @returns {Promise<String>}
* @returns {Promise<ScLoanSuccess>}
* @throws {ScLoanError}
*/
const apply = async (loanInfo) => {
const safeLoanInfo = safeObject(loanInfo);
Expand All @@ -42,7 +54,8 @@ const apply = async (loanInfo) => {
* Triggers the Repayment Journey
*
* @param {ScLoanInfo} loanInfo
* @returns {Promise<String>}
* @returns {Promise<ScLoanSuccess>}
* @throws {ScLoanError}
*/
const pay = async (loanInfo) => {
const safeLoanInfo = safeObject(loanInfo);
Expand All @@ -54,7 +67,8 @@ const pay = async (loanInfo) => {
* Triggers the Withdraw Journey
*
* @param {ScLoanInfo} loanInfo
* @returns {Promise<String>}
* @returns {Promise<ScLoanSuccess>}
* @throws {ScLoanError}
*/
const withdraw = async (loanInfo) => {
const safeLoanInfo = safeObject(loanInfo);
Expand All @@ -66,7 +80,8 @@ const withdraw = async (loanInfo) => {
* Triggers the Servicing Journey
*
* @param {ScLoanInfo} loanInfo
* @returns {Promise<String>}
* @returns {Promise<ScLoanSuccess>}
* @throws {ScLoanError}
*/
const service = async (loanInfo) => {
const safeLoanInfo = safeObject(loanInfo);
Expand Down

0 comments on commit 9880943

Please sign in to comment.