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 scgateway/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down Expand Up @@ -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())
}
}

Expand Down
198 changes: 190 additions & 8 deletions scgateway/ios/Classes/SwiftScgatewayFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})

Expand All @@ -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)
}
})

Expand Down Expand Up @@ -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)
}
})

Expand All @@ -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)
}
})

Expand Down
2 changes: 1 addition & 1 deletion scgateway/ios/scgateway_flutter_plugin.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
22 changes: 22 additions & 0 deletions scgateway/lib/scgateway_flutter_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?> launchSmallplug(SmallplugData smallplugData) async {
String? smallplugResponse;

Expand All @@ -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<String?> launchSmallplugWithBranding(
SmallplugData smallplugData,
{SmallplugUiConfig? smallplugUiConfig}) async {
Expand Down
2 changes: 1 addition & 1 deletion scgateway/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion smart_investing/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down