react-native-smallcase-gateway 1.0.2 → 1.2.1

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.2.1](https://github.com/smallcase/react-native-smallcase-gateway/compare/v1.2.0...v1.2.1) (2022-05-27)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * smallplug crash for blank page ([35996e9](https://github.com/smallcase/react-native-smallcase-gateway/commit/35996e90c6fe97f4d98e004ab7d319f34411db2d))
11
+
12
+ ## [1.2.0](https://github.com/smallcase/react-native-smallcase-gateway/compare/v1.1.0...v1.2.0) (2022-05-17)
13
+
14
+
15
+ ### Features
16
+
17
+ * show orders ([5ea8109](https://github.com/smallcase/react-native-smallcase-gateway/commit/5ea8109911ddd1f38dc666fb6815f10112bcce74))
18
+
19
+ ## [1.1.0](https://github.com/smallcase/react-native-smallcase-gateway/compare/v1.0.2...v1.1.0) (2022-04-07)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * transaction error response in onSuccess callback ([6d36aeb](https://github.com/smallcase/react-native-smallcase-gateway/commit/6d36aebc0af379d7d7782baa7e59bc3092654d76))
25
+
5
26
  ### [1.0.2](https://github.com/smallcase/react-native-smallcase-gateway/compare/v1.0.0...v1.0.2) (2022-04-04)
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.1.21'
85
+ implementation 'com.smallcase.gateway:sdk:3.2.0'
86
86
  implementation "androidx.core:core-ktx:1.3.1"
87
87
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
88
88
  }
@@ -13,6 +13,7 @@ import com.smallcase.gateway.data.listeners.TransactionResponseListener
13
13
  import com.smallcase.gateway.data.models.*
14
14
  import com.smallcase.gateway.data.requests.InitRequest
15
15
  import com.smallcase.gateway.portal.SmallcaseGatewaySdk
16
+ import com.smallcase.gateway.data.listeners.LeadGenResponseListener
16
17
 
17
18
 
18
19
  class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactContextBaseJavaModule(reactContext!!) {
@@ -32,7 +33,6 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
32
33
  isAmoEnabled: Boolean,
33
34
  preProvidedBrokers: ReadableArray,
34
35
  promise: Promise) {
35
- Log.d(TAG, "setConfigEnvironment: start")
36
36
 
37
37
  try {
38
38
  val brokerList = ArrayList<String>()
@@ -75,6 +75,12 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
75
75
  SmallcaseGatewaySdk.setHybridSDKVersion(sdkVersion)
76
76
  }
77
77
 
78
+ @ReactMethod
79
+ fun getSdkVersion(reactNativeSdkVersion: String, promise: Promise) {
80
+ val sdkString = "android:${SmallcaseGatewaySdk.getSdkVersion()},react-native:$reactNativeSdkVersion"
81
+ promise.resolve(sdkString)
82
+ }
83
+
78
84
  @ReactMethod
79
85
  fun init(sdkToken: String, promise: Promise) {
80
86
  Log.d(TAG, "init: start")
@@ -84,7 +90,7 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
84
90
  authRequest = initReq,
85
91
  gatewayInitialisationListener = object : DataListener<InitialisationResponse> {
86
92
  override fun onFailure(errorCode: Int, errorMessage: String) {
87
- val err = createErrorJSON(errorCode, errorMessage)
93
+ val err = createErrorJSON(errorCode, errorMessage, null)
88
94
  promise.reject("error", err)
89
95
  }
90
96
 
@@ -116,21 +122,15 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
116
122
  preProvidedBrokers = safeBrokerList,
117
123
  transactionResponseListener = object : TransactionResponseListener {
118
124
  override fun onSuccess(transactionResult: TransactionResult) {
119
- if (transactionResult.success) {
120
- val res = resultToWritableMap(transactionResult)
121
- promise.resolve(res)
122
- } else {
123
- val err = createErrorJSON(
124
- transactionResult.errorCode,
125
- transactionResult.error
126
- )
127
- promise.reject("error", err)
128
- }
125
+
126
+ val res = resultToWritableMap(transactionResult)
127
+ promise.resolve(res)
128
+
129
129
 
130
130
  }
131
131
 
132
- override fun onError(errorCode: Int, errorMessage: String) {
133
- val err = createErrorJSON(errorCode, errorMessage)
132
+ override fun onError(errorCode: Int, errorMessage: String, data: String?) {
133
+ val err = createErrorJSON(errorCode, errorMessage, data)
134
134
  promise.reject("error", err)
135
135
  }
136
136
  })
@@ -139,13 +139,33 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
139
139
  }
140
140
  }
141
141
 
142
+ @ReactMethod
143
+ fun showOrders(promise: Promise) {
144
+ val activity = currentActivity;
145
+ if (activity != null) {
146
+ SmallcaseGatewaySdk.showOrders(
147
+ activity = activity,
148
+ showOrdersResponseListener = object : DataListener<Any> {
149
+ override fun onSuccess(response: Any) {
150
+ promise.resolve(true)
151
+ }
152
+
153
+ override fun onFailure(errorCode: Int, errorMessage: String) {
154
+ val err = createErrorJSON(errorCode, errorMessage, null)
155
+ promise.reject("error", err)
156
+ }
157
+ }
158
+ )
159
+ }
160
+ }
161
+
142
162
  @ReactMethod
143
163
  fun launchSmallplug(targetEndpoint: String, params: String, promise: Promise) {
144
164
  Log.d(TAG, "launchSmallplug: start")
145
165
 
146
166
  SmallcaseGatewaySdk.launchSmallPlug(currentActivity!!, SmallplugData(targetEndpoint, params), object : SmallPlugResponseListener {
147
167
  override fun onFailure(errorCode: Int, errorMessage: String) {
148
- val err = createErrorJSON(errorCode, errorMessage)
168
+ val err = createErrorJSON(errorCode, errorMessage, null)
149
169
 
150
170
  promise.reject("error", err)
151
171
  }
@@ -169,7 +189,7 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
169
189
  }
170
190
 
171
191
  override fun onFailure(errorCode: Int, errorMessage: String) {
172
- val err = createErrorJSON(errorCode, errorMessage)
192
+ val err = createErrorJSON(errorCode, errorMessage, null)
173
193
  promise.reject("error", err)
174
194
  }
175
195
  })
@@ -187,7 +207,7 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
187
207
  }
188
208
 
189
209
  override fun onLogoutFailed(errorCode: Int, error: String) {
190
- val err = createErrorJSON(errorCode, error)
210
+ val err = createErrorJSON(errorCode, error, null)
191
211
  promise.reject("error", err)
192
212
  }
193
213
  })
