@tuwaio/quasar-sdk 0.7.3 → 0.9.0

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,1040 @@
1
+ /**
2
+ * @file Request and response types of the Payments API (`/v1/payments`): invoices, refunds, documents, quotes,
3
+ * payment methods and subscriptions, as the Quasar engine takes and returns them.
4
+ */
5
+ /** Fiat currency of an invoice or a subscription plan. */
6
+ type PaymentsCurrency = 'USD' | 'EUR';
7
+ /** Language of an invoice, its documents and its emails. */
8
+ type InvoiceLocale = 'en' | 'uk' | 'zh-CN' | 'es' | 'it' | 'de';
9
+ /**
10
+ * VAT category of a line (EN 16931 UNCL5305): `S` standard rate, `Z` zero rated, `E` exempt (needs
11
+ * `taxExemptionReason`), `AE` reverse charge, `K` intra-community supply, `G` export outside the EU, `O` outside the
12
+ * scope of VAT.
13
+ */
14
+ type TaxCategory = 'S' | 'Z' | 'E' | 'AE' | 'K' | 'G' | 'O';
15
+ /**
16
+ * State of an invoice: `open` until paid, `processing` while a payment is being confirmed, then `paid`, `underpaid`
17
+ * (the buyer may top it up), `held` (the merchant releases or refunds it), `partially_refunded`, `refunded`, or
18
+ * `expired`/`cancelled` without a payment.
19
+ */
20
+ type InvoiceStatus = 'open' | 'processing' | 'paid' | 'underpaid' | 'held' | 'partially_refunded' | 'refunded' | 'expired' | 'cancelled';
21
+ /** Whether an invoice or subscription belongs to the live or the test app: the key that issued it decides. */
22
+ type PaymentsEnvironment = 'live' | 'test';
23
+ /**
24
+ * The buyer of an invoice (EN 16931 BT-44 to BT-55). Every field is optional; an e-invoice is issued only when the
25
+ * fields it needs are there (otherwise the invoice says what was missing in `eInvoiceSkipped`).
26
+ */
27
+ interface Buyer {
28
+ /** Name of the person or the company. */
29
+ name?: string;
30
+ /** Email address; Quasar Cloud sends the invoice, receipt and credit notes to it. */
31
+ email?: string;
32
+ /** First address line. */
33
+ addressLine1?: string;
34
+ /** Second address line. */
35
+ addressLine2?: string;
36
+ /** Postal code. */
37
+ postalCode?: string;
38
+ /** City. */
39
+ city?: string;
40
+ /** Region or state. */
41
+ region?: string;
42
+ /** ISO 3166-1 alpha-2 country code, for example `DE`. */
43
+ country?: string;
44
+ /** Company registration number. */
45
+ registrationNumber?: string;
46
+ /** VAT or other tax ID; required for a reverse-charge invoice. */
47
+ taxId?: string;
48
+ /** Your ID of the buyer; filter invoices by it with `externalId`. */
49
+ externalId?: string;
50
+ }
51
+ /** One line of an invoice or a subscription plan, as you send it. */
52
+ interface InvoiceLineInput {
53
+ /** What is sold. */
54
+ name: string;
55
+ /** Optional details under the name. */
56
+ description?: string;
57
+ /** Quantity as a decimal string. Defaults to `'1'`. */
58
+ quantity?: string;
59
+ /** Price of one unit in the invoice currency, as a decimal string (`'49.00'`). */
60
+ unitPrice: string;
61
+ /** VAT category; defaults to the one in the app's document settings. */
62
+ taxCategory?: TaxCategory;
63
+ /** VAT rate in percent (`'21'`); defaults to the one in the app's document settings. */
64
+ taxRate?: string;
65
+ /** UN/ECE Recommendation 20 unit code for e-invoices (`C62` one, `HUR` hour, `MON` month). */
66
+ unitCode?: string;
67
+ }
68
+ /** The lines of an invoice: give either `lineItems` or a bare `amount`. */
69
+ type InvoiceLinesInput = {
70
+ /** The lines, 1 to 100. */
71
+ lineItems: InvoiceLineInput[];
72
+ amount?: never;
73
+ description?: never;
74
+ } | {
75
+ lineItems?: never;
76
+ /** A total as one line, as a decimal string (`'49.00'`). */
77
+ amount: string;
78
+ /** Name of that one line. Defaults to `Payment` (`Subscription` for a plan). */
79
+ description?: string;
80
+ };
81
+ /** Terms that an invoice and a subscription plan share. */
82
+ interface InvoiceTermsInput {
83
+ /** Currency. Defaults to `USD`. */
84
+ currency?: PaymentsCurrency;
85
+ /** Language of the documents and emails. Defaults to `en`. */
86
+ locale?: InvoiceLocale;
87
+ /** The buyer. */
88
+ buyer?: Buyer;
89
+ /** The CAIP-10 account you expect to pay (`eip155:8453:0x…`, `solana:<genesis hash>:<address>`). */
90
+ expectedPayer?: string;
91
+ /** BT-10, the reference the buyer asked for. */
92
+ buyerReference?: string;
93
+ /** BT-13, the buyer's purchase order. */
94
+ orderReference?: string;
95
+ /** Your data, returned with the invoice and its webhooks; at most 8 KiB as JSON. */
96
+ metadata?: Record<string, unknown>;
97
+ /** Where the checkout sends the buyer after paying. */
98
+ successUrl?: string;
99
+ /** Where the checkout sends a buyer who gives up. */
100
+ cancelUrl?: string;
101
+ /** A note printed on the invoice. */
102
+ notes?: string;
103
+ /** Whether unit prices include VAT; defaults to the app's document settings. */
104
+ pricesIncludeTax?: boolean;
105
+ /** A reverse-charge invoice (needs `buyer.taxId`). */
106
+ reverseCharge?: boolean;
107
+ /** Why the lines are exempt (needed for category `E`). */
108
+ taxExemptionReason?: string;
109
+ }
110
+ /** What {@link PaymentsModule.createInvoice} takes. */
111
+ type CreateInvoiceParams = InvoiceLinesInput & InvoiceTermsInput & {
112
+ /** When the invoice stops being payable; give it or `expiresInMinutes`. */
113
+ dueAt?: Date | string;
114
+ /** Minutes the invoice stays payable, from 5 to 90 days. */
115
+ expiresInMinutes?: number;
116
+ /** Date of supply (BT-72). Defaults to the issue date. */
117
+ supplyDate?: Date | string;
118
+ };
119
+ /** Options of a call that creates something. */
120
+ interface CreateOptions {
121
+ /**
122
+ * Sent as the `Idempotency-Key` header (1–255 characters): a retry with the same key returns what the first call
123
+ * created, with the same payment link, instead of creating it twice.
124
+ */
125
+ idempotencyKey?: string;
126
+ }
127
+ /** A line of an issued invoice, with its net amount. */
128
+ interface InvoiceLine {
129
+ /** What is sold. */
130
+ name: string;
131
+ /** Details under the name. */
132
+ description?: string;
133
+ /** Quantity as a decimal string. */
134
+ quantity: string;
135
+ /** Price of one unit. */
136
+ unitPrice: string;
137
+ /** VAT category. */
138
+ taxCategory: TaxCategory;
139
+ /** VAT rate in percent. */
140
+ taxRate: string;
141
+ /** Net amount of the line. */
142
+ net: string;
143
+ /** Unit code, when given. */
144
+ unitCode?: string;
145
+ }
146
+ /** The price an invoice was quoted at, once a buyer chose how to pay. */
147
+ interface InvoiceQuote {
148
+ /** The payment method. */
149
+ methodId: string | null;
150
+ /** CAIP-10 account the quote was issued to. */
151
+ payer: string;
152
+ /** Token amount that settles the invoice, in base units. */
153
+ cryptoAmountExpected: string | null;
154
+ /**
155
+ * What must still arrive, in base units, while the invoice takes a payment: the whole amount, or the rest of an
156
+ * `underpaid` invoice. `null` otherwise.
157
+ */
158
+ amountDue: string | null;
159
+ /**
160
+ * What the buyer sends, in base units: what must still arrive (the whole price, or the rest of an `underpaid` invoice)
161
+ * grossed up for a token's transfer fee.
162
+ */
163
+ amountToSend: string | null;
164
+ /** When the quote was locked. */
165
+ lockedAt: string | null;
166
+ /** When the quote expires. */
167
+ expiresAt: string | null;
168
+ /** The price rounds the quote used, as evidence. */
169
+ rate: unknown;
170
+ /** Solana Pay reference key of the quote. */
171
+ reference: string | null;
172
+ }
173
+ /**
174
+ * The payment that settled an invoice. An invoice paid in parts has several transfers: this names the last one, and
175
+ * {@link InvoiceDetails.payments} names them all.
176
+ */
177
+ interface InvoiceSettlement {
178
+ /** ID of the payment method paid with (see `listMethods`): its token and network read {@link InvoiceSettlement.amountPaid}. */
179
+ methodId: string | null;
180
+ /** CAIP-2 chain ID of the payment. */
181
+ chainId: string | null;
182
+ /** Transaction hash or Solana signature of the last transfer. */
183
+ txHash: string;
184
+ /** Block (EVM) or slot (Solana) of the last transfer. */
185
+ blockRef: string | null;
186
+ /** Amount received in all, in base units. */
187
+ amountPaid: string | null;
188
+ /** The address that paid. */
189
+ originWallet: string | null;
190
+ /** When it was paid. */
191
+ paidAt: string | null;
192
+ /** Base units received beyond what was due; a refund can return them. */
193
+ overpaid: string;
194
+ }
195
+ /**
196
+ * The seller of an invoice as printed, copied from the app's payment settings when it was issued. Every field may be
197
+ * missing or `null`: invoices issued before the address had its parts carry only `address`.
198
+ */
199
+ interface InvoiceSeller {
200
+ /** Legal name. */
201
+ legalName?: string | null;
202
+ /** The name buyers know. */
203
+ tradingName?: string | null;
204
+ /** The postal address as one text, as the checkout shows it. */
205
+ address?: string | null;
206
+ /** First address line. */
207
+ addressLine1?: string | null;
208
+ /** Second address line. */
209
+ addressLine2?: string | null;
210
+ /** Postal code. */
211
+ postalCode?: string | null;
212
+ /** City. */
213
+ city?: string | null;
214
+ /** ISO 3166-1 alpha-2 country code. */
215
+ country?: string | null;
216
+ /** Company registration number. */
217
+ registrationNumber?: string | null;
218
+ /** VAT or other tax ID. */
219
+ taxId?: string | null;
220
+ /** Support email address. */
221
+ supportEmail?: string | null;
222
+ /** Website. */
223
+ website?: string | null;
224
+ }
225
+ /** The payer's AML screening of an invoice. */
226
+ interface InvoiceAml {
227
+ /** `passed`, `flagged`, `blocked` or `failed`. */
228
+ status: string;
229
+ /** Why. */
230
+ reasons: string[];
231
+ /** What screened the payer, when known. */
232
+ coverage: string | null;
233
+ }
234
+ /** An invoice as the Payments API returns it. Amounts are decimal strings in the invoice currency. */
235
+ interface Invoice {
236
+ /** Invoice ID. */
237
+ id: string;
238
+ /** Always `invoice`. */
239
+ object: 'invoice';
240
+ /** Series number, for example `INV-2026-42` (`TEST-` for test invoices). */
241
+ number: string | null;
242
+ /** State of the invoice. */
243
+ status: InvoiceStatus;
244
+ /** Live or test. */
245
+ environment: PaymentsEnvironment | null;
246
+ /** Currency. */
247
+ currency: PaymentsCurrency;
248
+ /** Language of its documents and emails. */
249
+ locale: InvoiceLocale | null;
250
+ /** When it was issued (ISO 8601). */
251
+ issuedAt: string | null;
252
+ /** Date of supply. */
253
+ supplyDate: string | null;
254
+ /** When it stops being payable. */
255
+ dueAt: string | null;
256
+ /** The seller as printed, from the app's settings at issue. */
257
+ seller: InvoiceSeller | null;
258
+ /** The buyer as printed. */
259
+ buyer: (Buyer & {
260
+ companyInvoice?: boolean;
261
+ }) | null;
262
+ /** The CAIP-10 account you expected to pay. */
263
+ expectedPayer: string | null;
264
+ /** BT-10. */
265
+ buyerReference: string | null;
266
+ /** BT-13. */
267
+ orderReference: string | null;
268
+ /** The lines. */
269
+ lineItems: InvoiceLine[];
270
+ /** Whether unit prices include VAT. */
271
+ pricesIncludeTax: boolean | null;
272
+ /** Total without VAT. */
273
+ subtotal: string;
274
+ /** VAT. */
275
+ taxTotal: string;
276
+ /** Rounding. */
277
+ rounding: string;
278
+ /** Total to pay. */
279
+ total: string;
280
+ /** VAT per category and rate. */
281
+ taxBreakdown: {
282
+ taxCategory: TaxCategory;
283
+ taxRate: string;
284
+ taxable: string;
285
+ tax: string;
286
+ }[];
287
+ /** The note printed on the invoice. */
288
+ notes: string | null;
289
+ /** Whether it is a reverse-charge invoice. */
290
+ reverseCharge: boolean | null;
291
+ /** Why its lines are exempt. */
292
+ taxExemptionReason: string | null;
293
+ /** Your data. */
294
+ metadata: Record<string, unknown> | null;
295
+ /** Where the checkout sends the buyer after paying. */
296
+ successUrl: string | null;
297
+ /** Where the checkout sends a buyer who gives up. */
298
+ cancelUrl: string | null;
299
+ /**
300
+ * The checkout token while the invoice can be paid (`open`, `processing`, `underpaid`), for a checkout embedded in
301
+ * your page; `null` otherwise.
302
+ */
303
+ checkoutToken: string | null;
304
+ /** The payment page while the invoice can be paid: the link its emails carry. */
305
+ payUrl: string | null;
306
+ /** The locked quote, once there is one. */
307
+ quote: InvoiceQuote | null;
308
+ /** The payment, once there is one. */
309
+ settlement: InvoiceSettlement | null;
310
+ /**
311
+ * Why the payment waits for you: `overpaid` when the app flags overpayments, `quote_expired` when it arrived after
312
+ * its locked quote expired, `payment_reverted` when a payment Quasar credited is gone from the chain (check the
313
+ * transaction `payment.reverted` names; the invoice keeps its status). A transfer Quasar could tie to no invoice
314
+ * never holds the invoice: it is a held transfer of its own.
315
+ */
316
+ reviewReason: string | null;
317
+ /** The payer's AML screening, once there was one. */
318
+ aml: InvoiceAml | null;
319
+ /** The receipt number, once paid. */
320
+ receiptNumber: string | null;
321
+ /** What the e-invoice lacked when the invoice was issued as a plain PDF, for example `buyer.country`. */
322
+ eInvoiceSkipped: string[] | null;
323
+ /** Refunded so far, in the invoice currency. */
324
+ refundedTotal: string;
325
+ /** What refunds that arrived short delivered, of those nothing completes yet: a new refund has that much less to return. Read with one invoice only. */
326
+ refundShort?: string;
327
+ /** The invoice this one corrects. */
328
+ replaces: string | null;
329
+ /** The invoice that corrects this one. */
330
+ replacedBy: string | null;
331
+ /** The subscription it bills. */
332
+ subscriptionId: string | null;
333
+ /** The subscription period it bills. */
334
+ period: number | null;
335
+ /** When it was created. */
336
+ createdAt: string;
337
+ /** When it last changed. */
338
+ updatedAt: string;
339
+ }
340
+ /**
341
+ * A document issued for an invoice, as {@link PaymentsModule.listInvoiceDocuments} lists it: the invoice, its receipt
342
+ * or a credit note, in one format. {@link PaymentsModule.getDocument} downloads the invoice and the receipt,
343
+ * {@link PaymentsModule.getCreditNote} a credit note by its number or its refund.
344
+ */
345
+ interface InvoiceDocumentRef {
346
+ /** What it is. */
347
+ kind: 'invoice' | 'receipt' | 'credit_note';
348
+ /** `pdf`, or `ubl` for the e-invoice. */
349
+ format: 'pdf' | 'ubl';
350
+ /** Its number. */
351
+ number: string;
352
+ /** The refund a credit note credits; `null` for the invoice, the receipt and the credit note of a correction. */
353
+ refundId: string | null;
354
+ /** When it was issued. */
355
+ issuedAt: string;
356
+ }
357
+ /** A transfer credited to an invoice. An invoice paid in parts has several. */
358
+ interface InvoicePayment {
359
+ /** Transaction hash or Solana signature. */
360
+ txHash: string;
361
+ /** CAIP-2 chain ID of the transfer. */
362
+ chainId: string | null;
363
+ /** What it credited, in base units of the token of `methodId`. */
364
+ amount: string;
365
+ /** ID of the payment method paid with (see `listMethods`). */
366
+ methodId: string | null;
367
+ /** The addresses that sent it. */
368
+ senders: string[];
369
+ /** Block (EVM) or slot (Solana). */
370
+ blockRef: string | null;
371
+ /** When it was mined, or when it was verified if the network named no time. */
372
+ at: string;
373
+ }
374
+ /** A transaction that was tied to an invoice and did not pay it. */
375
+ interface InvoiceAttempt {
376
+ /** Transaction hash or Solana signature. */
377
+ txHash: string | null;
378
+ /** CAIP-2 chain ID of the transaction. */
379
+ chainId: string | null;
380
+ /** Why it did not pay the invoice, such as `reverted`, `no_matching_transfer` or `payer_mismatch`. */
381
+ reason: string;
382
+ /** What it carried to you without paying anything, when it did: base units of the invoice's token. */
383
+ amount: string | null;
384
+ /** The addresses that sent what it carried. */
385
+ senders: string[];
386
+ /** The held transfer it became, for a refund to its sender (see `listHeldTransfers`, which keeps its state). */
387
+ heldTransfer: string | null;
388
+ /** When it was recorded. */
389
+ at: string;
390
+ }
391
+ /** What a wallet signed to confirm an invoice. A wallet that confirms may still not be the one that pays: `InvoicePayment.senders` names who did. */
392
+ interface InvoiceWalletConfirmation {
393
+ /** The wallet, as a CAIP-10 account on the network it signed on. */
394
+ account: string;
395
+ /**
396
+ * How it confirmed: `eoa`, `eip1271` and `eip6492` signed an EIP-4361 message; `authorization` signed the EIP-3009
397
+ * authorization of a relayed payment.
398
+ */
399
+ kind: string;
400
+ /** CAIP-2 chain ID it signed on. */
401
+ chainId: string;
402
+ /** The signature. */
403
+ signature: string | null;
404
+ /** The EIP-4361 message it signed; `null` for an authorization. */
405
+ message: string | null;
406
+ /** The domain the message names. */
407
+ domain: string | null;
408
+ /** The nonce the message names. */
409
+ nonce: string | null;
410
+ /** When it was confirmed. */
411
+ at: string;
412
+ }
413
+ /**
414
+ * An invoice with its newest refunds and how many refunds and credit notes it has, as
415
+ * {@link PaymentsModule.getInvoice} returns it. It also names what happened to the money, oldest first. Every refund and correction adds a credit note, so the full lists are
416
+ * {@link PaymentsModule.listInvoiceRefunds} and {@link PaymentsModule.listInvoiceDocuments}.
417
+ */
418
+ interface InvoiceDetails extends Invoice {
419
+ /** Its five newest refunds and every refund still under way (`requested`, `submitted`), newest first. */
420
+ refunds: Refund[];
421
+ /** How many refunds it has. */
422
+ refundsTotal: number;
423
+ /** How many credit notes it has (one per correction and per refund of what the invoice still credits). */
424
+ creditNotesTotal: number;
425
+ /** Every transfer credited to it, oldest first, also through a correction: an invoice paid in parts has several. */
426
+ payments: InvoicePayment[];
427
+ /** The ten newest transactions that did not pay it, newest first; the ledger has them all. */
428
+ attempts: InvoiceAttempt[];
429
+ /** How many transactions did not pay it. */
430
+ attemptsTotal: number;
431
+ /** What the wallets that confirmed it signed, oldest first. */
432
+ walletConfirmations: InvoiceWalletConfirmation[];
433
+ }
434
+ /** An invoice with its checkout token and payment page. */
435
+ interface InvoiceWithCheckout {
436
+ /** The invoice. */
437
+ invoice: Invoice;
438
+ /** The checkout token, `null` when the invoice can no longer be paid. */
439
+ checkoutToken: string | null;
440
+ /** The payment page, `null` without a token or when the node has no dashboard URL. */
441
+ payUrl: string | null;
442
+ }
443
+ /** The answer of {@link PaymentsModule.correctInvoice}: the corrected invoice and the one it replaces. */
444
+ interface InvoiceCorrection extends InvoiceWithCheckout {
445
+ /** The invoice it replaces, now credited. */
446
+ replaced: Invoice;
447
+ }
448
+ /** What {@link PaymentsModule.correctInvoice} takes. */
449
+ interface CorrectInvoiceParams {
450
+ /** The corrected buyer; the buyer of the invoice stays when omitted. */
451
+ buyer?: Buyer;
452
+ /** The reason the credit note gives. */
453
+ reason?: string;
454
+ }
455
+ /** Filters and paging of {@link PaymentsModule.listInvoices}. */
456
+ interface ListInvoicesParams {
457
+ /** One status or several. */
458
+ status?: InvoiceStatus | InvoiceStatus[];
459
+ /** Live or test invoices. */
460
+ environment?: PaymentsEnvironment;
461
+ /** `buyer.externalId`. */
462
+ externalId?: string;
463
+ /** Created at or after. */
464
+ createdAfter?: Date | string;
465
+ /** Created before. */
466
+ createdBefore?: Date | string;
467
+ /** Page size, 1 to 100. Defaults to `20`. */
468
+ limit?: number;
469
+ /** `nextCursor` of the previous page. */
470
+ cursor?: string;
471
+ }
472
+ /**
473
+ * A page of a list, newest first.
474
+ *
475
+ * @typeParam T - Type of the items.
476
+ */
477
+ interface PaymentsList<T> {
478
+ /** Always `list`. */
479
+ object: 'list';
480
+ /** The items of the page. */
481
+ data: T[];
482
+ /** Pass it as `cursor` for the next page; `null` on the last page. */
483
+ nextCursor: string | null;
484
+ }
485
+ /** One step of an invoice ledger. Each step's `hash` covers the step and `prevHash`. */
486
+ interface LedgerEvent {
487
+ /** Event ID; webhooks of this step carry it as their `id`. */
488
+ id: string;
489
+ /** Position in the ledger, from 1. */
490
+ seq: number;
491
+ /** What happened, for example `invoice.issued`, `quote.locked`, `invoice.paid`. */
492
+ type: string;
493
+ /** Details of the step. */
494
+ data: unknown;
495
+ /** Who acted: `merchant_api`, `system`, `checkout`, `dashboard:<userId>`, `admin:<userId>`… */
496
+ actor: string;
497
+ /** Chain of an on-chain step. */
498
+ chainId: string | null;
499
+ /** Transaction of an on-chain step. */
500
+ txHash: string | null;
501
+ /** When. */
502
+ createdAt: string;
503
+ /** Hash of the previous step. */
504
+ prevHash: string | null;
505
+ /** Hash of this step. */
506
+ hash: string;
507
+ }
508
+ /** The result of checking a ledger's hash chain: intact, or where and why it breaks. */
509
+ type LedgerVerification = {
510
+ valid: true;
511
+ events: number;
512
+ } | {
513
+ valid: false;
514
+ seq: number;
515
+ reason: 'sequence' | 'link' | 'hash' | 'head';
516
+ };
517
+ /** Who created an invoice and when its payment steps happened, whatever page of its ledger is read. */
518
+ interface LedgerSummary {
519
+ /** The actor of the first step (`invoice.issued`). */
520
+ createdBy: string | null;
521
+ /** When the first quote was locked and the receipt issued (ISO 8601); `null` before. */
522
+ stepTimes: {
523
+ quoted: string | null;
524
+ receipt: string | null;
525
+ };
526
+ }
527
+ /** A page of an invoice ledger, oldest first, as {@link PaymentsModule.getEvents} returns it. */
528
+ interface InvoiceLedger {
529
+ /** Always `list`. */
530
+ object: 'list';
531
+ /** The steps of the page. */
532
+ data: LedgerEvent[];
533
+ /** How many steps the whole ledger has. */
534
+ total: number;
535
+ /** Pass it as `cursor` for the next page; `null` on the last page. */
536
+ nextCursor: string | null;
537
+ /** Who created the invoice and when its quote was locked and its receipt issued. */
538
+ summary: LedgerSummary;
539
+ /** The check of the whole chain, when asked for with `verify: true`. */
540
+ verification?: LedgerVerification;
541
+ }
542
+ /** What {@link PaymentsModule.getEvents} takes. */
543
+ interface GetEventsParams {
544
+ /** `true` adds the check of the whole hash chain, whatever the page. */
545
+ verify?: boolean;
546
+ /** Page size, 1 to 100. Defaults to `100`. */
547
+ limit?: number;
548
+ /** `nextCursor` of the previous page. */
549
+ cursor?: string;
550
+ }
551
+ /** How a refund is priced: at today's price of the invoice amount, or the whole payment as received. */
552
+ type RefundMode = 'fiat_value' | 'exact_received';
553
+ /** What {@link PaymentsModule.refund} takes. */
554
+ interface RefundParams {
555
+ /** Amount in the invoice currency; everything left when omitted. Leave it out with `exact_received`. */
556
+ amount?: string;
557
+ /** `fiat_value` (default) or `exact_received`. */
558
+ mode?: RefundMode;
559
+ /** Why; printed on the credit note. */
560
+ reason?: string;
561
+ }
562
+ /** A refund. You send it from your wallet; Quasar verifies the transaction and issues the credit note. */
563
+ interface Refund {
564
+ /** Refund ID. */
565
+ id: string;
566
+ /** Always `refund`. */
567
+ object: 'refund';
568
+ /** The invoice. */
569
+ invoiceId: string;
570
+ /** `requested` (waits for its transaction), `submitted`, `confirmed` or `failed`. */
571
+ status: 'requested' | 'submitted' | 'confirmed' | 'failed';
572
+ /** Amount in the invoice currency. */
573
+ amount: string;
574
+ /** Invoice currency. */
575
+ currency: string;
576
+ /** How it was priced. */
577
+ mode: RefundMode;
578
+ /** Token amount to send, in base units. */
579
+ cryptoAmount: string;
580
+ /** CAIP-19 asset to send. */
581
+ assetId: string;
582
+ /** CAIP-2 chain to send on. */
583
+ chainId: string;
584
+ /** The payer's address: refunds go back to it. */
585
+ to: string;
586
+ /** The refund transaction, once submitted. */
587
+ txHash: string | null;
588
+ /** The address it was sent from. */
589
+ from: string | null;
590
+ /** Why. */
591
+ reason: string | null;
592
+ /** Why it failed. */
593
+ failureReason: string | null;
594
+ /** The transaction that took the place of a cancelled one, when Quasar knows it. */
595
+ replacedBy?: string | null;
596
+ /** Its credit note, once confirmed; none for a held transfer or a payment that stayed on a corrected invoice. */
597
+ creditNoteNumber: string | null;
598
+ /** The held transfer it returns to its sender ({@link HeldTransfer}), or `null` for a refund of the invoice. */
599
+ heldTransfer: string | null;
600
+ /** When it was asked for. */
601
+ createdAt: string;
602
+ /** When it last changed; absent from an engine that does not send it yet. */
603
+ updatedAt?: string | null;
604
+ /** When it was confirmed. */
605
+ confirmedAt: string | null;
606
+ }
607
+ /** How far a {@link HeldTransfer} got: held, its refund on the way, refunded, or voided because it paid an invoice. */
608
+ type HeldTransferStatus = 'held' | 'refunding' | 'refunded' | 'voided';
609
+ /**
610
+ * A transfer that reached the address of one of your invoices without being tied to it by proof: from another wallet
611
+ * than the one the quote was for (`payer_mismatch`), from the quoted wallet that never confirmed the invoice
612
+ * (`payer_unconfirmed`), or a Solana Pay transfer without the invoice's reference whose amount alone does not tie it to
613
+ * the invoice (`reference_missing`). It paid nothing and the invoice stays as it was; refund it as a whole to the wallet
614
+ * that sent it with {@link PaymentsModule.refundHeldTransfer}. When the same transaction is proven to pay an invoice,
615
+ * Quasar voids the record (`voided`, `voidedBy`).
616
+ */
617
+ interface HeldTransfer {
618
+ /** Held transfer ID. */
619
+ id: string;
620
+ /** The invoice whose address it reached. */
621
+ invoice: string;
622
+ /** Where it is. */
623
+ status: HeldTransferStatus;
624
+ /** Why it is tied to no invoice. */
625
+ reason: 'payer_mismatch' | 'payer_unconfirmed' | 'reference_missing' | 'already_paid' | 'quote_changed' | 'too_many_parts';
626
+ /** Whether it arrived after the invoice expired or was cancelled. */
627
+ late: boolean;
628
+ /** CAIP-2 chain. */
629
+ chainId: string;
630
+ /** CAIP-19 asset it carried. */
631
+ assetId: string;
632
+ /** Symbol of the token. */
633
+ symbol: string;
634
+ /** Decimals of the token. */
635
+ decimals: number;
636
+ /** Its transaction. */
637
+ txHash: string;
638
+ /** What it carried, in base units. */
639
+ amount: string;
640
+ /** Its value at the rate of the invoice's quote, in minor units of `currency`. */
641
+ valueMinor: string | null;
642
+ /** Currency of `valueMinor`. */
643
+ currency: string | null;
644
+ /** The wallet it came from (CAIP-10): the refund goes back to it. */
645
+ sender: string;
646
+ /** Every wallet that sent it. */
647
+ senders: string[];
648
+ /** The sanctions screening of the sender: `blocked` gets no refund. */
649
+ screening: string | null;
650
+ /** The invoice it paid, once voided. */
651
+ voidedBy: string | null;
652
+ /** When Quasar recorded it. */
653
+ createdAt: string;
654
+ /** When it last changed. */
655
+ updatedAt: string;
656
+ }
657
+ /** What {@link PaymentsModule.listHeldTransfers} takes. */
658
+ interface ListHeldTransfersParams {
659
+ /** Only the held transfers of one invoice. */
660
+ invoice?: string;
661
+ /** Only those in one state; `held` for those still to refund. */
662
+ status?: HeldTransferStatus;
663
+ }
664
+ /** The answer of {@link PaymentsModule.refund}: the refund and what to send where. */
665
+ interface RefundStart {
666
+ /** The refund, `requested`. */
667
+ refund: Refund;
668
+ /** The transfer to make from your wallet, then pass its hash to {@link PaymentsModule.submitRefund}. */
669
+ instructions: {
670
+ /** CAIP-2 chain. */
671
+ chainId: string;
672
+ /** CAIP-19 asset. */
673
+ assetId: string;
674
+ /** Recipient: the payer. */
675
+ to: string | null;
676
+ /** Amount in base units. */
677
+ amount: string;
678
+ /** Decimals of the token. */
679
+ decimals: number;
680
+ /** Symbol of the token. */
681
+ symbol: string;
682
+ };
683
+ }
684
+ /**
685
+ * What a refund would send, as {@link PaymentsModule.previewRefund} returns it. A requested refund holds its amount until
686
+ * it is sent, so look before asking: the same amount in the invoice currency sends a different number of tokens once a
687
+ * volatile asset has moved.
688
+ */
689
+ interface RefundPreview {
690
+ /** The amount in the invoice currency. */
691
+ amount: string;
692
+ /** The invoice currency. */
693
+ currency: string;
694
+ /** What the refund would send now, in base units. */
695
+ cryptoAmount: string;
696
+ /** Symbol of the token. */
697
+ symbol: string;
698
+ /** Decimals of the token. */
699
+ decimals: number;
700
+ /** What the payment brought, in base units. */
701
+ received: string | null;
702
+ /** What this amount was worth in tokens at the rate of the payment, in base units; `null` for `exact_received`. */
703
+ atPaymentRate: string | null;
704
+ /** Whether `exact_received` would be taken now: it returns the whole invoice, so nothing may be refunded yet. */
705
+ exactPossible: boolean;
706
+ }
707
+ /** What {@link PaymentsModule.submitRefund} takes. */
708
+ interface SubmitRefundParams {
709
+ /** The refund transaction (hash or Solana signature). */
710
+ txHash: string;
711
+ /** Your wallet it was sent from. */
712
+ from: string;
713
+ }
714
+ /** A stored invoice document, receipt or credit note: PDF (PDF/A-3 with Factur-X when on) or UBL XML. */
715
+ type PaymentDocumentKind = 'invoice' | 'receipt' | 'invoice.xml';
716
+ /** A downloaded document, byte for byte as issued. */
717
+ interface PaymentDocument {
718
+ /** The file. */
719
+ bytes: Uint8Array;
720
+ /** Its media type, for example `application/pdf`. */
721
+ contentType: string | null;
722
+ /** Its file name, from `Content-Disposition`. */
723
+ filename: string | null;
724
+ }
725
+ /** What {@link PaymentsModule.quote} takes. */
726
+ interface QuoteParams {
727
+ /** Amount with up to two decimals (`'49.00'`). */
728
+ amount: string;
729
+ /** Currency. Defaults to `USD`. */
730
+ currency?: PaymentsCurrency;
731
+ /** The payment method. */
732
+ methodId: string;
733
+ }
734
+ /** The price of an amount in a payment method now; nothing is locked. */
735
+ interface PaymentQuote {
736
+ /** Always `quote`. */
737
+ object: 'quote';
738
+ /** The payment method. */
739
+ methodId: string;
740
+ /** Token symbol. */
741
+ symbol: string;
742
+ /** CAIP-2 chain. */
743
+ chainId: string;
744
+ /** The fiat amount. */
745
+ amount: string;
746
+ /** Its currency. */
747
+ currency: PaymentsCurrency;
748
+ /** Token amount the merchant receives, in base units. */
749
+ cryptoAmount: string;
750
+ /** Token amount the buyer sends (grossed up for a transfer fee), in base units. */
751
+ amountToSend: string;
752
+ /** The token's transfer fee, when it takes one. */
753
+ transferFee: {
754
+ bps: number;
755
+ maxFee: string | null;
756
+ source: 'contract' | 'method';
757
+ } | null;
758
+ /** Decimals of the token. */
759
+ decimals: number;
760
+ /** Markup of the method in basis points. */
761
+ markupBps: number;
762
+ /** Discount of the method in basis points. */
763
+ discountBps: number;
764
+ /** Price rounds used, as evidence. */
765
+ rates: unknown;
766
+ /** When it was priced. */
767
+ quotedAt: string;
768
+ }
769
+ /** An active payment method of the app. */
770
+ interface PaymentMethod {
771
+ /** Method ID. */
772
+ id: string;
773
+ /** Always `payment_method`. */
774
+ object: 'payment_method';
775
+ /** Its name. */
776
+ name: string;
777
+ /** Token symbol. */
778
+ symbol: string;
779
+ /** CAIP-2 chain. */
780
+ chainId: string;
781
+ /** CAIP-19 asset. */
782
+ assetId: string | null;
783
+ /** Decimals of the token. */
784
+ decimals: number;
785
+ /** The wallet that receives payments. */
786
+ recipient: string;
787
+ /** Smallest invoice total it takes. */
788
+ minAmount: string | number | null;
789
+ /** Largest invoice total it takes. */
790
+ maxAmount: string | number | null;
791
+ /** Markup in percent. */
792
+ markup: string | number | null;
793
+ /** Discount in percent. */
794
+ discount: string | number | null;
795
+ /** `off` or `auto`. */
796
+ gasless: string | null;
797
+ /** Marked "Popular" in the checkout. */
798
+ featured: boolean;
799
+ }
800
+ /** The billing period unit of a subscription. */
801
+ type SubscriptionInterval = 'day' | 'week' | 'month' | 'year';
802
+ /**
803
+ * State of a subscription: `trialing`, `incomplete` (its first or resumed period is unpaid), `active`, `past_due`,
804
+ * `paused`, `canceled`, `ended`.
805
+ */
806
+ type SubscriptionStatus = 'trialing' | 'incomplete' | 'active' | 'past_due' | 'paused' | 'canceled' | 'ended';
807
+ /** What {@link PaymentsModule.createSubscription} takes: a plan, billed every period as one invoice. */
808
+ type CreateSubscriptionParams = InvoiceLinesInput & InvoiceTermsInput & {
809
+ /** Period unit. */
810
+ interval: SubscriptionInterval;
811
+ /** Units per period; a period is at most one year. Defaults to `1`. */
812
+ intervalCount?: number;
813
+ /** Days before the first period starts. */
814
+ trialDays?: number;
815
+ /** Periods to bill, then it ends; give it or `endsAt`. */
816
+ cycles?: number;
817
+ /** When it ends. */
818
+ endsAt?: Date | string;
819
+ /** `send_invoice` (default: the buyer pays each invoice) or `auto_charge` (an ERC-7715 permission). */
820
+ collection?: 'send_invoice' | 'auto_charge';
821
+ /** The payment method to charge or offer first. */
822
+ preferredMethodId?: string;
823
+ /** Days an invoice stays payable after its period starts. */
824
+ graceDays?: number;
825
+ };
826
+ /** The automatic-charge permission a buyer granted (ERC-7715), without its context. */
827
+ interface SubscriptionPermission {
828
+ /** Whether it can still be charged. */
829
+ status: 'active' | 'revoked' | 'expired';
830
+ /** CAIP-2 chain. */
831
+ chainId: string | null;
832
+ /** The payment method. */
833
+ methodId: string | null;
834
+ /** The buyer's CAIP-10 account. */
835
+ payer: string | null;
836
+ /** The token. */
837
+ tokenAddress: string | null;
838
+ /** Amount per window, in base units. */
839
+ periodAmount: string | null;
840
+ /** Window length. */
841
+ periodSeconds: number;
842
+ /** When the first window starts. */
843
+ startsAt: string | null;
844
+ /** When it expires. */
845
+ expiresAt: string | null;
846
+ /** When it was granted. */
847
+ grantedAt: string | null;
848
+ /** When it was revoked. */
849
+ revokedAt: string | null;
850
+ }
851
+ /** A subscription as the Payments API returns it. */
852
+ interface Subscription {
853
+ /** Subscription ID. */
854
+ id: string;
855
+ /** Always `subscription`. */
856
+ object: 'subscription';
857
+ /** State. */
858
+ status: SubscriptionStatus;
859
+ /** Live or test. */
860
+ environment: PaymentsEnvironment;
861
+ /** The buyer. */
862
+ buyer: Buyer | null;
863
+ /** The CAIP-10 account you expect to pay. */
864
+ expectedPayer: string | null;
865
+ /** The plan's lines, as you sent them. */
866
+ lineItems: InvoiceLineInput[];
867
+ /** Currency. */
868
+ currency: PaymentsCurrency;
869
+ /** Period unit. */
870
+ interval: SubscriptionInterval;
871
+ /** Units per period. */
872
+ intervalCount: number;
873
+ /** Trial days. */
874
+ trialDays: number;
875
+ /** How it is collected. */
876
+ collection: 'send_invoice' | 'auto_charge';
877
+ /** The preferred payment method. */
878
+ preferredMethodId: string | null;
879
+ /** The automatic-charge permission, once granted. */
880
+ permission: SubscriptionPermission | null;
881
+ /** Grace days. */
882
+ graceDays: number;
883
+ /** The running period, from 1 (0 during a trial). */
884
+ currentPeriod: number;
885
+ /** Start of the running period. */
886
+ currentPeriodStart: string | null;
887
+ /** End of the running period. */
888
+ currentPeriodEnd: string | null;
889
+ /** Periods bought. */
890
+ cycles: number | null;
891
+ /** When it ends. */
892
+ endsAt: string | null;
893
+ /** Whether it is canceled when the running period ends. */
894
+ cancelAtPeriodEnd: boolean;
895
+ /** When it was canceled. */
896
+ canceledAt: string | null;
897
+ /** Why. */
898
+ cancellationReason: string | null;
899
+ /** When it was paused. */
900
+ pausedAt: string | null;
901
+ /** When it ended. */
902
+ endedAt: string | null;
903
+ /** Your data. */
904
+ metadata: Record<string, unknown> | null;
905
+ /** When it was created. */
906
+ createdAt: string;
907
+ }
908
+ /** An automatic charge of a subscription period. */
909
+ interface SubscriptionCharge {
910
+ /** Charge ID. */
911
+ id: string;
912
+ /** Always `subscription_charge`. */
913
+ object: 'subscription_charge';
914
+ /** The invoice it pays. */
915
+ invoiceId: string;
916
+ /** The period. */
917
+ period: number | null;
918
+ /**
919
+ * `pending` (waits for its window or a retry), `sending`, `submitted` (its transaction settles the invoice like any
920
+ * payment), `failed` or `canceled`.
921
+ */
922
+ status: 'pending' | 'sending' | 'submitted' | 'failed' | 'canceled';
923
+ /** Why it failed (a stable code). */
924
+ reason: string | null;
925
+ /** Attempts so far. */
926
+ attempts: number;
927
+ /** Amount in base units. */
928
+ amount: string | null;
929
+ /** CAIP-2 chain. */
930
+ chainId: string | null;
931
+ /** The user operation. */
932
+ userOpHash: string | null;
933
+ /** Its transaction. */
934
+ txHash: string | null;
935
+ /** Not before. */
936
+ notBefore: string | null;
937
+ /** When it finished. */
938
+ finishedAt: string | null;
939
+ /** When it was scheduled. */
940
+ createdAt: string;
941
+ }
942
+ /** Paging of {@link PaymentsModule.listSubscriptionInvoices} and {@link PaymentsModule.listSubscriptionCharges}. */
943
+ interface ListSubscriptionItemsParams {
944
+ /** Page size, 1 to 100. Defaults to `20`. */
945
+ limit?: number;
946
+ /** `nextCursor` of the previous page. */
947
+ cursor?: string;
948
+ }
949
+ /** Paging of {@link PaymentsModule.listInvoiceRefunds} and {@link PaymentsModule.listInvoiceDocuments}. */
950
+ interface ListInvoiceItemsParams {
951
+ /** Page size, 1 to 100. Defaults to `20`. */
952
+ limit?: number;
953
+ /** `nextCursor` of the previous page. */
954
+ cursor?: string;
955
+ }
956
+ /** A started or resumed subscription with the invoice of its period and that invoice's payment page. */
957
+ interface SubscriptionStart {
958
+ /** The subscription. */
959
+ subscription: Subscription;
960
+ /** The invoice of its first (or resumed) period; `null` during a trial. */
961
+ invoice: Invoice | null;
962
+ /** That invoice's checkout token. */
963
+ checkoutToken: string | null;
964
+ /** That invoice's payment page. */
965
+ payUrl: string | null;
966
+ }
967
+ /** Filters and paging of {@link PaymentsModule.listSubscriptions}. */
968
+ interface ListSubscriptionsParams {
969
+ /** One status or several. */
970
+ status?: SubscriptionStatus | SubscriptionStatus[];
971
+ /** Page size, 1 to 100. Defaults to `20`. */
972
+ limit?: number;
973
+ /** `nextCursor` of the previous page. */
974
+ cursor?: string;
975
+ }
976
+ /** What {@link PaymentsModule.cancelSubscription} takes. */
977
+ interface CancelSubscriptionParams {
978
+ /** Cancel when the running period ends instead of now. */
979
+ atPeriodEnd?: boolean;
980
+ /** Why. */
981
+ reason?: string;
982
+ }
983
+
984
+ /**
985
+ * @file Errors of the Quasar SDK: the error a failed request throws, and how an `ofetch` error becomes one.
986
+ */
987
+ /** A field of a request the API refused, and why: `path` names it with dots (`buyer.country`). */
988
+ interface QuasarRequestIssue {
989
+ /** The field, for example `buyer.country`. */
990
+ path: string;
991
+ /** Why it was refused. */
992
+ message: string;
993
+ }
994
+ /**
995
+ * Error thrown by the methods of the {@link Quasar} client when a request fails: an HTTP error status, a timeout or a
996
+ * network error. The Payments API also names the refusal with a stable `code` and, for an invalid request, the fields
997
+ * at fault (`issues`).
998
+ *
999
+ * @example
1000
+ * ```typescript
1001
+ * try {
1002
+ * await quasar.pulsar.getHistory();
1003
+ * } catch (err) {
1004
+ * if (err instanceof QuasarSDKError) {
1005
+ * console.error(err.status); // e.g. 401
1006
+ * console.error(err.message); // "[Quasar SDK] Request Failed (401): <error of the API>"
1007
+ * console.error(err.originalError); // FetchError from ofetch
1008
+ * }
1009
+ * }
1010
+ * ```
1011
+ */
1012
+ declare class QuasarSDKError extends Error {
1013
+ /** HTTP status code of the response, or `undefined` when no response was received. */
1014
+ readonly status: number | undefined;
1015
+ /** The error thrown by `ofetch`. */
1016
+ readonly originalError: Error;
1017
+ /** Stable code of the refusal, for example `invoice_not_found`; `undefined` when the API gave none. */
1018
+ readonly code: string | undefined;
1019
+ /** The fields of an invalid request and why each was refused (code `invalid_request`). */
1020
+ readonly issues: QuasarRequestIssue[] | undefined;
1021
+ /** Further fields of the refusal (for example `reason` of `auto_charge_unavailable`). */
1022
+ readonly details: Record<string, unknown> | undefined;
1023
+ /**
1024
+ * Creates the error.
1025
+ *
1026
+ * @param message - Message: `[Quasar SDK] Request Failed (<status>): <error>`, where `<error>` is the `error` field of
1027
+ * the response body or the message of the fetch error.
1028
+ * @param status - HTTP status code, or `undefined` when no response was received.
1029
+ * @param originalError - The error thrown by `ofetch`.
1030
+ * @param refusal - The code, issues and further fields of the refusal, when the API named them.
1031
+ */
1032
+ constructor(message: string, status: number | undefined, originalError: Error, refusal?: {
1033
+ code?: string;
1034
+ issues?: QuasarRequestIssue[];
1035
+ details?: Record<string, unknown>;
1036
+ });
1037
+ }
1038
+
1039
+ export { QuasarSDKError as a3 };
1040
+ export type { InvoiceWalletConfirmation as $, ListSubscriptionsParams as A, Buyer as B, CreateInvoiceParams as C, Subscription as D, ListSubscriptionItemsParams as E, SubscriptionCharge as F, GetEventsParams as G, HeldTransfer as H, InvoiceStatus as I, CancelSubscriptionParams as J, InvoiceSettlement as K, ListInvoiceItemsParams as L, InvoicePayment as M, HeldTransferStatus as N, InvoiceAml as O, PaymentsEnvironment as P, QuasarRequestIssue as Q, Refund as R, SubscriptionPermission as S, TaxCategory as T, InvoiceAttempt as U, InvoiceLine as V, InvoiceLineInput as W, InvoiceLinesInput as X, InvoiceQuote as Y, InvoiceSeller as Z, InvoiceTermsInput as _, PaymentsCurrency as a, LedgerEvent as a0, LedgerSummary as a1, LedgerVerification as a2, RefundMode as a4, InvoiceLocale as b, SubscriptionStatus as c, SubscriptionInterval as d, RefundStart as e, RefundParams as f, RefundPreview as g, SubmitRefundParams as h, CreateOptions as i, InvoiceWithCheckout as j, InvoiceDetails as k, PaymentsList as l, InvoiceDocumentRef as m, ListInvoicesParams as n, Invoice as o, CorrectInvoiceParams as p, InvoiceCorrection as q, InvoiceLedger as r, ListHeldTransfersParams as s, PaymentDocumentKind as t, PaymentDocument as u, QuoteParams as v, PaymentQuote as w, PaymentMethod as x, CreateSubscriptionParams as y, SubscriptionStart as z };