diff --git a/scgateway/android/build.gradle b/scgateway/android/build.gradle index 56e2703a..1e661c60 100644 --- a/scgateway/android/build.gradle +++ b/scgateway/android/build.gradle @@ -64,5 +64,5 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.smallcase.gateway:sdk:5.0.1' + implementation 'com.smallcase.gateway:sdk:6.0.0' } diff --git a/scgateway/android/src/main/kotlin/com/example/scgateway_flutter_plugin/ScgatewayFlutterPlugin.kt b/scgateway/android/src/main/kotlin/com/example/scgateway_flutter_plugin/ScgatewayFlutterPlugin.kt index d5dd4ec0..16fd480f 100644 --- a/scgateway/android/src/main/kotlin/com/example/scgateway_flutter_plugin/ScgatewayFlutterPlugin.kt +++ b/scgateway/android/src/main/kotlin/com/example/scgateway_flutter_plugin/ScgatewayFlutterPlugin.kt @@ -351,7 +351,34 @@ class ScgatewayFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { override fun onSuccess(smallPlugResult: SmallPlugResult) { uiThreadHandler.post { - result.success(Gson().toJson(smallPlugResult).toString()) + val responseDict = JSONObject() + responseDict.put("success", true) + + if (smallPlugResult.smallcaseAuthToken != null) { + responseDict.put("smallcaseAuthToken", smallPlugResult.smallcaseAuthToken) + } + + // Add userInfo inside data object if available + smallPlugResult.userInfo?.let { userInfo -> + val dataDict = JSONObject() + val userInfoDict = JSONObject() + + // number and countryCode are optional + userInfo.number?.let { + userInfoDict.put("number", it) + } + userInfo.countryCode?.let { + userInfoDict.put("countryCode", it) + } + + // Only add userInfo if it has at least one field + if (userInfoDict.length() > 0) { + dataDict.put("userInfo", userInfoDict) + responseDict.put("data", dataDict) + } + } + + result.success(responseDict.toString()) } } @@ -381,7 +408,34 @@ class ScgatewayFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { override fun onSuccess(smallPlugResult: SmallPlugResult) { uiThreadHandler.post { - result.success(Gson().toJson(smallPlugResult).toString()) + val responseDict = JSONObject() + responseDict.put("success", true) + + if (smallPlugResult.smallcaseAuthToken != null) { + responseDict.put("smallcaseAuthToken", smallPlugResult.smallcaseAuthToken) + } + + // Add userInfo inside data object if available + smallPlugResult.userInfo?.let { userInfo -> + val dataDict = JSONObject() + val userInfoDict = JSONObject() + + // number and countryCode are optional + userInfo.number?.let { + userInfoDict.put("number", it) + } + userInfo.countryCode?.let { + userInfoDict.put("countryCode", it) + } + + // Only add userInfo if it has at least one field + if (userInfoDict.length() > 0) { + dataDict.put("userInfo", userInfoDict) + responseDict.put("data", dataDict) + } + } + + result.success(responseDict.toString()) } } diff --git a/scgateway/ios/Classes/SwiftScgatewayFlutterPlugin.swift b/scgateway/ios/Classes/SwiftScgatewayFlutterPlugin.swift index d8f5733f..91e5c817 100644 --- a/scgateway/ios/Classes/SwiftScgatewayFlutterPlugin.swift +++ b/scgateway/ios/Classes/SwiftScgatewayFlutterPlugin.swift @@ -579,10 +579,57 @@ public class SwiftScgatewayFlutterPlugin: NSObject, FlutterPlugin { SCGateway.shared.launchSmallPlug(presentingController: currentViewController, smallplugData: SmallplugData(target, params), completion: { response, error in - if let smallplugResponse = response { + if let error = error { + let res = NSMutableDictionary() + res.setValue(false, forKey: "success") - result(self.getJsonStringResult(success: true, data: smallplugResponse as? String, errorCode: nil, errorMessage: nil, transaction: nil)) + var errorMessage = error.localizedDescription + if let objcError = error as? ObjcTransactionError { + errorMessage = objcError.domain + } + + res.setValue(errorMessage, forKey: "error") + + let jsonData = try! JSONSerialization.data(withJSONObject: res, options: []) + let jsonString = String(data: jsonData, encoding: .utf8) + + result(FlutterError.init(code: jsonString ?? "", message: nil, details: nil)) + return + } + + if let smallplugResult = response as? SmallPlugResult { + var responseDict = NSMutableDictionary() + responseDict.setValue(true, forKey: "success") + + if let authToken = smallplugResult.smallcaseAuthToken { + responseDict.setValue(authToken, forKey: "smallcaseAuthToken") + } + + // Add userInfo inside data object if available + if let userInfo = smallplugResult.userInfo { + let dataDict = NSMutableDictionary() + let userInfoDict = NSMutableDictionary() + + // number and countryCode are NON-OPTIONAL Strings + if !userInfo.number.isEmpty { + userInfoDict.setValue(userInfo.number, forKey: "number") + } + + if !userInfo.countryCode.isEmpty { + userInfoDict.setValue(userInfo.countryCode, forKey: "countryCode") + } + + // Only add userInfo if it has at least one field + if userInfoDict.count > 0 { + dataDict.setValue(userInfoDict, forKey: "userInfo") + responseDict.setValue(dataDict, forKey: "data") + } + } + + let jsonData = try! JSONSerialization.data(withJSONObject: responseDict, options: []) + let jsonString = String(data: jsonData, encoding: .utf8) + result(jsonString) } }) @@ -591,10 +638,58 @@ public class SwiftScgatewayFlutterPlugin: NSObject, FlutterPlugin { SCGateway.shared.launchSmallPlug(presentingController: currentViewController, smallplugData: nil, completion: { response, error in - if let smallplugResponse = response { + if let error = error { + let res = NSMutableDictionary() + res.setValue(false, forKey: "success") + + var errorMessage = error.localizedDescription + if let objcError = error as? ObjcTransactionError { + errorMessage = objcError.domain + } + + res.setValue(errorMessage, forKey: "error") + + let jsonData = try! JSONSerialization.data(withJSONObject: res, options: []) + let jsonString = String(data: jsonData, encoding: .utf8) + + result(FlutterError.init(code: jsonString ?? "", message: nil, details: nil)) + return + } + + if let smallplugResult = response as? SmallPlugResult { + var responseDict = NSMutableDictionary() + responseDict.setValue(true, forKey: "success") + + if let authToken = smallplugResult.smallcaseAuthToken { + responseDict.setValue(authToken, forKey: "smallcaseAuthToken") + } + + // Add userInfo inside data object if available + if let userInfo = smallplugResult.userInfo { + let dataDict = NSMutableDictionary() + let userInfoDict = NSMutableDictionary() + + // number and countryCode are NON-OPTIONAL Strings + if !userInfo.number.isEmpty { + userInfoDict.setValue(userInfo.number, forKey: "number") + } + + if !userInfo.countryCode.isEmpty { + userInfoDict.setValue(userInfo.countryCode, forKey: "countryCode") + } + + // Only add userInfo if it has at least one field + if userInfoDict.count > 0 { + dataDict.setValue(userInfoDict, forKey: "userInfo") + responseDict.setValue(dataDict, forKey: "data") + } + } + - result(self.getJsonStringResult(success: true, data: smallplugResponse as? String, errorCode: nil, errorMessage: nil, transaction: nil)) + let jsonData = try! JSONSerialization.data(withJSONObject: responseDict, options: []) + let jsonString = String(data: jsonData, encoding: .utf8) + result(jsonString) } }) @@ -639,10 +734,49 @@ public class SwiftScgatewayFlutterPlugin: NSObject, FlutterPlugin { completion: { response, error in - if let smallplugResponse = response { + if let error = error { + let res = NSMutableDictionary() + res.setValue(false, forKey: "success") + + var errorMessage = error.localizedDescription + if let objcError = error as? ObjcTransactionError { + errorMessage = objcError.domain + } + + res.setValue(errorMessage, forKey: "error") + + let jsonData = try! JSONSerialization.data(withJSONObject: res, options: []) + let jsonString = String(data: jsonData, encoding: .utf8) + + result(FlutterError.init(code: jsonString ?? "", message: nil, details: nil)) + return + } + + if let smallplugResult = response as? SmallPlugResult { + var responseDict = NSMutableDictionary() + responseDict.setValue(true, forKey: "success") - result(self.getJsonStringResult(success: true, data: smallplugResponse as? String, errorCode: nil, errorMessage: nil, transaction: nil)) + if let authToken = smallplugResult.smallcaseAuthToken { + responseDict.setValue(authToken, forKey: "smallcaseAuthToken") + } + // Add userInfo inside data object if available + if let userInfo = smallplugResult.userInfo { + let dataDict = NSMutableDictionary() + let userInfoDict = NSMutableDictionary() + + // number and countryCode are not optional in SmallPlugUserInfo + userInfoDict.setValue(userInfo.number, forKey: "number") + userInfoDict.setValue(userInfo.countryCode, forKey: "countryCode") + + dataDict.setValue(userInfoDict, forKey: "userInfo") + responseDict.setValue(dataDict, forKey: "data") + } + + let jsonData = try! JSONSerialization.data(withJSONObject: responseDict, options: []) + let jsonString = String(data: jsonData, encoding: .utf8) + + result(jsonString) } }) @@ -651,10 +785,58 @@ public class SwiftScgatewayFlutterPlugin: NSObject, FlutterPlugin { SCGateway.shared.launchSmallPlug(presentingController: currentViewController, smallplugData: nil, completion: { response, error in - if let smallplugResponse = response { + if let error = error { + let res = NSMutableDictionary() + res.setValue(false, forKey: "success") + + var errorMessage = error.localizedDescription + if let objcError = error as? ObjcTransactionError { + errorMessage = objcError.domain + } + + res.setValue(errorMessage, forKey: "error") + + let jsonData = try! JSONSerialization.data(withJSONObject: res, options: []) + let jsonString = String(data: jsonData, encoding: .utf8) + + result(FlutterError.init(code: jsonString ?? "", message: nil, details: nil)) + return + } + + if let smallplugResult = response as? SmallPlugResult { + var responseDict = NSMutableDictionary() + responseDict.setValue(true, forKey: "success") + + if let authToken = smallplugResult.smallcaseAuthToken { + responseDict.setValue(authToken, forKey: "smallcaseAuthToken") + } + + // Add userInfo inside data object if available + if let userInfo = smallplugResult.userInfo { + let dataDict = NSMutableDictionary() + let userInfoDict = NSMutableDictionary() + + // number and countryCode are NON-OPTIONAL Strings + if !userInfo.number.isEmpty { + userInfoDict.setValue(userInfo.number, forKey: "number") + } + + if !userInfo.countryCode.isEmpty { + userInfoDict.setValue(userInfo.countryCode, forKey: "countryCode") + } + + // Only add userInfo if it has at least one field + if userInfoDict.count > 0 { + dataDict.setValue(userInfoDict, forKey: "userInfo") + responseDict.setValue(dataDict, forKey: "data") + } + } + - result(self.getJsonStringResult(success: true, data: smallplugResponse as? String, errorCode: nil, errorMessage: nil, transaction: nil)) + let jsonData = try! JSONSerialization.data(withJSONObject: responseDict, options: []) + let jsonString = String(data: jsonData, encoding: .utf8) + result(jsonString) } }) diff --git a/scgateway/ios/scgateway_flutter_plugin.podspec b/scgateway/ios/scgateway_flutter_plugin.podspec index af789938..351bee25 100644 --- a/scgateway/ios/scgateway_flutter_plugin.podspec +++ b/scgateway/ios/scgateway_flutter_plugin.podspec @@ -15,7 +15,7 @@ Scgateway Flutter plugin. s.source = { :path => '.' } s.source_files = 'Classes/**/*' s.dependency 'Flutter' - s.dependency 'SCGateway', '6.1.1' + s.dependency 'SCGateway', '7.0.0' s.xcconfig = {'BUILD_LIBRARY_FOR_DISTRIBUTION' => 'YES'} s.vendored_frameworks = 'SCGateway.xcframework' s.platform = :ios, '13.0' diff --git a/scgateway/lib/scgateway_flutter_plugin.dart b/scgateway/lib/scgateway_flutter_plugin.dart index b9e776c2..df4efab7 100644 --- a/scgateway/lib/scgateway_flutter_plugin.dart +++ b/scgateway/lib/scgateway_flutter_plugin.dart @@ -288,6 +288,17 @@ class ScgatewayFlutterPlugin { return logoutResponse; } + /// Launches SmallPlug and returns a JSON string with the following structure: + /// { + /// "success": true, + /// "smallcaseAuthToken": "token", // optional + /// "data": { + /// "userInfo": { + /// "number": "1234567890", // optional + /// "countryCode": "+91" // optional + /// } + /// } + /// } static Future launchSmallplug(SmallplugData smallplugData) async { String? smallplugResponse; @@ -306,6 +317,17 @@ class ScgatewayFlutterPlugin { return smallplugResponse; } + /// Launches SmallPlug with custom branding and returns a JSON string with the following structure: + /// { + /// "success": true, + /// "smallcaseAuthToken": "token", // optional + /// "data": { + /// "userInfo": { + /// "number": "1234567890", // optional + /// "countryCode": "+91" // optional + /// } + /// } + /// } static Future launchSmallplugWithBranding( SmallplugData smallplugData, {SmallplugUiConfig? smallplugUiConfig}) async { diff --git a/scgateway/pubspec.yaml b/scgateway/pubspec.yaml index ffd6d66e..e3d94b9a 100644 --- a/scgateway/pubspec.yaml +++ b/scgateway/pubspec.yaml @@ -1,6 +1,6 @@ name: scgateway_flutter_plugin description: Scgateway Flutter plugin. -version: 6.0.1 +version: 7.0.0 homepage: https://github.com/smallcase/gw-mob-sdk-flutter # The following line prevents the package from being accidentally published to diff --git a/smart_investing/pubspec.yaml b/smart_investing/pubspec.yaml index 6bdb5b43..186f0a38 100644 --- a/smart_investing/pubspec.yaml +++ b/smart_investing/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 3.0.1 +version: 3.0.2 environment: sdk: ^3.8.1