@@ -208,27 +228,13 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
208
228
 
209
229
  @ReactMethod
210
230
  fun triggerLeadGenWithStatus(userDetails: ReadableMap, promise: Promise) {
211
- val activity = currentActivity;
231
+ val activity = currentActivity
212
232
  if (activity != null) {
213
- SmallcaseGatewaySdk.triggerLeadGen(activity,readableMapToStrHashMap(userDetails), object : TransactionResponseListener {
214
- override fun onSuccess(transactionResult: TransactionResult) {
215
- if (transactionResult.success) {
216
- val res = resultToWritableMap(transactionResult)
217
- promise.resolve(res)
218
- } else {
219
- val err = createErrorJSON(
220
- transactionResult.errorCode,
221
- transactionResult.error
222
- )
223
- promise.reject("error", err)
224
- }
225
- }
226
233
 
227
- override fun onError(errorCode: Int, errorMessage: String) {
228
- val err = createErrorJSON(errorCode, errorMessage)
229
- promise.reject("error", err)
234
+ SmallcaseGatewaySdk.triggerLeadGen(activity, readableMapToStrHashMap(userDetails), object: LeadGenResponseListener {
235
+ override fun onSuccess(leadResponse: String) {
236
+ promise.resolve(leadResponse)
230
237
  }
231
-
232
238
  })
233
239
  }
234
240
  }
@@ -263,15 +269,11 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
263
269
  val writableMap: WritableMap = Arguments.createMap()
264
270
 
265
271
  writableMap.putString("data", result.data)
266
- writableMap.putBoolean("success", result.success)
267
- writableMap.putString("error", result.error)
268
- result.errorCode?.let {
269
- writableMap.putInt("errorCode", it)
270
- }
271
272
  writableMap.putString("transaction", result.transaction.name)
272
273
  return writableMap
273
274
  }
274
275
 
276
+
275
277
  private fun resultToWritableMap(result: SmallPlugResult): WritableMap {
276
278
  val writableMap: WritableMap = Arguments.createMap()
277
279
 
@@ -281,11 +283,12 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext?) : ReactCont
281
283
  return writableMap
282
284
  }
283
285
 
284
- private fun createErrorJSON(errorCode: Int?, errorMessage: String?): WritableMap {
286
+ private fun createErrorJSON(errorCode: Int?, errorMessage: String?, data: String?): WritableMap {
285
287
  val errObj = Arguments.createMap()
286
288
 
287
289
  errorCode?.let { errObj.putInt("errorCode", it) }
288
290
  errorMessage?.let { errObj.putString("errorMessage", it) }
291
+ data?.let { errObj.putString("data", it) }
289
292
 
290
293
  return errObj
291
294
  }
@@ -13,6 +13,19 @@ RCT_REMAP_METHOD(setHybridSdkVersion, sdkVersion: (NSString *)sdkVersion) {
13
13
  [SCGateway.shared setHybridSDKVersionWithVersion:sdkVersion];
14
14
  }
15
15
 
16
+ RCT_REMAP_METHOD(getSdkVersion,
17
+ reactNativeSdkVersion: (NSString *)reactNativeSdkVersion
18
+ initWithResolver:(RCTPromiseResolveBlock)resolve
19
+ rejecter:(RCTPromiseRejectBlock)reject) {
20
+
21
+ NSString *nativeSdkString = [NSString stringWithFormat: @"ios:%@", [SCGateway.shared getSdkVersion]];
22
+ NSString *reactNativeSdkString = [NSString stringWithFormat: @",react-native:%@", reactNativeSdkVersion];
23
+
24
+ NSString *result = [nativeSdkString stringByAppendingString: reactNativeSdkString];
25
+
26
+ resolve(result);
27
+ }
28
+
16
29
  RCT_REMAP_METHOD(setConfigEnvironment,
17
30
  envName:(NSString *)envName
18
31
  gateway:(NSString *)gateway
@@ -82,34 +95,6 @@ RCT_REMAP_METHOD(init,
82
95
  }];
83
96
  }
84
97
 
85
- RCT_REMAP_METHOD(archiveSmallcase,
86
- iscid:(NSString *)iscid
87
- initWithResolver:(RCTPromiseResolveBlock)resolve
88
- rejecter:(RCTPromiseRejectBlock)reject)
89
- {
90
- [SCGateway.shared markSmallcaseArchiveWithIscid:iscid completion: ^(id response, NSError * error) {
91
- if(error != nil) {
92
- NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
93
- [responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
94
- [responseDict setValue:error.domain forKey:@"errorMessage"];
95
-
96
- NSError *err = [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:responseDict];
97
-
98
- reject(@"archiveSmallcase", @"Error during transaction", err);
99
- return;
100
- }
101
-
102
- NSString *archiveResponseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
103
-
104
- NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
105
- [responseDict setValue:[NSNumber numberWithBool:true] forKey:@"success"];
106
-
107
- [responseDict setObject:archiveResponseString forKey:@"data"];
108
- resolve(responseDict);
109
- return;
110
- }];
111
- }
112
-
113
98
  RCT_REMAP_METHOD(triggerTransaction,
114
99
  transactionId:(NSString *)transactionId
115
100
  utmParams:(NSDictionary *)utmParams
@@ -241,6 +226,29 @@ RCT_REMAP_METHOD(triggerTransaction,
241
226
  });
242
227
  }
243
228
 
229
+ RCT_REMAP_METHOD(showOrders,
230
+ showOrdersWithResolver: (RCTPromiseResolveBlock)resolve
231
+ rejecter:(RCTPromiseRejectBlock)reject)
232
+ {
233
+ dispatch_async(dispatch_get_main_queue(), ^(void) {
234
+
235
+ NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
236
+
237
+ [SCGateway.shared
238
+ showOrdersWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController]
239
+ completion:^(BOOL success, NSError * error) {
240
+
241
+ if(success){
242
+ resolve(@(YES));
243
+ } else {
244
+ [responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
245
+ [responseDict setValue:error.domain forKey:@"error"];
246
+ resolve(responseDict);
247
+ }
248
+ }];
249
+ });
250
+ }
251
+
244
252
  RCT_REMAP_METHOD(launchSmallplug,
245
253
  targetEndpoint:(NSString *)targetEndpoint
246
254
  params:(NSString *)params
@@ -291,28 +299,38 @@ RCT_REMAP_METHOD(launchSmallplug,
291
299
  });
292
300
  }
