react-native-smallcase-gateway 1.3.3 → 1.4.2

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 CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  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.
4
4
 
5
+ ### [1.4.2](https://github.com/smallcase/react-native-smallcase-gateway/compare/v1.4.0...v1.4.2) (2022-07-21)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * version not null ([479109d](https://github.com/smallcase/react-native-smallcase-gateway/commit/479109d9d491a853f1d09744fe2f36fffb1409dc))
11
+
12
+ ### [1.4.1](https://github.com/smallcase/react-native-smallcase-gateway/compare/v1.4.0...v1.4.1) (2022-06-27)
13
+
14
+ ## [1.4.0](https://github.com/smallcase/react-native-smallcase-gateway/compare/v1.3.3...v1.4.0) (2022-06-23)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * android native module for dmbranding ([df816f6](https://github.com/smallcase/react-native-smallcase-gateway/commit/df816f6dfa987dfdfc6297aec362fdb2c7d1e3c3))
20
+ * dm partner branding ([78fb73f](https://github.com/smallcase/react-native-smallcase-gateway/commit/78fb73f56055c74eecebcff03c7560a794c06c7f))
21
+ * iOS null issue & Android def val ([a852397](https://github.com/smallcase/react-native-smallcase-gateway/commit/a852397e2aa4e0ffc6669f0345cbd93f2e63a6b8))
22
+ * method signature for ios native dm ([daedabc](https://github.com/smallcase/react-native-smallcase-gateway/commit/daedabca1180b16c3eacd2c956a51b8d63457435))
23
+ * Platform check for dm branding ([0d80e79](https://github.com/smallcase/react-native-smallcase-gateway/commit/0d80e797b80e4c92e940b2763da81299ba05c9c6))
24
+ * type error ([e2b1394](https://github.com/smallcase/react-native-smallcase-gateway/commit/e2b139426a488a94bfe514265a8599c81ffb31b8))
25
+
5
26
  ### [1.3.3](https://github.com/smallcase/react-native-smallcase-gateway/compare/v1.3.2...v1.3.3) (2022-06-02)
6
27
 
7
28
 
@@ -82,7 +82,7 @@ repositories {
82
82
  dependencies {
83
83
  //noinspection GradleDynamicVersion
84
84
  implementation 'com.facebook.react:react-native:+' // From node_modules
85
- implementation 'com.smallcase.gateway:sdk:3.3.2'
85
+ implementation 'com.smallcase.gateway:sdk:3.4.3'
86
86
  implementation "androidx.core:core-ktx:1.3.1"
87
87
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
88
88
  }
@@ -1,9 +1,6 @@
1
1
  package com.smallcase.gateway.reactnative
2
2
 
3
- import android.content.ClipboardManager
4
- import android.content.Context
5
3
  import android.util.Log
6
- import android.widget.Toast
7
4
  import com.facebook.react.bridge.*
8
5
  import com.smallcase.gateway.data.SmallcaseGatewayListeners
9
6
  import com.smallcase.gateway.data.SmallcaseLogoutListener
@@ -14,6 +11,8 @@ import com.smallcase.gateway.data.models.*
14
11
  import com.smallcase.gateway.data.requests.InitRequest
15
12
  import com.smallcase.gateway.portal.SmallcaseGatewaySdk
16
13
  import com.smallcase.gateway.data.listeners.LeadGenResponseListener
14
+ import com.smallcase.gateway.portal.SmallplugPartnerProps
15
+ import kotlin.Error
17
16
 
18
17
 
19
18
  class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactContextBaseJavaModule(reactContext!!) {
@@ -26,13 +25,7 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
26
25
  }
27
26
 
28
27
  @ReactMethod
29
- fun setConfigEnvironment(
30
- envName: String,
31
- gateway: String,
32
- isLeprechaunActive: Boolean,
33
- isAmoEnabled: Boolean,
34
- preProvidedBrokers: ReadableArray,
35
- promise: Promise) {
28
+ fun setConfigEnvironment(envName: String, gateway: String, isLeprechaunActive: Boolean, isAmoEnabled: Boolean, preProvidedBrokers: ReadableArray, promise: Promise) {
36
29
 
37
30
  try {
38
31
  val brokerList = ArrayList<String>()
@@ -45,25 +38,17 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
45
38
 
46
39
  val protocol = getProtocol(envName)
47
40
 
48
- val env = Environment(
49
- gateway = gateway,
50
- buildType = protocol,
51
- isAmoEnabled = isAmoEnabled,
52
- preProvidedBrokers = brokerList,
53
- isLeprachaunActive = isLeprechaunActive
54
- )
55
-
56
- SmallcaseGatewaySdk.setConfigEnvironment(
57
- environment = env,
58
- smallcaseGatewayListeners = object : SmallcaseGatewayListeners {
59
- override fun onGatewaySetupSuccessfull() {
60
- promise.resolve(true)
61
- }
62
-
63
- override fun onGatewaySetupFailed(error: String) {
64
- promise.reject(Throwable(error))
65
- }
66
- })
41
+ val env = Environment(gateway = gateway, buildType = protocol, isAmoEnabled = isAmoEnabled, preProvidedBrokers = brokerList, isLeprachaunActive = isLeprechaunActive)
42
+
43
+ SmallcaseGatewaySdk.setConfigEnvironment(environment = env, smallcaseGatewayListeners = object : SmallcaseGatewayListeners {
44
+ override fun onGatewaySetupSuccessfull() {
45
+ promise.resolve(true)
46
+ }
47
+
48
+ override fun onGatewaySetupFailed(error: String) {
49
+ promise.reject(Throwable(error))
50
+ }
51
+ })
67
52
  } catch (e: Exception) {
68
53
  promise.reject(e)
69
54
  }
@@ -86,19 +71,17 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
86
71
  Log.d(TAG, "init: start")
87
72
 
88
73
  val initReq = InitRequest(sdkToken)
89
- SmallcaseGatewaySdk.init(
90
- authRequest = initReq,
91
- gatewayInitialisationListener = object : DataListener<InitialisationResponse> {
92
- override fun onFailure(errorCode: Int, errorMessage: String) {
93
- val err = createErrorJSON(errorCode, errorMessage, null)
94
- promise.reject("error", err)
95
- }
74
+ SmallcaseGatewaySdk.init(authRequest = initReq, gatewayInitialisationListener = object : DataListener<InitialisationResponse> {
75
+ override fun onFailure(errorCode: Int, errorMessage: String) {
76
+ val err = createErrorJSON(errorCode, errorMessage, null)
77
+ promise.reject("error", err)
78
+ }
96
79
 
97
- override fun onSuccess(response: InitialisationResponse) {
98
- promise.resolve(true)
99
- }
80
+ override fun onSuccess(response: InitialisationResponse) {
81
+ promise.resolve(true)
82
+ }
100
83
 
101
- })
84
+ })
102
85
  }
103
86
 
104
87
  @ReactMethod
@@ -115,22 +98,21 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
115
98
  val activity = currentActivity;
116
99
  if (activity != null) {
117
100
  val utm = readableMapToStrHashMap(utmParams)
118
- SmallcaseGatewaySdk.triggerTransaction(
119
- utmParams = utm,
120
- activity = activity,
121
- transactionId = transactionId,
122
- preProvidedBrokers = safeBrokerList,
123
- transactionResponseListener = object : TransactionResponseListener {
124
- override fun onSuccess(transactionResult: TransactionResult) {
125
- val res = resultToWritableMap(transactionResult, true)
126
- promise.resolve(res)
127
- }
128
-
129
- override fun onError(errorCode: Int, errorMessage: String, data: String?) {
130
- val err = createErrorJSON(errorCode, errorMessage, data)
131
- promise.reject("error", err)
132
- }
133
- })
101
+ SmallcaseGatewaySdk.triggerTransaction(utmParams = utm,
102
+ activity = activity,
103
+ transactionId = transactionId,
104
+ preProvidedBrokers = safeBrokerList,
105
+ transactionResponseListener = object : TransactionResponseListener {
106
+ override fun onSuccess(transactionResult: TransactionResult) {
107
+ val res = resultToWritableMap(transactionResult, true)
108
+ promise.resolve(res)
109
+ }
110
+
111
+ override fun onError(errorCode: Int, errorMessage: String, data: String?) {
112
+ val err = createErrorJSON(errorCode, errorMessage, data)
113
+ promise.reject("error", err)
114
+ }
115
+ })
134
116
  } else {
135
117
  promise.reject(Throwable("no activity"))
136
118
  }
@@ -140,19 +122,16 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
140
122
  fun showOrders(promise: Promise) {
141
123
  val activity = currentActivity;
142
124
  if (activity != null) {
143
- SmallcaseGatewaySdk.showOrders(
144
- activity = activity,
145
- showOrdersResponseListener = object : DataListener<Any> {
146
- override fun onSuccess(response: Any) {
147
- promise.resolve(true)
148
- }
125
+ SmallcaseGatewaySdk.showOrders(activity = activity, showOrdersResponseListener = object : DataListener<Any> {
126
+ override fun onSuccess(response: Any) {
127
+ promise.resolve(true)
128
+ }
149
129
 
150
- override fun onFailure(errorCode: Int, errorMessage: String) {
151
- val err = createErrorJSON(errorCode, errorMessage, null)
152
- promise.reject("error", err)
153
- }
130
+ override fun onFailure(errorCode: Int, errorMessage: String) {
131
+ val err = createErrorJSON(errorCode, errorMessage, null)
132
+ promise.reject("error", err)
154
133
  }
155
- )
134
+ })
156
135
  }
157
136
  }
158
137
 
@@ -172,7 +151,51 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
172
151
  promise.resolve(res)
173
152
  }
174
153
 
175
- })
154
+ }, smallplugPartnerProps = SmallplugPartnerProps(headerColor = "#2F363F", backIconColor = "ffffff"))
155
+ }
156
+
157
+ @ReactMethod
158
+ fun launchSmallplugWithBranding(targetEndpoint: String, params: String, readableMap: ReadableMap?, promise: Promise) {
159
+
160
+ fun getColorValue(value: Any?, defaultValue: String): String {
161
+ return when (value) {
162
+ is String -> {
163
+ if (value.length < 6) defaultValue else if (!value.contains("#")) "#$value" else value
164
+ }
165
+ else -> {
166
+ defaultValue
167
+ }
168
+ }
169
+ }
170
+ Log.d(TAG, "launchSmallplugWithBranding: start")
171
+
172
+ var partnerProps: SmallplugPartnerProps? = SmallplugPartnerProps(headerColor = "#2F363F", backIconColor = "ffffff")
173
+
174
+ try {
175
+ partnerProps = readableMap?.toHashMap()?.let { map ->
176
+ val hc = getColorValue(map["headerColor"], "#2F363F")
177
+ val ho = map["headerOpacity"]?.let { if (it is Double) it else 1.0 } ?: 1.0
178
+ val bc = getColorValue(map["backIconColor"], "#ffffff")
179
+ val bo = map["backIconOpacity"]?.let { if (it is Double) it else 1.0 } ?: 1.0
180
+ SmallplugPartnerProps(headerColor = hc, headerOpacity = ho, backIconColor = bc, backIconOpacity = bo)
181
+ }
182
+ } catch (e: Throwable) {
183
+ }
184
+
185
+
186
+ SmallcaseGatewaySdk.launchSmallPlug(currentActivity!!, SmallplugData(targetEndpoint, params), object : SmallPlugResponseListener {
187
+ override fun onFailure(errorCode: Int, errorMessage: String) {
188
+ val err = createErrorJSON(errorCode, errorMessage, null)
189
+
190
+ promise.reject("error", err)
191
+ }
192
+
193
+ override fun onSuccess(smallPlugResult: SmallPlugResult) {
194
+ val res = resultToWritableMap(smallPlugResult)
195
+ promise.resolve(res)
196
+ }
197
+
198
+ }, partnerProps)
176
199
  }
177
200
 
178
201
  @ReactMethod
@@ -196,18 +219,16 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
196
219
  fun logoutUser(promise: Promise) {
197
220
  val activity = currentActivity;
198
221
  if (activity != null) {
199
- SmallcaseGatewaySdk.logoutUser(
200
- activity = activity,
201
- logoutListener = object : SmallcaseLogoutListener {
202
- override fun onLogoutSuccessfull() {
203
- promise.resolve(true)
204
- }
205
-
206
- override fun onLogoutFailed(errorCode: Int, error: String) {
207
- val err = createErrorJSON(errorCode, error, null)
208
- promise.reject("error", err)
209
- }
210
- })
222
+ SmallcaseGatewaySdk.logoutUser(activity = activity, logoutListener = object : SmallcaseLogoutListener {
223
+ override fun onLogoutSuccessfull() {
224
+ promise.resolve(true)
225
+ }
226
+
227
+ override fun onLogoutFailed(errorCode: Int, error: String) {
228
+ val err = createErrorJSON(errorCode, error, null)
229
+ promise.reject("error", err)
230
+ }
231
+ })
211
232
  }
212
233
  }
213
234
 
@@ -215,11 +236,7 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
215
236
  fun triggerLeadGen(userDetails: ReadableMap, utmData: ReadableMap) {
216
237
  val activity = currentActivity;
217
238
  if (activity != null) {
218
- SmallcaseGatewaySdk.triggerLeadGen(
219
- activity=activity,
220
- utmParams = readableMapToStrHashMap(utmData),
221
- params = readableMapToStrHashMap(userDetails)
222
- )
239
+ SmallcaseGatewaySdk.triggerLeadGen(activity = activity, utmParams = readableMapToStrHashMap(utmData), params = readableMapToStrHashMap(userDetails))
223
240
  }
224
241
  }
225
242
 
@@ -228,7 +245,7 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
228
245
  val activity = currentActivity
229
246
  if (activity != null) {
230
247
 
231
- SmallcaseGatewaySdk.triggerLeadGen(activity, readableMapToStrHashMap(userDetails), object: LeadGenResponseListener {
248
+ SmallcaseGatewaySdk.triggerLeadGen(activity, readableMapToStrHashMap(userDetails), object : LeadGenResponseListener {
232
249
  override fun onSuccess(leadResponse: String) {
233
250
  promise.resolve(leadResponse)
234
251
  }
@@ -299,6 +299,61 @@ RCT_REMAP_METHOD(launchSmallplug,
299
299
  });
300
300
  }
301
301
 
302
+ RCT_REMAP_METHOD(launchSmallplugWithBranding,
303
+ targetEndpoint:(NSString *)targetEndpoint
304
+ params:(NSString *)params
305
+ headerColor:(NSString *)headerColor
306
+ headerOpacity:(nonnull NSNumber *)headerOpacity
307
+ backIconColor:(NSString *)backIconColor
308
+ backIconOpacity:(nonnull NSNumber *)backIconOpacity
309
+ launchSmallplugWithResolver:(RCTPromiseResolveBlock)resolve
310
+ rejecter:(RCTPromiseRejectBlock)reject)
311
+ {
312
+ dispatch_async(dispatch_get_main_queue(), ^(void) {
313
+
314
+ SmallplugData *smallplugData = [[SmallplugData alloc] init:targetEndpoint :params];
315
+ SmallplugUiConfig *smallplugUiConfig = [[SmallplugUiConfig alloc] initWithSmallplugHeaderColor:headerColor headerColorOpacity:headerOpacity backIconColor:backIconColor backIconColorOpacity:backIconOpacity];
316
+
317
+ [SCGateway.shared launchSmallPlugWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController] smallplugData:smallplugData smallplugUiConfig:smallplugUiConfig completion:^(id smallplugResponse, NSError * error) {
318
+
319
+ NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
320
+
321
+ if (error != nil) {
322
+ NSLog(@"%@", error.domain);
323
+ double delayInSeconds = 0.5;
324
+ dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
325
+ dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
326
+ NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
327
+ [responseDict setValue:[NSNumber numberWithBool:false] forKey:@"success"];
328
+ [responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
329
+ [responseDict setValue:error.domain forKey:@"error"];
330
+
331
+ resolve(responseDict);
332
+ return;
333
+ });
334
+ } else {
335
+
336
+ if ([smallplugResponse isKindOfClass: [NSString class]]) {
337
+ NSLog(@"%@", smallplugResponse);
338
+
339
+ [responseDict setValue:[NSNumber numberWithBool: true] forKey:@"success"];
340
+ [responseDict setValue:smallplugResponse forKey:@"smallcaseAuthToken"];
341
+
342
+ double delayInSeconds = 0.5;
343
+ dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
344
+ dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
345
+
346
+ resolve(responseDict);
347
+ return;
348
+
349
+ });
350
+ }
351
+ }
352
+
353
+ }];
354
+ });
355
+ }
356
+
302
357
  RCT_REMAP_METHOD(archiveSmallcase,
303
358
  iscid:(NSString *)iscid
304
359
  initWithResolver:(RCTPromiseResolveBlock)resolve
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-smallcase-gateway",
3
3
  "title": "React Native Smallcase Gateway",
4
- "version": "1.3.3",
4
+ "version": "1.4.2",
5
5
  "description": "smallcase gateway bindings for react native",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -23,6 +23,7 @@ Pod::Spec.new do |s|
23
23
  s.requires_arc = true
24
24
 
25
25
  s.dependency "React-Core"
26
- s.dependency 'SCGateway', '3.2.4'
26
+ s.dependency 'SCGateway', '3.4.4'
27
+ # s.dependency "Mixpanel-swift"
27
28
  end
28
29
 
@@ -1,6 +1,6 @@
1
- import { NativeModules } from "react-native";
1
+ import { NativeModules, Platform } from "react-native";
2
2
  import { ENV } from "./constants";
3
- import { safeObject } from "./util";
3
+ import { safeObject, platformSpecificColorHex } from "./util";
4
4
  import { version } from "../package.json";
5
5
  const { SmallcaseGateway: SmallcaseGatewayNative } = NativeModules;
6
6
 
@@ -24,6 +24,12 @@ const { SmallcaseGateway: SmallcaseGatewayNative } = NativeModules;
24
24
  * @property {String} email - email of user
25
25
  * @property {String} contact - contact of user
26
26
  * @property {String} pinCode - pin-code of user
27
+ *
28
+ * @typedef {Object} SmallplugUiConfig
29
+ * @property {String} headerColor - color of the header background
30
+ * @property {Number} headerOpacity - opacity of the header background
31
+ * @property {String} backIconColor - color of the back icon
32
+ * @property {Number} backIconOpacity - opacity of the back icon
27
33
  */
28
34
 
29
35
  let defaultBrokerList = [];
@@ -36,7 +42,7 @@ const setConfigEnvironment = async (envConfig) => {
36
42
  const safeConfig = safeObject(envConfig);
37
43
 
38
44
  await SmallcaseGatewayNative.setHybridSdkVersion(version);
39
-
45
+
40
46
  const {
41
47
  brokerList,
42
48
  gatewayName,
@@ -115,6 +121,45 @@ const launchSmallplug = async (targetEndpoint, params) => {
115
121
 
116
122
  }
117
123
 
124
+ const safeGatewayName = typeof gatewayName === "string" ? gatewayName : "";
125
+ /**
126
+ * launches smallcases module
127
+ *
128
+ * @param {string} targetEndpoint
129
+ * @param {string} params
130
+ * @param {string} headerColor
131
+ * @param {number} headerOpacity
132
+ * @param {string} backIconColor
133
+ * @param {number} backIconOpacity
134
+ */
135
+ const launchSmallplugWithBranding = async (targetEndpoint, params, headerColor, headerOpacity, backIconColor, backIconOpacity) => {
136
+ const safeEndpoint = typeof targetEndpoint === "string" ? targetEndpoint : ""
137
+ const safeParams = typeof params === "string" ? params : ""
138
+ const safeHeaderColor = typeof headerColor === "string" ? headerColor : platformSpecificColorHex("2F363F")
139
+ const safeHeaderOpacity = typeof headerOpacity === "number" ? headerOpacity : 1
140
+ const safeBackIconColor = typeof backIconColor === "string" ? backIconColor : platformSpecificColorHex("FFFFFF")
141
+ const safeBackIconOpacity = typeof backIconOpacity === "number" ? backIconOpacity : 1
142
+
143
+ return Platform.OS === 'android' ?
144
+ SmallcaseGatewayNative.launchSmallplugWithBranding(
145
+ safeEndpoint, safeParams,
146
+ {
147
+ headerColor: safeHeaderColor,
148
+ headerOpacity: safeHeaderOpacity,
149
+ backIconColor: safeBackIconColor,
150
+ backIconOpacity: safeBackIconOpacity
151
+ })
152
+ : SmallcaseGatewayNative.launchSmallplugWithBranding(
153
+ safeEndpoint,
154
+ safeParams,
155
+ safeHeaderColor,
156
+ safeHeaderOpacity,
157
+ safeBackIconColor,
158
+ safeBackIconOpacity
159
+ );
160
+
161
+ }
162
+
118
163
  /**
119
164
  * Logs the user out and removes the web session.
120
165
  *
@@ -154,7 +199,7 @@ const triggerLeadGen = (userDetails, utmParams) => {
154
199
  * @param {userDetails} [userDetails]
155
200
  * * @returns {Promise}
156
201
  */
157
- const triggerLeadGenWithStatus = async (userDetails) => {
202
+ const triggerLeadGenWithStatus = async (userDetails) => {
158
203
  const safeParams = safeObject(userDetails);
159
204
 
160
205
  return SmallcaseGatewayNative.triggerLeadGenWithStatus(safeParams);
@@ -189,6 +234,7 @@ const SmallcaseGateway = {
189
234
  triggerTransaction,
190
235
  setConfigEnvironment,
191
236
  launchSmallplug,
237
+ launchSmallplugWithBranding,
192
238
  getSdkVersion,
193
239
  showOrders
194
240
  };
package/src/util.js CHANGED
@@ -9,3 +9,10 @@
9
9
  export const safeObject = (obj) => {
10
10
  return obj && typeof obj === "object" ? obj : {};
11
11
  };
12
+
13
+ export function platformSpecificColorHex(hex) {
14
+ if (Platform.OS === 'android') {
15
+ return `#${hex}`
16
+ }
17
+ return hex
18
+ }