@fire-spark/payments-clisitef-pinpad-rn 0.7.2 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.d.ts +131 -10
  2. package/dist/index.js +811 -205
  3. package/package.json +5 -5
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { DeviceField, PaymentAdapter, PaymentAdapterCapabilities, PaymentErrorEntry, PaymentMetadata, PaymentStorage, PaymentUI, StandardPaymentError } from "@fire-spark/payments";
2
- import { CLISITEF_MODALITY, ClisitefClient, ClisitefConfigureParams, ClisitefFinishParams, ClisitefStartParams } from "@fire-spark/payments-clisitef-client";
1
+ import { DeviceField, PaymentAdapter, PaymentAdapterCapabilities, PaymentErrorEntry, PaymentMetadata, PaymentResult, PaymentStorage, PaymentUI, StandardPaymentError } from "@fire-spark/payments";
2
+ import { CLISITEF_MODALITY, ClisitefClient, ClisitefConfigureParams, ClisitefFinishParams, ClisitefMenuOption, ClisitefStartParams } from "@fire-spark/payments-clisitef-client";
3
3
  import { TenderDetails } from "@fire-spark/types";
4
4
  //#region src/adapter.d.ts
5
5
  /** Confirmed in the act (`finishTransaction(1)`), never captured later. */
@@ -36,8 +36,8 @@ declare const clisitefPinPadPayments: (options?: ClisitefPinPadOptions) => Payme
36
36
  /**
37
37
  * `onData` commands handled by the adapter (Fiserv "Tabela de códigos de
38
38
  * comando"). Not handled, so they abort the transaction: 29 (silent field),
39
- * 31 (check), 35 (barcode), 42 (identified menu, only with
40
- * `ItemMenuIdentificado`) and 50/51 (QR, PIX only).
39
+ * 31 (check), 35 (barcode) and 42 (identified menu, only with
40
+ * `ItemMenuIdentificado`).
41
41
  */