293
301
 
294
- RCT_REMAP_METHOD(logoutUser,
295
- logoutUserWithResolver:(RCTPromiseResolveBlock)resolve
302
+ RCT_REMAP_METHOD(archiveSmallcase,
303
+ iscid:(NSString *)iscid
304
+ initWithResolver:(RCTPromiseResolveBlock)resolve
296
305
  rejecter:(RCTPromiseRejectBlock)reject)
297
306
  {
298
- dispatch_async(dispatch_get_main_queue(), ^(void) {
299
- [SCGateway.shared
300
- logoutUserWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController]
301
- completion:^(BOOL success, NSError * error) {
302
- if(success){
303
- resolve(@(YES));
304
- } else {
305
- reject(@"logout", @"Error during logout", error);
306
- }
307
- }];
308
- });
307
+ [SCGateway.shared markSmallcaseArchiveWithIscid:iscid completion: ^(id response, NSError * error) {
308
+ if(error != nil) {
309
+ NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
310
+ [responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
311
+ [responseDict setValue:error.domain forKey:@"errorMessage"];
312
+
313
+ NSError *err = [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:responseDict];
314
+
315
+ reject(@"archiveSmallcase", @"Error during transaction", err);
316
+ return;
317
+ }
318
+
319
+ NSString *archiveResponseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
320
+
321
+ NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
322
+ [responseDict setValue:[NSNumber numberWithBool:true] forKey:@"success"];
323
+
324
+ [responseDict setObject:archiveResponseString forKey:@"data"];
325
+ resolve(responseDict);
326
+ return;
327
+ }];
309
328
  }
310
329
 
311
-
312
330
  RCT_REMAP_METHOD(triggerLeadGenWithStatus,
313
- userParams: (NSDictionary *)userParams
314
- leadGenGenWithResolver: (RCTPromiseResolveBlock)resolve
315
- rejecter:(RCTPromiseRejectBlock)reject)
331
+ userParams: (NSDictionary *)userParams
332
+ leadGenGenWithResolver: (RCTPromiseResolveBlock)resolve
333
+ rejecter:(RCTPromiseRejectBlock)reject)
316
334
  {
317
335
  dispatch_async(dispatch_get_main_queue(), ^(void) {
318
336
 
@@ -320,7 +338,7 @@ RCT_REMAP_METHOD(triggerLeadGenWithStatus,
320
338
  completion:^(NSString * leadGenResponse) {
321
339
  resolve(leadGenResponse);
322
340
  }
323
- ];
341
+ ];
324
342
 
325
343
  });
