gap-nodejs-sdk 1.0.134 → 1.0.136

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.
Files changed (35) hide show
  1. package/dist/clover/Clover.d.ts +2 -2
  2. package/dist/clover/Clover.d.ts.map +1 -1
  3. package/dist/clover/Clover.js +16 -13
  4. package/dist/clover/CloverPayment.d.ts +19 -0
  5. package/dist/clover/CloverPayment.d.ts.map +1 -0
  6. package/dist/clover/CloverPayment.js +72 -0
  7. package/dist/clover/CloverPaymentObject.d.ts +68 -0
  8. package/dist/clover/CloverPaymentObject.d.ts.map +1 -0
  9. package/dist/clover/CloverPaymentObject.js +505 -0
  10. package/dist/clover/clover_payment_response_model.d.ts +6 -0
  11. package/dist/clover/clover_payment_response_model.d.ts.map +1 -0
  12. package/dist/clover/clover_payment_response_model.js +72 -0
  13. package/dist/clover/enums.d.ts +11 -0
  14. package/dist/clover/enums.d.ts.map +1 -0
  15. package/dist/clover/enums.js +11 -0
  16. package/dist/clover/payment_response_model.d.ts +3 -11
  17. package/dist/clover/payment_response_model.d.ts.map +1 -1
  18. package/dist/clover/payment_response_model.js +1 -73
  19. package/dist/executor/callback.d.ts +6 -0
  20. package/dist/executor/callback.d.ts.map +1 -0
  21. package/dist/executor/callback.js +1 -0
  22. package/dist/executor/executor_helper.d.ts +13 -0
  23. package/dist/executor/executor_helper.d.ts.map +1 -0
  24. package/dist/executor/executor_helper.js +41 -0
  25. package/dist/gap-sdk.js +1 -1
  26. package/dist/index.d.ts +4 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +4 -1
  29. package/dist/payment/payment_interface.d.ts +18 -0
  30. package/dist/payment/payment_interface.d.ts.map +1 -0
  31. package/dist/payment/payment_interface.js +1 -0
  32. package/dist/payment/type.d.ts +9 -0
  33. package/dist/payment/type.d.ts.map +1 -0
  34. package/dist/payment/type.js +5 -0
  35. package/package.json +1 -1