42
42
  declare const CLISITEF_COMMAND: {
43
43
  readonly STORE_FIELD: 0;
@@ -58,6 +58,9 @@ declare const CLISITEF_COMMAND: {
58
58
  readonly READ_FIELD: 30;
59
59
  readonly READ_AMOUNT: 34;
60
60
  readonly READ_MASKED: 41;
61
+ /** PIX: show the QR (`fieldId` 584 carries the copy-and-paste payload). */
62
+ readonly QR_SHOW: 50;
63
+ readonly QR_HIDE: 51;
61
64
  readonly FOOTER: 52;
62
65
  };
63
66
  /** `continueTransaction` answers to `CONFIRM` (20). */
@@ -75,9 +78,17 @@ declare const CLISITEF_FIELD: {
75
78
  readonly AUTHORIZATION_CODE: 135;
76
79
  readonly CARD_BIN: 136;
77
80
  readonly INSTITUTION_NAME: 156;
81
+ readonly QR_PAYLOAD: 584;
78
82
  readonly LAST4: 1190;
79
83
  readonly ENTRY_MODE: 2090;
80
84
  };
85
+ /** Fields a void asks for (`READ_*` commands), answered without the UI. */
86
+ declare const CLISITEF_VOID_FIELD: {
87
+ readonly AMOUNT: 146;
88
+ readonly SUPERVISOR_PASSWORD: 500;
89
+ readonly ORIGINAL_DATE: 515;
90
+ readonly ORIGINAL_HOST_NSU: 516;
91
+ };
81
92
  /** Fields that prove the card was read: an error after them is ambiguous. */
82
93
  declare const CLISITEF_CAPTURE_FIELDS: ReadonlySet<number>;
83
94
  /** Operator, pinpad or automation cancelled (ficha §11). */
@@ -95,6 +106,12 @@ declare const CLISITEF_PAYMENT_TIMEOUT_MS = 180000;
95
106
  declare const CLISITEF_DEFAULT_OPERATOR = "KIOSKO_BR";
96
107
  /** Device-wide record of the last transaction, to undo it after a crash. */
97
108
  declare const CLISITEF_STORAGE_KEY = "clisitef:transaction:v1";
109
+ /** Device-wide record of the last refund, apart from the charge one. */
110
+ declare const CLISITEF_REFUND_STORAGE_KEY = "clisitef:refund:v1";
111
+ /** Device-wide queue of voids that did not complete, retried later. */
112
+ declare const CLISITEF_REVERSALS_KEY = "clisitef:reversals:v1";
113
+ /** Device-wide record of completed voids, by attempt reference. */
114
+ declare const CLISITEF_REFUNDS_KEY = "clisitef:refunds:v1";
98
115
  //#endregion
99
116
  //#region src/errors.d.ts
100
117
  /**
@@ -124,6 +141,7 @@ declare const clisitefPinPadErrors: Readonly<Record<string, PaymentErrorEntry>>
124
141
  "-50": PaymentErrorEntry;
125
142
  "-100": PaymentErrorEntry;
126
143
  CLISITEF_TIMEOUT: PaymentErrorEntry;
144
+ FINANCING_ONLY: PaymentErrorEntry;
127
145
  };
128
146
  //#endregion
129
147
  //#region src/settings.d.ts
@@ -134,19 +152,44 @@ declare const CLISITEF_PINPAD_TYPES: readonly ["ANDROID_USB", "ANDROID_BT", "AND
134
152
  * the device values only override them.
135
153
  */
136
154
  declare const clisitefPinPadDeviceFields: DeviceField[];
155
+ declare const redactSecrets: (values?: Record<string, unknown>) => {
156
+ [k: string]: unknown;
157
+ };
137
158
  type ClisitefModality = keyof typeof CLISITEF_MODALITY;
138
- type ClisitefCardModality = Exclude<ClisitefModality, "PIX">;
159
+ declare const CLISITEF_MODALITIES: readonly ClisitefModality[];
139
160
  type ClisitefPinPadSettings = {
140
161
  configure: ClisitefConfigureParams;
141
162
  /** Asked to the customer when there is more than one. */
142
- modalities: ClisitefCardModality[];
163
+ modalities: ClisitefModality[];
143
164
  operator: string;
144
- restrictions: Partial<Record<ClisitefCardModality, string>>;
165
+ restrictions: Partial<Record<ClisitefModality, string>>;
145
166
  terminalNumber: string;
167
+ /** Field 500 of a void: device secret, else the store one. */
168
+ supervisorPassword: string;
146
169
  };
170
+ declare const isClisitefModality: (value: unknown) => value is ClisitefModality;
147
171
  /** `payments.config` (merchant) + device settings; throws when incomplete. */
148
172
  declare const readClisitefPinPadSettings: (config: Record<string, unknown>, device: Record<string, unknown>) => ClisitefPinPadSettings;
149
173
  //#endregion
174
+ //#region src/menu.d.ts
175
+ type ClisitefMenuPurpose = "charge" | "void";
176
+ type ClisitefMenuDecision = {
177
+ kind: "pick";
178
+ value: string;
179
+ } | {
180
+ kind: "ask";
181
+ options: ClisitefMenuOption[];
182
+ } | {
183
+ kind: "abort";
184
+ message: string;
185
+ };
186
+ /**
187
+ * Command 21. Labels compare without accents and in upper case. A void
188
+ * picks the original modality when one option matches it; a charge does it
189
+ * only for debit and credit, then drops the financing options.
190
+ */
191
+ declare const resolveClisitefMenu: (options: ClisitefMenuOption[], modality: ClisitefModality, purpose: ClisitefMenuPurpose) => ClisitefMenuDecision;
192
+ //#endregion
150
193
  //#region src/metadata.d.ts
151
194
  type ClisitefFields = ReadonlyMap<number, string>;
152
195
  /** Last 4 digits of the masked PAN printed on the receipt. */
@@ -159,10 +202,81 @@ type MetadataInput = {
159
202
  fiscalCoupon: string;
160
203
  fiscalDate: string;
161
204
  };
205
+ /** `provider` section: the Spark modality and the CliSiTef function used. */
206
+ type ClisitefProviderMetadata = {
207
+ modality: ClisitefModality;
208
+ function: number;
209
+ };
162
210
  declare const clisitefMetadata: (input: MetadataInput) => PaymentMetadata;
211
+ type VoidMetadataInput = {
212
+ fields: ClisitefFields;
213
+ function: number;
214
+ fiscalCoupon: string;
215
+ fiscalDate: string;
216
+ };
217
+ /** Void data kept under `provider.void`, next to the charge's metadata. */
218
+ declare const clisitefVoidMetadata: (input: VoidMetadataInput) => {
219
+ function: number;
220
+ provider_transaction_id: string | null;
221
+ reference: string | null;
222
+ ticket_number: string;
223
+ transaction_date: string;
224
+ receipt: {
225
+ customer: string | null;
226
+ merchant: string | null;
227
+ format: "text";
228
+ } | null;
229
+ };
230
+ /** Spark modality of a charge; older charges only kept `card_type`. */
231
+ declare const clisitefModalityOf: (metadata: PaymentMetadata) => ClisitefModality | null;
163
232
  /** PIN_PAD tender details; `null` without brand and last 4 (schema minimum). */
164
233
  declare const clisitefDetails: (metadata: PaymentMetadata) => TenderDetails | null;
165
234
  //#endregion
235
+ //#region src/refund.d.ts
236
+ type ClisitefVoidDeps = {
237
+ client: ClisitefClient;
238
+ now: () => Date;
239
+ timeZone?: string;
240
+ confirmationTimeoutMs: number;
241
+ };
242
+ type ClisitefVoidContext = {
243
+ ui: PaymentUI;
244
+ signal: AbortSignal;
245
+ storage: PaymentStorage;
246
+ settings: ClisitefPinPadSettings;
247
+ attempt: number;
248
+ /** The pinpad could not be prepared: queue the void without starting it. */
249
+ unavailable?: StandardPaymentError | null;
250
+ };
251
+ /**
252
+ * Voids a confirmed charge with its cancellation function (credit 210,
253
+ * debit and voucher 211, PIX 123). `REFUNDED` only after `stage 2` = 0;
254
+ * any other end keeps the charge `PAID` with `needs_review`, and a
255
+ * retryable one goes to the pending queue.
256
+ */
257
+ declare const runClisitefVoid: (deps: ClisitefVoidDeps, ctx: ClisitefVoidContext, result: PaymentResult) => Promise<PaymentResult>;
258
+ //#endregion
259
+ //#region src/reversals.d.ts
260
+ /** A void that did not complete; retried from the operator panel. */
261
+ type ClisitefPendingReversal = {
262
+ attemptReference: string;
263
+ amount: number;
264
+ transactionDate: string;
265
+ hostNsu: string;
266
+ modality: ClisitefModality;
267
+ reason: string;
268
+ attempts: number;
269
+ createdAt: number;
270
+ /** The `PAID` result to void again. */
271
+ result: PaymentResult;
272
+ };
273
+ declare const readPendingReversals: (storage: PaymentStorage) => Promise<ClisitefPendingReversal[]>;
274
+ /** Adds the void or bumps its attempts. */
275
+ declare const queueReversal: (storage: PaymentStorage, entry: Omit<ClisitefPendingReversal, "attempts" | "createdAt">, now: number) => Promise<void>;
276
+ declare const dropReversal: (storage: PaymentStorage, attemptReference: string) => Promise<void>;
277
+ declare const readRefund: (storage: PaymentStorage, attemptReference: string) => Promise<PaymentResult | null>;
278
+ declare const writeRefund: (storage: PaymentStorage, attemptReference: string, result: PaymentResult) => Promise<void>;
279
+ //#endregion
166
280
  //#region src/store.d.ts
167
281
  /**
168
282
  * `started`: `startTransaction` called. `approved`: `finishTransaction(1)`
@@ -183,8 +297,8 @@ type ClisitefTransactionRecord = {
183
297
  details?: TenderDetails | null;
184
298
  error?: StandardPaymentError;
185
299
  };
186
- declare const readTransaction: (storage: PaymentStorage) => Promise<ClisitefTransactionRecord | null>;
187
- declare const writeTransaction: (storage: PaymentStorage, record: ClisitefTransactionRecord) => Promise<void>;
300
+ declare const readTransaction: (storage: PaymentStorage, key?: string) => Promise<ClisitefTransactionRecord | null>;
301
+ declare const writeTransaction: (storage: PaymentStorage, record: ClisitefTransactionRecord, key?: string) => Promise<void>;
188
302
  declare const isOpen: (record: ClisitefTransactionRecord) => boolean;
189
303
  //#endregion
190
304
  //#region src/transaction.d.ts
@@ -201,6 +315,8 @@ type ClisitefOutcome = {
201
315
  message: string | null;
202
316
  fields: ClisitefFields;
203
317
  aborted: boolean;
318
+ /** The card was read, a receipt arrived or the PIX QR was shown. */
319
+ evidence: boolean;
204
320
  /** Error thrown by `ctx.ui` (e.g. the customer did not answer). */
205
321
  error?: unknown;
206
322
  };