326
344
  }
@@ -332,6 +350,23 @@ RCT_EXPORT_METHOD(triggerLeadGen: (NSDictionary *)userParams utmParams:(NSDictio
332
350
  });
333
351
  }
334
352
 
353
+ RCT_REMAP_METHOD(logoutUser,
354
+ logoutUserWithResolver:(RCTPromiseResolveBlock)resolve
355
+ rejecter:(RCTPromiseRejectBlock)reject)
356
+ {
357
+ dispatch_async(dispatch_get_main_queue(), ^(void) {
358
+ [SCGateway.shared
359
+ logoutUserWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController]
360
+ completion:^(BOOL success, NSError * error) {
361
+ if(success){
362
+ resolve(@(YES));
363
+ } else {
364
+ reject(@"logout", @"Error during logout", error);
365
+ }
366
+ }];
367
+ });
368
+ }
369
+
335
370
  @end
336
371
 
337
372
 
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.0.2",
4
+ "version": "1.2.1",
5
5
  "description": "smallcase gateway bindings for react native",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -23,6 +23,6 @@ Pod::Spec.new do |s|
23
23
  s.requires_arc = true
24
24
 
25
25
  s.dependency "React-Core"
26
- s.dependency 'SCGateway', '3.1.18'
26
+ s.dependency 'SCGateway', '3.2.0'
27
27
  end
