react-native-smallcase-gateway 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +130 -0
- package/LICENSE +21 -0
- package/README.md +147 -0
- package/android/README.md +14 -0
- package/android/build.gradle +161 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/smallcase/gateway/reactnative/SmallcaseGatewayModule.kt +260 -0
- package/android/src/main/java/com/smallcase/gateway/reactnative/SmallcaseGatewayPackage.kt +18 -0
- package/index.js +4 -0
- package/ios/SmallcaseGateway.h +5 -0
- package/ios/SmallcaseGateway.m +287 -0
- package/ios/SmallcaseGateway.xcodeproj/project.pbxproj +290 -0
- package/ios/SmallcaseGateway.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/SmallcaseGateway.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/package.json +62 -0
- package/react-native-smallcase-gateway.podspec +28 -0
- package/src/SmallcaseGateway.js +169 -0
- package/src/constants.js +33 -0
- package/src/util.js +11 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
package com.smallcase.gateway.reactnative
|
|
2
|
+
|
|
3
|
+
import android.content.ClipboardManager
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.util.Log
|
|
6
|
+
import android.widget.Toast
|
|
7
|
+
import com.facebook.react.bridge.*
|
|
8
|
+
import com.smallcase.gateway.data.SmallcaseGatewayListeners
|
|
9
|
+
import com.smallcase.gateway.data.SmallcaseLogoutListener
|
|
10
|
+
import com.smallcase.gateway.data.listeners.DataListener
|
|
11
|
+
import com.smallcase.gateway.data.listeners.TransactionResponseListener
|
|
12
|
+
import com.smallcase.gateway.data.models.Environment
|
|
13
|
+
import com.smallcase.gateway.data.models.InitialisationResponse
|
|
14
|
+
import com.smallcase.gateway.data.models.SmallcaseGatewayDataResponse
|
|
15
|
+
import com.smallcase.gateway.data.models.TransactionResult
|
|
16
|
+
import com.smallcase.gateway.data.requests.InitRequest
|
|
17
|
+
import com.smallcase.gateway.portal.SmallcaseGatewaySdk
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactContextBaseJavaModule(reactContext!!) {
|
|
21
|
+
companion object {
|
|
22
|
+
const val TAG = "SmallcaseGatewayModule"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override fun getName(): String {
|
|
26
|
+
return "SmallcaseGateway"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@ReactMethod
|
|
30
|
+
fun setConfigEnvironment(
|
|
31
|
+
envName: String,
|
|
32
|
+
gateway: String,
|
|
33
|
+
isLeprechaunActive: Boolean,
|
|
34
|
+
isAmoEnabled: Boolean,
|
|
35
|
+
preProvidedBrokers: ReadableArray,
|
|
36
|
+
promise: Promise) {
|
|
37
|
+
Log.d(TAG, "setConfigEnvironment: start")
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
val brokerList = ArrayList<String>()
|
|
41
|
+
for (index in 0 until preProvidedBrokers.size()) {
|
|
42
|
+
val broker = preProvidedBrokers.getString(index)
|
|
43
|
+
if (broker != null) {
|
|
44
|
+
brokerList.add(broker)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
val protocol = getProtocol(envName)
|
|
49
|
+
|
|
50
|
+
val env = Environment(
|
|
51
|
+
gateway = gateway,
|
|
52
|
+
buildType = protocol,
|
|
53
|
+
isAmoEnabled = isAmoEnabled,
|
|
54
|
+
preProvidedBrokers = brokerList,
|
|
55
|
+
isLeprachaunActive = isLeprechaunActive
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
SmallcaseGatewaySdk.setConfigEnvironment(
|
|
59
|
+
environment = env,
|
|
60
|
+
smallcaseGatewayListeners = object : SmallcaseGatewayListeners {
|
|
61
|
+
override fun onGatewaySetupSuccessfull() {
|
|
62
|
+
promise.resolve(true)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override fun onGatewaySetupFailed(error: String) {
|
|
66
|
+
promise.reject(Throwable(error))
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
} catch (e: Exception) {
|
|
70
|
+
promise.reject(e)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@ReactMethod
|
|
75
|
+
fun init(sdkToken: String, promise: Promise) {
|
|
76
|
+
Log.d(TAG, "init: start")
|
|
77
|
+
|
|
78
|
+
val initReq = InitRequest(sdkToken)
|
|
79
|
+
SmallcaseGatewaySdk.init(
|
|
80
|
+
authRequest = initReq,
|
|
81
|
+
gatewayInitialisationListener = object : DataListener<InitialisationResponse> {
|
|
82
|
+
override fun onFailure(errorCode: Int, errorMessage: String) {
|
|
83
|
+
val err = createErrorJSON(errorCode, errorMessage)
|
|
84
|
+
promise.reject("error", err)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
override fun onSuccess(response: InitialisationResponse) {
|
|
88
|
+
promise.resolve(true)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@ReactMethod
|
|
95
|
+
fun triggerTransaction(transactionId: String, utmParams: ReadableMap?, brokerList: ReadableArray?, promise: Promise) {
|
|
96
|
+
Log.d(TAG, "triggerTransaction: start")
|
|
97
|
+
|
|
98
|
+
var safeBrokerList = listOf<String>()
|
|
99
|
+
|
|
100
|
+
if (brokerList != null) {
|
|
101
|
+
safeBrokerList = brokerList.toArrayList().map { it as String }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
val activity = currentActivity;
|
|
106
|
+
if (activity != null) {
|
|
107
|
+
val utm = readableMapToStrHashMap(utmParams)
|
|
108
|
+
SmallcaseGatewaySdk.triggerTransaction(
|
|
109
|
+
utmParams = utm,
|
|
110
|
+
activity = activity,
|
|
111
|
+
transactionId = transactionId,
|
|
112
|
+
preProvidedBrokers = safeBrokerList,
|
|
113
|
+
transactionResponseListener = object : TransactionResponseListener {
|
|
114
|
+
override fun onSuccess(transactionResult: TransactionResult) {
|
|
115
|
+
if (transactionResult.success) {
|
|
116
|
+
val res = resultToWritableMap(transactionResult)
|
|
117
|
+
promise.resolve(res)
|
|
118
|
+
} else {
|
|
119
|
+
val err = createErrorJSON(
|
|
120
|
+
transactionResult.errorCode,
|
|
121
|
+
transactionResult.error
|
|
122
|
+
)
|
|
123
|
+
promise.reject("error", err)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
override fun onError(errorCode: Int, errorMessage: String) {
|
|
129
|
+
val err = createErrorJSON(errorCode, errorMessage)
|
|
130
|
+
promise.reject("error", err)
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
} else {
|
|
134
|
+
promise.reject(Throwable("no activity"))
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@ReactMethod
|
|
139
|
+
fun archiveSmallcase(iscid: String, promise: Promise) {
|
|
140
|
+
Log.d(TAG, "markSmallcaseArchive: start")
|
|
141
|
+
|
|
142
|
+
SmallcaseGatewaySdk.markSmallcaseArchived(iscid, object : DataListener<SmallcaseGatewayDataResponse> {
|
|
143
|
+
|
|
144
|
+
override fun onSuccess(response: SmallcaseGatewayDataResponse) {
|
|
145
|
+
promise.resolve(response)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
override fun onFailure(errorCode: Int, errorMessage: String) {
|
|
149
|
+
val err = createErrorJSON(errorCode, errorMessage)
|
|
150
|
+
promise.reject("error", err)
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@ReactMethod
|
|
156
|
+
fun logoutUser(promise: Promise) {
|
|
157
|
+
val activity = currentActivity;
|
|
158
|
+
if (activity != null) {
|
|
159
|
+
SmallcaseGatewaySdk.logoutUser(
|
|
160
|
+
activity = activity,
|
|
161
|
+
logoutListener = object : SmallcaseLogoutListener {
|
|
162
|
+
override fun onLogoutSuccessfull() {
|
|
163
|
+
promise.resolve(true)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
override fun onLogoutFailed(errorCode: Int, error: String) {
|
|
167
|
+
val err = createErrorJSON(errorCode, error)
|
|
168
|
+
promise.reject("error", err)
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@ReactMethod
|
|
175
|
+
fun triggerLeadGen(userDetails: ReadableMap, utmData: ReadableMap) {
|
|
176
|
+
val activity = currentActivity;
|
|
177
|
+
if (activity != null) {
|
|
178
|
+
SmallcaseGatewaySdk.triggerLeadGen(
|
|
179
|
+
activity=activity,
|
|
180
|
+
utmParams = readableMapToStrHashMap(utmData),
|
|
181
|
+
params = readableMapToStrHashMap(userDetails)
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@ReactMethod
|
|
187
|
+
fun triggerLeadGenWithStatus(userDetails: ReadableMap, promise: Promise) {
|
|
188
|
+
val activity = currentActivity;
|
|
189
|
+
if (activity != null) {
|
|
190
|
+
SmallcaseGatewaySdk.triggerLeadGen(activity,readableMapToStrHashMap(userDetails), object : TransactionResponseListener {
|
|
191
|
+
override fun onSuccess(transactionResult: TransactionResult) {
|
|
192
|
+
if (transactionResult.success) {
|
|
193
|
+
val res = resultToWritableMap(transactionResult)
|
|
194
|
+
promise.resolve(res)
|
|
195
|
+
} else {
|
|
196
|
+
val err = createErrorJSON(
|
|
197
|
+
transactionResult.errorCode,
|
|
198
|
+
transactionResult.error
|
|
199
|
+
)
|
|
200
|
+
promise.reject("error", err)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
override fun onError(errorCode: Int, errorMessage: String) {
|
|
205
|
+
val err = createErrorJSON(errorCode, errorMessage)
|
|
206
|
+
promise.reject("error", err)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private fun getProtocol(envName: String): Environment.PROTOCOL {
|
|
214
|
+
return when (envName) {
|
|
215
|
+
"production" -> Environment.PROTOCOL.PRODUCTION
|
|
216
|
+
"development" -> Environment.PROTOCOL.DEVELOPMENT
|
|
217
|
+
"staging" -> Environment.PROTOCOL.STAGING
|
|
218
|
+
else -> Environment.PROTOCOL.PRODUCTION
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private fun readableMapToStrHashMap(params: ReadableMap?): HashMap<String, String> {
|
|
223
|
+
val data = HashMap<String, String>()
|
|
224
|
+
|
|
225
|
+
if (params != null) {
|
|
226
|
+
val keyIterator = params.keySetIterator()
|
|
227
|
+
|
|
228
|
+
while (keyIterator.hasNextKey()) {
|
|
229
|
+
val key = keyIterator.nextKey()
|
|
230
|
+
params.getString(key)?.let {
|
|
231
|
+
data.put(key, it)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return data
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private fun resultToWritableMap(result: TransactionResult): WritableMap {
|
|
240
|
+
val writableMap: WritableMap = Arguments.createMap()
|
|
241
|
+
|
|
242
|
+
writableMap.putString("data", result.data)
|
|
243
|
+
writableMap.putBoolean("success", result.success)
|
|
244
|
+
writableMap.putString("error", result.error)
|
|
245
|
+
result.errorCode?.let {
|
|
246
|
+
writableMap.putInt("errorCode", it)
|
|
247
|
+
}
|
|
248
|
+
writableMap.putString("transaction", result.transaction.name)
|
|
249
|
+
return writableMap
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
private fun createErrorJSON(errorCode: Int?, errorMessage: String?): WritableMap {
|
|
253
|
+
val errObj = Arguments.createMap()
|
|
254
|
+
|
|
255
|
+
errorCode?.let { errObj.putInt("errorCode", it) }
|
|
256
|
+
errorMessage?.let { errObj.putString("errorMessage", it) }
|
|
257
|
+
|
|
258
|
+
return errObj
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package com.smallcase.gateway.reactnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.JavaScriptModule
|
|
5
|
+
import com.facebook.react.bridge.NativeModule
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.uimanager.ViewManager
|
|
8
|
+
import java.util.*
|
|
9
|
+
|
|
10
|
+
class SmallcaseGatewayPackage : ReactPackage {
|
|
11
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
12
|
+
return Arrays.asList<NativeModule>(SmallcaseGatewayModule(reactContext))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
16
|
+
return emptyList()
|
|
17
|
+
}
|
|
18
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
#import "SmallcaseGateway.h"
|
|
2
|
+
|
|
3
|
+
#import <SCGateway/SCGateway.h>
|
|
4
|
+
#import <SCGateway/SCGateway-Swift.h>
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@implementation SmallcaseGateway
|
|
8
|
+
|
|
9
|
+
RCT_EXPORT_MODULE()
|
|
10
|
+
|
|
11
|
+
RCT_REMAP_METHOD(setConfigEnvironment,
|
|
12
|
+
envName:(NSString *)envName
|
|
13
|
+
gateway:(NSString *)gateway
|
|
14
|
+
isLeprechaunActive: (BOOL *)isLeprechaunActive
|
|
15
|
+
isAmoEnabled: (BOOL *)isAmoEnabled
|
|
16
|
+
preProvidedBrokers: (NSArray *)preProvidedBrokers
|
|
17
|
+
setConfigEnvironmentWithResolver:(RCTPromiseResolveBlock)resolve
|
|
18
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
19
|
+
{
|
|
20
|
+
NSInteger environment = EnvironmentProduction;
|
|
21
|
+
|
|
22
|
+
if([envName isEqualToString:@"production"]) {
|
|
23
|
+
environment = EnvironmentProduction;
|
|
24
|
+
}
|
|
25
|
+
else if([envName isEqualToString:@"development"]) {
|
|
26
|
+
environment = EnvironmentDevelopment;
|
|
27
|
+
} else {
|
|
28
|
+
environment = EnvironmentStaging;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
GatewayConfig *config = [[GatewayConfig alloc]
|
|
32
|
+
initWithGatewayName:gateway
|
|
33
|
+
brokerConfig:preProvidedBrokers
|
|
34
|
+
apiEnvironment:environment
|
|
35
|
+
isLeprechaunActive:isLeprechaunActive
|
|
36
|
+
isAmoEnabled:isAmoEnabled];
|
|
37
|
+
|
|
38
|
+
[SCGateway.shared setupWithConfig: config completion:^(BOOL success,NSError * error)
|
|
39
|
+
{
|
|
40
|
+
if(success)
|
|
41
|
+
{
|
|
42
|
+
resolve(@(YES));
|
|
43
|
+
} else {
|
|
44
|
+
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
|
|
45
|
+
[responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
|
|
46
|
+
[responseDict setValue:error.domain forKey:@"errorMessage"];
|
|
47
|
+
|
|
48
|
+
NSError *err = [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:responseDict];
|
|
49
|
+
|
|
50
|
+
reject(@"setConfigEnvironment", @"Env setup failed", err);
|
|
51
|
+
}
|
|
52
|
+
}];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
RCT_REMAP_METHOD(init,
|
|
56
|
+
sdkToken:(NSString *)sdkToken
|
|
57
|
+
initWithResolver:(RCTPromiseResolveBlock)resolve
|
|
58
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
59
|
+
{
|
|
60
|
+
[SCGateway.shared initializeGatewayWithSdkToken:sdkToken completion:^(BOOL success, NSError * error) {
|
|
61
|
+
if(success){
|
|
62
|
+
resolve(@(YES));
|
|
63
|
+
} else {
|
|
64
|
+
if(error != nil)
|
|
65
|
+
{
|
|
66
|
+
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
|
|
67
|
+
[responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
|
|
68
|
+
[responseDict setValue:error.domain forKey:@"errorMessage"];
|
|
69
|
+
|
|
70
|
+
NSError *err = [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:responseDict];
|
|
71
|
+
|
|
72
|
+
reject(@"init", @"Error during init", err);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
reject(@"init", @"Error during init", error);
|
|
76
|
+
}
|
|
77
|
+
}];
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
RCT_REMAP_METHOD(archiveSmallcase,
|
|
83
|
+
iscid:(NSString *)iscid
|
|
84
|
+
initWithResolver:(RCTPromiseResolveBlock)resolve
|
|
85
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
86
|
+
{
|
|
87
|
+
[SCGateway.shared markSmallcaseArchiveWithIscid:iscid completion: ^(id response, NSError * error) {
|
|
88
|
+
if(error != nil) {
|
|
89
|
+
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
|
|
90
|
+
[responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
|
|
91
|
+
[responseDict setValue:error.domain forKey:@"errorMessage"];
|
|
92
|
+
|
|
93
|
+
NSError *err = [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:responseDict];
|
|
94
|
+
|
|
95
|
+
reject(@"archiveSmallcase", @"Error during transaction", err);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
NSString *archiveResponseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
|
100
|
+
|
|
101
|
+
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
|
|
102
|
+
[responseDict setValue:[NSNumber numberWithBool:true] forKey:@"success"];
|
|
103
|
+
|
|
104
|
+
[responseDict setObject:archiveResponseString forKey:@"data"];
|
|
105
|
+
resolve(responseDict);
|
|
106
|
+
return;
|
|
107
|
+
}];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
RCT_REMAP_METHOD(triggerTransaction,
|
|
111
|
+
transactionId:(NSString *)transactionId
|
|
112
|
+
utmParams:(NSDictionary *)utmParams
|
|
113
|
+
brokerList:(NSArray *)brokerList
|
|
114
|
+
triggerTransactionWithResolver:(RCTPromiseResolveBlock)resolve
|
|
115
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
116
|
+
{
|
|
117
|
+
dispatch_async(dispatch_get_main_queue(), ^(void) {
|
|
118
|
+
[SCGateway.shared
|
|
119
|
+
triggerTransactionFlowWithTransactionId:transactionId
|
|
120
|
+
presentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController]
|
|
121
|
+
utmParams:utmParams
|
|
122
|
+
brokerConfig:brokerList
|
|
123
|
+
completion: ^(id response, NSError * error) {
|
|
124
|
+
if (error != nil) {
|
|
125
|
+
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
|
|
126
|
+
[responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
|
|
127
|
+
[responseDict setValue:error.domain forKey:@"errorMessage"];
|
|
128
|
+
|
|
129
|
+
NSError *err = [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:responseDict];
|
|
130
|
+
|
|
131
|
+
reject(@"triggerTransaction", @"Error during transaction", err);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
|
|
136
|
+
[responseDict setValue:[NSNumber numberWithBool:true] forKey:@"success"];
|
|
137
|
+
|
|
138
|
+
// intent - transaction
|
|
139
|
+
if ([response isKindOfClass: [ObjcTransactionIntentTransaction class]]) {
|
|
140
|
+
ObjcTransactionIntentTransaction *trxResponse = response;
|
|
141
|
+
[responseDict setObject:@"TRANSACTION" forKey:@"transaction"];
|
|
142
|
+
|
|
143
|
+
NSData *decodedStringData = [[NSData alloc] initWithBase64EncodedString:trxResponse.transaction options: 0];
|
|
144
|
+
NSString *decodedResponse = [[NSString alloc] initWithData:decodedStringData encoding:1];
|
|
145
|
+
|
|
146
|
+
[responseDict setObject:decodedResponse forKey:@"data"];
|
|
147
|
+
resolve(responseDict);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// intent - connect
|
|
152
|
+
if([response isKindOfClass: [ObjCTransactionIntentConnect class]]) {
|
|
153
|
+
ObjCTransactionIntentConnect *trxResponse = response;
|
|
154
|
+
[responseDict setValue:@"CONNECT" forKey:@"transaction"];
|
|
155
|
+
|
|
156
|
+
if (trxResponse.response != nil) {
|
|
157
|
+
[responseDict setValue:trxResponse.response forKey:@"data"];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
resolve(responseDict);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// intent - holdings import
|
|
165
|
+
if([response isKindOfClass: [ObjcTransactionIntentHoldingsImport class]]) {
|
|
166
|
+
ObjcTransactionIntentHoldingsImport *trxResponse = response;
|
|
167
|
+
[responseDict setValue:@"HOLDING_IMPORT" forKey:@"transaction"];
|
|
168
|
+
|
|
169
|
+
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
|
170
|
+
[dict setValue: trxResponse.authToken forKey:@"smallcaseAuthToken"];
|
|
171
|
+
[dict setValue: trxResponse.transactionId forKey:@"transactionId"];
|
|
172
|
+
[dict setValue: trxResponse.broker forKey:@"broker"];
|
|
173
|
+
|
|
174
|
+
[responseDict setValue:dict forKey:@"data"];
|
|
175
|
+
resolve(responseDict);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// intent - fetch funds
|
|
180
|
+
if([response isKindOfClass: [ObjcTransactionIntentFetchFunds class]]) {
|
|
181
|
+
ObjcTransactionIntentFetchFunds *trxResponse = response;
|
|
182
|
+
[responseDict setValue:@"FETCH_FUNDS" forKey:@"transaction"];
|
|
183
|
+
|
|
184
|
+
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
|
185
|
+
[dict setValue: trxResponse.authToken forKey:@"smallcaseAuthToken"];
|
|
186
|
+
[dict setValue: trxResponse.transactionId forKey:@"transactionId"];
|
|
187
|
+
|
|
188
|
+
[dict setValue:[NSNumber numberWithDouble:trxResponse.fund] forKey:@"fund"];
|
|
189
|
+
|
|
190
|
+
[responseDict setValue:dict forKey:@"data"];
|
|
191
|
+
resolve(responseDict);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// intent - sip setup
|
|
196
|
+
if([response isKindOfClass: [ObjcTransactionIntentSipSetup class]]) {
|
|
197
|
+
ObjcTransactionIntentSipSetup *trxResponse = response;
|
|
198
|
+
[responseDict setValue:@"SIP_SETUP" forKey:@"transaction"];
|
|
199
|
+
|
|
200
|
+
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
|
201
|
+
[dict setValue: trxResponse.authToken forKey:@"smallcaseAuthToken"];
|
|
202
|
+
[dict setValue: trxResponse.transactionId forKey:@"transactionId"];
|
|
203
|
+
[dict setValue: trxResponse.sipAction forKey:@"sipAction"];
|
|
204
|
+
[dict setValue: trxResponse.sipType forKey:@"sipType"];
|
|
205
|
+
[dict setValue: trxResponse.frequency forKey:@"frequency"];
|
|
206
|
+
[dict setValue: trxResponse.iscid forKey:@"iscid"];
|
|
207
|
+
[dict setValue: trxResponse.scheduledDate forKey:@"scheduledDate"];
|
|
208
|
+
[dict setValue: trxResponse.scid forKey:@"scid"];
|
|
209
|
+
[dict setValue: trxResponse.sipActive ? @"YES" : @"NO" forKey:@"sipActive"];
|
|
210
|
+
[dict setValue: [NSNumber numberWithDouble: trxResponse.sipAmount] forKey:@"sipAmount"];
|
|
211
|
+
|
|
212
|
+
[responseDict setValue:dict forKey:@"data"];
|
|
213
|
+
resolve(responseDict);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
// intent - authorize holdings
|
|
219
|
+
if([response isKindOfClass: [ObjcTransactionIntentAuthoriseHoldings class]]) {
|
|
220
|
+
ObjcTransactionIntentAuthoriseHoldings *trxResponse = response;
|
|
221
|
+
[responseDict setValue:@"AUTHORISE_HOLDINGS" forKey:@"transaction"];
|
|
222
|
+
|
|
223
|
+
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
|
224
|
+
[dict setValue: trxResponse.authToken forKey:@"smallcaseAuthToken"];
|
|
225
|
+
[dict setValue: trxResponse.transactionId forKey:@"transactionId"];
|
|
226
|
+
|
|
227
|
+
[dict setValue: [NSNumber numberWithBool:trxResponse.status] forKey:@"status"];
|
|
228
|
+
|
|
229
|
+
[responseDict setValue:dict forKey:@"data"];
|
|
230
|
+
resolve(responseDict);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// no matching intent type
|
|
235
|
+
NSError *err = [[NSError alloc] initWithDomain:@"com.smallcase.gateway" code:0 userInfo:@{@"Error reason": @"no matching response type"}];
|
|
236
|
+
reject(@"triggerTransaction", @"no matching response type", err);
|
|
237
|
+
}];
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
RCT_REMAP_METHOD(logoutUser,
|
|
242
|
+
logoutUserWithResolver:(RCTPromiseResolveBlock)resolve
|
|
243
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
244
|
+
{
|
|
245
|
+
dispatch_async(dispatch_get_main_queue(), ^(void) {
|
|
246
|
+
[SCGateway.shared
|
|
247
|
+
logoutUserWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController]
|
|
248
|
+
completion:^(BOOL success, NSError * error) {
|
|
249
|
+
if(success){
|
|
250
|
+
resolve(@(YES));
|
|
251
|
+
} else {
|
|
252
|
+
reject(@"logout", @"Error during logout", error);
|
|
253
|
+
}
|
|
254
|
+
}];
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
RCT_REMAP_METHOD(triggerLeadGenWithStatus,
|
|
260
|
+
userParams: (NSDictionary *)userParams
|
|
261
|
+
leadGenGenWithResolver: (RCTPromiseResolveBlock)resolve
|
|
262
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
263
|
+
{
|
|
264
|
+
dispatch_async(dispatch_get_main_queue(), ^(void) {
|
|
265
|
+
|
|
266
|
+
[SCGateway.shared triggerLeadGenWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController] params:userParams
|
|
267
|
+
completion:^(NSString * leadGenResponse) {
|
|
268
|
+
resolve(leadGenResponse);
|
|
269
|
+
}
|
|
270
|
+
];
|
|
271
|
+
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
RCT_EXPORT_METHOD(triggerLeadGen: (NSDictionary *)userParams utmParams:(NSDictionary *)utmParams)
|
|
276
|
+
{
|
|
277
|
+
dispatch_async(dispatch_get_main_queue(), ^(void) {
|
|
278
|
+
[SCGateway.shared triggerLeadGenWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController] params:userParams utmParams: utmParams];
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
@end
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|