gap-nodejs-sdk 1.0.64 → 1.0.67

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.
@@ -0,0 +1,53 @@
1
+ import * as clover from "@xuantan97/remote-pay-cloud";
2
+ import { AdjustInput, PaymentInput, RefundInput, RetrieveInput, VoidInput } from "./types";
3
+ export default class Clover {
4
+ static instance: Clover | null;
5
+ cloverConnector: clover.remotepay.ICloverConnector | null;
6
+ pairingCode: any;
7
+ authToken: string;
8
+ pendingSaleRequest: any;
9
+ cloverConfig: any;
10
+ cloverConnectionListener: clover.remotepay.ICloverConnectorListener;
11
+ isReady: boolean;
12
+ onPairingCode: (pairingCode: string) => void;
13
+ onPairingSuccess: (authToken: string) => void;
14
+ saleResponse: clover.remotepay.SaleResponse | null;
15
+ authResponse: clover.remotepay.AuthResponse | null;
16
+ tipAdjustAuthResponse: clover.remotepay.TipAdjustAuthResponse | null;
17
+ voidPaymentResponse: clover.remotepay.VoidPaymentResponse | null;
18
+ refundPaymentResponse: clover.remotepay.RefundPaymentResponse | null;
19
+ closeoutResponse: clover.remotepay.CloseoutResponse | null;
20
+ retrievePaymentResponse: clover.remotepay.RetrievePaymentResponse | null;
21
+ retrievePendingPaymentsResponse: clover.remotepay.RetrievePendingPaymentsResponse | null;
22
+ constructor({ cloverConfig, onPairingCode, onPairingSuccess }: {
23
+ cloverConfig: any;
24
+ onPairingCode: (pairingCode: string) => void;
25
+ onPairingSuccess: (authToken: string) => void;
26
+ });
27
+ static createInstance(options?: {
28
+ cloverConfig: any;
29
+ onPairingCode: (pairingCode: string) => void;
30
+ onPairingSuccess: (authToken: string) => void;
31
+ }): Clover;
32
+ static getInstance(options?: {
33
+ cloverConfig: any;
34
+ onPairingCode: (pairingCode: string) => void;
35
+ onPairingSuccess: (authToken: string) => void;
36
+ }): Clover;
37
+ connect(): void;
38
+ doSale(paymentInput: PaymentInput): void;
39
+ doAuth(paymentInput: PaymentInput): void;
40
+ doTipAdjust(adjustInput: AdjustInput): void;
41
+ doVoid(voidInput: VoidInput): void;
42
+ doRefund(refundInput: RefundInput): void;
43
+ doRetrievePayment(retrieveInput: RetrieveInput): void;
44
+ doRetrievePendingPayment(): void;
45
+ doCloseout(): void;
46
+ cleanup(): void;
47
+ showMessage(message: any): void;
48
+ private buildCloverConnectionListener;
49
+ private getDeviceConfigurationForNetwork;
50
+ private resetDevice;
51
+ private checkPaymentStatus;
52
+ }
53
+ //# sourceMappingURL=Clover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Clover.d.ts","sourceRoot":"","sources":["../../src/clover/Clover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE3F,MAAM,CAAC,OAAO,OAAO,MAAM;IACvB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC,SAAS,CAAC,gBAAgB,GAAG,IAAI,CAAQ;IACjE,WAAW,EAAE,GAAG,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAIlB,kBAAkB,EAAE,GAAG,CAAQ;IAC/B,YAAY,EAAE,GAAG,CAAC;IAClB,wBAAwB,EAAE,MAAM,CAAC,SAAS,CAAC,wBAAwB,CAAC;IACpE,OAAO,EAAE,OAAO,CAAS;IAEzB,aAAa,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAE9C,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC,YAAY,GAAG,IAAI,CAAQ;IAC1D,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC,YAAY,GAAG,IAAI,CAAQ;IAC1D,qBAAqB,EAAE,MAAM,CAAC,SAAS,CAAC,qBAAqB,GAAG,IAAI,CAAQ;IAC5E,mBAAmB,EAAE,MAAM,CAAC,SAAS,CAAC,mBAAmB,GAAG,IAAI,CAAQ;IACxE,qBAAqB,EAAE,MAAM,CAAC,SAAS,CAAC,qBAAqB,GAAG,IAAI,CAAQ;IAC5E,gBAAgB,EAAE,MAAM,CAAC,SAAS,CAAC,gBAAgB,GAAG,IAAI,CAAQ;IAClE,uBAAuB,EAAE,MAAM,CAAC,SAAS,CAAC,uBAAuB,GAAG,IAAI,CAAQ;IAChF,+BAA+B,EAAE,MAAM,CAAC,SAAS,CAAC,+BAA+B,GAAG,IAAI,CAAQ;gBAEpF,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,EACzD;QACI,YAAY,EAAE,GAAG,CAAC;QAClB,aAAa,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;QAC7C,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;KACjD;IAML,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE;QAC5B,YAAY,EAAE,GAAG,CAAC;QAClB,aAAa,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;QAC7C,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;KACjD;IAQD,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE;QACzB,YAAY,EAAE,GAAG,CAAC;QAClB,aAAa,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;QAC7C,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;KACjD;IASD,OAAO;IAYP,MAAM,CAAC,YAAY,EAAE,YAAY;IAmBjC,MAAM,CAAC,YAAY,EAAE,YAAY;IAmBjC,WAAW,CAAC,WAAW,EAAE,WAAW;IAgBpC,MAAM,CAAC,SAAS,EAAE,SAAS;IAgB3B,QAAQ,CAAC,WAAW,EAAE,WAAW;IAgBjC,iBAAiB,CAAC,aAAa,EAAE,aAAa;IAc9C,wBAAwB;IAUxB,UAAU;IAcV,OAAO;IAMP,WAAW,CAAC,OAAO,KAAA;IAInB,OAAO,CAAC,6BAA6B;IAuLrC,OAAO,CAAC,gCAAgC;IAwBxC,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,kBAAkB;CAmB7B"}
@@ -0,0 +1,412 @@
1
+ import * as clover from "@xuantan97/remote-pay-cloud";
2
+ export default class Clover {
3
+ constructor({ cloverConfig, onPairingCode, onPairingSuccess }) {
4
+ this.cloverConnector = null;
5
+ // Stores active/open SaleRequests, we should NOT allow our POS to perform a new SaleRequest until we have received
6
+ // a SaleResponse for any open requests. For a production POS system this should be persisted so that it can survive
7
+ // across page refreshes, etc.
8
+ this.pendingSaleRequest = null;
9
+ this.isReady = false;
10
+ this.saleResponse = null;
11
+ this.authResponse = null;
12
+ this.tipAdjustAuthResponse = null;
13
+ this.voidPaymentResponse = null;
14
+ this.refundPaymentResponse = null;
15
+ this.closeoutResponse = null;
16
+ this.retrievePaymentResponse = null;
17
+ this.retrievePendingPaymentsResponse = null;
18
+ this.cloverConfig = cloverConfig;
19
+ this.onPairingCode = onPairingCode;
20
+ this.onPairingSuccess = onPairingSuccess;
21
+ }
22
+ static createInstance(options) {
23
+ if (options) {
24
+ var object = new Clover(options);
25
+ return object;
26
+ }
27
+ throw new Error("Missing 'options' parameters");
28
+ }
29
+ static getInstance(options) {
30
+ if (!Clover.instance) {
31
+ Clover.instance = Clover.createInstance(options);
32
+ }
33
+ else if (options) {
34
+ throw Error('Instance is already instantiate with `options`');
35
+ }
36
+ return Clover.instance;
37
+ }
38
+ connect() {
39
+ this.cleanup();
40
+ let cloverDeviceConnectionConfiguration;
41
+ cloverDeviceConnectionConfiguration = this.getDeviceConfigurationForNetwork();
42
+ let builderConfiguration = {};
43
+ builderConfiguration[clover.CloverConnectorFactoryBuilder.FACTORY_VERSION] = clover.CloverConnectorFactoryBuilder.VERSION_12;
44
+ let cloverConnectorFactory = clover.CloverConnectorFactoryBuilder.createICloverConnectorFactory(builderConfiguration);
45
+ this.cloverConnector = cloverConnectorFactory.createICloverConnector(cloverDeviceConnectionConfiguration);
46
+ this.cloverConnector.addCloverConnectorListener(this.buildCloverConnectionListener());
47
+ this.cloverConnector.initializeConnection();
48
+ }
49
+ doSale(paymentInput) {
50
+ var _a;
51
+ this.saleResponse = null;
52
+ if (!this.pendingSaleRequest) {
53
+ this.pendingSaleRequest = new clover.remotepay.SaleRequest();
54
+ this.pendingSaleRequest.setExternalId(paymentInput.refId);
55
+ this.pendingSaleRequest.setAmount(paymentInput.amount);
56
+ this.pendingSaleRequest.setAutoAcceptSignature(true);
57
+ this.pendingSaleRequest.setApproveOfflinePaymentWithoutPrompt(true);
58
+ this.pendingSaleRequest.setDisableDuplicateChecking(true);
59
+ this.pendingSaleRequest.setCardEntryMethods(clover.CardEntryMethods.ALL);
60
+ console.log({ message: "Sending sale", request: this.pendingSaleRequest });
61
+ console.log(`Payment: ${this.pendingSaleRequest.getExternalId()} for $${this.pendingSaleRequest.getAmount() / 100} is in progress.`);
62
+ // Send the sale to the device.
63
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.sale(this.pendingSaleRequest);
64
+ }
65
+ else {
66
+ this.checkPaymentStatus();
67
+ }
68
+ }
69
+ doAuth(paymentInput) {
70
+ var _a;
71
+ this.authResponse = null;
72
+ if (!this.pendingSaleRequest) {
73
+ this.pendingSaleRequest = new clover.remotepay.AuthRequest();
74
+ this.pendingSaleRequest.setExternalId(paymentInput.refId);
75
+ this.pendingSaleRequest.setAmount(paymentInput.amount);
76
+ this.pendingSaleRequest.setAutoAcceptSignature(true);
77
+ this.pendingSaleRequest.setApproveOfflinePaymentWithoutPrompt(true);
78
+ this.pendingSaleRequest.setDisableDuplicateChecking(true);
79
+ this.pendingSaleRequest.setCardEntryMethods(clover.CardEntryMethods.ALL);
80
+ console.log({ message: "Sending auth", request: this.pendingSaleRequest });
81
+ console.log(`Payment: ${this.pendingSaleRequest.getExternalId()} for $${this.pendingSaleRequest.getAmount() / 100} is in progress.`);
82
+ // Send the auth to the device.
83
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.auth(this.pendingSaleRequest);
84
+ }
85
+ else {
86
+ this.checkPaymentStatus();
87
+ }
88
+ }
89
+ doTipAdjust(adjustInput) {
90
+ var _a;
91
+ this.tipAdjustAuthResponse = null;
92
+ if (!this.pendingSaleRequest) {
93
+ this.pendingSaleRequest = new clover.remotepay.TipAdjustAuthRequest();
94
+ this.pendingSaleRequest.setOrderId(adjustInput.orderId);
95
+ this.pendingSaleRequest.setTipAmount(adjustInput.amount);
96
+ this.pendingSaleRequest.setPaymentId(adjustInput.paymentId);
97
+ console.log({ message: "Sending tip adjust", request: this.pendingSaleRequest });
98
+ console.log(`Payment: ${this.pendingSaleRequest.getPaymentId()} for $${this.pendingSaleRequest.getTipAmount() / 100} is in progress.`);
99
+ // Send the tip adjust to the device.
100
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.tipAdjustAuth(this.pendingSaleRequest);
101
+ }
102
+ else {
103
+ this.checkPaymentStatus();
104
+ }
105
+ }
106
+ doVoid(voidInput) {
107
+ var _a;
108
+ this.voidPaymentResponse = null;
109
+ if (!this.pendingSaleRequest) {
110
+ this.pendingSaleRequest = new clover.remotepay.VoidPaymentRequest();
111
+ this.pendingSaleRequest.setOrderId(voidInput.orderId);
112
+ this.pendingSaleRequest.setPaymentId(voidInput.paymentId);
113
+ this.pendingSaleRequest.setVoidReason(clover.order.VoidReason.USER_CANCEL);
114
+ console.log({ message: "Sending void", request: this.pendingSaleRequest });
115
+ console.log(`Payment: ${this.pendingSaleRequest.getPaymentId()} is in progress.`);
116
+ // Send the void to the device.
117
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.voidPayment(this.pendingSaleRequest);
118
+ }
119
+ else {
120
+ this.checkPaymentStatus();
121
+ }
122
+ }
123
+ doRefund(refundInput) {
124
+ var _a;
125
+ this.refundPaymentResponse = null;
126
+ if (!this.pendingSaleRequest) {
127
+ this.pendingSaleRequest = new clover.remotepay.RefundPaymentRequest();
128
+ this.pendingSaleRequest.setOrderId(refundInput.orderId);
129
+ this.pendingSaleRequest.setAmount(refundInput.amount);
130
+ this.pendingSaleRequest.setPaymentId(refundInput.paymentId);
131
+ console.log({ message: "Sending refund", request: this.pendingSaleRequest });
132
+ console.log(`Payment: ${this.pendingSaleRequest.getPaymentId()} for $${this.pendingSaleRequest.getAmount() / 100} is in progress.`);
133
+ // Send the refund to the device.
134
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.refundPayment(this.pendingSaleRequest);
135
+ }
136
+ else {
137
+ this.checkPaymentStatus();
138
+ }
139
+ }
140
+ doRetrievePayment(retrieveInput) {
141
+ var _a;
142
+ this.retrievePaymentResponse = null;
143
+ if (!this.pendingSaleRequest) {
144
+ this.pendingSaleRequest = new clover.remotepay.RetrievePaymentRequest();
145
+ this.pendingSaleRequest.setExternalId(retrieveInput.refId);
146
+ console.log({ message: "Sending retrieve", request: this.pendingSaleRequest });
147
+ console.log(`Payment: ${this.pendingSaleRequest.getExternalId()} is in progress.`);
148
+ // Send the retrieve to the device.
149
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.retrievePayment(this.pendingSaleRequest);
150
+ }
151
+ else {
152
+ this.checkPaymentStatus();
153
+ }
154
+ }
155
+ doRetrievePendingPayment() {
156
+ var _a;
157
+ this.retrievePendingPaymentsResponse = null;
158
+ if (!this.pendingSaleRequest) {
159
+ console.log({ message: "Sending retrieve pending payments" });
160
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.retrievePendingPayments();
161
+ }
162
+ else {
163
+ this.checkPaymentStatus();
164
+ }
165
+ }
166
+ doCloseout() {
167
+ var _a;
168
+ this.closeoutResponse = null;
169
+ if (!this.pendingSaleRequest) {
170
+ this.pendingSaleRequest = new clover.remotepay.CloseoutRequest();
171
+ this.pendingSaleRequest.setAllowOpenTabs(false);
172
+ console.log({ message: "Sending closeout", request: this.pendingSaleRequest });
173
+ console.log(`Payment: closeout is in progress.`);
174
+ // Send the retrieve to the device.
175
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.closeout(this.pendingSaleRequest);
176
+ }
177
+ else {
178
+ this.checkPaymentStatus();
179
+ }
180
+ }
181
+ cleanup() {
182
+ if (this.cloverConnector) {
183
+ this.cloverConnector.dispose();
184
+ }
185
+ }
186
+ showMessage(message) {
187
+ var _a;
188
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.showMessage(message);
189
+ }
190
+ buildCloverConnectionListener() {
191
+ return Object.assign({}, clover.remotepay.ICloverConnectorListener.prototype, {
192
+ onSaleResponse: (response) => {
193
+ var _a;
194
+ console.log({ message: "Payment response received", response: response });
195
+ const requestAmount = this.pendingSaleRequest.getAmount();
196
+ const requestExternalId = this.pendingSaleRequest.getExternalId();
197
+ this.pendingSaleRequest = null; // The sale is complete
198
+ this.saleResponse = response;
199
+ if (response.getSuccess()) {
200
+ const payment = response.getPayment();
201
+ // We are choosing to void the payment if it was not authorized for the full amount.
202
+ if (payment && payment.getAmount() < requestAmount) {
203
+ const voidPaymentRequest = new clover.remotepay.VoidPaymentRequest();
204
+ voidPaymentRequest.setPaymentId(payment.getId());
205
+ voidPaymentRequest.setVoidReason(clover.order.VoidReason.REJECT_PARTIAL_AUTH);
206
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.voidPayment(voidPaymentRequest);
207
+ }
208
+ else {
209
+ console.log(`${payment.getResult()}: Payment ${payment.getExternalPaymentId()} for $${payment.getAmount() / 100} is complete.`, response.getResult() === clover.remotepay.ResponseCode.SUCCESS);
210
+ if (!response.getIsSale()) {
211
+ console.log({ error: "Response is not a sale!" });
212
+ }
213
+ }
214
+ }
215
+ else {
216
+ this.resetDevice(); // The device may be stuck.
217
+ }
218
+ },
219
+ onAuthResponse: (response) => {
220
+ var _a, _b;
221
+ console.log({ message: "Payment response received", response: response });
222
+ const requestAmount = this.pendingSaleRequest.getAmount();
223
+ const requestExternalId = this.pendingSaleRequest.getExternalId();
224
+ this.pendingSaleRequest = null; // The sale is complete
225
+ this.authResponse = response;
226
+ if (response.getSuccess()) {
227
+ const payment = response.getPayment();
228
+ //auto tip = 0 on auth
229
+ const autoTipAdjustRequest = new clover.remotepay.TipAdjustAuthRequest();
230
+ autoTipAdjustRequest.setTipAmount(0);
231
+ autoTipAdjustRequest.setOrderId(payment.getOrder().getId());
232
+ autoTipAdjustRequest.setPaymentId(payment.getId());
233
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.tipAdjustAuth(autoTipAdjustRequest);
234
+ // We are choosing to void the payment if it was not authorized for the full amount.
235
+ if (payment && payment.getAmount() < requestAmount) {
236
+ const voidPaymentRequest = new clover.remotepay.VoidPaymentRequest();
237
+ voidPaymentRequest.setPaymentId(payment.getId());
238
+ voidPaymentRequest.setVoidReason(clover.order.VoidReason.REJECT_PARTIAL_AUTH);
239
+ (_b = this.cloverConnector) === null || _b === void 0 ? void 0 : _b.voidPayment(voidPaymentRequest);
240
+ }
241
+ else {
242
+ console.log(`${payment.getResult()}: Payment ${payment.getExternalPaymentId()} for $${payment.getAmount() / 100} is complete.`, response.getResult() === clover.remotepay.ResponseCode.SUCCESS);
243
+ if (!response.getIsAuth()) {
244
+ console.log({ error: "Response is not a auth!" });
245
+ }
246
+ }
247
+ }
248
+ else {
249
+ this.resetDevice(); // The device may be stuck.
250
+ }
251
+ },
252
+ onTipAdjustAuthResponse: (response) => {
253
+ console.log({ message: "Payment response received", response: response });
254
+ this.pendingSaleRequest = null; // The sale is complete
255
+ this.tipAdjustAuthResponse = response;
256
+ if (response.getSuccess()) {
257
+ }
258
+ else {
259
+ this.resetDevice(); // The device may be stuck.
260
+ }
261
+ },
262
+ onVoidPaymentResponse: (response) => {
263
+ console.log({ message: "Payment response received", response: response });
264
+ this.pendingSaleRequest = null; // The sale is complete
265
+ this.voidPaymentResponse = response;
266
+ if (response.getSuccess()) {
267
+ }
268
+ else {
269
+ this.resetDevice(); // The device may be stuck.
270
+ }
271
+ },
272
+ onRefundPaymentResponse: (response) => {
273
+ console.log({ message: "Payment response received", response: response });
274
+ this.pendingSaleRequest = null; // The sale is complete
275
+ this.refundPaymentResponse = response;
276
+ if (response.getSuccess()) {
277
+ }
278
+ else {
279
+ this.resetDevice(); // The device may be stuck.
280
+ }
281
+ },
282
+ onCloseoutResponse: (response) => {
283
+ console.log({ message: "Payment response received", response: response });
284
+ this.pendingSaleRequest = null; // The sale is complete
285
+ this.closeoutResponse = response;
286
+ if (response.getSuccess()) {
287
+ }
288
+ else {
289
+ this.resetDevice(); // The device may be stuck.
290
+ }
291
+ },
292
+ //clover.remotepay.ResultStatus.SUCCESS
293
+ onRetrievePaymentResponse: (retrievePaymentResponse) => {
294
+ console.log({ message: "onRetrievePaymentResponse", response: retrievePaymentResponse });
295
+ if (this.pendingSaleRequest) {
296
+ if (retrievePaymentResponse.getExternalPaymentId() === this.pendingSaleRequest.getExternalId()) {
297
+ if (retrievePaymentResponse.getQueryStatus() === clover.remotepay.QueryStatus.FOUND) {
298
+ // The payment's status can be used to resolve the payment in your POS.
299
+ const payment = retrievePaymentResponse.getPayment();
300
+ console.log(`${payment.getResult()}: Payment ${this.pendingSaleRequest.getExternalId()} is complete.`, payment.getResult() === clover.payments.Result.SUCCESS);
301
+ this.pendingSaleRequest = null; // The pending sale is complete.
302
+ }
303
+ else if (retrievePaymentResponse.getQueryStatus() === clover.remotepay.QueryStatus.IN_PROGRESS) {
304
+ // payment either not found or in progress,
305
+ console.log(`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()}. If you would like to reset the device anyway please <a onclick="forceResetDevice()" href="#">click here</a> to confirm.`);
306
+ }
307
+ else if (retrievePaymentResponse.getQueryStatus() === clover.remotepay.QueryStatus.NOT_FOUND) {
308
+ console.log(`Payment: ${this.pendingSaleRequest.getExternalId()} wasn't taken or was voided.`, false);
309
+ }
310
+ }
311
+ }
312
+ },
313
+ onResetDeviceResponse: (retrievePaymentResponse) => {
314
+ var _a;
315
+ console.log(retrievePaymentResponse);
316
+ if (this.pendingSaleRequest) {
317
+ // Verify the payment status, the reset will generally void payments, but not in all cases.
318
+ const retrievePaymentRequest = new clover.remotepay.RetrievePaymentRequest();
319
+ retrievePaymentRequest.setExternalPaymentId(this.pendingSaleRequest.getExternalId());
320
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.retrievePayment(retrievePaymentRequest);
321
+ }
322
+ },
323
+ // See https://docs.clover.com/build/working-with-challenges/
324
+ onConfirmPaymentRequest: (request) => {
325
+ var _a;
326
+ console.log({ message: "Automatically accepting payment", request: request });
327
+ console.log("Automatically accepting payment", true);
328
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.acceptPayment(request.getPayment());
329
+ // to reject a payment, pass the payment and the challenge that was the basis for the rejection
330
+ // getCloverConnector().rejectPayment(request.getPayment(), request.getChallenges()[REJECTED_CHALLENGE_INDEX]);
331
+ },
332
+ // See https://docs.clover.com/build/working-with-challenges/
333
+ onVerifySignatureRequest: (request) => {
334
+ var _a;
335
+ console.log({ message: "Automatically accepting signature", request: request });
336
+ console.log("Automatically accepting signature", true);
337
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.acceptSignature(request);
338
+ // to reject a signature, pass the request to verify
339
+ // getCloverConnector().rejectSignature(request);
340
+ },
341
+ onDeviceReady: (merchantInfo) => {
342
+ var _a;
343
+ console.log("The connection to your Clover Device has been established.", true);
344
+ if (!this.pendingSaleRequest) {
345
+ console.log({ message: "Device Ready to process requests!", merchantInfo: merchantInfo });
346
+ this.isReady = true;
347
+ }
348
+ else {
349
+ // We have an unresolved sale. The connection to the device was lost and the customer is in the
350
+ // middle of or finished the payment with the POS disconnected. Calling retrieveDeviceStatus
351
+ // with setSendLastMessage will ask the Clover device to send us the last message it
352
+ // sent which may allow us to proceed with the payment.
353
+ const retrieveDeviceStatusRequest = new clover.remotepay.RetrieveDeviceStatusRequest();
354
+ retrieveDeviceStatusRequest.setSendLastMessage(true);
355
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.retrieveDeviceStatus(retrieveDeviceStatusRequest);
356
+ }
357
+ },
358
+ onDeviceError: function (cloverDeviceErrorEvent) {
359
+ console.log({ message: `An error has occurred: ${cloverDeviceErrorEvent.getMessage()}` });
360
+ console.log(`An error has occurred: ${cloverDeviceErrorEvent.getMessage()}`, false);
361
+ },
362
+ onDeviceDisconnected: function () {
363
+ console.log({ message: "You have been disconnected from the Clover device." });
364
+ console.log("The connection to your Clover Device has been dropped.", false);
365
+ }
366
+ });
367
+ }
368
+ getDeviceConfigurationForNetwork() {
369
+ // const onPairingCode = (pairingCode) => {
370
+ // const pairingCodeMessage = `Please enter pairing code ${pairingCode} on the device`;
371
+ // console.log(` > ${pairingCodeMessage}`);
372
+ // this.pairingCode = pairingCode;
373
+ // };
374
+ // const onPairingSuccess = (authTokenFromPairing) => {
375
+ // console.log(` > Got Pairing Auth Token: ${authTokenFromPairing}`);
376
+ // this.authToken = authTokenFromPairing;
377
+ // this.pairingCode = null;
378
+ // };
379
+ const configBuilder = new clover.WebSocketPairedCloverDeviceConfigurationBuilder(this.cloverConfig.applicationId, this.cloverConfig.endpoint, this.cloverConfig.posName, this.cloverConfig.serialNumber, this.cloverConfig.authToken, this.onPairingCode, this.onPairingSuccess);
380
+ return configBuilder.build();
381
+ }
382
+ resetDevice() {
383
+ var _a;
384
+ if (this.pendingSaleRequest) {
385
+ this.checkPaymentStatus();
386
+ }
387
+ else {
388
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.resetDevice();
389
+ }
390
+ }
391
+ checkPaymentStatus() {
392
+ var _a, _b;
393
+ if (this.pendingSaleRequest) {
394
+ // If a message was lost etc. the retrieveDevice status request will ask the device to send the last message.
395
+ // This can help the POS recover if the device is stuck on a challenge screen, etc. The last message will
396
+ // be sent independently of the retrieveDeviceStatus response and thus the retrieveDeviceStatus response
397
+ // does not need to be checked.
398
+ const retrieveDeviceStatusRequest = new clover.remotepay.RetrieveDeviceStatusRequest();
399
+ retrieveDeviceStatusRequest.setSendLastMessage(true);
400
+ (_a = this.cloverConnector) === null || _a === void 0 ? void 0 : _a.retrieveDeviceStatus(retrieveDeviceStatusRequest);
401
+ // Retrieve the payment status.
402
+ console.log(`Payment is currently pending. Checking payment status ...`);
403
+ console.log(this.pendingSaleRequest);
404
+ const retrievePaymentRequest = new clover.remotepay.RetrievePaymentRequest();
405
+ retrievePaymentRequest.setExternalPaymentId(this.pendingSaleRequest.getExternalId());
406
+ (_b = this.cloverConnector) === null || _b === void 0 ? void 0 : _b.retrievePayment(retrievePaymentRequest);
407
+ }
408
+ else {
409
+ console.log(`There is currently no pending payment.`);
410
+ }
411
+ }
412
+ }
@@ -0,0 +1,23 @@
1
+ export declare type PaymentInput = {
2
+ amount: number;
3
+ method: "sale" | "auth";
4
+ refId: number | string;
5
+ };
6
+ export declare type AdjustInput = {
7
+ amount: number;
8
+ orderId: number | string;
9
+ paymentId: number | string;
10
+ };
11
+ export declare type VoidInput = {
12
+ orderId: number | string;
13
+ paymentId: number | string;
14
+ };
15
+ export declare type RefundInput = {
16
+ orderId: number | string;
17
+ paymentId: number | string;
18
+ amount: number;
19
+ };
20
+ export declare type RetrieveInput = {
21
+ refId: number | string;
22
+ };
23
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/clover/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,MAAM,YAAY,GAAG;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B,CAAA;AAED,MAAM,CAAC,OAAO,MAAM,WAAW,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;CAC9B,CAAA;AAED,MAAM,CAAC,OAAO,MAAM,SAAS,GAAG;IAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;CAC9B,CAAA;AAED,MAAM,CAAC,OAAO,MAAM,WAAW,GAAG;IAC9B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,CAAC,OAAO,MAAM,aAAa,GAAG;IAChC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B,CAAA"}
@@ -0,0 +1 @@
1
+ export {};