@@ -0,0 +1,505 @@
1
+ import * as clover from "@xuantan97/remote-pay-cloud";
2
+ import { ExecutorHelper } from "../executor/executor_helper";
3
+ import { CloverPaymentResponseModel } from "./clover_payment_response_model";
4
+ export { clover };
5
+ export default class CloverPaymentObject {
6
+ constructor({ cloverConfig, onPairingCode, onPairingSuccess }) {
7
+ this.cloverConnector = null;
8
+ // Stores active/open SaleRequests, we should NOT allow our POS to perform a new SaleRequest until we have received
9
+ // a SaleResponse for any open requests. For a production POS system this should be persisted so that it can survive
10
+ // across page refreshes, etc.
11
+ this.pendingSaleRequest = null;
12
+ this.isReady = false;
13
+ this.deviceError = null;
14
+ this.deviceDisconnected = true;
15
+ this.saleResponse = null;
16
+ this.authResponse = null;
17
+ this.tipAdjustAuthResponse = null;
18
+ this.voidPaymentResponse = null;
19
+ this.refundPaymentResponse = null;
20
+ this.closeoutResponse = null;
21
+ this.retrievePaymentResponse = null;
22
+ this.retrievePendingPaymentsResponse = null;
23
+ this.retrieveDeviceStatusResponse = null;
24
+ this.paymentResponse = null;
25
+ this.currentCallback = null;
26
+ this.cloverConfig = cloverConfig;
27
+ this.onPairingCode = onPairingCode;
28
+ this.onPairingSuccess = onPairingSuccess;
29
+ }
30
+ static createInstance(options) {
31
+ if (options) {
32
+ var object = new CloverPaymentObject(options);
33
+ return object;
34
+ }
35
+ throw new Error("Missing 'options' parameters");
36
+ }
37
+ static getInstance(options) {
38
+ var _a;
39
+ if (!CloverPaymentObject.instance) {
40
+ CloverPaymentObject.instance = CloverPaymentObject.createInstance(options);
41
+ }
42
+ else if (options) {
43
+ if (options.createNew == true) {
44
+ (_a = CloverPaymentObject.instance.cloverConnector) === null || _a === void 0 ? void 0 : _a.dispose();
45
+ CloverPaymentObject.instance = CloverPaymentObject.createInstance(options);
46
+ return CloverPaymentObject.instance;
47
+ }
48
+ else {
49
+ throw Error('Instance is already instantiate with `options`');
50
+ }
51
+ }
52
+ return CloverPaymentObject.instance;
53
+ }
54
+ connect() {
55
+ this.cleanup();
56
+ let cloverDeviceConnectionConfiguration;
57
+ cloverDeviceConnectionConfiguration = this.getDeviceConfigurationForNetwork();
58
+ let builderConfiguration = {};
59
+ builderConfiguration[clover.CloverConnectorFactoryBuilder.FACTORY_VERSION] = clover.CloverConnectorFactoryBuilder.VERSION_12;
60
+ let cloverConnectorFactory = clover.CloverConnectorFactoryBuilder.createICloverConnectorFactory(builderConfiguration);
61
+ this.cloverConnector = cloverConnectorFactory.createICloverConnector(cloverDeviceConnectionConfiguration);
62
+ this.cloverConnector.addCloverConnectorListener(this.buildCloverConnectionListener());
63
+ this.cloverConnector.initializeConnection();
64
+ }
65
+ doSale(paymentInput, callback) {
66
+ var _a;
67
+ this.saleResponse = null;
68
+ this.paymentResponse = null;
69
+ if (!this.pendingSaleRequest) {
70
+ this.pendingSaleRequest = new clover.remotepay.SaleRequest();
71
+ this.pendingSaleRequest.setExternalId(paymentInput.refId);
72
+ this.pendingSaleRequest.setAmount(paymentInput.amount);
73
+ this.pendingSaleRequest.setAutoAcceptSignature(true);
74
+ this.pendingSaleRequest.setApproveOfflinePaymentWithoutPrompt(true);
75
+ this.pendingSaleRequest.setDisableDuplicateChecking(true);
76
+ this.pendingSaleRequest.setCardEntryMethods(clover.CardEntryMethods.ALL);
77
+ this.currentCallback = callback;
78
+ console.log({ message: "Sending sale", request: this.pendingSaleRequest });
79
+ console.log(`Payment: ${this.pendingSaleRequest.getExternalId()} for $${this.pendingSaleRequest.getAmount() / 100} is in progress.`);
80
+ // Send the sale to the device.
81
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.sale(this.pendingSaleRequest);
82
+ }
83
+ else {
84
+ this.checkPaymentStatus();
85
+ }
86
+ }
87
+ doAuth(paymentInput, callback) {
88
+ var _a;
89
+ this.authResponse = null;
90
+ this.paymentResponse = null;
91
+ this.currentCallback = callback;
92
+ if (!this.pendingSaleRequest) {
93
+ this.pendingSaleRequest = new clover.remotepay.AuthRequest();
94
+ this.pendingSaleRequest.setExternalId(paymentInput.refId);
95
+ this.pendingSaleRequest.setAmount(paymentInput.amount);
96
+ this.pendingSaleRequest.setAutoAcceptSignature(true);
97
+ this.pendingSaleRequest.setApproveOfflinePaymentWithoutPrompt(true);
98
+ this.pendingSaleRequest.setDisableDuplicateChecking(true);
99
+ this.pendingSaleRequest.setCardEntryMethods(clover.CardEntryMethods.ALL);
100
+ console.log({ message: "Sending auth", request: this.pendingSaleRequest });
101
+ console.log(`Payment: ${this.pendingSaleRequest.getExternalId()} for $${this.pendingSaleRequest.getAmount() / 100} is in progress.`);
102
+ // Send the auth to the device.
103
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.auth(this.pendingSaleRequest);
104
+ }
105
+ else {
106
+ this.checkPaymentStatus();
107
+ }
108
+ }
109
+ doTipAdjust(adjustInput, callback) {
110
+ var _a;
111
+ this.tipAdjustAuthResponse = null;
112
+ this.paymentResponse = null;
113
+ this.currentCallback = callback;
114
+ if (!this.pendingSaleRequest) {
115
+ this.pendingSaleRequest = new clover.remotepay.TipAdjustAuthRequest();
116
+ this.pendingSaleRequest.setOrderId(adjustInput.orderId);
117
+ this.pendingSaleRequest.setTipAmount(adjustInput.amount);
118
+ this.pendingSaleRequest.setPaymentId(adjustInput.paymentId);
119
+ console.log({ message: "Sending tip adjust", request: this.pendingSaleRequest });
120
+ console.log(`Payment: ${this.pendingSaleRequest.getPaymentId()} for $${this.pendingSaleRequest.getTipAmount() / 100} is in progress.`);
121
+ // Send the tip adjust to the device.
122
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.tipAdjustAuth(this.pendingSaleRequest);
123
+ }
124
+ else {
125
+ this.checkPaymentStatus();
126
+ }
127
+ }
128
+ doVoid(voidInput, callback) {
129
+ var _a;
130
+ this.voidPaymentResponse = null;
131
+ this.paymentResponse = null;
132
+ this.currentCallback = callback;
133
+ if (!this.pendingSaleRequest) {
134
+ this.pendingSaleRequest = new clover.remotepay.VoidPaymentRequest();
135
+ this.pendingSaleRequest.setOrderId(voidInput.orderId);
136
+ this.pendingSaleRequest.setPaymentId(voidInput.paymentId);
137
+ this.pendingSaleRequest.setVoidReason(clover.order.VoidReason.USER_CANCEL);
138
+ console.log({ message: "Sending void", request: this.pendingSaleRequest });
139
+ console.log(`Payment: ${this.pendingSaleRequest.getPaymentId()} is in progress.`);
140
+ // Send the void to the device.
141
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.voidPayment(this.pendingSaleRequest);
142
+ }
143
+ else {
144
+ this.checkPaymentStatus();
145
+ }
146
+ }
147
+ doRefund(refundInput, callback) {
148
+ var _a;
149
+ this.refundPaymentResponse = null;
150
+ this.paymentResponse = null;
151
+ this.currentCallback = callback;
152
+ if (!this.pendingSaleRequest) {
153
+ this.pendingSaleRequest = new clover.remotepay.RefundPaymentRequest();
154
+ this.pendingSaleRequest.setOrderId(refundInput.orderId);
155
+ this.pendingSaleRequest.setAmount(refundInput.amount);
156
+ this.pendingSaleRequest.setPaymentId(refundInput.paymentId);
157
+ console.log({ message: "Sending refund", request: this.pendingSaleRequest });
158
+ console.log(`Payment: ${this.pendingSaleRequest.getPaymentId()} for $${this.pendingSaleRequest.getAmount() / 100} is in progress.`);
159
+ // Send the refund to the device.
160
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.refundPayment(this.pendingSaleRequest);
161
+ }
162
+ else {
163
+ this.checkPaymentStatus();
164
+ }
165
+ }
166
+ doRetrievePayment(retrieveInput, callback) {
167
+ var _a;
168
+ this.retrievePaymentResponse = null;
169
+ this.paymentResponse = null;
170
+ this.currentCallback = callback;
171
+ if (!this.pendingSaleRequest) {
172
+ this.pendingSaleRequest = new clover.remotepay.RetrievePaymentRequest();
173
+ this.pendingSaleRequest.setExternalId(retrieveInput.refId);
174
+ console.log({ message: "Sending retrieve", request: this.pendingSaleRequest });
175
+ console.log(`Payment: ${this.pendingSaleRequest.getExternalId()} is in progress.`);
176
+ // Send the retrieve to the device.
177
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.retrievePayment(this.pendingSaleRequest);
178
+ }
179
+ else {
180
+ this.checkPaymentStatus();
181
+ }
182
+ }
183
+ doRetrievePendingPayment() {
184
+ var _a;
185
+ this.retrievePendingPaymentsResponse = null;
186
+ this.paymentResponse = null;
187
+ if (!this.pendingSaleRequest) {
188
+ console.log({ message: "Sending retrieve pending payments" });
189
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.retrievePendingPayments();
190
+ }
191
+ else {
192
+ this.checkPaymentStatus();
193
+ }
194
+ }
195
+ doCloseout(callback) {
196
+ var _a;
197
+ this.closeoutResponse = null;
198
+ this.paymentResponse = null;
199
+ this.currentCallback = callback;
200
+ if (!this.pendingSaleRequest) {
201
+ this.pendingSaleRequest = new clover.remotepay.CloseoutRequest();
202
+ this.pendingSaleRequest.setAllowOpenTabs(false);
203
+ console.log({ message: "Sending closeout", request: this.pendingSaleRequest });
204
+ console.log(`Payment: closeout is in progress.`);
205
+ // Send the retrieve to the device.
206
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.closeout(this.pendingSaleRequest);
207
+ }
208
+ else {
209
+ this.checkPaymentStatus();
210
+ }
211
+ }
212
+ doPrint(printRequest) {
213
+ var _a;
214
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.print(printRequest);
215
+ }
216
+ cleanup() {
217
+ if (this.cloverConnector) {
218
+ this.cloverConnector.dispose();
219
+ }
220
+ }
221
+ showMessage(message) {
222
+ var _a;
223
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.showMessage(message);
224
+ }
225
+ checkDeviceStatus() {
226
+ var _a;
227
+ this.retrieveDeviceStatusResponse = null;
228
+ let retrieveDeviceStatus = new clover.remotepay.RetrieveDeviceStatusRequest();
229
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.retrieveDeviceStatus(retrieveDeviceStatus);
230
+ }
231
+ showWelcomeScreen() {
232
+ var _a;
233
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.showWelcomeScreen();
234
+ }
235
+ showThankYouScreen() {
236
+ var _a;
237
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.showThankYouScreen();
238
+ }
239
+ buildCloverConnectionListener() {
240
+ return Object.assign({}, clover.remotepay.ICloverConnectorListener.prototype, {
241
+ onDeviceConnected: () => {
242
+ this.deviceDisconnected = false;
243
+ },
244
+ onSaleResponse: (response) => {
245
+ var _a;
246
+ console.log({ message: "Payment response received", response: response });
247
+ const requestAmount = this.pendingSaleRequest.getAmount();
248
+ const requestExternalId = this.pendingSaleRequest.getExternalId();
249
+ this.pendingSaleRequest = null; // The sale is complete
250
+ this.saleResponse = response;
251
+ this.paymentResponse = CloverPaymentResponseModel.build(response);
252
+ this.handleSuccessCallback(this.paymentResponse);
253
+ if (response.getSuccess()) {
254
+ const payment = response.getPayment();
255
+ // We are choosing to void the payment if it was not authorized for the full amount.
256
+ if (payment && payment.getAmount() < requestAmount) {
257
+ const voidPaymentRequest = new clover.remotepay.VoidPaymentRequest();
258
+ voidPaymentRequest.setPaymentId(payment.getId());
259
+ voidPaymentRequest.setVoidReason(clover.order.VoidReason.REJECT_PARTIAL_AUTH);
260
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.voidPayment(voidPaymentRequest);
261
+ }
262
+ else {
263
+ console.log(`${payment.getResult()}: Payment ${payment.getExternalPaymentId()} for $${payment.getAmount() / 100} is complete.`, response.getResult() === clover.remotepay.ResponseCode.SUCCESS);
264
+ if (!response.getIsSale()) {
265
+ console.log({ error: "Response is not a sale!" });
266
+ }
267
+ }
268
+ }
269
+ else {
270
+ this.resetDevice(); // The device may be stuck.
271
+ }
272
+ },
273
+ onAuthResponse: (response) => {
274
+ var _a, _b;
275
+ console.log({ message: "Payment response received", response: response });
276
+ const requestAmount = this.pendingSaleRequest.getAmount();
277
+ const requestExternalId = this.pendingSaleRequest.getExternalId();
278
+ this.pendingSaleRequest = null; // The sale is complete
279
+ this.authResponse = response;
280
+ this.paymentResponse = CloverPaymentResponseModel.build(response);
281
+ this.handleSuccessCallback(this.paymentResponse);
282
+ if (response.getSuccess()) {
283
+ const payment = response.getPayment();
284
+ //auto tip = 0 on auth
285
+ const autoTipAdjustRequest = new clover.remotepay.TipAdjustAuthRequest();
286
+ autoTipAdjustRequest.setTipAmount(0);
287
+ autoTipAdjustRequest.setOrderId(payment.getOrder().getId());
288
+ autoTipAdjustRequest.setPaymentId(payment.getId());
289
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.tipAdjustAuth(autoTipAdjustRequest);
290
+ // We are choosing to void the payment if it was not authorized for the full amount.
291
+ if (payment && payment.getAmount() < requestAmount) {
292
+ const voidPaymentRequest = new clover.remotepay.VoidPaymentRequest();
293
+ voidPaymentRequest.setPaymentId(payment.getId());
294
+ voidPaymentRequest.setVoidReason(clover.order.VoidReason.REJECT_PARTIAL_AUTH);
295
+ (_b = this.cloverConnector) === null || _b === void 0 ? void 0 : _b.voidPayment(voidPaymentRequest);
296
+ }
297
+ else {
298
+ console.log(`${payment.getResult()}: Payment ${payment.getExternalPaymentId()} for $${payment.getAmount() / 100} is complete.`, response.getResult() === clover.remotepay.ResponseCode.SUCCESS);
299
+ if (!response.getIsAuth()) {
300
+ console.log({ error: "Response is not a auth!" });
301
+ }
302
+ }
303
+ }
304
+ else {
305
+ this.resetDevice(); // The device may be stuck.
306
+ }
307
+ },
308
+ onTipAdjustAuthResponse: (response) => {
309
+ console.log({ message: "Payment response received", response: response });
310
+ this.pendingSaleRequest = null; // The sale is complete
311
+ this.tipAdjustAuthResponse = response;
312
+ this.paymentResponse = CloverPaymentResponseModel.build(response);
313
+ this.handleSuccessCallback(this.paymentResponse);
314
+ if (response.getSuccess()) {
315
+ }
316
+ else {
317
+ this.resetDevice(); // The device may be stuck.
318
+ }
319
+ },
320
+ onVoidPaymentResponse: (response) => {
321
+ console.log({ message: "Payment response received", response: response });
322
+ this.pendingSaleRequest = null; // The sale is complete
323
+ this.voidPaymentResponse = response;
324
+ this.paymentResponse = CloverPaymentResponseModel.build(response);
325
+ this.handleSuccessCallback(this.paymentResponse);
326
+ if (response.getSuccess()) {
327
+ }
328
+ else {
329
+ this.resetDevice(); // The device may be stuck.
330
+ }
331
+ },
332
+ onRefundPaymentResponse: (response) => {
333
+ console.log({ message: "Payment response received", response: response });
334
+ this.pendingSaleRequest = null; // The sale is complete
335
+ this.refundPaymentResponse = response;
336
+ this.paymentResponse = CloverPaymentResponseModel.build(response);
337
+ this.handleSuccessCallback(this.paymentResponse);
338
+ if (response.getSuccess()) {
339
+ }
340
+ else {
341
+ this.resetDevice(); // The device may be stuck.
342
+ }
343
+ },
344
+ onCloseoutResponse: (response) => {
345
+ console.log({ message: "Payment response received", response: response });
346
+ this.pendingSaleRequest = null; // The sale is complete
347
+ this.closeoutResponse = response;
348
+ this.paymentResponse = CloverPaymentResponseModel.build(response);
349
+ this.handleSuccessCallback(this.paymentResponse);
350
+ if (response.getSuccess()) {
351
+ }
352
+ else {
353
+ this.resetDevice(); // The device may be stuck.
354
+ }
355
+ },
356
+ //clover.remotepay.ResultStatus.SUCCESS
357
+ onRetrievePaymentResponse: (retrievePaymentResponse) => {
358
+ console.log({ message: "onRetrievePaymentResponse", response: retrievePaymentResponse });
359
+ if (this.pendingSaleRequest) {
360
+ if (retrievePaymentResponse.getExternalPaymentId() === this.pendingSaleRequest.getExternalId()) {
361
+ if (retrievePaymentResponse.getQueryStatus() === clover.remotepay.QueryStatus.FOUND) {
362
+ // The payment's status can be used to resolve the payment in your POS.
363
+ const payment = retrievePaymentResponse.getPayment();
364
+ this.handleSuccessCallback(payment);
365
+ console.log(`${payment.getResult()}: Payment ${this.pendingSaleRequest.getExternalId()} is complete.`, payment.getResult() === clover.payments.Result.SUCCESS);
366
+ this.pendingSaleRequest = null; // The pending sale is complete.
367
+ }
368
+ else if (retrievePaymentResponse.getQueryStatus() === clover.remotepay.QueryStatus.IN_PROGRESS) {
369
+ // payment either not found or in progress,
370
+ let message = `Payment: ${this.pendingSaleRequest.getExternalId()} for $${this.pendingSaleRequest.getAmount() / 100} is in progress. If you would like to start a new payment, you may reset the device. However, doing so may void payment ${this.pendingSaleRequest.getExternalId()}.`;
371
+ this.handleErrorCallback(message);
372
+ console.log();
373
+ }
374
+ else if (retrievePaymentResponse.getQueryStatus() === clover.remotepay.QueryStatus.NOT_FOUND) {
375
+ let message = `Payment: ${this.pendingSaleRequest.getExternalId()} wasn't taken or was voided.`;
376
+ this.handleErrorCallback(message);
377
+ }
378
+ }
379
+ }
380
+ },
381
+ onResetDeviceResponse: (resetDeviceResponse) => {
382
+ var _a;
383
+ console.log(resetDeviceResponse);
384
+ this.handleSuccessCallback(true);
385
+ if (this.pendingSaleRequest) {
386
+ // Verify the payment status, the reset will generally void payments, but not in all cases.
387
+ const retrievePaymentRequest = new clover.remotepay.RetrievePaymentRequest();
388
+ retrievePaymentRequest.setExternalPaymentId(this.pendingSaleRequest.getExternalId());
389
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.retrievePayment(retrievePaymentRequest);
390
+ }
391
+ },
392
+ // See https://docs.clover.com/build/working-with-challenges/
393
+ onConfirmPaymentRequest: (request) => {
394
+ var _a;
395
+ console.log({ message: "Automatically accepting payment", request: request });
396
+ console.log("Automatically accepting payment", true);
397
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.acceptPayment(request.getPayment());
398
+ // to reject a payment, pass the payment and the challenge that was the basis for the rejection
399
+ // getCloverConnector().rejectPayment(request.getPayment(), request.getChallenges()[REJECTED_CHALLENGE_INDEX]);
400
+ },
401
+ // See https://docs.clover.com/build/working-with-challenges/
402
+ onVerifySignatureRequest: (request) => {
403
+ var _a;
404
+ console.log({ message: "Automatically accepting signature", request: request });
405
+ console.log("Automatically accepting signature", true);
406
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.acceptSignature(request);
407
+ // to reject a signature, pass the request to verify
408
+ // getCloverConnector().rejectSignature(request);
409
+ },
410
+ onDeviceReady: (merchantInfo) => {
411
+ var _a;
412
+ console.log("The connection to your Clover Device has been established.", true);
413
+ if (!this.pendingSaleRequest) {
414
+ console.log({ message: "Device Ready to process requests!", merchantInfo: merchantInfo });
415
+ this.isReady = true;
416
+ this.deviceError = null;
417
+ }
418
+ else {
419
+ // We have an unresolved sale. The connection to the device was lost and the customer is in the
420
+ // middle of or finished the payment with the POS disconnected. Calling retrieveDeviceStatus
421
+ // with setSendLastMessage will ask the Clover device to send us the last message it
422
+ // sent which may allow us to proceed with the payment.
423
+ const retrieveDeviceStatusRequest = new clover.remotepay.RetrieveDeviceStatusRequest();
424
+ retrieveDeviceStatusRequest.setSendLastMessage(true);
425
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.retrieveDeviceStatus(retrieveDeviceStatusRequest);
426
+ }
427
+ },
428
+ onDeviceError: (cloverDeviceErrorEvent) => {
429
+ this.deviceError = cloverDeviceErrorEvent;
430
+ },
431
+ onDeviceDisconnected: () => {
432
+ this.deviceDisconnected = true;
433
+ },
434
+ onRetrieveDeviceStatusResponse: (response) => {
435
+ this.retrieveDeviceStatusResponse = response;
436
+ }
437
+ });
438
+ }
439
+ resetDevice(callback) {
440
+ var _a;
441
+ if (callback) {
442
+ this.currentCallback = callback;
443
+ }
444
+ //force reset
445
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.resetDevice();
446
+ //check if pending payment before reset
447
+ // if (this.pendingSaleRequest) {
448
+ // this.checkPaymentStatus();
449
+ // } else {
450
+ // this.cloverConnector?.resetDevice();
451
+ // }
452
+ }
453
+ getDeviceConfigurationForNetwork() {
454
+ const onPairingCode = (pairingCode) => {
455
+ const pairingCodeMessage = `Please enter pairing code ${pairingCode} on the device`;
456
+ console.log(` > ${pairingCodeMessage}`);
457
+ };
458
+ const onPairingSuccess = (authTokenFromPairing) => {
459
+ console.log(` > Got Pairing Auth Token: ${authTokenFromPairing}`);
460
+ };
461
+ if (typeof this.pairingCode === 'undefined') {
462
+ this.pairingCode = onPairingCode;
463
+ }
464
+ if (typeof this.onPairingSuccess === 'undefined') {
465
+ this.pairingCode = onPairingSuccess;
466
+ }
467
+ const configBuilder = new clover.WebSocketPairedCloverDeviceConfigurationBuilder(this.cloverConfig.applicationId, this.cloverConfig.endpoint, this.cloverConfig.posName, this.cloverConfig.serialNumber, this.cloverConfig.authToken, this.onPairingCode, this.onPairingSuccess);
468
+ return configBuilder.build();
469
+ }
470
+ checkPaymentStatus() {
471
+ var _a, _b;
472
+ if (this.pendingSaleRequest) {
473
+ // If a message was lost etc. the retrieveDevice status request will ask the device to send the last message.
474
+ // This can help the POS recover if the device is stuck on a challenge screen, etc. The last message will
475
+ // be sent independently of the retrieveDeviceStatus response and thus the retrieveDeviceStatus response
476
+ // does not need to be checked.
477
+ const retrieveDeviceStatusRequest = new clover.remotepay.RetrieveDeviceStatusRequest();
478
+ retrieveDeviceStatusRequest.setSendLastMessage(true);
479
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.retrieveDeviceStatus(retrieveDeviceStatusRequest);
480
+ // Retrieve the payment status.
481
+ console.log(`Payment is currently pending. Checking payment status ...`);
482
+ console.log(this.pendingSaleRequest);
483
+ const retrievePaymentRequest = new clover.remotepay.RetrievePaymentRequest();
484
+ retrievePaymentRequest.setExternalPaymentId(this.pendingSaleRequest.getExternalId());
485
+ (_b = this.cloverConnector) === null || _b === void 0 ? void 0 : _b.retrievePayment(retrievePaymentRequest);
486
+ }
487
+ else {
488
+ console.log(`There is currently no pending payment.`);
489
+ }
490
+ }
491
+ handleSuccessCallback(response) {
492
+ var _a;
493
+ if (this.currentCallback) {
494
+ ExecutorHelper.getInstance().execSuccessCallback((_a = this.currentCallback) === null || _a === void 0 ? void 0 : _a.id, response);
495
+ this.currentCallback = null;
496
+ }
497
+ }
498
+ handleErrorCallback(error) {
499
+ var _a;
500
+ if (this.currentCallback) {
501
+ ExecutorHelper.getInstance().execErrorCallback((_a = this.currentCallback) === null || _a === void 0 ? void 0 : _a.id, error);
502
+ this.currentCallback = null;
503
+ }
504
+ }
505
+ }
@@ -0,0 +1,6 @@
1
+ import { clover } from "./Clover";
2
+ import { PaymentResponseModel } from "./payment_response_model";
3
+ export declare class CloverPaymentResponseModel extends PaymentResponseModel {
4
+ static build(data: clover.remotepay.SaleResponse | clover.remotepay.AuthResponse | clover.remotepay.TipAdjustAuthResponse | clover.remotepay.VoidPaymentResponse | clover.remotepay.RefundPaymentResponse | clover.remotepay.CloseoutResponse | clover.remotepay.RetrievePaymentResponse | clover.remotepay.RetrievePendingPaymentsResponse): PaymentResponseModel;
5
+ }
6
+ //# sourceMappingURL=clover_payment_response_model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clover_payment_response_model.d.ts","sourceRoot":"","sources":["../../src/clover/clover_payment_response_model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,qBAAa,0BAA2B,SAAQ,oBAAoB;IAChE,MAAM,CAAC,KAAK,CAAC,IAAI,EACb,MAAM,CAAC,SAAS,CAAC,YAAY,GAC3B,MAAM,CAAC,SAAS,CAAC,YAAY,GAC7B,MAAM,CAAC,SAAS,CAAC,qBAAqB,GACtC,MAAM,CAAC,SAAS,CAAC,mBAAmB,GACpC,MAAM,CAAC,SAAS,CAAC,qBAAqB,GACtC,MAAM,CAAC,SAAS,CAAC,gBAAgB,GACjC,MAAM,CAAC,SAAS,CAAC,uBAAuB,GACxC,MAAM,CAAC,SAAS,CAAC,+BAA+B;CAmEzD"}
@@ -0,0 +1,72 @@
1
+ import { clover } from "./Clover";
2
+ import { CloverAction } from "./enums";
3
+ import { PaymentResponseModel } from "./payment_response_model";
4
+ export class CloverPaymentResponseModel extends PaymentResponseModel {
5
+ static build(data) {
6
+ let paymentResponse = new PaymentResponseModel();
7
+ //Check status of reponse
8
+ if (data.getSuccess()) {
9
+ paymentResponse.status = PaymentResponseModel.STATUS_OK;
10
+ paymentResponse.statusCode = PaymentResponseModel.STATUS_CODE_OK;
11
+ }
12
+ else {
13
+ paymentResponse.status = PaymentResponseModel.STATUS_FAIL;
14
+ paymentResponse.statusCode = PaymentResponseModel.STATUS_CODE_FAIL;
15
+ }
16
+ paymentResponse.statusMessage = data.getMessage();
17
+ paymentResponse.data = data;
18
+ switch (true) {
19
+ case data instanceof clover.remotepay.SaleResponse:
20
+ data = data;
21
+ paymentResponse.action = CloverAction.ACTION_CLOVER_SALE_RESPONSE;
22
+ if (data.getPayment()) {
23
+ paymentResponse.refID = data.getPayment().getId();
24
+ paymentResponse.approveAmount = data.getPayment().getAmount();
25
+ }
26
+ break;
27
+ case data instanceof clover.remotepay.AuthResponse:
28
+ data = data;
29
+ paymentResponse.action = CloverAction.ACTION_CLOVER_AUTH_RESPONSE;
30
+ if (data.getPayment()) {
31
+ paymentResponse.refID = data.getPayment().getId();
32
+ paymentResponse.approveAmount = data.getPayment().getAmount();
33
+ }
34
+ break;
35
+ case data instanceof clover.remotepay.TipAdjustAuthResponse:
36
+ data = data;
37
+ paymentResponse.action = CloverAction.ACTION_CLOVER_ADJUST_RESPONSE;
38
+ paymentResponse.refID = data.getPaymentId();
39
+ break;
40
+ case data instanceof clover.remotepay.VoidPaymentResponse:
41
+ data = data;
42
+ paymentResponse.action = CloverAction.ACTION_CLOVER_VOID_RESPONSE;
43
+ if (data.getReason() == clover.order.VoidReason.REJECT_PARTIAL_AUTH) {
44
+ paymentResponse.action = CloverAction.ACTION_CLOVER_CANCEL_TRANSACTION_WITH_DUE_AMOUNT;
45
+ }
46
+ if (data.getPayment()) {
47
+ paymentResponse.refID = data.getPayment().getId();
48
+ }
49
+ break;
50
+ case data instanceof clover.remotepay.RefundPaymentResponse:
51
+ data = data;
52
+ paymentResponse.action = CloverAction.ACTION_CLOVER_RETURN_RESPONSE;
53
+ paymentResponse.refID = data.getPaymentId();
54
+ break;
55
+ case data instanceof clover.remotepay.CloseoutResponse:
56
+ data = data;
57
+ paymentResponse.action = CloverAction.ACTION_CLOVER_BATCH_CLOSE_RESPONSE;
58
+ break;
59
+ case data instanceof clover.remotepay.RetrievePaymentResponse:
60
+ data = data;
61
+ paymentResponse.action = CloverAction.ACTION_CLOVER_RETRIEVE_PAYMENT_RESPONSE;
62
+ if (data.getPayment()) {
63
+ paymentResponse.refID = data.getPayment().getId();
64
+ }
65
+ break;
66
+ case data instanceof clover.remotepay.RetrievePendingPaymentsResponse:
67
+ data = data;
68
+ break;
69
+ }
70
+ return paymentResponse;
71
+ }
72
+ }
@@ -0,0 +1,11 @@
1
+ export declare enum CloverAction {
2
+ ACTION_CLOVER_AUTH_RESPONSE = "CLOVER_AUTH_RESPONSE",
3
+ ACTION_CLOVER_ADJUST_RESPONSE = "CLOVER_ADJUST_RESPONSE",
4
+ ACTION_CLOVER_SALE_RESPONSE = "CLOVER_SALE_RESPONSE",
5
+ ACTION_CLOVER_VOID_RESPONSE = "CLOVER_VOID_RESPONSE",
6
+ ACTION_CLOVER_BATCH_CLOSE_RESPONSE = "CLOVER_BATCH_CLOSE_RESPONSE",
7
+ ACTION_CLOVER_RETURN_RESPONSE = "CLOVER_RETURN_RESPONSE",
8
+ ACTION_CLOVER_CANCEL_TRANSACTION_WITH_DUE_AMOUNT = "CLOVER_CANCEL_TRANSACTION_WITH_DUE_AMOUNT",
9
+ ACTION_CLOVER_RETRIEVE_PAYMENT_RESPONSE = "CLOVER_RETRIEVE_PAYMENT_RESPONSE"
10
+ }
11
+ //# sourceMappingURL=enums.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../src/clover/enums.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY;IACpB,2BAA2B,yBAAyB;IACpD,6BAA6B,2BAA2B;IACxD,2BAA2B,yBAAyB;IACpD,2BAA2B,yBAAyB;IACpD,kCAAkC,gCAAgC;IAClE,6BAA6B,2BAA2B;IACxD,gDAAgD,8CAA8C;IAC9F,uCAAuC,qCAAqC;CAC/E"}
@@ -0,0 +1,11 @@
1
+ export var CloverAction;
2
+ (function (CloverAction) {
3
+ CloverAction["ACTION_CLOVER_AUTH_RESPONSE"] = "CLOVER_AUTH_RESPONSE";
4
+ CloverAction["ACTION_CLOVER_ADJUST_RESPONSE"] = "CLOVER_ADJUST_RESPONSE";
5
+ CloverAction["ACTION_CLOVER_SALE_RESPONSE"] = "CLOVER_SALE_RESPONSE";
6
+ CloverAction["ACTION_CLOVER_VOID_RESPONSE"] = "CLOVER_VOID_RESPONSE";
7
+ CloverAction["ACTION_CLOVER_BATCH_CLOSE_RESPONSE"] = "CLOVER_BATCH_CLOSE_RESPONSE";
8
+ CloverAction["ACTION_CLOVER_RETURN_RESPONSE"] = "CLOVER_RETURN_RESPONSE";
9
+ CloverAction["ACTION_CLOVER_CANCEL_TRANSACTION_WITH_DUE_AMOUNT"] = "CLOVER_CANCEL_TRANSACTION_WITH_DUE_AMOUNT";
10
+ CloverAction["ACTION_CLOVER_RETRIEVE_PAYMENT_RESPONSE"] = "CLOVER_RETRIEVE_PAYMENT_RESPONSE";
11
+ })(CloverAction || (CloverAction = {}));
@@ -1,4 +1,4 @@
1
- import * as clover from "@xuantan97/remote-pay-cloud";
1
+ import { CloverAction } from "./enums";
2
2
  export declare class PaymentResponseModel {
3
3
  static STATUS_OK: string;
4
4
  static STATUS_FAIL: string;
@@ -6,22 +6,14 @@ export declare class PaymentResponseModel {
6
6
  static STATUS_CODE_FAIL: string;
7
7
  static STATUS_CODE_WARNING: string;
8
8
  static STATUS_CODE_TIMEOUT: string;
9
- static ACTION_CLOVER_AUTH_RESPONSE: string;
10
- static ACTION_CLOVER_ADJUST_RESPONSE: string;
11
- static ACTION_CLOVER_SALE_RESPONSE: string;
12
- static ACTION_CLOVER_VOID_RESPONSE: string;
13
- static ACTION_CLOVER_BATCH_CLOSE_RESPONSE: string;
14
- static ACTION_CLOVER_RETURN_RESPONSE: string;
15
- static ACTION_CLOVER_CANCEL_TRANSACTION_WITH_DUE_AMOUNT: string;
16
- static ACTION_CLOVER_RETRIEVE_PAYMENT_RESPONSE: string;
17
9
  status: string | null;
18
10
  statusCode: string | null;
19
11
  statusMessage: string | null;
20
12
  data: any;
21
13
  refID: string | null;
22
- action: string | null;
14
+ action: CloverAction | string | null;
23
15
  approveAmount: number | null;
24
16
  amountDue: number | null;
25
- static build(data: clover.remotepay.SaleResponse | clover.remotepay.AuthResponse | clover.remotepay.TipAdjustAuthResponse | clover.remotepay.VoidPaymentResponse | clover.remotepay.RefundPaymentResponse | clover.remotepay.CloseoutResponse | clover.remotepay.RetrievePaymentResponse | clover.remotepay.RetrievePendingPaymentsResponse): PaymentResponseModel;
17
+ static build(_data: any): PaymentResponseModel;
26
18
  }
27
19
  //# sourceMappingURL=payment_response_model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"payment_response_model.d.ts","sourceRoot":"","sources":["../../src/clover/payment_response_model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AAEtD,qBAAa,oBAAoB;IAC7B,MAAM,CAAC,SAAS,SAAQ;IACxB,MAAM,CAAC,WAAW,SAAU;IAE5B,MAAM,CAAC,cAAc,SAAQ;IAC7B,MAAM,CAAC,gBAAgB,SAAU;IACjC,MAAM,CAAC,mBAAmB,SAAa;IACvC,MAAM,CAAC,mBAAmB,SAAa;IAEvC,MAAM,CAAC,2BAA2B,SAA0B;IAC5D,MAAM,CAAC,6BAA6B,SAA4B;IAChE,MAAM,CAAC,2BAA2B,SAA0B;IAC5D,MAAM,CAAC,2BAA2B,SAA0B;IAC5D,MAAM,CAAC,kCAAkC,SAAiC;IAC1E,MAAM,CAAC,6BAA6B,SAA4B;IAChE,MAAM,CAAC,gDAAgD,SAA+C;IACtG,MAAM,CAAC,uCAAuC,SAAsC;IAGpF,MAAM,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC7B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAQ;IACjC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAQ;IACpC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC5B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC7B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAQ;IACpC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAQ;IAEhC,MAAM,CAAC,KAAK,CAAC,IAAI,EACb,MAAM,CAAC,SAAS,CAAC,YAAY,GAC3B,MAAM,CAAC,SAAS,CAAC,YAAY,GAC7B,MAAM,CAAC,SAAS,CAAC,qBAAqB,GACtC,MAAM,CAAC,SAAS,CAAC,mBAAmB,GACpC,MAAM,CAAC,SAAS,CAAC,qBAAqB,GACtC,MAAM,CAAC,SAAS,CAAC,gBAAgB,GACjC,MAAM,CAAC,SAAS,CAAC,uBAAuB,GACxC,MAAM,CAAC,SAAS,CAAC,+BAA+B;CAmEzD"}
1
+ {"version":3,"file":"payment_response_model.d.ts","sourceRoot":"","sources":["../../src/clover/payment_response_model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,qBAAa,oBAAoB;IAC7B,MAAM,CAAC,SAAS,SAAQ;IACxB,MAAM,CAAC,WAAW,SAAU;IAE5B,MAAM,CAAC,cAAc,SAAQ;IAC7B,MAAM,CAAC,gBAAgB,SAAU;IACjC,MAAM,CAAC,mBAAmB,SAAa;IACvC,MAAM,CAAC,mBAAmB,SAAa;IAIvC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC7B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAQ;IACjC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAQ;IACpC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC5B,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CAAQ;IAC5C,aAAa,EAAE,MAAM,GAAG,IAAI,CAAQ;IACpC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAQ;IAEhC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG;CAI1B"}