28
28
 
@@ -126,6 +126,15 @@ const logoutUser = async () => {
126
126
  return SmallcaseGatewayNative.logoutUser();
127
127
  };
128
128
 
129
+ /**
130
+ * This will display a list of all the orders that a user recently placed.
131
+ * This includes pending, successful, and failed orders.
132
+ * @returns
133
+ */
134
+ const showOrders = async () => {
135
+ return SmallcaseGatewayNative.showOrders();
136
+ };
137
+
129
138
  /**
130
139
  * triggers the lead gen flow
131
140
  *
@@ -139,20 +148,6 @@ const triggerLeadGen = (userDetails, utmParams) => {
139
148
  return SmallcaseGatewayNative.triggerLeadGen(safeParams, safeUtm);
140
149
  };
141
150
 
142
- // /**
143
- // * triggers the lead gen flow
144
- // *
145
- // * @param {userDetails} [userDetails]
146
- // * @param {Object} [utmParams]
147
- // * * @returns {Promise}
148
- // */
149
- // const triggerLeadGen = async (userDetails, utmParams) => {
150
- // const safeParams = safeObject(userDetails);
151
- // const safeUtm = safeObject(utmParams);
152
-
153
- // return SmallcaseGatewayNative.triggerLeadGen(safeParams, safeUtm)
154
- // }
155
-
156
151
  /**
157
152
  * triggers the lead gen flow
158
153
  *
@@ -176,6 +171,15 @@ const archiveSmallcase = async (iscid) => {
176
171
  return SmallcaseGatewayNative.archiveSmallcase(safeIscid);
177
172
  };
178
173
 
174
+ /**
175
+ * Returns the native android/ios and react-native sdk version
176
+ * (internal-tracking)
177
+ * @returns {Promise}
178
+ */
179
+ const getSdkVersion = async () => {
180
+ return SmallcaseGatewayNative.getSdkVersion(version);
181
+ }
182
+
179
183
  const SmallcaseGateway = {
180
184
  init,
181
185
  logoutUser,
@@ -184,7 +188,9 @@ const SmallcaseGateway = {
184
188
  archiveSmallcase,
185
189
  triggerTransaction,
186
190
  setConfigEnvironment,
187
- launchSmallplug
191
+ launchSmallplug,
192
+ getSdkVersion,
193
+ showOrders
188
194
  };
189
195
 
190
196
  export default SmallcaseGateway;