@aptos-scp/scp-component-rn-device-services 0.2.5 → 0.2.7

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.
@@ -35,10 +35,14 @@ let AurusDevice = class AurusDevice {
35
35
  * are created in the constructor, which only accepts JavaScript parameters.
36
36
  */
37
37
  constructor() {
38
- this._initialized = false;
38
+ this._initializeCalled = false;
39
39
  this._listenersAdded = false;
40
+ this._registrationInProgress = false; // EMV Config now happens during registration
41
+ this._waitingForDeviceConnected = false;
40
42
  this._scannerEnabled = true; //todo: once enable/disable is implemented in client, defaulting to false.
41
43
  this._paymentEnvironment = "Aurus"; // string representation of payment environment for trans object
44
+ this._requestInProgress = false;
45
+ this._requestQueue = [];
42
46
  const entryMessage = logger.traceEntry("constructor");
43
47
  this._devicePaymentTerminal = react_native_1.NativeModules.AurusPaymentTerminal;
44
48
  this._nativeEventEmitter = new react_native_1.NativeEventEmitter(react_native_1.NativeModules.AurusPaymentTerminal);
@@ -101,6 +105,7 @@ let AurusDevice = class AurusDevice {
101
105
  return __awaiter(this, void 0, void 0, function* () {
102
106
  const entryMessage = logger.traceEntry("enableScannerDevice");
103
107
  this._scannerEnabled = true;
108
+ this.sendUpgradeRequest(constants_1.UpgradeType.ENABLE_SCANNER);
104
109
  logger.traceExit(entryMessage);
105
110
  });
106
111
  }
@@ -108,6 +113,7 @@ let AurusDevice = class AurusDevice {
108
113
  return __awaiter(this, void 0, void 0, function* () {
109
114
  const entryMessage = logger.traceEntry("disableScannerDevice");
110
115
  this._scannerEnabled = false;
116
+ this.sendUpgradeRequest(constants_1.UpgradeType.DISABLE_SCANNER);
111
117
  logger.traceExit(entryMessage);
112
118
  });
113
119
  }
@@ -175,9 +181,7 @@ let AurusDevice = class AurusDevice {
175
181
  processTimeout() {
176
182
  return __awaiter(this, void 0, void 0, function* () {
177
183
  const entryMessage = logger.traceEntry("processTimeout");
178
- sdk_interface_1.AurusSupport.authResponse.responseCode = _1.ResponseCodes.Timeout;
179
- sdk_interface_1.AurusSupport.authResponse.status = "TIMEOUT WAITING FOR RESPONSE";
180
- this._paymentEmitter.emit(_1.EventResponseTypes.Authorization, sdk_interface_1.AurusSupport.authResponse);
184
+ this.emitAuthorizationResponse(_1.ResponseCodes.Timeout, "TIMEOUT WAITING FOR RESPONSE");
181
185
  //Send cancel to aurus
182
186
  this.sendCancelTranRequest();
183
187
  logger.traceExit(entryMessage);
@@ -188,24 +192,15 @@ let AurusDevice = class AurusDevice {
188
192
  const entryMessage = logger.traceEntry("authorize", authRequest);
189
193
  sdk_interface_1.AurusSupport.authRequest = authRequest;
190
194
  sdk_interface_1.AurusSupport.authResponse = Object.assign({ paymentEnvironment: this._paymentEnvironment }, authRequest);
191
- if (!this._initInProgress && !this._registrationInProgress) {
192
- if (sdk_interface_1.AurusSupport.requireGetCard(authRequest)) {
193
- this.sendGetCardBin(authRequest);
194
- }
195
- else {
196
- this.sendCardTransRequest();
197
- }
195
+ if (this._registrationInProgress) {
196
+ logger.debug("Payment is unavailalbe while device registration is in progress. Emitting error response.");
197
+ this.emitAuthorizationResponse(_1.ResponseCodes.Error, "Payment Unavailable. Device Registration in Progress");
198
+ }
199
+ else if (sdk_interface_1.AurusSupport.requireGetCard(authRequest)) {
200
+ this.sendGetCardBin(authRequest);
198
201
  }
199
202
  else {
200
- sdk_interface_1.AurusSupport.authResponse.responseCode = _1.ResponseCodes.Error;
201
- if (this._initInProgress) {
202
- sdk_interface_1.AurusSupport.authResponse.status = "EMV INIT IN PROGRESS";
203
- }
204
- else if (this._registrationInProgress) {
205
- sdk_interface_1.AurusSupport.authResponse.status = "DEVICE REGISTRATION IN PROGRESS";
206
- }
207
- logger.debug(`Payment not initialized. Sending response: ${JSON.stringify(sdk_interface_1.AurusSupport.authResponse)}`);
208
- this._paymentEmitter.emit(_1.EventResponseTypes.Authorization, sdk_interface_1.AurusSupport.authResponse);
203
+ this.sendCardTransRequest();
209
204
  }
210
205
  logger.traceExit(entryMessage);
211
206
  });
@@ -214,17 +209,18 @@ let AurusDevice = class AurusDevice {
214
209
  return __awaiter(this, void 0, void 0, function* () {
215
210
  const entryMessage = logger.traceEntry("initializeNative");
216
211
  if (!this._listenersAdded) {
212
+ this._listenersAdded = true;
217
213
  let context = {};
218
214
  this._nativeSubscriptions = [
219
215
  this._nativeEventEmitter.addListener(native_onAESDKResponse, this.onAESDKResponse.bind(this), context),
220
216
  this._nativeEventEmitter.addListener(native_onNotificationReceived, this.onNotificationReceived.bind(this), context),
221
217
  this._nativeEventEmitter.addListener(native_onAESDKLogResponse, this.onAESDKLogResponse.bind(this), context)
222
218
  ];
223
- this._listenersAdded = true;
224
219
  }
225
- if (!this._initialized) {
220
+ if (!this._initializeCalled) {
221
+ this._initializeCalled = true;
222
+ this._waitingForDeviceConnected = true;
226
223
  this._devicePaymentTerminal.initialize();
227
- this._initialized = true;
228
224
  }
229
225
  logger.traceExit(entryMessage);
230
226
  });
@@ -252,19 +248,14 @@ let AurusDevice = class AurusDevice {
252
248
  // of events can be sent or just for safety.
253
249
  let withResponse = args[0];
254
250
  logger.debug(`In onAESDKResponse, withResponse: ${JSON.stringify(withResponse)}`);
255
- // Parse xml and determine next steps. Call back into native if needed.
256
- let returnServer = this.handleAESDKResponse(withResponse);
257
- if (returnServer & constants_1.ResponseType.PaymentStatus) {
258
- // If returnServer has PaymentStatus, send IPaymentStatus to POS.
259
- logger.debug(`In onAESDKResponse, publishing paymentStatus: ${JSON.stringify(sdk_interface_1.AurusSupport.paymentStatus)}`);
260
- this._paymentEmitter.emit(_1.EventResponseTypes.PaymentDeviceStatus, sdk_interface_1.AurusSupport.paymentStatus);
261
- sdk_interface_1.AurusSupport.paymentStatus = { deviceAvailable: false };
262
- }
263
- if (returnServer & constants_1.ResponseType.AuthResponse) {
264
- // If returnServer has AuthResponse, send IAuthorizationResponse to POS.
265
- logger.debug(`In onAESDKResponse, publishing authResponse: ${JSON.stringify(sdk_interface_1.AurusSupport.authResponse)}`);
266
- this._paymentEmitter.emit(_1.EventResponseTypes.Authorization, sdk_interface_1.AurusSupport.authResponse);
251
+ if (this._requestInProgress) {
252
+ this._requestInProgress = false;
253
+ if (this._requestQueue.length > 0) {
254
+ this.sendRequest(this._requestQueue.shift());
255
+ }
267
256
  }
257
+ // Parse xml and determine next steps. Call back into native if needed.
258
+ this.handleAESDKResponse(withResponse);
268
259
  }
269
260
  else {
270
261
  throw logger.throwing(new Error("Empty event received. withResponse data is missing"), entryMessage);
@@ -275,28 +266,28 @@ let AurusDevice = class AurusDevice {
275
266
  const entryMessage = logger.traceEntry("sendCancelTranRequest");
276
267
  sdk_interface_1.AurusSupport.requestType = constants_1.RequestTypes.CancelTransaction;
277
268
  let xmlreq = sdk_interface_1.AurusSupport.createCancelTranRequest();
278
- this._devicePaymentTerminal.OnAESDKProcessRequest(xmlreq);
269
+ this.sendRequest(xmlreq);
279
270
  logger.traceExit(entryMessage);
280
271
  }
281
272
  sendCancelLastTranRequest() {
282
273
  const entryMessage = logger.traceEntry("sendCancelLastTranRequest");
283
274
  sdk_interface_1.AurusSupport.requestType = constants_1.RequestTypes.CancelTransaction;
284
275
  let xmlreq = sdk_interface_1.AurusSupport.createCancelLastTranRequest();
285
- this._devicePaymentTerminal.OnAESDKProcessRequest(xmlreq);
276
+ this.sendRequest(xmlreq);
286
277
  logger.traceExit(entryMessage);
287
278
  }
288
279
  sendTransRequest(getCardBinResp) {
289
280
  const entryMessage = logger.traceEntry("sendTransRequest", getCardBinResp);
290
281
  sdk_interface_1.AurusSupport.requestType = constants_1.RequestTypes.Transaction;
291
282
  let xmlreq = sdk_interface_1.AurusSupport.createCardTranRequest(getCardBinResp);
292
- this._devicePaymentTerminal.OnAESDKProcessRequest(xmlreq);
283
+ this.sendRequest(xmlreq);
293
284
  logger.traceExit(entryMessage);
294
285
  }
295
286
  sendCardTransRequest() {
296
287
  const entryMessage = logger.traceEntry("sendCardTransRequest");
297
288
  sdk_interface_1.AurusSupport.requestType = constants_1.RequestTypes.Transaction;
298
289
  let xmlreq = sdk_interface_1.AurusSupport.createCardTranRequest();
299
- this._devicePaymentTerminal.OnAESDKProcessRequest(xmlreq);
290
+ this.sendRequest(xmlreq);
300
291
  logger.traceExit(entryMessage);
301
292
  }
302
293
  /**
@@ -307,7 +298,7 @@ let AurusDevice = class AurusDevice {
307
298
  const entryMessage = logger.traceEntry("sendGetCardBin", authRequest);
308
299
  sdk_interface_1.AurusSupport.requestType = constants_1.RequestTypes.GetCardBin;
309
300
  let xmlreq = sdk_interface_1.AurusSupport.createGetCardBinRequest();
310
- this._devicePaymentTerminal.OnAESDKProcessRequest(xmlreq);
301
+ this.sendRequest(xmlreq);
311
302
  logger.traceExit(entryMessage);
312
303
  }
313
304
  /**
@@ -319,32 +310,41 @@ let AurusDevice = class AurusDevice {
319
310
  sdk_interface_1.AurusSupport.requestType = constants_1.RequestTypes.Registration;
320
311
  let xmlreq = sdk_interface_1.AurusSupport.createAESDKRegistrationRequest();
321
312
  this._registrationInProgress = true;
322
- this._devicePaymentTerminal.OnAESDKProcessRequest(xmlreq);
313
+ this.sendRequest(xmlreq);
314
+ logger.traceExit(entryMessage);
315
+ }
316
+ sendUpgradeRequest(upgradeType) {
317
+ const entryMessage = logger.traceEntry("sendUpgradeRequest");
318
+ if (upgradeType !== constants_1.UpgradeType.ENABLE_SCANNER && upgradeType !== constants_1.UpgradeType.DISABLE_SCANNER) {
319
+ // Enable/Disable scanner is fire and forget and may interrupt other calls. Don't update the request type.
320
+ sdk_interface_1.AurusSupport.requestType = constants_1.RequestTypes.Upgrade;
321
+ }
322
+ let xmlreq = sdk_interface_1.AurusSupport.createUpgradeRequest(upgradeType);
323
+ this.sendRequest(xmlreq);
323
324
  logger.traceExit(entryMessage);
324
325
  }
325
326
  handleAESDKResponse(xml) {
326
327
  const entryMessage = logger.traceEntry("handleAESDKResponse", xml);
327
- let returnServer = constants_1.ResponseType.None;
328
328
  let xmlResponse = this.convertXmlToJs(xml);
329
329
  if (!xmlResponse) {
330
330
  logger.warn(`In handleAESDKResponse, unable to convert to JSON: ${xml}`);
331
331
  }
332
332
  else if (constants_1.AesdkResponseTypes.Registration in xmlResponse) {
333
- returnServer = this.processAESDKRegistration(xmlResponse[constants_1.AesdkResponseTypes.Registration]);
333
+ this.processAESDKRegistration(xmlResponse[constants_1.AesdkResponseTypes.Registration]);
334
334
  }
335
335
  else if (constants_1.AesdkResponseTypes.GetCardBin in xmlResponse) {
336
- returnServer = this.processGetCardBin(xmlResponse[constants_1.AesdkResponseTypes.GetCardBin]);
336
+ this.processGetCardBin(xmlResponse[constants_1.AesdkResponseTypes.GetCardBin]);
337
337
  }
338
338
  else if (constants_1.AesdkResponseTypes.Transaction in xmlResponse) {
339
- returnServer = this.processTrans(xmlResponse[constants_1.AesdkResponseTypes.Transaction]);
339
+ this.processTrans(xmlResponse[constants_1.AesdkResponseTypes.Transaction]);
340
340
  }
341
341
  else if (constants_1.AesdkResponseTypes.AESDK in xmlResponse) {
342
- returnServer = this.processAESDK(xmlResponse[constants_1.AesdkResponseTypes.AESDK]);
342
+ this.processAESDK(xmlResponse[constants_1.AesdkResponseTypes.AESDK]);
343
343
  }
344
344
  else if (constants_1.AesdkResponseTypes.CancelTransaction in xmlResponse) {
345
- returnServer = this.processCancelTrans(xmlResponse[constants_1.AesdkResponseTypes.CancelTransaction]);
345
+ this.processCancelTrans(xmlResponse[constants_1.AesdkResponseTypes.CancelTransaction]);
346
346
  }
347
- return logger.traceExit(entryMessage, returnServer);
347
+ logger.traceExit(entryMessage);
348
348
  }
349
349
  convertXmlToJs(xml) {
350
350
  const entryMessage = logger.traceEntry("convertXmlToJs", xml);
@@ -358,21 +358,20 @@ let AurusDevice = class AurusDevice {
358
358
  }
359
359
  processTrans(response) {
360
360
  const entryMessage = logger.traceEntry("processTrans", response);
361
- let responseType = constants_1.ResponseType.AuthResponse;
362
361
  let tranDetails = response.TransDetailsData.TransDetailData;
363
- sdk_interface_1.AurusSupport.authResponse.responseCode = this.mapAurusResponseCode(tranDetails.ResponseCode.value);
364
- sdk_interface_1.AurusSupport.authResponse.status = tranDetails.TransactionResponseText.value;
365
- if (sdk_interface_1.AurusSupport.authResponse.responseCode === _1.ResponseCodes.Approved) {
362
+ const responseCode = this.mapAurusResponseCode(tranDetails.ResponseCode.value);
363
+ if (responseCode === _1.ResponseCodes.Approved) {
366
364
  sdk_interface_1.AurusSupport.authResponse.approvedAmount = sdk_interface_1.AurusSupport.stringToMoney(tranDetails.TransactionAmount.value);
367
365
  sdk_interface_1.AurusSupport.authResponse.cardNumber = tranDetails.CardNumber.value;
368
366
  sdk_interface_1.AurusSupport.authResponse.cardType = this.mapAurusCardType(tranDetails.CardType.value);
369
367
  sdk_interface_1.AurusSupport.authResponse.tenderType = this.mapAurusTenderType(tranDetails.CardType.value);
370
368
  sdk_interface_1.AurusSupport.authResponse.referenceNumber = response.AurusPayTicketNum.value;
371
369
  sdk_interface_1.AurusSupport.authResponse.balance = tranDetails.BalanceAmount.value;
370
+ sdk_interface_1.AurusSupport.authResponse.approvalCode = tranDetails.ApprovalCode.value;
372
371
  sdk_interface_1.AurusSupport.authResponse.EMVData = this.parseEMVData(tranDetails.EMVData.value);
373
372
  sdk_interface_1.AurusSupport.authResponse.EMVData.receiptData = tranDetails.EMVData && tranDetails.EMVData.value &&
374
373
  tranDetails.EMVData.value.replace(/~/g, ": ").split("[FS]");
375
- // FIXME: AdditionalReceiptInfo should be parsed based on the format of the aurus response.
374
+ // FIXME: AdditionalReceiptInfo should be parsed based on the format of the aurus response.
376
375
  // Resolve when we receive next sdk with correct format
377
376
  sdk_interface_1.AurusSupport.authResponse.receiptData =
378
377
  tranDetails.AdditionalReceiptInfo && [tranDetails.AdditionalReceiptInfo.value];
@@ -381,32 +380,27 @@ let AurusDevice = class AurusDevice {
381
380
  this.mapAurusSignatureRequired(tranDetails.SignatureReceiptFlag.value);
382
381
  sdk_interface_1.AurusSupport.authResponse.pinCaptured = this.mapAurusPinCaptured(tranDetails.SignatureReceiptFlag.value);
383
382
  }
384
- return logger.traceExit(entryMessage, responseType);
383
+ this.emitAuthorizationResponse(responseCode, tranDetails.TransactionResponseText.value);
384
+ logger.traceExit(entryMessage);
385
385
  }
386
386
  processGetCardBin(response) {
387
387
  const entryMessage = logger.traceEntry("processGetCardBin", response);
388
- let responseType = constants_1.ResponseType.None;
389
388
  if (sdk_interface_1.AurusSupport.requestType === constants_1.RequestTypes.GetCardBin) {
390
389
  if (response.ResponseCode.value === constants_1.ResponseCodes.Approved) {
391
390
  this.sendTransRequest(response);
392
391
  }
393
392
  else {
394
- responseType |= constants_1.ResponseType.AuthResponse;
395
- sdk_interface_1.AurusSupport.authResponse.responseCode = this.mapAurusResponseCode(response.ResponseCode.value);
396
- sdk_interface_1.AurusSupport.authResponse.status = response.ResponseText.value;
393
+ this.emitAuthorizationResponse(this.mapAurusResponseCode(response.ResponseCode.value), response.ResponseText.value);
397
394
  }
398
395
  }
399
396
  else {
400
397
  //handle additional request types with getcardbinresponses
401
- responseType |= constants_1.ResponseType.AuthResponse;
402
- sdk_interface_1.AurusSupport.authResponse.responseCode = _1.ResponseCodes.Error;
403
- sdk_interface_1.AurusSupport.authResponse.status = response.ResponseText.value;
398
+ this.emitAuthorizationResponse(_1.ResponseCodes.Error, response.ResponseText.value);
404
399
  }
405
- return logger.traceExit(entryMessage, responseType);
400
+ logger.traceExit(entryMessage);
406
401
  }
407
402
  processCancelTrans(response) {
408
403
  const entryMessage = logger.traceEntry("processCancelTrans", response);
409
- let responseType = constants_1.ResponseType.None;
410
404
  if (response.ResponseCode.value === constants_1.ResponseCodes.Approved) {
411
405
  logger.debug(`processCancelTrans success: ${sdk_interface_1.AurusSupport.authResponse.posReference}`);
412
406
  }
@@ -415,44 +409,39 @@ let AurusDevice = class AurusDevice {
415
409
  logger.debug(`processCancelTrans failed, attempting CancelLastTrans: ${sdk_interface_1.AurusSupport.authRequest.transactionNumber}`);
416
410
  this.sendCancelLastTranRequest();
417
411
  }
418
- return logger.traceExit(entryMessage, responseType);
412
+ logger.traceExit(entryMessage);
419
413
  }
420
414
  processAESDKRegistration(response) {
421
415
  const entryMessage = logger.traceEntry("processAESDKRegistration", response);
422
- let responseType = constants_1.ResponseType.None;
423
416
  if (sdk_interface_1.AurusSupport.requestType === constants_1.RequestTypes.GetCardBin) {
424
- responseType |= constants_1.ResponseType.AuthResponse;
425
- sdk_interface_1.AurusSupport.authResponse.responseCode = _1.ResponseCodes.Error;
426
- sdk_interface_1.AurusSupport.authResponse.status = response.ResponseText.value;
427
417
  if (response.ResponseCode.value === constants_1.ResponseCodes.DeviceNotRegistered) {
428
418
  this.sendAESDKRegistration(sdk_interface_1.AurusSupport.authRequest);
429
419
  }
420
+ this.emitAuthorizationResponse(_1.ResponseCodes.Error, response.ResponseText.value);
430
421
  }
431
422
  if (sdk_interface_1.AurusSupport.requestType === constants_1.RequestTypes.Registration) {
432
- responseType |= constants_1.ResponseType.PaymentStatus;
433
- sdk_interface_1.AurusSupport.paymentStatus.deviceAvailable = true;
434
- sdk_interface_1.AurusSupport.paymentStatus.status = response.ResponseText.value;
435
- sdk_interface_1.AurusSupport.paymentStatus.statusCode = _1.StatusCode.InitializationComplete;
436
423
  this._registrationInProgress = false;
424
+ this.emitPaymentStatus(true, _1.StatusCode.InitializationComplete);
425
+ //enable/disable scanner
426
+ this._scannerEnabled ? this.enableScannerDevice() : this.disableScannerDevice();
437
427
  }
438
- return logger.traceExit(entryMessage, responseType);
428
+ logger.traceExit(entryMessage);
439
429
  }
440
430
  processAESDK(response) {
441
431
  const entryMessage = logger.traceEntry("processAESDK", response);
442
- let responseType = constants_1.ResponseType.None;
443
432
  if (sdk_interface_1.AurusSupport.requestType === constants_1.RequestTypes.GetCardBin) {
444
- responseType |= constants_1.ResponseType.AuthResponse;
445
- sdk_interface_1.AurusSupport.authResponse.responseCode = _1.ResponseCodes.Error;
446
- sdk_interface_1.AurusSupport.authResponse.status = response.ResponseText.value;
433
+ this.emitAuthorizationResponse(_1.ResponseCodes.Error, response.ResponseText.value);
447
434
  }
435
+ // this scenario could happen if the registration request fails
448
436
  if (sdk_interface_1.AurusSupport.requestType === constants_1.RequestTypes.Registration) {
449
- responseType |= constants_1.ResponseType.PaymentStatus;
450
- sdk_interface_1.AurusSupport.paymentStatus.deviceAvailable = true;
451
- sdk_interface_1.AurusSupport.paymentStatus.status = response.ResponseText.value;
452
- sdk_interface_1.AurusSupport.paymentStatus.statusCode = _1.StatusCode.InitializationComplete;
453
437
  this._registrationInProgress = false;
438
+ // enable payment button or it will be permanately disabled without the user knowing why
439
+ // registration can be re-attempted when clicked and/or an error given to the user
440
+ this.emitPaymentStatus(true, _1.StatusCode.InitializationComplete);
441
+ //enable/disable scanner
442
+ this._scannerEnabled ? this.enableScannerDevice() : this.disableScannerDevice();
454
443
  }
455
- return logger.traceExit(entryMessage, responseType);
444
+ logger.traceExit(entryMessage);
456
445
  }
457
446
  mapAurusResponseCode(responseCode) {
458
447
  const entryMessage = logger.traceEntry("mapAurusResponseCode", responseCode);
@@ -564,180 +553,137 @@ let AurusDevice = class AurusDevice {
564
553
  ;
565
554
  return logger.traceExit(entryMessage, emvData);
566
555
  }
567
- handleBarcodeDataReceived(xml) {
568
- const entryMessage = logger.traceEntry("handleBarcodeDataReceived", xml);
569
- let scanDataNotification;
556
+ /**
557
+ * This method handles events published by the native components. This is an adapter between the native and JavaScript
558
+ * components for asynchronous events from the native layer.
559
+ */
560
+ onNotificationReceived(...args) {
561
+ const entryMessage = logger.traceEntry("onNotificationReceived", args);
562
+ if (args.length >= 1 && args[0]) {
563
+ const userInfo = args[0];
564
+ logger.debug(`In onNotificationReceived, userInfo: ${JSON.stringify(userInfo)}`);
565
+ this.handleNotificationEvent(userInfo);
566
+ }
567
+ else {
568
+ throw logger.throwing(new Error("Empty event received. userInfo data is missing"), entryMessage);
569
+ }
570
+ logger.traceExit(entryMessage);
571
+ }
572
+ handleNotificationEvent(userInfo) {
573
+ if (userInfo && userInfo.CODE !== undefined) {
574
+ (({
575
+ [NotificationEvent.BarcodeInformation]: () => { this.handleBarcodeInformationEvent(userInfo.AE_BARCODE_INFO); },
576
+ [NotificationEvent.DeviceNotConnected]: () => { this.handleDeviceNotConnectedEvent(); },
577
+ [NotificationEvent.DeviceConnected]: () => { this.handleDeviceConnectedEvent(); },
578
+ [NotificationEvent.DeviceConfigurationStarted]: () => { this.handleDeviceConfigurationStartedEvent(); },
579
+ [NotificationEvent.DeviceConfigurationCompleted]: () => { this.handleDeviceConfigurationCompletedEvent(); },
580
+ [NotificationEvent.DeviceConfigurationFailed]: () => { this.handleDeviceConfigurationFailedEvent(); },
581
+ [NotificationEvent.DeviceAlreadyConfigured]: () => { this.handleDeviceAlreadyConfiguredEvent(); }
582
+ })[userInfo.CODE] || (() => { this.handleDefaultEvent(userInfo.CODE); }))();
583
+ }
584
+ }
585
+ handleBarcodeInformationEvent(xmlBarcodeInfo) {
586
+ const entryMessage = logger.traceEntry("handleBarcodeInformationEvent", xmlBarcodeInfo);
570
587
  if (!this._scannerEnabled) {
571
588
  logger.debug("Scanning is not enabled, not processing the scan.");
572
589
  // todo: make a sound to indicate the scan failed due to not being enabled.
573
590
  }
574
591
  else {
575
- let xmlResponse = this.convertXmlToJs(xml);
592
+ let xmlResponse = this.convertXmlToJs(xmlBarcodeInfo);
576
593
  if (!xmlResponse) {
577
- logger.warn(`In handleBarcodeDataReceived, unable to convert to JSON: ${xml}`);
594
+ logger.warn(`In handleBarcodeInformationEvent, unable to convert to JSON: ${xmlBarcodeInfo}`);
578
595
  }
579
596
  else if (constants_1.AesdkResponseTypes.Barcode in xmlResponse) {
580
- scanDataNotification = this.processBarcodeData(xmlResponse[constants_1.AesdkResponseTypes.Barcode]);
597
+ this.processBarcodeData(xmlResponse[constants_1.AesdkResponseTypes.Barcode]);
581
598
  }
582
599
  else {
583
- logger.warn(`In handleBarcodeDataReceived, unexpected root element received, ignoring xml: ${xml}`);
600
+ logger.warn(`In handleBarcodeInformationEvent, unexpected root element received, ignoring xml: ${xmlBarcodeInfo}`);
584
601
  }
585
602
  }
586
- if (scanDataNotification) {
587
- this._scannerEmitter.emit(_1.EventResponseTypes.Scan, scanDataNotification);
588
- }
589
- return logger.traceExit(entryMessage, scanDataNotification);
603
+ logger.traceExit(entryMessage);
590
604
  }
591
605
  processBarcodeData(barcode) {
592
606
  const entryMessage = logger.traceEntry("processBarcodeData", barcode);
593
- return logger.traceExit(entryMessage, {
607
+ const scanDataNotification = {
594
608
  data: barcode.Barcode.value,
595
609
  encoding: sdk_interface_1.AurusSupport.getBarcodeType(barcode.BarcodeType.value)
596
- });
610
+ };
611
+ logger.debug(`In processBarcodeData, publishing scanDataNotification: ${JSON.stringify(scanDataNotification)}`);
612
+ this._scannerEmitter.emit(_1.EventResponseTypes.Scan, scanDataNotification);
613
+ logger.traceExit(entryMessage);
597
614
  }
598
- /**
599
- * This method handles events published by the native components. This is an adapter between the native and JavaScript
600
- * components for asynchronous events from the native layer.
601
- *
602
- * @param args
603
- * @return {any}
604
- */
605
- onNotificationReceived(...args) {
606
- const entryMessage = logger.traceEntry("onNotificationReceived", args);
607
- if (args.length >= 1 && args[0]) {
608
- const notificationUserInfo = args[0];
609
- logger.debug(`In onNotificationReceived, notificationUserInfo: ${JSON.stringify(notificationUserInfo)}`);
610
- switch (notificationUserInfo.CODE) {
611
- // TODO: Determine if we want to use any the commented out events. (Status messages, logging, etc.)
612
- // case NotificationEvent.ProcessingRequest: {
613
- // break;
614
- // }
615
- // case NotificationEvent.SwipeOrInsertOrTap: {
616
- // break;
617
- // }
618
- // case NotificationEvent.EnterManualCardEntry: {
619
- // break;
620
- // }
621
- // case NotificationEvent.Processing: {
622
- // break;
623
- // }
624
- // case NotificationEvent.CardAuthorization: {
625
- // break;
626
- // }
627
- // case NotificationEvent.EnterPIN: {
628
- // break;
629
- // }
630
- // case NotificationEvent.EnterZIP: {
631
- // break;
632
- // }
633
- // case NotificationEvent.EnterSSN: {
634
- // break;
635
- // }
636
- // case NotificationEvent.EnterSIN: {
637
- // break;
638
- // }
639
- // case NotificationEvent.EnterAnnualDebitIncome: {
640
- // break;
641
- // }
642
- // case NotificationEvent.EnterMonthlyDebitIncome: {
643
- // break;
644
- // }
645
- // case NotificationEvent.EnterPhoneNumber: {
646
- // break;
647
- // }
648
- // case NotificationEvent.EnterPasscode: {
649
- // break;
650
- // }
651
- // case NotificationEvent.EnterExpiryDate: {
652
- // break;
653
- // }
654
- // case NotificationEvent.EnterCVV: {
655
- // break;
656
- // }
657
- // case NotificationEvent.EnterTIP: {
658
- // break;
659
- // }
660
- // case NotificationEvent.Confirmation: {
661
- // break;
662
- // }
663
- // case NotificationEvent.ProcessingTransaction: {
664
- // break;
665
- // }
666
- case NotificationEvent.BarcodeInformation: {
667
- //await this.handleBarcodeDataReceived(notificationUserInfo.AE_BARCODE_INFO);
668
- this.handleBarcodeDataReceived(notificationUserInfo.AE_BARCODE_INFO);
669
- break;
670
- }
671
- // case NotificationEvent.DeviceNotConnected: {
672
- // break;
673
- // }
674
- // case NotificationEvent.DeviceConnecting: {
675
- // break;
676
- // }
677
- // case NotificationEvent.DeviceConnected: {
678
- // break;
679
- // }
680
- case NotificationEvent.DeviceConfigurationStarted: {
681
- this._initInProgress = true;
682
- break;
683
- }
684
- case NotificationEvent.DeviceConfigurationCompleted: {
685
- this._initInProgress = false;
686
- this.sendAESDKRegistration(sdk_interface_1.AurusSupport.authRequest);
687
- break;
688
- }
689
- case NotificationEvent.DeviceConfigurationFailed: {
690
- logger.debug("In onNotificationReceived, DeviceConfigurationFailed");
691
- this._initInProgress = false;
692
- break;
693
- }
694
- case NotificationEvent.DeviceAlreadyConfigured: {
695
- this.sendAESDKRegistration(sdk_interface_1.AurusSupport.authRequest);
696
- break;
697
- }
698
- // case NotificationEvent.FileDownloading: {
699
- // break;
700
- // }
701
- // case NotificationEvent.FileDownloadFailed: {
702
- // break;
703
- // }
704
- // case NotificationEvent.FileDownloadRetrying: {
705
- // break;
706
- // }
707
- // case NotificationEvent.FileUpgradingToPED: {
708
- // break;
709
- // }
710
- // case NotificationEvent.FileUpgradingToPEDFailed: {
711
- // break;
712
- // }
713
- // case NotificationEvent.FileUpgradingToPEDCompleted: {
714
- // break;
715
- // }
716
- // case NotificationEvent.FileTransferToPEDInfo: {
717
- // break;
718
- // }
719
- // case NotificationEvent.FileTransferToPEDProgress: {
720
- // break;
721
- // }
722
- // case NotificationEvent.None: {
723
- // break;
724
- // }
725
- default: {
726
- // logger.debug(`notificationUserInfo.CODE not handled: ${notificationUserInfo.CODE}`);
727
- break;
728
- }
729
- }
615
+ handleDeviceNotConnectedEvent() {
616
+ const entryMessage = logger.traceEntry("handleDeviceNotConnectedEvent");
617
+ this.emitPaymentStatus(false, _1.StatusCode.DeviceDisconnected);
618
+ logger.traceExit(entryMessage);
619
+ }
620
+ handleDeviceConnectedEvent() {
621
+ const entryMessage = logger.traceEntry("handleDeviceConnectedEvent");
622
+ if (this._waitingForDeviceConnected) {
623
+ this._waitingForDeviceConnected = false;
624
+ this.sendAESDKRegistration(sdk_interface_1.AurusSupport.authRequest);
730
625
  }
731
626
  else {
732
- throw logger.throwing(new Error("Empty event received. notificationUserInfo data is missing"), entryMessage);
627
+ this.emitPaymentStatus(true, _1.StatusCode.DeviceReconnected);
628
+ //enable/disable scanner
629
+ this._scannerEnabled ? this.enableScannerDevice() : this.disableScannerDevice();
733
630
  }
734
631
  logger.traceExit(entryMessage);
735
632
  }
633
+ handleDeviceConfigurationStartedEvent() {
634
+ const entryMessage = logger.traceEntry("handleDeviceConfigurationStartedEvent");
635
+ logger.traceExit(entryMessage);
636
+ }
637
+ handleDeviceConfigurationCompletedEvent() {
638
+ const entryMessage = logger.traceEntry("handleDeviceConfigurationCompletedEvent");
639
+ logger.traceExit(entryMessage);
640
+ }
641
+ handleDeviceConfigurationFailedEvent() {
642
+ const entryMessage = logger.traceEntry("handleDeviceConfigurationFailedEvent");
643
+ logger.traceExit(entryMessage);
644
+ }
645
+ handleDeviceAlreadyConfiguredEvent() {
646
+ const entryMessage = logger.traceEntry("handleDeviceAlreadyConfiguredEvent");
647
+ logger.traceExit(entryMessage);
648
+ }
649
+ handleDefaultEvent(userInfoCode) {
650
+ // Should we log this? If we do, we should convert the userInfoCode into readable text.
651
+ }
652
+ emitPaymentStatus(deviceAvailable, statusCode) {
653
+ const entryMessage = logger.traceEntry("emitPaymentStatus");
654
+ sdk_interface_1.AurusSupport.paymentStatus.deviceAvailable = deviceAvailable;
655
+ sdk_interface_1.AurusSupport.paymentStatus.statusCode = statusCode;
656
+ logger.debug(`In emitPaymentStatus, publishing paymentStatus: ${JSON.stringify(sdk_interface_1.AurusSupport.paymentStatus)}`);
657
+ this._paymentEmitter.emit(_1.EventResponseTypes.PaymentDeviceStatus, sdk_interface_1.AurusSupport.paymentStatus);
658
+ sdk_interface_1.AurusSupport.paymentStatus = { deviceAvailable: false };
659
+ logger.traceExit(entryMessage);
660
+ }
661
+ emitAuthorizationResponse(responseCode, status) {
662
+ const entryMessage = logger.traceEntry("emitAuthorizationResponse");
663
+ sdk_interface_1.AurusSupport.authResponse.responseCode = responseCode;
664
+ sdk_interface_1.AurusSupport.authResponse.status = status;
665
+ logger.debug(`In emitAuthorizationResponse, publishing authResponse: ${JSON.stringify(sdk_interface_1.AurusSupport.authResponse)}`);
666
+ this._paymentEmitter.emit(_1.EventResponseTypes.Authorization, sdk_interface_1.AurusSupport.authResponse);
667
+ logger.traceExit(entryMessage);
668
+ }
736
669
  onAESDKLogResponse(...args) {
737
670
  if (args.length >= 1 && args[0]) {
738
671
  logger.debug(`onAESDKLogResponse: ${args[0]}`);
739
672
  }
740
673
  }
674
+ sendRequest(xmlRequest) {
675
+ logger.debug(`sendRequest: _requestInProgress = ${this._requestInProgress}`);
676
+ if (this._requestInProgress) {
677
+ // Note: This is being used to maintain order for rapid requests.
678
+ // It safeguards against enable/disable scanner from POS at the same time as other requests.
679
+ // If additional use cases are added, this should be revisted as well to maintain additional data.
680
+ this._requestQueue.push(xmlRequest);
681
+ }
682
+ else {
683
+ this._requestInProgress = true;
684
+ this._devicePaymentTerminal.OnAESDKProcessRequest(xmlRequest);
685
+ }
686
+ }
741
687
  };
742
688
  AurusDevice = __decorate([
743
689
  inversify_1.injectable(),