@@ -211,8 +327,13 @@ type ClisitefTransactionInput = {
211
327
  start: ClisitefStartParams;
212
328
  finish: Omit<ClisitefFinishParams, "confirm">;
213
329
  confirmationTimeoutMs: number;
330
+ /** Spark modality of the charge, or of the charge a void undoes. */
331
+ modality: ClisitefModality;
332
+ purpose: ClisitefMenuPurpose;
214
333
  /** Runs before `finishTransaction(1)`, to persist the approval. */
215
334
  onApproved: (fields: ClisitefFields) => Promise<void>;
335
+ /** Answer for a `READ_*` field without the UI; `null` asks `ui.input`. */
336
+ answerField?: (fieldId: number) => string | null;
216
337
  };
217
338
  /**
218
339
  * One CliSiTef transaction: `startTransaction`, the `onData` loop answered
@@ -221,4 +342,4 @@ type ClisitefTransactionInput = {
221
342
  */
222
343
  declare const runClisitefTransaction: (input: ClisitefTransactionInput) => Promise<ClisitefOutcome>;
223
344
  //#endregion
224
- export { CLISITEF_CANCEL_CODES, CLISITEF_CAPTURE_FIELDS, CLISITEF_COMMAND, CLISITEF_CONFIRMATION_TIMEOUT_MS, CLISITEF_DEFAULT_OPERATOR, CLISITEF_FIELD, CLISITEF_INCONCLUSIVE_CODES, CLISITEF_NO, CLISITEF_PAYMENT_TIMEOUT_MS, CLISITEF_PINPAD_TYPES, CLISITEF_STORAGE_KEY, CLISITEF_YES, ClisitefCardModality, ClisitefFields, ClisitefModality, ClisitefOutcome, ClisitefOutcomeStatus, ClisitefPinPadOptions, ClisitefPinPadSettings, ClisitefTransactionInput, ClisitefTransactionRecord, ClisitefTransactionState, clisitefDetails, clisitefLast4, clisitefMetadata, clisitefPinPadCapabilities, clisitefPinPadDeviceFields, clisitefPinPadErrors, clisitefPinPadPayments, isOpen, readClisitefPinPadSettings, readTransaction, runClisitefTransaction, writeTransaction };
345
+ export { CLISITEF_CANCEL_CODES, CLISITEF_CAPTURE_FIELDS, CLISITEF_COMMAND, CLISITEF_CONFIRMATION_TIMEOUT_MS, CLISITEF_DEFAULT_OPERATOR, CLISITEF_FIELD, CLISITEF_INCONCLUSIVE_CODES, CLISITEF_MODALITIES, CLISITEF_NO, CLISITEF_PAYMENT_TIMEOUT_MS, CLISITEF_PINPAD_TYPES, CLISITEF_REFUNDS_KEY, CLISITEF_REFUND_STORAGE_KEY, CLISITEF_REVERSALS_KEY, CLISITEF_STORAGE_KEY, CLISITEF_VOID_FIELD, CLISITEF_YES, ClisitefFields, ClisitefMenuDecision, ClisitefMenuPurpose, ClisitefModality, ClisitefOutcome, ClisitefOutcomeStatus, ClisitefPendingReversal, ClisitefPinPadOptions, ClisitefPinPadSettings, ClisitefProviderMetadata, ClisitefTransactionInput, ClisitefTransactionRecord, ClisitefTransactionState, ClisitefVoidContext, ClisitefVoidDeps, clisitefDetails, clisitefLast4, clisitefMetadata, clisitefModalityOf, clisitefPinPadCapabilities, clisitefPinPadDeviceFields, clisitefPinPadErrors, clisitefPinPadPayments, clisitefVoidMetadata, dropReversal, isClisitefModality, isOpen, queueReversal, readClisitefPinPadSettings, readPendingReversals, readRefund, readTransaction, redactSecrets, resolveClisitefMenu, runClisitefTransaction, runClisitefVoid, writeRefund, writeTransaction };