@tuwaio/payments-sdk 0.0.0-stage → 0.0.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.
- package/LICENSE +201 -0
- package/README.md +76 -2
- package/dist/OwnConnection-ET76SUMX-4JFMOO7Z.cjs +1 -0
- package/dist/OwnConnection-ET76SUMX-G7ZHJN57.js +1 -0
- package/dist/checkout-C05-kSiE.d.cts +1616 -0
- package/dist/checkout-C05-kSiE.d.ts +1616 -0
- package/dist/checkout.cjs +1 -0
- package/dist/checkout.d.cts +2 -0
- package/dist/checkout.d.ts +2 -0
- package/dist/checkout.js +1 -0
- package/dist/chunk-LB2KDA4M.js +2 -0
- package/dist/chunk-MJOZIUWN.cjs +1 -0
- package/dist/chunk-NQ26UU24.cjs +1 -0
- package/dist/chunk-TN5VGRRA.cjs +2 -0
- package/dist/chunk-UJ2TJGKY.js +1 -0
- package/dist/chunk-VTOKR3DS.js +1 -0
- package/dist/de-53SSE6O2-GWJEBBVJ.js +1 -0
- package/dist/de-53SSE6O2-SX2QT2XZ.cjs +1 -0
- package/dist/es-LP3HJ4KB-7RFRVGPQ.cjs +1 -0
- package/dist/es-LP3HJ4KB-JN7LQABB.js +1 -0
- package/dist/evm.cjs +1 -0
- package/dist/evm.d.cts +34 -0
- package/dist/evm.d.ts +34 -0
- package/dist/evm.js +1 -0
- package/dist/i18n.cjs +1 -0
- package/dist/i18n.d.cts +10 -0
- package/dist/i18n.d.ts +10 -0
- package/dist/i18n.js +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2979 -0
- package/dist/index.d.ts +2979 -0
- package/dist/index.js +2 -0
- package/dist/it-JJ5Z5EUF-2BNC5I2D.cjs +1 -0
- package/dist/it-JJ5Z5EUF-HOA77BWJ.js +1 -0
- package/dist/locales-DzMinYsr.d-DzMinYsr.d.cts +1221 -0
- package/dist/locales-DzMinYsr.d-DzMinYsr.d.ts +1221 -0
- package/dist/solana.cjs +1 -0
- package/dist/solana.d.cts +42 -0
- package/dist/solana.d.ts +42 -0
- package/dist/solana.js +1 -0
- package/dist/styles.css +1324 -0
- package/dist/types-Bp6JUt56.d-ByIsb1F7.d.cts +350 -0
- package/dist/types-Bp6JUt56.d-C5vQkYhR.d.ts +350 -0
- package/dist/uk-EI4N5BMM-5PL2AYKV.js +1 -0
- package/dist/uk-EI4N5BMM-UN76BFNO.cjs +1 -0
- package/dist/zhCN-BZBMKUUA-E7M3WG4Q.js +1 -0
- package/dist/zhCN-BZBMKUUA-VSNNE3YC.cjs +1 -0
- package/package.json +136 -3
- package/socket.json +17 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,2979 @@
|
|
|
1
|
+
import { C as CheckoutWallet, N as NativeFee, a as PaymentFamily, P as PaymentsAdapter } from './types-Bp6JUt56.d-ByIsb1F7.cjs';
|
|
2
|
+
export { b as PulsarTransactionParams, c as canPayWithQr, d as connectedWallet, f as familyOf, i as isWalletIconUrl, m as methodFamily, e as methodToken, n as networkName, p as payerFor, g as priceAdjustment, w as walletLabel } from './types-Bp6JUt56.d-ByIsb1F7.cjs';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { ComponentType, ReactNode, ButtonHTMLAttributes, Context } from 'react';
|
|
5
|
+
import { b as RefundPreview, B as Buyer } from './checkout-C05-kSiE.cjs';
|
|
6
|
+
import { RefundPhase, RefundState, CheckoutError, PaymentInstructions, CheckoutStore, CheckoutState, CheckoutView, CheckoutMethod, CheckoutQuote, PayerProofMessage, CheckoutApi, EventSourceConstructor, RefundStore, AutoChargeOffer, CheckoutPhase, CheckoutMerchant } from './checkout.cjs';
|
|
7
|
+
import { NovaPaymentsLabels, CheckoutLocale, NovaPaymentsLabelOverrides } from './i18n.cjs';
|
|
8
|
+
import { Transaction } from '@tuwaio/sdk/pulsar';
|
|
9
|
+
import { StatusTone, StatusEdgeProps } from '@tuwaio/sdk/nova-core';
|
|
10
|
+
import { TxStatusVisualProps, TxProgressIndicatorProps, HashLinkProps } from '@tuwaio/sdk/nova-transactions';
|
|
11
|
+
import { NovaConnectProviderPropsWithCustomization } from '@tuwaio/sdk/nova-connect';
|
|
12
|
+
import { SatelliteConnectProviderProps } from '@tuwaio/sdk/satellite/react';
|
|
13
|
+
export { shortAddress } from '@tuwaio/sdk/orbit';
|
|
14
|
+
import 'zustand/vanilla';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The automatic payments offer of a subscription, after a paid period: the limit the seller may take each period, the
|
|
18
|
+
* period, the paying wallet and the seller's wallet the charges are paid to, until when, that Quasar sends each charge
|
|
19
|
+
* for the seller, and how to turn it off. "Allow" takes the wallet through what it needs: to the network of the
|
|
20
|
+
* permission, from a plain account to its smart account (see `smartAccountStatus`: the offer says so first, and MetaMask
|
|
21
|
+
* asks only then), then the ERC-7715 permission, which Quasar takes (the paid outcome then says automatic payments are
|
|
22
|
+
* on); "Not now" keeps paying each invoice. Without a wallet the main button connects one.
|
|
23
|
+
*
|
|
24
|
+
* Each press is a try with a number: Cancel closes the window, and an answer the wallet gives later changes nothing on
|
|
25
|
+
* the page, except that a permission it grants still reaches Quasar. A request still open in the wallet is not asked
|
|
26
|
+
* again, so the buyer never approves two; what the wallet already granted is not asked again after a refusal of the free
|
|
27
|
+
* confirmation.
|
|
28
|
+
*
|
|
29
|
+
* Side effects: wallet prompts and, for a plain account, a transaction whose fee the buyer pays; `POST permission` of
|
|
30
|
+
* the checkout; network and wallet reads for the kind of account.
|
|
31
|
+
*
|
|
32
|
+
* @returns The automatic payments step.
|
|
33
|
+
*/
|
|
34
|
+
declare function AutoPayScreen(): react.JSX.Element | null;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The buyer details step, shown when the merchant's settings ask for the buyer and the invoice was issued without
|
|
38
|
+
* them: the email, then a company invoice on request (a card under the email), then the details — the name, the
|
|
39
|
+
* country, the address, and for a company its tax ID. The fields carry `autocomplete` tokens (WCAG 1.3.5), errors are
|
|
40
|
+
* tied to their fields and announced, and the invoice document is issued once the details are taken.
|
|
41
|
+
*
|
|
42
|
+
* @returns The buyer details step.
|
|
43
|
+
*/
|
|
44
|
+
declare function BuyerScreen(): react.JSX.Element | null;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @file What the checkout shows for the state of a checkout store: the screen, the steps, the payment methods by
|
|
48
|
+
* token, and when to count down and warn about time.
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A screen of the checkout: the steps of a payment (`buyer`, `method`, `confirmWallet` — the paying wallet confirms the
|
|
53
|
+
* invoice with a free signature before the price —, `pay` or `qr`, `confirm`, `autoPay`), a payment Quasar could not
|
|
54
|
+
* confirm (`unconfirmed`: it may still arrive, so the buyer checks the wallet before paying again) or its outcome.
|
|
55
|
+
*/
|
|
56
|
+
type CheckoutScreen = 'loading' | 'error' | 'buyer' | 'method' | 'confirmWallet' | 'pay' | 'qr' | 'confirm' | 'unconfirmed' | 'paid' | 'autoPay' | 'autoPayOff' | 'underpaid' | 'held' | 'refunded' | 'expired' | 'cancelled' | 'replaced' | 'blocked';
|
|
57
|
+
/** Choices of the buyer that the checkout store does not hold. */
|
|
58
|
+
interface CheckoutScreenChoices {
|
|
59
|
+
/** Pay from a wallet in this browser (default) or scan a QR code with a phone. */
|
|
60
|
+
payWith?: 'wallet' | 'qr';
|
|
61
|
+
/** The buyer opened the automatic payments offer after paying the first period of a subscription. */
|
|
62
|
+
autoPay?: boolean;
|
|
63
|
+
/** The buyer opened the screen that turns automatic payments off, while they are on. */
|
|
64
|
+
autoPayOff?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The buyer continues on a phone: with `payWith` `qr`, the QR code of the payment page shows before any price is
|
|
67
|
+
* locked (an EVM method, paid from the phone's wallet on that page).
|
|
68
|
+
*/
|
|
69
|
+
handoff?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The labels of the invoice's language are loaded (default `true`). Until then the checkout stays on `loading`, so
|
|
72
|
+
* its first screen never shows in English before the buyer's language arrives.
|
|
73
|
+
*/
|
|
74
|
+
labelsReady?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* The buyer continued with a wallet that must confirm the invoice before the price (`payerProof` of the checkout
|
|
77
|
+
* store is `required`): the step that confirms it shows while the store waits for the signature and locks the price
|
|
78
|
+
* after it.
|
|
79
|
+
*/
|
|
80
|
+
confirmWallet?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Whether the permission screen can open from this phase: another wallet takes over a permission from the steps before a
|
|
84
|
+
* payment, not from an outcome that keeps its own screen.
|
|
85
|
+
*
|
|
86
|
+
* @param phase - The phase of the checkout store.
|
|
87
|
+
* @returns Whether "Use this wallet" leads somewhere.
|
|
88
|
+
*/
|
|
89
|
+
declare const takeOverOpens: (phase: string | undefined) => boolean;
|
|
90
|
+
/**
|
|
91
|
+
* The screen for the state of a checkout store.
|
|
92
|
+
*
|
|
93
|
+
* @param state - The `phase`, `checkout` and `quote` of the store.
|
|
94
|
+
* @param state.phase - Where the payment stands.
|
|
95
|
+
* @param state.checkout - What the checkout token opens; `null` until loaded.
|
|
96
|
+
* @param state.quote - The locked price; while the first one is being locked the method screen stays, with its button
|
|
97
|
+
* busy, so a refused payer or a failed request is shown where the buyer chose (the step that confirms the wallet, when
|
|
98
|
+
* the price is locked after it).
|
|
99
|
+
* @param state.payerProof - Whether the connected wallet must confirm the invoice (`payerProof` of the checkout store;
|
|
100
|
+
* left out by older stores).
|
|
101
|
+
* @param state.error - The store's last error: a price refused after the signature shows on the method step.
|
|
102
|
+
* @param choices - What the buyer chose on the page.
|
|
103
|
+
* @returns The screen: `confirmWallet` once the buyer continued (`choices.confirmWallet`) while the wallet must
|
|
104
|
+
* confirm the invoice or confirms it, and after it until the price is locked (unless it was refused), also on an
|
|
105
|
+
* underpaid invoice whose rest another wallet pays, `qr` instead of `pay` when the buyer pays
|
|
106
|
+
* with a QR code (or the price was locked without a payer), `replaced` for an invoice the seller
|
|
107
|
+
* corrected, `autoPay` after a paid subscription period while the automatic payments offer is open, `loading` until
|
|
108
|
+
* the labels of the invoice's language are loaded, `unconfirmed` in the phase of that name of a current
|
|
109
|
+
* `@tuwaio/quasar-sdk` (Quasar could not confirm the payment, which may still arrive). While the store hands a transaction
|
|
110
|
+
* over again (`submit_retrying`) it is `confirm`: only Quasar is out of reach, and the payment goes on.
|
|
111
|
+
*/
|
|
112
|
+
declare function checkoutScreen(state: {
|
|
113
|
+
phase: CheckoutPhase;
|
|
114
|
+
checkout: CheckoutView | null;
|
|
115
|
+
quote?: CheckoutQuote | null;
|
|
116
|
+
readonly payerProof?: string;
|
|
117
|
+
error?: CheckoutError | null;
|
|
118
|
+
}, choices?: CheckoutScreenChoices): CheckoutScreen;
|
|
119
|
+
/** A step of the stepper in the checkout header. */
|
|
120
|
+
interface CheckoutStep {
|
|
121
|
+
/** `details` (buyer details), `method`, `pay`, `confirm`, `autoPay` (automatic payments of a subscription). */
|
|
122
|
+
key: 'details' | 'method' | 'pay' | 'confirm' | 'autoPay';
|
|
123
|
+
/** Before, at or after the current step. */
|
|
124
|
+
state: 'done' | 'current' | 'upcoming';
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The steps of the stepper for a screen.
|
|
128
|
+
*
|
|
129
|
+
* @param screen - The current screen.
|
|
130
|
+
* @param options - Steps that apply to this invoice.
|
|
131
|
+
* @param options.withDetails - The checkout asked for the buyer details first.
|
|
132
|
+
* @returns The steps, or `null` on an outcome screen, whose header shows its title instead.
|
|
133
|
+
*/
|
|
134
|
+
declare function checkoutSteps(screen: CheckoutScreen, options?: {
|
|
135
|
+
withDetails?: boolean;
|
|
136
|
+
}): CheckoutStep[] | null;
|
|
137
|
+
/**
|
|
138
|
+
* The steps of the stepper on the paid screen of a payment page, all done. Elsewhere that screen has no stepper
|
|
139
|
+
* ({@link checkoutSteps}).
|
|
140
|
+
*
|
|
141
|
+
* @param options - Steps that apply to this invoice.
|
|
142
|
+
* @param options.withDetails - The checkout asked for the buyer details first.
|
|
143
|
+
* @returns The steps.
|
|
144
|
+
*/
|
|
145
|
+
declare function paidSteps(options?: {
|
|
146
|
+
withDetails?: boolean;
|
|
147
|
+
}): CheckoutStep[];
|
|
148
|
+
/** The methods of one token, as the method step shows it: the token first, then its network. */
|
|
149
|
+
interface CheckoutTokenGroup {
|
|
150
|
+
/** Token symbol. */
|
|
151
|
+
symbol: string;
|
|
152
|
+
/** Its methods, one per network: the connected wallet's network first, then the Popular ones. */
|
|
153
|
+
methods: CheckoutMethod[];
|
|
154
|
+
/** The merchant marks one of its methods Popular. */
|
|
155
|
+
featured: boolean;
|
|
156
|
+
/** One of its methods is on the network of the connected wallet. */
|
|
157
|
+
inWallet: boolean;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Groups payment methods by token: the token picked first, then its network. Groups with a
|
|
161
|
+
* method on the connected wallet's network come first, then those the merchant marks Popular; otherwise the
|
|
162
|
+
* merchant's order stays.
|
|
163
|
+
*
|
|
164
|
+
* @param methods - The methods of the checkout, in the merchant's order.
|
|
165
|
+
* @param walletChainId - CAIP-2 chain of the connected wallet, if any.
|
|
166
|
+
* @returns The groups.
|
|
167
|
+
*/
|
|
168
|
+
declare function groupMethodsByToken(methods: CheckoutMethod[], walletChainId?: string | null): CheckoutTokenGroup[];
|
|
169
|
+
/**
|
|
170
|
+
* Where the invoice deadline stands for the checkout: the countdown shows through every step of the payment, also while
|
|
171
|
+
* the wallet signs, the payment is handed to Quasar and it confirms, and on a payer the wallet check refused
|
|
172
|
+
* (`blocked`, where the buyer can pay with another wallet); it ends with the paid outcome and with the outcomes in which
|
|
173
|
+
* a deadline means nothing. A payment sent before the deadline counts: Quasar keeps an `open` or `underpaid` invoice
|
|
174
|
+
* while a payment it learned of before the deadline confirms (for a limited time), and holds a payment that lands after
|
|
175
|
+
* the invoice closed for the seller to accept or return.
|
|
176
|
+
*
|
|
177
|
+
* @param status - The invoice state (`checkout.invoice.status`).
|
|
178
|
+
* @param screen - The screen shown.
|
|
179
|
+
* @param restPayable - Whether the rest of an underpaid invoice can be paid (`invoice.restPayable`).
|
|
180
|
+
* @returns `paying` while the buyer can still pay (the countdown shows and screen readers hear the minutes left),
|
|
181
|
+
* `confirming` while the payment is on its way (the countdown shows; at zero the confirm step says that the payment
|
|
182
|
+
* sent in time is being confirmed) and while Quasar could not confirm it (`unconfirmed`: the buyer checks the wallet
|
|
183
|
+
* before paying again, so no minutes left to pay are announced), or `null` once the payment succeeded (`paid`,
|
|
184
|
+
* `autoPay`), on the outcomes in
|
|
185
|
+
* which a deadline means nothing (`held`, `refunded`, `expired`, `cancelled`, `replaced`) and for an invoice that can
|
|
186
|
+
* no longer be paid. `closed` while part of an underpaid invoice arrived and its rest cannot be paid: the countdown still
|
|
187
|
+
* shows, as the time after which the seller can refund, and no minutes left to pay are announced.
|
|
188
|
+
*/
|
|
189
|
+
declare function deadlineState(status: string, screen: CheckoutScreen, restPayable?: boolean): 'paying' | 'confirming' | 'closed' | null;
|
|
190
|
+
/** Minutes before the invoice deadline at which screen readers hear how much time is left. */
|
|
191
|
+
declare const DEADLINE_ANNOUNCEMENTS: readonly [10, 5, 1];
|
|
192
|
+
/**
|
|
193
|
+
* Whether a tick of the invoice countdown crossed one of the announcement minutes ({@link DEADLINE_ANNOUNCEMENTS} by
|
|
194
|
+
* default): the checkout announces the time left then (WCAG 2.2.1), not every second.
|
|
195
|
+
*
|
|
196
|
+
* @param previousMs - Time left at the previous tick; `null` on the first one.
|
|
197
|
+
* @param ms - Time left now.
|
|
198
|
+
* @param announcements - The minutes before the deadline to announce at.
|
|
199
|
+
* @returns The minutes to announce (the nearest when several were crossed at once), or `null`.
|
|
200
|
+
*/
|
|
201
|
+
declare function deadlineAnnouncement(previousMs: number | null, ms: number, announcements?: readonly number[]): number | null;
|
|
202
|
+
/** How long before a locked price ends the checkout offers to keep it (WCAG 2.2.1: 20 seconds at least). */
|
|
203
|
+
declare const QUOTE_WARNING_MS = 60000;
|
|
204
|
+
/**
|
|
205
|
+
* What the active wallet changing does to a locked price. A wallet connected to turn automatic payments off pays
|
|
206
|
+
* nothing, so it changes nothing while that screen is open; back on the payment, what follows applies.
|
|
207
|
+
*
|
|
208
|
+
* @param params - What the change happens over.
|
|
209
|
+
* @param params.autoPayOffOpen - The screen that turns automatic payments off is open.
|
|
210
|
+
* @param params.phase - The phase of the payment; a price is locked only in `awaitingPayment`.
|
|
211
|
+
* @param params.quotePayer - The payer the price is locked for.
|
|
212
|
+
* @param params.payer - The payer the active wallet gives for the method of that price, or `null`.
|
|
213
|
+
* @returns `keep`: nothing changes; `lock`: lock the price again for `payer`; `release`: release it, back to the methods.
|
|
214
|
+
*/
|
|
215
|
+
declare function lockedPriceOnWallet(params: {
|
|
216
|
+
autoPayOffOpen: boolean;
|
|
217
|
+
phase: string;
|
|
218
|
+
quotePayer: string | null | undefined;
|
|
219
|
+
payer: string | null;
|
|
220
|
+
}): 'keep' | 'lock' | 'release';
|
|
221
|
+
/**
|
|
222
|
+
* What the active wallet changing does on the step that confirms the wallet, where no new price is locked yet: the step
|
|
223
|
+
* asks the wallet connected to sign, never the one the store last held.
|
|
224
|
+
*
|
|
225
|
+
* @param params - What the change happens over.
|
|
226
|
+
* @param params.open - The step shows.
|
|
227
|
+
* @param params.storePayer - The payer the store holds, which the step would ask to sign for.
|
|
228
|
+
* @param params.payer - The payer the active wallet gives for the chosen method, or `null`.
|
|
229
|
+
* @param params.paysRest - That wallet may pay: only the first wallet pays the rest of an underpaid invoice.
|
|
230
|
+
* @returns `keep`: nothing changes; `follow`: this wallet signs, or goes on to the price if it confirmed already; `leave`:
|
|
231
|
+
* the step closes, with no wallet to ask.
|
|
232
|
+
*/
|
|
233
|
+
declare function walletOnConfirmStep(params: {
|
|
234
|
+
open: boolean;
|
|
235
|
+
storePayer: string | null;
|
|
236
|
+
payer: string | null;
|
|
237
|
+
paysRest: boolean;
|
|
238
|
+
}): 'keep' | 'follow' | 'leave';
|
|
239
|
+
/**
|
|
240
|
+
* Whether a locked price is in its last minute, when the checkout offers to keep it.
|
|
241
|
+
*
|
|
242
|
+
* @param ms - Time left of the price lock.
|
|
243
|
+
* @returns `true` from {@link QUOTE_WARNING_MS} down to the end.
|
|
244
|
+
*/
|
|
245
|
+
declare function isQuoteEnding(ms: number): boolean;
|
|
246
|
+
/**
|
|
247
|
+
* Whether the merchant checks paying wallets before payment: `amlScreening` of the checkout, `true` when its AML mode
|
|
248
|
+
* is `block` or `flag`. The pay step says so only then. A checkout of a Quasar version without the field counts as
|
|
249
|
+
* checking, as the pay step always said before.
|
|
250
|
+
*
|
|
251
|
+
* @param checkout - What the checkout token opens.
|
|
252
|
+
* @returns `false` only when the checkout says that the merchant does not check paying wallets.
|
|
253
|
+
*/
|
|
254
|
+
declare function screensPayingWallets(checkout: CheckoutView): boolean;
|
|
255
|
+
/**
|
|
256
|
+
* Whether a payment this page handed over is on its way: `paymentOnTheWay` of the checkout store of a current
|
|
257
|
+
* `@tuwaio/quasar-sdk` (`true` from a successful submit or relay, also a relay answered `sending`, which has no
|
|
258
|
+
* transaction key, until the payment settles or fails), else, with an older store without the field, whether the page
|
|
259
|
+
* handed over a transaction (`txKey` or `txHash`).
|
|
260
|
+
*
|
|
261
|
+
* @param state - The state of the checkout store.
|
|
262
|
+
* @param state.paymentOnTheWay - What the store says, when it has the field.
|
|
263
|
+
* @param state.txKey - The transaction this page submitted.
|
|
264
|
+
* @param state.txHash - The transaction of the payment, once known.
|
|
265
|
+
* @param state.error - The store's error, which names a transaction of its own when its nonce is unexplained.
|
|
266
|
+
* @returns Whether a payment of this page may still arrive.
|
|
267
|
+
*/
|
|
268
|
+
declare function isPaymentOnTheWay(state: Pick<CheckoutState, 'txKey' | 'txHash'> & {
|
|
269
|
+
readonly paymentOnTheWay?: boolean;
|
|
270
|
+
}): boolean;
|
|
271
|
+
/**
|
|
272
|
+
* Whether Quasar reports a payment of the invoice on its way, whoever handed it over (another tab, the page before it
|
|
273
|
+
* was reloaded, a Solana Pay transfer Quasar found): `invoicePaymentOnTheWay` of the checkout store of a current
|
|
274
|
+
* `@tuwaio/quasar-sdk`, else, with an older store without the field, the `pendingPayments` of the checkout it read.
|
|
275
|
+
*
|
|
276
|
+
* @param state - The state of the checkout store.
|
|
277
|
+
* @param state.invoicePaymentOnTheWay - What the store says, when it has the field.
|
|
278
|
+
* @param checkout - What the checkout token opens; `null` until loaded.
|
|
279
|
+
* @returns Whether a payment of the invoice may still arrive.
|
|
280
|
+
*/
|
|
281
|
+
declare function isInvoicePaymentOnTheWay(state: object & {
|
|
282
|
+
readonly invoicePaymentOnTheWay?: boolean;
|
|
283
|
+
}, checkout: CheckoutView | null): boolean;
|
|
284
|
+
/** What {@link sentBeforeDeadline} decides with. */
|
|
285
|
+
interface SentBeforeDeadlineParams {
|
|
286
|
+
/**
|
|
287
|
+
* The state of the checkout store: `paymentCountsUntil`, `paymentSentInTime` and `paymentOnTheWay` of a current
|
|
288
|
+
* `@tuwaio/quasar-sdk` (`txKey`/`txHash` with an older one).
|
|
289
|
+
*/
|
|
290
|
+
state: object & {
|
|
291
|
+
readonly paymentCountsUntil?: string | null;
|
|
292
|
+
readonly paymentSentInTime?: boolean | null;
|
|
293
|
+
readonly paymentOnTheWay?: boolean;
|
|
294
|
+
readonly txKey?: string | null;
|
|
295
|
+
readonly txHash?: string | null;
|
|
296
|
+
};
|
|
297
|
+
/** The checkout: its invoice's `paymentCountsUntil` tells whether Quasar reports it, and is read with an older store. */
|
|
298
|
+
checkout: CheckoutView;
|
|
299
|
+
/** When this page handed its payment over, by its clock; `null` when it does not know (a reload, another tab). */
|
|
300
|
+
handedOverAt: number | null;
|
|
301
|
+
/** The invoice deadline (`dueAt`) in milliseconds. */
|
|
302
|
+
dueAt: number;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Whether the payment on its way counts as sent before the invoice deadline. For a payment this page handed over that
|
|
306
|
+
* Quasar already reported on, Quasar's word on that payment decides (`paymentSentInTime` of the checkout store: its keys
|
|
307
|
+
* are among the `onTimeTxKeys` Quasar learned of before `dueAt`), whatever the clock of the page says. Otherwise Quasar
|
|
308
|
+
* says it for the invoice with `paymentCountsUntil` (it learned of a payment of the invoice before `dueAt` and waits for
|
|
309
|
+
* it): its word decides, except for a payment this page handed over at or after the deadline by its clock, which Quasar
|
|
310
|
+
* holds even while it waits for another one. A Quasar that does not report the field leaves the clock of the page: a
|
|
311
|
+
* payment this page handed over before the deadline.
|
|
312
|
+
*
|
|
313
|
+
* @param params - See {@link SentBeforeDeadlineParams}.
|
|
314
|
+
* @returns `true` to say that the payment was sent in time and is being confirmed.
|
|
315
|
+
*/
|
|
316
|
+
declare function sentBeforeDeadline({ state, checkout, handedOverAt, dueAt }: SentBeforeDeadlineParams): boolean;
|
|
317
|
+
/**
|
|
318
|
+
* Whether the last error says that the payment can never pay the invoice: `payment_failed` (reverted, cancelled…) or
|
|
319
|
+
* `payment_mismatch` (it does not pay the invoice: a wrong amount or recipient…), with the reason Quasar gave. A failure
|
|
320
|
+
* without a reason comes from a Quasar or a `@tuwaio/quasar-sdk` that cannot tell a final failure from a payment that
|
|
321
|
+
* may still arrive, so it does not count, nor does `settlement_failed` (a payment the network confirmed that Quasar has
|
|
322
|
+
* not recorded yet, which an older store reports as `payment_mismatch`).
|
|
323
|
+
*
|
|
324
|
+
* @param error - The store's error.
|
|
325
|
+
* @returns `true` when the payment failed for good.
|
|
326
|
+
*/
|
|
327
|
+
declare function isFinalPaymentFailure(error: CheckoutError | null | undefined): boolean;
|
|
328
|
+
/**
|
|
329
|
+
* Whether the last error says that the transaction succeeded on chain but does not pay the invoice (a wrong amount,
|
|
330
|
+
* asset or recipient, no Solana Pay reference, sent before the price was locked…): `payment_mismatch` of a current
|
|
331
|
+
* `@tuwaio/quasar-sdk`, or `payment_failed` with such a reason from an older one. It may have moved money, so the
|
|
332
|
+
* checkout never says that it did not go through or that nothing was charged: it says that the transaction does not pay
|
|
333
|
+
* the invoice, and to contact the seller if money left the wallet. A payment the network confirmed that Quasar has not
|
|
334
|
+
* recorded yet (`settlement_failed`, which an older store reports as `payment_mismatch`) is not one: it pays the
|
|
335
|
+
* invoice once Quasar records it.
|
|
336
|
+
*
|
|
337
|
+
* @param error - The store's error.
|
|
338
|
+
* @returns `true` for a transaction that does not pay the invoice.
|
|
339
|
+
*/
|
|
340
|
+
declare function isMovedMoneyFailure(error: CheckoutError | null | undefined): boolean;
|
|
341
|
+
/**
|
|
342
|
+
* Whether the last error says that Quasar credited the transaction to another invoice of the seller, the one the
|
|
343
|
+
* wallet that sent it confirmed or whose mark it carries (`tx_already_used` of a transaction that does not pay this
|
|
344
|
+
* invoice): the buyer names it to the seller if it was the payment of this invoice.
|
|
345
|
+
*
|
|
346
|
+
* @param error - The store's error.
|
|
347
|
+
* @returns `true` for a transaction that pays another invoice.
|
|
348
|
+
*/
|
|
349
|
+
declare function isPaidElsewhere(error: CheckoutError | null | undefined): boolean;
|
|
350
|
+
/**
|
|
351
|
+
* Whether Quasar reports a payment of the invoice that may still arrive, with no time limit (one stuck past the minutes
|
|
352
|
+
* `pendingPayments` counts, or one whose result Quasar did not see and reads again for 24 hours):
|
|
353
|
+
* `invoicePaymentUnresolved` of the checkout store of a current `@tuwaio/quasar-sdk`, else the `unresolvedPayments` of
|
|
354
|
+
* the checkout it read. While it is `true` the checkout never says that nothing was charged.
|
|
355
|
+
*
|
|
356
|
+
* @param state - The state of the checkout store.
|
|
357
|
+
* @param state.invoicePaymentUnresolved - What the store says, when it has the field.
|
|
358
|
+
* @param checkout - What the checkout token opens; `null` until loaded.
|
|
359
|
+
* @returns Whether a payment of the invoice may still arrive.
|
|
360
|
+
*/
|
|
361
|
+
declare function isInvoicePaymentUnresolved(state: object & {
|
|
362
|
+
readonly invoicePaymentUnresolved?: boolean;
|
|
363
|
+
}, checkout: CheckoutView | null): boolean;
|
|
364
|
+
/**
|
|
365
|
+
* What the checkout tells the buyer about a payment that may have left the wallet and that Quasar did not confirm:
|
|
366
|
+
* `rechecked` (Quasar still reads it again, for up to 24 hours after it learned of it, and records it for the seller if
|
|
367
|
+
* it arrives), `retrying` (the checkout store keeps handing over a transaction the wallet sent, which Quasar has not
|
|
368
|
+
* received yet: keep the page open), `notReceived` (the store gave up handing it over after an hour: Quasar never
|
|
369
|
+
* received it), `contact` (a reason Quasar never reads again: a relay operation lost, `transaction_failed`, a Quasar
|
|
370
|
+
* or a store that does not say), `closed` (Quasar saw no result on chain within 24 hours and closed it),
|
|
371
|
+
* `takenElsewhere` (the page of another invoice handed the transaction over first: Quasar credits it to the invoice
|
|
372
|
+
* that the wallet that sent it confirmed, and the page shows the result while it follows the payment),
|
|
373
|
+
* `settlementRetrying` (the network confirmed it, but Quasar has not recorded it yet and settles it again daily, for 30
|
|
374
|
+
* days after it learned of it: `rechecked`), `settlementFailed` (the same, without Quasar saying that it still
|
|
375
|
+
* tries) and `invoiceFull` (the invoice takes no more payments: Quasar keeps the hash for the seller and follows nothing). For all but `rechecked` and `retrying` the buyer contacts the seller with the transaction hash; after
|
|
376
|
+
* `takenElsewhere`, `settlementRetrying` and `settlementFailed` the payment left the wallet, so the checkout offers no
|
|
377
|
+
* payment.
|
|
378
|
+
*/
|
|
379
|
+
type UnconfirmedFollowUp = 'nonceSpent' | 'unmined' | 'rechecked' | 'retrying' | 'notReceived' | 'contact' | 'closed' | 'takenElsewhere' | 'settlementRetrying' | 'settlementFailed' | 'invoiceFull';
|
|
380
|
+
/**
|
|
381
|
+
* What to tell the buyer about a payment Quasar did not confirm, from the store's error: `payment_unconfirmed` with
|
|
382
|
+
* `rechecked` (set by a current `@tuwaio/quasar-sdk` only while Quasar reads the payment again) promises the 24-hour
|
|
383
|
+
* re-check, its `submit_retrying` and `submit_failed` reasons are the store's hand-over, `tx_already_used` a transaction
|
|
384
|
+
* another invoice handed over first, any other is for the seller; `payment_failed` with the reason
|
|
385
|
+
* `unresolved_after_24h` is a payment Quasar closed without a result; the reason `settlement_failed` (`payment_mismatch`
|
|
386
|
+
* of an older store) a confirmed payment Quasar has not recorded yet, which Quasar settles again daily only while
|
|
387
|
+
* `rechecked` (for 30 days after it learned of it).
|
|
388
|
+
*
|
|
389
|
+
* @param error - The store's error.
|
|
390
|
+
* @returns See {@link UnconfirmedFollowUp}; `null` for any other error, or none.
|
|
391
|
+
*/
|
|
392
|
+
declare function unconfirmedFollowUp(error: CheckoutError | null | undefined): UnconfirmedFollowUp | null;
|
|
393
|
+
/**
|
|
394
|
+
* The transaction the buyer names to the seller about a payment Quasar did not confirm: the one this page handed over
|
|
395
|
+
* (`txHash`, else `txKey` of the checkout store), else, on a reopened page, the newest one Quasar rejected.
|
|
396
|
+
*
|
|
397
|
+
* @param state - The state of the checkout store.
|
|
398
|
+
* @param state.txKey - The transaction this page submitted.
|
|
399
|
+
* @param state.txHash - The transaction of the payment, once known.
|
|
400
|
+
* @param checkout - What the checkout token opens; `null` until loaded.
|
|
401
|
+
* @returns The transaction hash (EVM) or signature (Solana), or `null` when the page does not know it.
|
|
402
|
+
*/
|
|
403
|
+
declare function unconfirmedTxKey(state: Pick<CheckoutState, 'txKey' | 'txHash'> & {
|
|
404
|
+
error?: object | null;
|
|
405
|
+
}, checkout: CheckoutView | null): string | null;
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* @file Handing a payment the wallet sent over to the app's Pulsar store when the checkout closes before Quasar
|
|
409
|
+
* settled it: Pulsar keeps tracking it, and Nova Transactions shows its toast.
|
|
410
|
+
*/
|
|
411
|
+
|
|
412
|
+
/** A payment the wallet sent, as the checkout remembers it until Quasar settles it. */
|
|
413
|
+
interface SentPayment {
|
|
414
|
+
/** The transaction hash (EVM) or signature (Solana). */
|
|
415
|
+
txKey: string;
|
|
416
|
+
/** What the wallet sent. */
|
|
417
|
+
instructions: PaymentInstructions;
|
|
418
|
+
/** The sender. */
|
|
419
|
+
account: string;
|
|
420
|
+
/** The connector of the wallet. */
|
|
421
|
+
connectorType: string;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* The part of the app's Pulsar store (`createPulsarStore` of `@tuwaio/pulsar-core`) the checkout uses: pass
|
|
425
|
+
* `injectExternalPendingTxs` of the store, as `pulsar` of `NovaPaymentsProvider`.
|
|
426
|
+
*/
|
|
427
|
+
interface PaymentsPulsar {
|
|
428
|
+
/**
|
|
429
|
+
* Adds pending transactions to the pool and tracks them.
|
|
430
|
+
*
|
|
431
|
+
* @param transactions - The pending transactions.
|
|
432
|
+
* @returns Resolves when their trackers started.
|
|
433
|
+
*/
|
|
434
|
+
injectExternalPendingTxs(transactions: Transaction[]): Promise<void>;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Whether a sent payment still needs tracking when the checkout closes: Quasar has not settled it, and it did not
|
|
438
|
+
* fail on-chain or turn out not to pay the invoice.
|
|
439
|
+
*
|
|
440
|
+
* @param state - The `phase` and `error` of the checkout store.
|
|
441
|
+
* @param state.phase - Where the payment stands.
|
|
442
|
+
* @param state.error - The last failure; `payment_failed` means the transaction failed on-chain, `payment_mismatch`
|
|
443
|
+
* that it succeeded without paying the invoice: Quasar already has the final word on both.
|
|
444
|
+
* @returns `true` to hand it over.
|
|
445
|
+
*/
|
|
446
|
+
declare function shouldHandOver(state: {
|
|
447
|
+
phase: CheckoutPhase;
|
|
448
|
+
error: CheckoutError | null;
|
|
449
|
+
}): boolean;
|
|
450
|
+
/** What {@link handOverPayment} needs. */
|
|
451
|
+
interface HandOverParams {
|
|
452
|
+
/** The adapter of the payment's chain family. */
|
|
453
|
+
adapter: PaymentsAdapter | undefined;
|
|
454
|
+
/** The app's Pulsar store, if any. */
|
|
455
|
+
pulsar: PaymentsPulsar | undefined;
|
|
456
|
+
/** The sent payment. */
|
|
457
|
+
payment: SentPayment;
|
|
458
|
+
/** The labels of the checkout language. */
|
|
459
|
+
labels: NovaPaymentsLabels;
|
|
460
|
+
/** The seller's name. */
|
|
461
|
+
merchant: string;
|
|
462
|
+
/** The invoice: its ID and number (`null` before its document is issued). */
|
|
463
|
+
invoice: {
|
|
464
|
+
id: string;
|
|
465
|
+
number: string | null;
|
|
466
|
+
};
|
|
467
|
+
/** The amount sent, with its symbol. */
|
|
468
|
+
amount: string;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Hands a sent payment over to the app's Pulsar store as a pending transaction: Pulsar tracks it and keeps it in the
|
|
472
|
+
* history, and Nova Transactions shows its toast. Without a Pulsar store, or an adapter that describes its
|
|
473
|
+
* transactions, nothing happens.
|
|
474
|
+
*
|
|
475
|
+
* Side effects: writes the transaction to the Pulsar store (persisted to `localStorage` by `createPulsarStore`) and
|
|
476
|
+
* starts its tracker (network reads).
|
|
477
|
+
*
|
|
478
|
+
* @param params - See {@link HandOverParams}.
|
|
479
|
+
* @returns Whether the payment was handed over.
|
|
480
|
+
*/
|
|
481
|
+
declare function handOverPayment({ adapter, pulsar, payment, labels, merchant, invoice, amount, }: HandOverParams): Promise<boolean>;
|
|
482
|
+
|
|
483
|
+
/** Props of {@link CheckoutHeader}. */
|
|
484
|
+
interface CheckoutHeaderProps {
|
|
485
|
+
/** The heading of an outcome screen, shown instead of the steps. */
|
|
486
|
+
title?: ReactNode;
|
|
487
|
+
/** The checkout asked for the buyer details first: the steps start with them. */
|
|
488
|
+
withDetails?: boolean;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* The header of the checkout: the steps (or the heading of an outcome), then the language menu and the close button,
|
|
492
|
+
* which stay in the top right corner on every screen and on a phone. On a phone the steps move under the order and
|
|
493
|
+
* the header shows the merchant.
|
|
494
|
+
*
|
|
495
|
+
* @param props - See {@link CheckoutHeaderProps}.
|
|
496
|
+
* @returns The header.
|
|
497
|
+
*/
|
|
498
|
+
declare function CheckoutHeader({ title, withDetails }: CheckoutHeaderProps): react.JSX.Element;
|
|
499
|
+
/** The steps on a phone, under the order. @internal */
|
|
500
|
+
declare function MobileSteps({ withDetails }: {
|
|
501
|
+
withDetails?: boolean;
|
|
502
|
+
}): react.JSX.Element | null;
|
|
503
|
+
|
|
504
|
+
/** Props of {@link CheckoutStepper}. */
|
|
505
|
+
interface CheckoutStepperProps {
|
|
506
|
+
/** The steps, from `checkoutSteps`. */
|
|
507
|
+
steps: CheckoutStep[];
|
|
508
|
+
/** The labels of the checkout language. */
|
|
509
|
+
labels: NovaPaymentsLabels;
|
|
510
|
+
/** Classes added to the list. */
|
|
511
|
+
className?: string;
|
|
512
|
+
/**
|
|
513
|
+
* Classes added to a step (`customization.classNames.step` of `PaymentCheckout`).
|
|
514
|
+
*
|
|
515
|
+
* @param step - The step.
|
|
516
|
+
* @param index - Its position, from 0.
|
|
517
|
+
* @returns The classes, or nothing.
|
|
518
|
+
*/
|
|
519
|
+
stepClassName?: (step: CheckoutStep, index: number) => string | undefined;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* The steps of the payment, as an ordered list: done steps show a check, the current one is marked
|
|
523
|
+
* `aria-current="step"` and named "Step 2 of 3: Pay" to screen readers (WCAG 1.3.1). When the names of all steps do not
|
|
524
|
+
* fit (a phone, a long language), only the current step shows its name; screen readers still read every name.
|
|
525
|
+
*
|
|
526
|
+
* @param props - See {@link CheckoutStepperProps}.
|
|
527
|
+
* @returns The stepper.
|
|
528
|
+
*/
|
|
529
|
+
declare function CheckoutStepper({ steps, labels, className, stepClassName }: CheckoutStepperProps): react.JSX.Element;
|
|
530
|
+
|
|
531
|
+
/** The outcomes this screen shows. */
|
|
532
|
+
type OutcomeKind = Extract<CheckoutScreen, 'unconfirmed' | 'underpaid' | 'held' | 'refunded' | 'expired' | 'cancelled' | 'replaced' | 'blocked'>;
|
|
533
|
+
/**
|
|
534
|
+
* An outcome other than paid: a payment Quasar could not confirm (`unconfirmed`: it may still arrive, so the buyer
|
|
535
|
+
* checks the wallet before paying again; only while Quasar still reads it again, `error.rechecked` of the checkout
|
|
536
|
+
* store, the screen says that Quasar checks it for 24 hours and records it for the seller if it arrives; while the
|
|
537
|
+
* store hands a transaction the wallet sent over again, the buyer keeps the page open; otherwise (a reason Quasar never
|
|
538
|
+
* reads again, a hand-over the store gave up) the buyer contacts the seller with the transaction hash, which the screen
|
|
539
|
+
* shows; a transfer that moved money without paying the invoice says so, and one Quasar credited to another invoice
|
|
540
|
+
* says that it pays that one; a transaction the page of another invoice handed over first, which Quasar credits to the
|
|
541
|
+
* invoice whose quoted wallet sent it, and a payment the network confirmed that Quasar has not recorded yet are named
|
|
542
|
+
* with their hash for the seller, and the buyer is asked not to pay again; no payment is offered, only, on a payable
|
|
543
|
+
* invoice and for a payment that may not have left the wallet, "The payment did not leave my wallet", which goes back
|
|
544
|
+
* to it with `payAgain` of the checkout store), an
|
|
545
|
+
* underpaid invoice ("Pay the rest"), a payment the seller reviews (screening,
|
|
546
|
+
* late, overpaid, after the price lock ran out), a refunded invoice, an expired one (with what arrived before the
|
|
547
|
+
* deadline, which the seller can refund; never "nothing was charged" while a payment may still arrive: one this page
|
|
548
|
+
* handed over or saw on its way, or that the wallet sent, also after the checkout stopped following it, which Quasar
|
|
549
|
+
* records and shows to the seller if it arrives, one Quasar could not confirm or reports as unresolved, to check in the
|
|
550
|
+
* wallet, one Quasar does not read again or closed after 24 hours without a result, for the seller with its transaction
|
|
551
|
+
* hash, one that does not pay the invoice and may have moved money, and after a QR code showed, a payment made with it,
|
|
552
|
+
* as this page does not see it; while this page follows a payment on its way, until when it does, `followingUntil` of
|
|
553
|
+
* the checkout store), a cancelled one (the same: never "nothing was charged" while a payment may still
|
|
554
|
+
* arrive, also after a QR code showed, and "recorded if it arrives" only for a payment Quasar records), a corrected one
|
|
555
|
+
* ("Open <new invoice>" opens it here) and a payer the wallet check refused ("Use another wallet"). Each offers to
|
|
556
|
+
* contact the seller.
|
|
557
|
+
*
|
|
558
|
+
* @param props - The outcome.
|
|
559
|
+
* @param props.kind - Which outcome.
|
|
560
|
+
* @returns The outcome step.
|
|
561
|
+
*/
|
|
562
|
+
declare function OutcomeScreen({ kind }: {
|
|
563
|
+
kind: OutcomeKind;
|
|
564
|
+
}): react.JSX.Element | null;
|
|
565
|
+
|
|
566
|
+
/** What every class name function of {@link PaymentCheckoutClassNames} receives. */
|
|
567
|
+
interface CheckoutPartState {
|
|
568
|
+
/** The screen shown. */
|
|
569
|
+
screen: CheckoutScreen;
|
|
570
|
+
/** The state of the checkout store: its phase, the chosen method, the locked price, the last error. */
|
|
571
|
+
checkoutState: CheckoutState;
|
|
572
|
+
/** The checkout, once loaded. */
|
|
573
|
+
checkout: CheckoutView | null;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Class name functions of the parts of {@link PaymentCheckout}. Each returns classes added after the default ones of
|
|
577
|
+
* its part (or nothing), from the state of the checkout and what the part knows; `className` of a replacement
|
|
578
|
+
* component (`PaymentCheckoutComponents`) gets them too. A color or size a part already sets is changed with the
|
|
579
|
+
* `--tuwa-*` theme variables of `@tuwaio/nova-core`, or by replacing the part: which of two classes for the same
|
|
580
|
+
* property wins depends on the order of the stylesheets.
|
|
581
|
+
*/
|
|
582
|
+
interface PaymentCheckoutClassNames {
|
|
583
|
+
/**
|
|
584
|
+
* The checkout block with the order panel, the header and the screen (where `className` of `PaymentCheckout` goes:
|
|
585
|
+
* inside the dialog, or the bordered block in the page).
|
|
586
|
+
*
|
|
587
|
+
* @param params - The state of the checkout.
|
|
588
|
+
* @returns Classes to add.
|
|
589
|
+
*/
|
|
590
|
+
container?: (params: CheckoutPartState) => string | undefined;
|
|
591
|
+
/**
|
|
592
|
+
* The order panel on the left (from 640 px).
|
|
593
|
+
*
|
|
594
|
+
* @param params - The state of the checkout.
|
|
595
|
+
* @returns Classes to add.
|
|
596
|
+
*/
|
|
597
|
+
summary?: (params: CheckoutPartState) => string | undefined;
|
|
598
|
+
/**
|
|
599
|
+
* The order above the steps on a phone.
|
|
600
|
+
*
|
|
601
|
+
* @param params - The state of the checkout.
|
|
602
|
+
* @returns Classes to add.
|
|
603
|
+
*/
|
|
604
|
+
compactSummary?: (params: CheckoutPartState) => string | undefined;
|
|
605
|
+
/**
|
|
606
|
+
* The header: the steps (or the heading of an outcome), the language menu and the close button.
|
|
607
|
+
*
|
|
608
|
+
* @param params - The state of the checkout.
|
|
609
|
+
* @returns Classes to add.
|
|
610
|
+
*/
|
|
611
|
+
header?: (params: CheckoutPartState) => string | undefined;
|
|
612
|
+
/**
|
|
613
|
+
* The list of steps.
|
|
614
|
+
*
|
|
615
|
+
* @param params - The state of the checkout.
|
|
616
|
+
* @returns Classes to add.
|
|
617
|
+
*/
|
|
618
|
+
stepper?: (params: CheckoutPartState) => string | undefined;
|
|
619
|
+
/**
|
|
620
|
+
* One step of the list.
|
|
621
|
+
*
|
|
622
|
+
* @param params - The state of the checkout and the step.
|
|
623
|
+
* @param params.step - The step: its key and whether it is done, current or upcoming.
|
|
624
|
+
* @param params.index - Its position, from 0.
|
|
625
|
+
* @returns Classes to add.
|
|
626
|
+
*/
|
|
627
|
+
step?: (params: CheckoutPartState & {
|
|
628
|
+
step: CheckoutStep;
|
|
629
|
+
index: number;
|
|
630
|
+
}) => string | undefined;
|
|
631
|
+
/**
|
|
632
|
+
* The area of the screen, under the header. It scrolls in a modal and inline; on a page the window does.
|
|
633
|
+
*
|
|
634
|
+
* @param params - The state of the checkout.
|
|
635
|
+
* @returns Classes to add.
|
|
636
|
+
*/
|
|
637
|
+
body?: (params: CheckoutPartState) => string | undefined;
|
|
638
|
+
/**
|
|
639
|
+
* The content of a step screen (buyer details, method, QR code, automatic payments), with its heading.
|
|
640
|
+
*
|
|
641
|
+
* @param params - The state of the checkout.
|
|
642
|
+
* @returns Classes to add.
|
|
643
|
+
*/
|
|
644
|
+
screen?: (params: CheckoutPartState) => string | undefined;
|
|
645
|
+
/**
|
|
646
|
+
* The bottom of a screen, with its main button.
|
|
647
|
+
*
|
|
648
|
+
* @param params - The state of the checkout.
|
|
649
|
+
* @returns Classes to add.
|
|
650
|
+
*/
|
|
651
|
+
footer?: (params: CheckoutPartState) => string | undefined;
|
|
652
|
+
/**
|
|
653
|
+
* The main button of a screen (Continue, Pay, Sign to pay, Pay the rest…).
|
|
654
|
+
*
|
|
655
|
+
* @param params - The state of the checkout.
|
|
656
|
+
* @returns Classes to add.
|
|
657
|
+
*/
|
|
658
|
+
primaryButton?: (params: CheckoutPartState) => string | undefined;
|
|
659
|
+
/**
|
|
660
|
+
* The second action under the main button (back, close, not now, contact).
|
|
661
|
+
*
|
|
662
|
+
* @param params - The state of the checkout.
|
|
663
|
+
* @returns Classes to add.
|
|
664
|
+
*/
|
|
665
|
+
secondaryButton?: (params: CheckoutPartState) => string | undefined;
|
|
666
|
+
/**
|
|
667
|
+
* A refusal or error message of a screen.
|
|
668
|
+
*
|
|
669
|
+
* @param params - The state of the checkout.
|
|
670
|
+
* @returns Classes to add.
|
|
671
|
+
*/
|
|
672
|
+
error?: (params: CheckoutPartState) => string | undefined;
|
|
673
|
+
/**
|
|
674
|
+
* A token card of the method step.
|
|
675
|
+
*
|
|
676
|
+
* @param params - The state of the checkout and the token.
|
|
677
|
+
* @param params.group - The token and its methods.
|
|
678
|
+
* @param params.selected - Whether it is selected.
|
|
679
|
+
* @returns Classes to add.
|
|
680
|
+
*/
|
|
681
|
+
tokenOption?: (params: CheckoutPartState & {
|
|
682
|
+
group: CheckoutTokenGroup;
|
|
683
|
+
selected: boolean;
|
|
684
|
+
}) => string | undefined;
|
|
685
|
+
/**
|
|
686
|
+
* A network option of the method step (when the token is on several networks).
|
|
687
|
+
*
|
|
688
|
+
* @param params - The state of the checkout and the method.
|
|
689
|
+
* @param params.method - The method: the token on this network.
|
|
690
|
+
* @param params.selected - Whether it is selected.
|
|
691
|
+
* @returns Classes to add.
|
|
692
|
+
*/
|
|
693
|
+
networkOption?: (params: CheckoutPartState & {
|
|
694
|
+
method: CheckoutMethod;
|
|
695
|
+
selected: boolean;
|
|
696
|
+
}) => string | undefined;
|
|
697
|
+
/**
|
|
698
|
+
* A "Pay with" option of the method step.
|
|
699
|
+
*
|
|
700
|
+
* @param params - The state of the checkout and the option.
|
|
701
|
+
* @param params.payWith - `wallet` (a wallet in this browser) or `qr` (a QR code on a phone).
|
|
702
|
+
* @param params.selected - Whether it is selected.
|
|
703
|
+
* @returns Classes to add.
|
|
704
|
+
*/
|
|
705
|
+
payWithOption?: (params: CheckoutPartState & {
|
|
706
|
+
payWith: 'wallet' | 'qr';
|
|
707
|
+
selected: boolean;
|
|
708
|
+
}) => string | undefined;
|
|
709
|
+
/**
|
|
710
|
+
* The card of the seller's consent on the method step (`checkout.consent`): the box the buyer ticks and the seller's
|
|
711
|
+
* words.
|
|
712
|
+
*
|
|
713
|
+
* @param params - The state of the checkout and the consent.
|
|
714
|
+
* @param params.checked - Whether the buyer ticked it.
|
|
715
|
+
* @param params.required - Whether the buyer cannot continue without ticking it.
|
|
716
|
+
* @returns Classes to add.
|
|
717
|
+
*/
|
|
718
|
+
consentOption?: (params: CheckoutPartState & {
|
|
719
|
+
checked: boolean;
|
|
720
|
+
required: boolean;
|
|
721
|
+
}) => string | undefined;
|
|
722
|
+
/**
|
|
723
|
+
* A card of grouped facts (the transaction, the rate and fees, the terms of automatic payments).
|
|
724
|
+
*
|
|
725
|
+
* @param params - The state of the checkout.
|
|
726
|
+
* @returns Classes to add.
|
|
727
|
+
*/
|
|
728
|
+
detailsCard?: (params: CheckoutPartState) => string | undefined;
|
|
729
|
+
/**
|
|
730
|
+
* A row of a card of facts (rate, network fee, recipient…).
|
|
731
|
+
*
|
|
732
|
+
* @param params - The state of the checkout.
|
|
733
|
+
* @returns Classes to add.
|
|
734
|
+
*/
|
|
735
|
+
detailRow?: (params: CheckoutPartState) => string | undefined;
|
|
736
|
+
/**
|
|
737
|
+
* The total of the order panel.
|
|
738
|
+
*
|
|
739
|
+
* @param params - The state of the checkout.
|
|
740
|
+
* @returns Classes to add.
|
|
741
|
+
*/
|
|
742
|
+
total?: (params: CheckoutPartState) => string | undefined;
|
|
743
|
+
/**
|
|
744
|
+
* A QR code (Solana Pay, or the payment page for a phone).
|
|
745
|
+
*
|
|
746
|
+
* @param params - The state of the checkout.
|
|
747
|
+
* @returns Classes to add.
|
|
748
|
+
*/
|
|
749
|
+
qrCode?: (params: CheckoutPartState) => string | undefined;
|
|
750
|
+
/**
|
|
751
|
+
* The icon of an outcome other than paid.
|
|
752
|
+
*
|
|
753
|
+
* @param params - The state of the checkout and the outcome.
|
|
754
|
+
* @param params.kind - The outcome.
|
|
755
|
+
* @returns Classes to add.
|
|
756
|
+
*/
|
|
757
|
+
statusIcon?: (params: CheckoutPartState & {
|
|
758
|
+
kind: OutcomeKind;
|
|
759
|
+
}) => string | undefined;
|
|
760
|
+
/**
|
|
761
|
+
* The strip and the wash of the status color along the top of the checkout, on a payment on its way and its outcome.
|
|
762
|
+
*
|
|
763
|
+
* @param params - The state of the checkout, and `tone`, the state the strip shows.
|
|
764
|
+
* @param params.tone - The state the strip shows.
|
|
765
|
+
* @returns Classes to add.
|
|
766
|
+
*/
|
|
767
|
+
statusEdge?: (params: CheckoutPartState & {
|
|
768
|
+
tone: StatusTone;
|
|
769
|
+
}) => string | undefined;
|
|
770
|
+
}
|
|
771
|
+
/** Props of a replacement token card content (`PaymentCheckoutComponents.TokenOption`). */
|
|
772
|
+
interface CheckoutTokenOptionProps {
|
|
773
|
+
/** The token and its methods, one per network. */
|
|
774
|
+
group: CheckoutTokenGroup;
|
|
775
|
+
/** Whether the token is selected. */
|
|
776
|
+
selected: boolean;
|
|
777
|
+
}
|
|
778
|
+
/** Props of a replacement network option content (`PaymentCheckoutComponents.NetworkOption`). */
|
|
779
|
+
interface CheckoutNetworkOptionProps {
|
|
780
|
+
/** The method: the token on this network. */
|
|
781
|
+
method: CheckoutMethod;
|
|
782
|
+
/** Whether it is selected. */
|
|
783
|
+
selected: boolean;
|
|
784
|
+
}
|
|
785
|
+
/** Props of a replacement main button (`PaymentCheckoutComponents.PrimaryButton`): a `<button>`'s props and `busy`. */
|
|
786
|
+
type CheckoutPrimaryButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
787
|
+
/** The action is running: the default button shows the Quasar loader and is disabled. */
|
|
788
|
+
busy?: boolean;
|
|
789
|
+
};
|
|
790
|
+
/** Props of a replacement QR code (`PaymentCheckoutComponents.QrCode`). */
|
|
791
|
+
interface CheckoutQrCodeProps {
|
|
792
|
+
/** The text the code holds (a Solana Pay URL, or the payment page). */
|
|
793
|
+
value: string;
|
|
794
|
+
/** The text alternative of the code (WCAG 1.1.1). */
|
|
795
|
+
label: string;
|
|
796
|
+
/** The classes of the code: its size, and those of `classNames.qrCode`. */
|
|
797
|
+
className?: string;
|
|
798
|
+
}
|
|
799
|
+
/** Props of a replacement outcome icon (`PaymentCheckoutComponents.StatusIcon`). */
|
|
800
|
+
interface CheckoutStatusIconProps {
|
|
801
|
+
/** The outcome. */
|
|
802
|
+
kind: OutcomeKind;
|
|
803
|
+
/** The classes of `classNames.statusIcon`. */
|
|
804
|
+
className?: string;
|
|
805
|
+
}
|
|
806
|
+
/** Props of a replacement screen (`PaymentCheckoutComponents.screens`). */
|
|
807
|
+
interface CheckoutScreenProps {
|
|
808
|
+
/** The screen it replaces. */
|
|
809
|
+
screen: CheckoutScreen;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Components that replace parts of {@link PaymentCheckout}. A replacement reads the checkout with
|
|
813
|
+
* {@link useCheckoutContext} (the store, its state, the labels of the checkout language, the connected wallet and the
|
|
814
|
+
* actions of the steps).
|
|
815
|
+
*/
|
|
816
|
+
interface PaymentCheckoutComponents {
|
|
817
|
+
/** The header: the steps (or the heading of an outcome), the language menu and the close button; on a phone too. */
|
|
818
|
+
Header?: ComponentType<CheckoutHeaderProps>;
|
|
819
|
+
/**
|
|
820
|
+
* The content of the order panel on the left (from 640 px; `classNames.summary` styles the panel around it). On a page
|
|
821
|
+
* the panel is a flex column as tall as the sheet.
|
|
822
|
+
*/
|
|
823
|
+
Summary?: ComponentType;
|
|
824
|
+
/** The order above the steps on a phone; `className` holds the classes of `classNames.compactSummary`. */
|
|
825
|
+
CompactSummary?: ComponentType<{
|
|
826
|
+
className?: string;
|
|
827
|
+
}>;
|
|
828
|
+
/** The list of steps, in the header and, on a phone, under the order. */
|
|
829
|
+
Stepper?: ComponentType<CheckoutStepperProps>;
|
|
830
|
+
/** The content of a token card of the method step (the card itself stays a radio button). */
|
|
831
|
+
TokenOption?: ComponentType<CheckoutTokenOptionProps>;
|
|
832
|
+
/** The content of a network option of the method step (the option itself stays a radio button). */
|
|
833
|
+
NetworkOption?: ComponentType<CheckoutNetworkOptionProps>;
|
|
834
|
+
/** The main button of every screen. */
|
|
835
|
+
PrimaryButton?: ComponentType<CheckoutPrimaryButtonProps>;
|
|
836
|
+
/** A QR code. Keep it dark on light: scanners read inverted codes badly. */
|
|
837
|
+
QrCode?: ComponentType<CheckoutQrCodeProps>;
|
|
838
|
+
/** The icon of an outcome other than paid. */
|
|
839
|
+
StatusIcon?: ComponentType<CheckoutStatusIconProps>;
|
|
840
|
+
/** The strip and the wash of the status color along the top of the checkout (`StatusEdge` of `@tuwaio/nova-core`). */
|
|
841
|
+
StatusEdge?: ComponentType<StatusEdgeProps>;
|
|
842
|
+
/** Whole screens, by the screen they replace (for example `paid` or `loading`). */
|
|
843
|
+
screens?: Partial<Record<CheckoutScreen, ComponentType<CheckoutScreenProps>>>;
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Handlers of {@link PaymentCheckout}: some wrap an action of the buyer (call `proceed()` or `select()` to run it, or
|
|
847
|
+
* do something else instead), the others tell the app what happened. `onPaid`, `onClose` and `onContact` are props of
|
|
848
|
+
* the checkout.
|
|
849
|
+
*/
|
|
850
|
+
interface PaymentCheckoutHandlers {
|
|
851
|
+
/**
|
|
852
|
+
* The buyer picked a token or a network. Without the handler the method is chosen.
|
|
853
|
+
*
|
|
854
|
+
* @param params - The pick.
|
|
855
|
+
* @param params.method - The method picked.
|
|
856
|
+
* @param params.select - Chooses it.
|
|
857
|
+
*/
|
|
858
|
+
onMethodSelect?: (params: {
|
|
859
|
+
method: CheckoutMethod;
|
|
860
|
+
select: () => void;
|
|
861
|
+
}) => void;
|
|
862
|
+
/**
|
|
863
|
+
* The buyer pressed "Continue" on the method step. Without the handler the checkout locks the price for the
|
|
864
|
+
* connected wallet (or connects one first), or shows the QR code.
|
|
865
|
+
*
|
|
866
|
+
* @param params - The step.
|
|
867
|
+
* @param params.method - The chosen method.
|
|
868
|
+
* @param params.payWith - `wallet` or `qr`.
|
|
869
|
+
* @param params.proceed - Goes on as the checkout would.
|
|
870
|
+
*/
|
|
871
|
+
onQuote?: (params: {
|
|
872
|
+
method: CheckoutMethod;
|
|
873
|
+
payWith: 'wallet' | 'qr';
|
|
874
|
+
proceed: () => Promise<void>;
|
|
875
|
+
}) => void | Promise<void>;
|
|
876
|
+
/**
|
|
877
|
+
* The buyer pressed the pay button ("Pay", "Sign to pay"). Without the handler the wallet prompt opens.
|
|
878
|
+
*
|
|
879
|
+
* @param params - The payment.
|
|
880
|
+
* @param params.quote - The locked price: amount, recipient, network.
|
|
881
|
+
* @param params.method - The method.
|
|
882
|
+
* @param params.proceed - Opens the wallet prompt.
|
|
883
|
+
*/
|
|
884
|
+
onSubmit?: (params: {
|
|
885
|
+
quote: CheckoutQuote;
|
|
886
|
+
method: CheckoutMethod;
|
|
887
|
+
proceed: () => Promise<void>;
|
|
888
|
+
}) => void | Promise<void>;
|
|
889
|
+
/**
|
|
890
|
+
* The buyer picked a language. Without the handler the checkout switches to it and saves it on the invoice.
|
|
891
|
+
*
|
|
892
|
+
* @param params - The language.
|
|
893
|
+
* @param params.locale - The language picked.
|
|
894
|
+
* @param params.proceed - Switches and saves it.
|
|
895
|
+
*/
|
|
896
|
+
onLocaleChange?: (params: {
|
|
897
|
+
locale: CheckoutLocale;
|
|
898
|
+
proceed: () => Promise<void>;
|
|
899
|
+
}) => void | Promise<void>;
|
|
900
|
+
/**
|
|
901
|
+
* The phase of the checkout or the status of the invoice changed; also called once with the first ones.
|
|
902
|
+
*
|
|
903
|
+
* @param params - The state.
|
|
904
|
+
* @param params.phase - The phase of the checkout store.
|
|
905
|
+
* @param params.status - The invoice status, `null` before the invoice loads.
|
|
906
|
+
* @param params.screen - The screen shown.
|
|
907
|
+
*/
|
|
908
|
+
onStatusChange?: (params: {
|
|
909
|
+
phase: CheckoutState['phase'];
|
|
910
|
+
status: CheckoutView['invoice']['status'] | null;
|
|
911
|
+
screen: CheckoutScreen;
|
|
912
|
+
}) => void;
|
|
913
|
+
/**
|
|
914
|
+
* The checkout got a new error (Quasar refused an action, or did not answer); the screen shows it.
|
|
915
|
+
*
|
|
916
|
+
* @param params - The error.
|
|
917
|
+
* @param params.error - Its code and message.
|
|
918
|
+
* @param params.screen - The screen shown.
|
|
919
|
+
*/
|
|
920
|
+
onError?: (params: {
|
|
921
|
+
error: CheckoutError;
|
|
922
|
+
screen: CheckoutScreen;
|
|
923
|
+
}) => void;
|
|
924
|
+
/**
|
|
925
|
+
* The locked price ran out (`quote`), or the invoice expired (`invoice`). Either can happen while a payment is on its
|
|
926
|
+
* way: the invoice can still close while it confirms (Quasar waits for a payment it learned of
|
|
927
|
+
* before the deadline only for a limited time, and holds a payment that lands later for the seller to accept or
|
|
928
|
+
* return), so do not offer a new invoice at once when `paymentOnTheWay` is `true`; the checkout keeps following the
|
|
929
|
+
* invoice and shows a paid or held outcome if it changes.
|
|
930
|
+
*
|
|
931
|
+
* @param params - What expired.
|
|
932
|
+
* @param params.kind - `quote` or `invoice`.
|
|
933
|
+
* @param params.paymentOnTheWay - A payment is on its way: one this page handed over (`paymentOnTheWay` of the
|
|
934
|
+
* checkout store, or, with an older `@tuwaio/quasar-sdk`, a transaction handed over), one of the invoice Quasar
|
|
935
|
+
* reports (`invoicePaymentOnTheWay`: the page was reopened while it was on its way, another tab paid), or one Quasar
|
|
936
|
+
* could not confirm yet and reads again (`invoicePaymentUnresolved`).
|
|
937
|
+
*/
|
|
938
|
+
onExpire?: (params: {
|
|
939
|
+
kind: 'quote' | 'invoice';
|
|
940
|
+
paymentOnTheWay: boolean;
|
|
941
|
+
}) => void;
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Options of {@link PaymentCheckout}. Every text and accessible name comes from the labels, and amounts and dates
|
|
945
|
+
* follow the language of the checkout.
|
|
946
|
+
*/
|
|
947
|
+
interface PaymentCheckoutConfig {
|
|
948
|
+
/** Animations. They always follow `prefers-reduced-motion`; `disabled: true` turns them off for everyone. */
|
|
949
|
+
animation?: {
|
|
950
|
+
/** Turns the animations off. */
|
|
951
|
+
disabled?: boolean;
|
|
952
|
+
};
|
|
953
|
+
/** Whether the header shows the steps of the payment (default `true`). */
|
|
954
|
+
showSteps?: boolean;
|
|
955
|
+
/**
|
|
956
|
+
* Whether the pay step reads the wallet's balance (through the chain adapter) and, when it is short, offers what the
|
|
957
|
+
* wallet can pay with (default `true`).
|
|
958
|
+
*/
|
|
959
|
+
balanceCheck?: boolean;
|
|
960
|
+
/**
|
|
961
|
+
* Minutes before the invoice deadline at which screen readers hear the time left, while the buyer can still pay (not
|
|
962
|
+
* once the payment is on its way) (default `[10, 5, 1]`).
|
|
963
|
+
*/
|
|
964
|
+
deadlineAnnouncements?: readonly number[];
|
|
965
|
+
}
|
|
966
|
+
/** Customization of the Nova Transactions parts the confirm and paid steps show. */
|
|
967
|
+
interface PaymentCheckoutChildCustomizations {
|
|
968
|
+
/** The status icon (`TxStatusVisual` of `@tuwaio/nova-transactions`). */
|
|
969
|
+
statusVisual?: Pick<TxStatusVisualProps, 'className' | 'iconClassNames'>;
|
|
970
|
+
/** The steps Sent, Confirming, Paid (`TxProgressIndicator` of `@tuwaio/nova-transactions`). */
|
|
971
|
+
progressIndicator?: Pick<TxProgressIndicatorProps, 'className' | 'stepClassNames' | 'StepComponent'>;
|
|
972
|
+
/** The transaction with its explorer link (`HashLink` of `@tuwaio/nova-transactions`). */
|
|
973
|
+
hashLink?: Pick<HashLinkProps, 'className' | 'classNames'>;
|
|
974
|
+
}
|
|
975
|
+
/** Customization of {@link PaymentCheckout} (`customization`). */
|
|
976
|
+
interface PaymentCheckoutCustomization {
|
|
977
|
+
/** Classes added to the parts, from the state of the checkout. */
|
|
978
|
+
classNames?: PaymentCheckoutClassNames;
|
|
979
|
+
/** Components that replace parts. */
|
|
980
|
+
components?: PaymentCheckoutComponents;
|
|
981
|
+
/** Handlers that wrap the actions of the buyer or tell what happened. */
|
|
982
|
+
handlers?: PaymentCheckoutHandlers;
|
|
983
|
+
/** Options: animations, steps, the balance check, the deadline announcements. */
|
|
984
|
+
config?: PaymentCheckoutConfig;
|
|
985
|
+
/** Customization of the Nova Transactions parts of the confirm and paid steps. */
|
|
986
|
+
childCustomizations?: PaymentCheckoutChildCustomizations;
|
|
987
|
+
}
|
|
988
|
+
/** What a part adds to {@link CheckoutPartState} for its class name function. */
|
|
989
|
+
type PartExtra<K extends keyof PaymentCheckoutClassNames> = Omit<Parameters<NonNullable<PaymentCheckoutClassNames[K]>>[0], keyof CheckoutPartState>;
|
|
990
|
+
/**
|
|
991
|
+
* The classes `customization.classNames` adds to a part of the checkout.
|
|
992
|
+
*
|
|
993
|
+
* @param context - The checkout context (its customization, screen, store state and checkout).
|
|
994
|
+
* @param part - The part.
|
|
995
|
+
* @param extra - What the part adds to the state, such as the method of an option.
|
|
996
|
+
* @returns The classes, or `undefined`.
|
|
997
|
+
* @internal
|
|
998
|
+
*/
|
|
999
|
+
declare function checkoutClassName<K extends keyof PaymentCheckoutClassNames>(context: Pick<CheckoutContextValue, 'customization' | 'screen' | 'state' | 'checkout'>, part: K, extra?: PartExtra<K>): string | undefined;
|
|
1000
|
+
|
|
1001
|
+
/** Where the checkout is shown. */
|
|
1002
|
+
type PaymentCheckoutDisplay = 'modal' | 'inline' | 'page';
|
|
1003
|
+
/** Props of {@link PaymentCheckout}. */
|
|
1004
|
+
interface PaymentCheckoutProps {
|
|
1005
|
+
/** The checkout token of the invoice (its `checkoutToken`, or the end of its `payUrl`). */
|
|
1006
|
+
token: string;
|
|
1007
|
+
/**
|
|
1008
|
+
* `modal` (default): a dialog over the page, 760 px wide (less on a narrower window), a sheet from the bottom under
|
|
1009
|
+
* 640 px; `inline`: a block in the page, as wide as its place up to 760 px; `page`: the whole page, as the Quasar
|
|
1010
|
+
* payment page shows it: a sheet 880 px wide, centered in the window (`min-height: 100svh`; set `--novapay-page-height`
|
|
1011
|
+
* on an ancestor for a page with a header of its own), that grows downward with its step and scrolls nothing inside,
|
|
1012
|
+
* full-bleed under 640 px.
|
|
1013
|
+
*/
|
|
1014
|
+
display?: PaymentCheckoutDisplay;
|
|
1015
|
+
/** Whether the modal is open (`display="modal"`; default `true`). */
|
|
1016
|
+
open?: boolean;
|
|
1017
|
+
/**
|
|
1018
|
+
* Called when the modal opens or closes.
|
|
1019
|
+
*
|
|
1020
|
+
* @param open - The new state.
|
|
1021
|
+
*/
|
|
1022
|
+
onOpenChange?: (open: boolean) => void;
|
|
1023
|
+
/** Called when the buyer closes the checkout; without it an inline checkout has no close button. */
|
|
1024
|
+
onClose?: () => void;
|
|
1025
|
+
/** The Quasar API; overrides `baseUrl` of `NovaPaymentsProvider`. */
|
|
1026
|
+
baseUrl?: string;
|
|
1027
|
+
/** Calls to make instead of the HTTP ones, for tests and simulations (`CheckoutApi` of `@tuwaio/quasar-sdk/checkout`). */
|
|
1028
|
+
api?: CheckoutApi;
|
|
1029
|
+
/** The `EventSource` to follow the invoice with; `null` reads it every `pollMs` (default: the browser's). */
|
|
1030
|
+
EventSource?: EventSourceConstructor | null;
|
|
1031
|
+
/** How often to read the invoice without an event stream, in milliseconds (default `5000`). */
|
|
1032
|
+
pollMs?: number;
|
|
1033
|
+
/**
|
|
1034
|
+
* The payment page of the invoice (its `payUrl` from the Quasar API, passed as it comes): with it, an EVM method can
|
|
1035
|
+
* also be paid by scanning a QR code that opens the page on a phone. `null` (a node without a dashboard URL) or
|
|
1036
|
+
* leaving it out offers the QR code for Solana methods only.
|
|
1037
|
+
*/
|
|
1038
|
+
payUrl?: string | null;
|
|
1039
|
+
/**
|
|
1040
|
+
* Connects a wallet of a chain family, for apps without Nova Connect; overrides the `onConnectWallet` of
|
|
1041
|
+
* `NovaPaymentsProvider`. Inside `NovaConnectProvider` (the app's, or Nova's own connection of `NovaPaymentsProvider`)
|
|
1042
|
+
* the checkout opens its connect modal instead.
|
|
1043
|
+
*
|
|
1044
|
+
* @param family - The family of the chosen method.
|
|
1045
|
+
*/
|
|
1046
|
+
onConnectWallet?: (family: PaymentFamily) => void;
|
|
1047
|
+
/**
|
|
1048
|
+
* Called once when the invoice is paid (Quasar confirmed the payment). Fulfil orders from the `invoice.paid` webhook
|
|
1049
|
+
* on your server: this callback is for the page only.
|
|
1050
|
+
*
|
|
1051
|
+
* @param invoice - The paid invoice.
|
|
1052
|
+
*/
|
|
1053
|
+
onPaid?: (invoice: CheckoutView['invoice']) => void;
|
|
1054
|
+
/**
|
|
1055
|
+
* Seconds before the paid outcome sends the buyer back to the invoice's `successUrl`, with a visible countdown and
|
|
1056
|
+
* "Stay here" (`0` for no automatic return). Default `5` on a page; `0` in a modal, whose paid outcome offers Close
|
|
1057
|
+
* instead, since the page under it is the seller's (handle the payment there with `onPaid`).
|
|
1058
|
+
*/
|
|
1059
|
+
autoReturnSeconds?: number;
|
|
1060
|
+
/** Replaces the link of "Contact <seller>" (the seller's support email, else site) with the app's own handler. */
|
|
1061
|
+
onContact?: () => void;
|
|
1062
|
+
/** Classes added to the checkout block. */
|
|
1063
|
+
className?: string;
|
|
1064
|
+
/**
|
|
1065
|
+
* Class name functions of the parts, from the state of the checkout, and components that replace parts (the
|
|
1066
|
+
* header, the order, the steps, the options of the method step, the main button, the QR code, the outcome icon or
|
|
1067
|
+
* whole screens).
|
|
1068
|
+
*/
|
|
1069
|
+
customization?: PaymentCheckoutCustomization;
|
|
1070
|
+
}
|
|
1071
|
+
/** The screen of the current step or outcome, or its replacement (`customization.components.screens`). @internal */
|
|
1072
|
+
declare function ScreenBody(): react.JSX.Element;
|
|
1073
|
+
/**
|
|
1074
|
+
* The checkout block: the order on the left (from 640 px; on a phone a compact order above the steps), the header
|
|
1075
|
+
* with the steps, language and close, and the current screen. The language follows the invoice, its texts the labels
|
|
1076
|
+
* of that language, and `lang` is set on the block (WCAG 3.1.2). Screen readers hear the time left at 10, 5 and 1
|
|
1077
|
+
* minutes before the deadline while the buyer can still pay. `customization` adds classes to the order and the screen area, and can replace the
|
|
1078
|
+
* header and the order.
|
|
1079
|
+
*
|
|
1080
|
+
* @internal
|
|
1081
|
+
*/
|
|
1082
|
+
declare function CheckoutFrame({ className, withDetails, leave, }: {
|
|
1083
|
+
className?: string;
|
|
1084
|
+
withDetails?: boolean;
|
|
1085
|
+
leave: {
|
|
1086
|
+
onStay: () => void;
|
|
1087
|
+
onLeave: () => void;
|
|
1088
|
+
} | null;
|
|
1089
|
+
}): react.JSX.Element;
|
|
1090
|
+
/**
|
|
1091
|
+
* The checkout of a Quasar Payments invoice, opened by its checkout token: the order, the steps of the payment and
|
|
1092
|
+
* its outcome, in the language of the invoice. It reads the invoice with `createCheckoutStore` of
|
|
1093
|
+
* `@tuwaio/quasar-sdk/checkout` and follows it until it is final; no secret key reaches the browser.
|
|
1094
|
+
*
|
|
1095
|
+
* Side effects: requests to the checkout routes of the Quasar API (`baseUrl`) and an `EventSource` on the invoice
|
|
1096
|
+
* events while the invoice can change; changing the language saves it on the invoice (`POST locale`).
|
|
1097
|
+
*
|
|
1098
|
+
* @param props - See {@link PaymentCheckoutProps}.
|
|
1099
|
+
* @returns The checkout.
|
|
1100
|
+
*
|
|
1101
|
+
* @example
|
|
1102
|
+
* ```tsx
|
|
1103
|
+
* import { PaymentCheckout } from '@tuwaio/payments-sdk';
|
|
1104
|
+
* import { useState } from 'react';
|
|
1105
|
+
*
|
|
1106
|
+
* export function PayButton({ token }: { token: string }) {
|
|
1107
|
+
* const [open, setOpen] = useState(false);
|
|
1108
|
+
* return (
|
|
1109
|
+
* <>
|
|
1110
|
+
* <button onClick={() => setOpen(true)}>Pay</button>
|
|
1111
|
+
* <PaymentCheckout token={token} open={open} onOpenChange={setOpen} />
|
|
1112
|
+
* </>
|
|
1113
|
+
* );
|
|
1114
|
+
* }
|
|
1115
|
+
* ```
|
|
1116
|
+
*/
|
|
1117
|
+
declare function PaymentCheckout({ token, display, open, onOpenChange, onClose, baseUrl, api, EventSource, pollMs, payUrl, onConnectWallet, onPaid, autoReturnSeconds, onContact, className, customization, }: PaymentCheckoutProps): react.JSX.Element;
|
|
1118
|
+
/**
|
|
1119
|
+
* The checkout as a whole page: the block, centered from a floor (`styles/app.css`) and not from its own height, so that
|
|
1120
|
+
* no step can move its top.
|
|
1121
|
+
*
|
|
1122
|
+
* @internal
|
|
1123
|
+
*/
|
|
1124
|
+
declare function CheckoutPageRoot({ label, className, children, }: {
|
|
1125
|
+
label: string;
|
|
1126
|
+
className?: string;
|
|
1127
|
+
children: ReactNode;
|
|
1128
|
+
}): react.JSX.Element;
|
|
1129
|
+
|
|
1130
|
+
/** What the parts of a checkout share: its store and state, the screen, the language and its labels. */
|
|
1131
|
+
interface CheckoutContextValue {
|
|
1132
|
+
/** The checkout store of the invoice. */
|
|
1133
|
+
store: CheckoutStore;
|
|
1134
|
+
/** The state of the store. */
|
|
1135
|
+
state: CheckoutState;
|
|
1136
|
+
/** The checkout, once loaded. */
|
|
1137
|
+
checkout: CheckoutView | null;
|
|
1138
|
+
/** The screen shown. */
|
|
1139
|
+
screen: CheckoutScreen;
|
|
1140
|
+
/** The language of the checkout (a BCP 47 tag). */
|
|
1141
|
+
locale: string;
|
|
1142
|
+
/** The labels of that language. */
|
|
1143
|
+
labels: NovaPaymentsLabels;
|
|
1144
|
+
/** `Date.now()` of the latest second tick. */
|
|
1145
|
+
now: number;
|
|
1146
|
+
/**
|
|
1147
|
+
* When this page handed its current payment over (the phase became `confirming`), by the clock of the page; `null`
|
|
1148
|
+
* while no payment of it is confirming, or when it was already confirming as the checkout opened.
|
|
1149
|
+
*/
|
|
1150
|
+
handedOverAt: number | null;
|
|
1151
|
+
/** The checkout showed a QR code for the invoice, which the buyer may have paid with from a phone. */
|
|
1152
|
+
qrShown: boolean;
|
|
1153
|
+
/**
|
|
1154
|
+
* This page handed a payment of the invoice over, or saw one on its way, and Quasar did not say that it failed for
|
|
1155
|
+
* good: it may still arrive, also after the store stopped following it.
|
|
1156
|
+
*/
|
|
1157
|
+
paymentSent: boolean;
|
|
1158
|
+
/** Closes the checkout; `undefined` when it cannot be closed (inline without `onClose`). */
|
|
1159
|
+
close?: () => void;
|
|
1160
|
+
/** The wallet connected through Satellite Connect, if any. */
|
|
1161
|
+
wallet: CheckoutWallet | null;
|
|
1162
|
+
/** How the buyer pays: from a wallet in this browser, or with a QR code on a phone. */
|
|
1163
|
+
payWith: 'wallet' | 'qr';
|
|
1164
|
+
/**
|
|
1165
|
+
* Sets how the buyer pays.
|
|
1166
|
+
*
|
|
1167
|
+
* @param payWith - `wallet` or `qr`.
|
|
1168
|
+
*/
|
|
1169
|
+
setPayWith: (payWith: 'wallet' | 'qr') => void;
|
|
1170
|
+
/** The payment page of the invoice (its `payUrl`), for the QR code of an EVM method; `null` without one. */
|
|
1171
|
+
payUrl?: string | null;
|
|
1172
|
+
/**
|
|
1173
|
+
* Asks the buyer to connect a wallet of the method's chain family; the price is locked for it once connected.
|
|
1174
|
+
*
|
|
1175
|
+
* @param method - The chosen method.
|
|
1176
|
+
* @returns Whether the page can connect a wallet (Nova Connect or the app's handler).
|
|
1177
|
+
*/
|
|
1178
|
+
connectWallet: (method: CheckoutMethod) => boolean;
|
|
1179
|
+
/**
|
|
1180
|
+
* Asks the buyer to connect a wallet of a chain family and nothing more: no price is locked for it.
|
|
1181
|
+
*
|
|
1182
|
+
* @param family - The chain family.
|
|
1183
|
+
* @returns Whether the page can connect a wallet.
|
|
1184
|
+
*/
|
|
1185
|
+
connectFamily: (family: 'eip155' | 'solana') => boolean;
|
|
1186
|
+
/** Whether the page opened on an invoice already paid: the buyer reads its receipt, nothing was just paid. */
|
|
1187
|
+
openedPaid: boolean;
|
|
1188
|
+
/**
|
|
1189
|
+
* The adapter that pays a chain family from the connected wallet.
|
|
1190
|
+
*
|
|
1191
|
+
* @param family - The family.
|
|
1192
|
+
* @returns The adapter of `NovaPaymentsProvider`, if any.
|
|
1193
|
+
*/
|
|
1194
|
+
adapterFor: (family: PaymentFamily) => PaymentsAdapter | undefined;
|
|
1195
|
+
/** The buyer continues on a phone: the QR code of the payment page shows before any price. */
|
|
1196
|
+
handoff: boolean;
|
|
1197
|
+
/**
|
|
1198
|
+
* Shows or hides the QR code of the payment page.
|
|
1199
|
+
*
|
|
1200
|
+
* @param handoff - Whether it shows.
|
|
1201
|
+
*/
|
|
1202
|
+
setHandoff: (handoff: boolean) => void;
|
|
1203
|
+
/** Goes back to the method step: forgets the locked price and the phone hand-off. */
|
|
1204
|
+
backToMethods: () => void;
|
|
1205
|
+
/**
|
|
1206
|
+
* Whether the buyer continued with a wallet that must confirm the invoice before the price: the step that confirms
|
|
1207
|
+
* it shows while the checkout store waits for the signature (`ConfirmWalletScreen`).
|
|
1208
|
+
*/
|
|
1209
|
+
confirmWallet: boolean;
|
|
1210
|
+
/**
|
|
1211
|
+
* Shows or leaves the step that confirms the wallet ("Back to methods").
|
|
1212
|
+
*
|
|
1213
|
+
* @param show - Whether it shows.
|
|
1214
|
+
*/
|
|
1215
|
+
setConfirmWallet: (show: boolean) => void;
|
|
1216
|
+
/**
|
|
1217
|
+
* Locks the price for the wallet set on the checkout store, or shows the step that confirms the wallet first while
|
|
1218
|
+
* the store says it must (before the price).
|
|
1219
|
+
*
|
|
1220
|
+
* @returns Resolves when the price is locked, refused, or the step shows.
|
|
1221
|
+
*/
|
|
1222
|
+
lockPrice: () => Promise<void>;
|
|
1223
|
+
/**
|
|
1224
|
+
* Remembers the payment the wallet sent: the checkout tracks it while open, and hands it over to the app's Pulsar
|
|
1225
|
+
* store when it closes before Quasar settled it.
|
|
1226
|
+
*
|
|
1227
|
+
* @param payment - The transaction and what it pays.
|
|
1228
|
+
*/
|
|
1229
|
+
onPaymentSent: (payment: SentPayment) => void;
|
|
1230
|
+
/** The buyer opened the automatic payments offer after paying a subscription period. */
|
|
1231
|
+
autoPay: boolean;
|
|
1232
|
+
/**
|
|
1233
|
+
* Opens or closes the automatic payments offer.
|
|
1234
|
+
*
|
|
1235
|
+
* @param autoPay - Whether it shows.
|
|
1236
|
+
*/
|
|
1237
|
+
setAutoPay: (autoPay: boolean) => void;
|
|
1238
|
+
/** The screen that turns automatic payments off is open (`open`), or they were turned off (`done`). */
|
|
1239
|
+
autoPayOff: 'open' | 'done' | null;
|
|
1240
|
+
/**
|
|
1241
|
+
* Opens or closes the screen that turns automatic payments off, or says they were turned off.
|
|
1242
|
+
*
|
|
1243
|
+
* @param autoPayOff - The new state.
|
|
1244
|
+
*/
|
|
1245
|
+
setAutoPayOff: (autoPayOff: 'open' | 'done' | null) => void;
|
|
1246
|
+
/** Whether the wallet has sent the transaction that revokes the permission of this invoice's subscription. */
|
|
1247
|
+
revokeSent: boolean;
|
|
1248
|
+
/**
|
|
1249
|
+
* Keeps that for as long as the page shows the invoice, so the buyer leaving the screen does not send it twice.
|
|
1250
|
+
*
|
|
1251
|
+
* @param sent - Whether it was sent.
|
|
1252
|
+
*/
|
|
1253
|
+
setRevokeSent: (sent: boolean) => void;
|
|
1254
|
+
/**
|
|
1255
|
+
* Opens another invoice in this checkout: the one that replaced a corrected invoice.
|
|
1256
|
+
*
|
|
1257
|
+
* @param token - Its checkout token.
|
|
1258
|
+
*/
|
|
1259
|
+
openInvoice: (token: string) => void;
|
|
1260
|
+
/** Replaces the link of "Contact <seller>", when the app handles it. */
|
|
1261
|
+
onContact?: () => void;
|
|
1262
|
+
/** Seconds before the paid outcome sends the buyer back to the seller; `0` for no automatic return. */
|
|
1263
|
+
autoReturnSeconds: number;
|
|
1264
|
+
/**
|
|
1265
|
+
* How the checkout shows (`display` of `PaymentCheckout`): a modal belongs to the page under it, so its paid outcome
|
|
1266
|
+
* closes it instead of sending the buyer back to the seller's page.
|
|
1267
|
+
*/
|
|
1268
|
+
display: PaymentCheckoutDisplay;
|
|
1269
|
+
/** Class name functions and replacement components of the parts (`customization` of `PaymentCheckout`). */
|
|
1270
|
+
customization: PaymentCheckoutCustomization;
|
|
1271
|
+
}
|
|
1272
|
+
declare const CheckoutContext: react.Context<CheckoutContextValue | null>;
|
|
1273
|
+
/** Gives the parts of a checkout what they share. @internal */
|
|
1274
|
+
declare const CheckoutContextProvider: react.Provider<CheckoutContextValue | null>;
|
|
1275
|
+
|
|
1276
|
+
/** The merchant's logo (or the first letter of its name), name and website, and the test badge. @internal */
|
|
1277
|
+
declare function MerchantBadge({ compact }: {
|
|
1278
|
+
compact?: boolean;
|
|
1279
|
+
}): react.JSX.Element | null;
|
|
1280
|
+
/** The seller as the invoice document names them, the merchant's policies and what Quasar is. @internal */
|
|
1281
|
+
declare function SellerDetailsContent({ checkout, labels }: {
|
|
1282
|
+
checkout: CheckoutView;
|
|
1283
|
+
labels: NovaPaymentsLabels;
|
|
1284
|
+
}): react.JSX.Element;
|
|
1285
|
+
/**
|
|
1286
|
+
* The countdown to the invoice deadline, through every step of the payment until it succeeded (`deadlineState`); it
|
|
1287
|
+
* stays at 00:00 when the deadline passes while the payment confirms. @internal
|
|
1288
|
+
*/
|
|
1289
|
+
declare function DeadlineTimer(): react.JSX.Element | null;
|
|
1290
|
+
/** The lines, subtotal and tax of the invoice. @internal */
|
|
1291
|
+
declare function OrderLines(): react.JSX.Element | null;
|
|
1292
|
+
/** The total of the invoice, which stays in place while the lines scroll. @internal */
|
|
1293
|
+
declare function OrderTotal(): react.JSX.Element | null;
|
|
1294
|
+
/** "Secured by Quasar" and the seller's support email, at the same place on every step (WCAG 3.2.6). @internal */
|
|
1295
|
+
declare function SummaryFooter(): react.JSX.Element;
|
|
1296
|
+
/** A button that shows or hides a part, with `aria-expanded` and `aria-controls`. @internal */
|
|
1297
|
+
declare function Disclosure({ label, children, className, buttonClassName, growsUp, }: {
|
|
1298
|
+
label: string;
|
|
1299
|
+
children: ReactNode;
|
|
1300
|
+
className?: string;
|
|
1301
|
+
buttonClassName?: string;
|
|
1302
|
+
/** The part stands at the bottom of its panel, so its content pushes the button upwards: the arrow says so. */
|
|
1303
|
+
growsUp?: boolean;
|
|
1304
|
+
}): react.JSX.Element;
|
|
1305
|
+
/**
|
|
1306
|
+
* The order panel on the left of the checkout (from 640 px): the merchant, the seller details (unfolded in place, the
|
|
1307
|
+
* lines scroll while the deadline and the total stay), the countdown to the deadline (through every step of the
|
|
1308
|
+
* payment, also while it confirms, until it succeeded), the lines and the total, and the help.
|
|
1309
|
+
*
|
|
1310
|
+
* @returns The order panel.
|
|
1311
|
+
*/
|
|
1312
|
+
declare function CheckoutSummary(): react.JSX.Element | null;
|
|
1313
|
+
/**
|
|
1314
|
+
* The order on a phone, above the steps: the total and the countdown to the deadline (until the payment succeeded), with
|
|
1315
|
+
* the lines and the seller details behind a "Details" button.
|
|
1316
|
+
*
|
|
1317
|
+
* @param props - The classes.
|
|
1318
|
+
* @param props.className - Classes added to the order (`customization.classNames.compactSummary`).
|
|
1319
|
+
* @returns The compact order.
|
|
1320
|
+
*/
|
|
1321
|
+
declare function CompactSummary({ className }?: {
|
|
1322
|
+
className?: string;
|
|
1323
|
+
}): react.JSX.Element | null;
|
|
1324
|
+
|
|
1325
|
+
/**
|
|
1326
|
+
* The confirm step: the transaction is on its way and Quasar follows it until it is final. It reuses the status and
|
|
1327
|
+
* progress of Nova Transactions (Sent → Confirming → Paid, in the language of the checkout) and shows the network, the
|
|
1328
|
+
* amount, the transaction with its explorer link and the sender. The buyer may close the window: the payment keeps
|
|
1329
|
+
* going. It also shows a payment of the invoice that this page did not hand over while Quasar reports it on its way
|
|
1330
|
+
* (the page was reopened or reloaded, another tab paid, Quasar found a Solana Pay transfer), instead of offering to pay
|
|
1331
|
+
* again: its note asks the buyer to wait for it. When the invoice deadline passes while a payment is on its way (the
|
|
1332
|
+
* countdown of the order stays at 00:00), and the invoice is still `open` or `underpaid`, the note follows the payment:
|
|
1333
|
+
* sent before the deadline, it says that the payment was sent in time and is being confirmed (Quasar keeps the invoice
|
|
1334
|
+
* open for a payment it learned of before the deadline while it confirms: for this page's payment Quasar's word on it
|
|
1335
|
+
* decides, `paymentSentInTime` of the checkout store, whatever the clock of the page says; else `paymentCountsUntil`;
|
|
1336
|
+
* with a Quasar that reports neither, a payment this page handed over before the deadline by its clock); otherwise it
|
|
1337
|
+
* says that the seller accepts or returns a payment that arrives after the invoice closes. A payment that failed or settled is no
|
|
1338
|
+
* longer on its way, and the usual note comes back. While the store hands the transaction over again, as Quasar is out of
|
|
1339
|
+
* reach for a moment, the note asks to keep the page open: closing it is what could lose the hand-over.
|
|
1340
|
+
*
|
|
1341
|
+
* @returns The confirm step.
|
|
1342
|
+
*/
|
|
1343
|
+
declare function ConfirmScreen(): react.JSX.Element;
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* The step that confirms the paying wallet, right after the wallet and the method and before
|
|
1347
|
+
* the price, for an EVM payment the buyer's wallet sends itself (`payerProof` of the checkout store is `required`): one
|
|
1348
|
+
* sentence that it is free and moves no money, the summary of what the wallet signs (the invoice, the seller, the
|
|
1349
|
+
* amount and the wallet), and the main button that opens the wallet's signature request. Meanwhile the window of the
|
|
1350
|
+
* wallet covers the step, with the site the message names to check, a line that the wallet may show it as a sign-in
|
|
1351
|
+
* request for that site, and "Try again" (signing again moves no money); a smart wallet is said to ask for its passkey.
|
|
1352
|
+
* Once the window is closed the button works again, also while the wallet never answered. A refusal keeps the buyer
|
|
1353
|
+
* on the step, with its reason and the same button to try again; "Back to methods" returns to the methods (or to the
|
|
1354
|
+
* underpaid invoice whose rest another wallet pays). Once the wallet signed, the price is locked on this step and the
|
|
1355
|
+
* pay step follows. One signature per invoice and wallet: a new price or token needs no new one, nor a new network for
|
|
1356
|
+
* an ordinary wallet (a smart wallet's signature counts on its network only).
|
|
1357
|
+
*
|
|
1358
|
+
* Side effects: wallet prompts (a network switch, the signature); `POST payer-proof/message`, `POST payer-proof` and
|
|
1359
|
+
* `POST quote` through the checkout store.
|
|
1360
|
+
*
|
|
1361
|
+
* @returns The step.
|
|
1362
|
+
*/
|
|
1363
|
+
declare function ConfirmWalletScreen(): react.JSX.Element | null;
|
|
1364
|
+
|
|
1365
|
+
/**
|
|
1366
|
+
* The question when the buyer closes the checkout before anything is sent: the invoice stays open until its deadline,
|
|
1367
|
+
* reopened from the email or the seller's site, and the locked price is released. It is a Nova dialog of its own, over
|
|
1368
|
+
* the checkout: one backdrop dims the whole screen, the checkout and its frame included (a layer inside the checkout
|
|
1369
|
+
* left its frame sharp around the dimmed content); on a phone it slides up from the bottom like the other Nova dialogs.
|
|
1370
|
+
* "Stay and pay", Escape or a click outside keep the checkout and give the focus back where it was, "Leave" closes it.
|
|
1371
|
+
* The heading takes the focus.
|
|
1372
|
+
*
|
|
1373
|
+
* @param props - The answers.
|
|
1374
|
+
* @param props.onStay - Keeps the checkout open.
|
|
1375
|
+
* @param props.onLeave - Closes it.
|
|
1376
|
+
* @returns The question, over the checkout.
|
|
1377
|
+
*/
|
|
1378
|
+
declare function LeaveDialog({ onStay, onLeave }: {
|
|
1379
|
+
onStay: () => void;
|
|
1380
|
+
onLeave: () => void;
|
|
1381
|
+
}): react.JSX.Element;
|
|
1382
|
+
|
|
1383
|
+
/** Props of {@link LocaleSwitcher}. */
|
|
1384
|
+
interface LocaleSwitcherProps {
|
|
1385
|
+
/** The language of the checkout. */
|
|
1386
|
+
locale: string;
|
|
1387
|
+
/** The labels of that language. */
|
|
1388
|
+
labels: NovaPaymentsLabels;
|
|
1389
|
+
/** Whether the receipt is issued: then the language changes the page only. */
|
|
1390
|
+
receiptIssued?: boolean;
|
|
1391
|
+
/**
|
|
1392
|
+
* Called with the language the buyer picks.
|
|
1393
|
+
*
|
|
1394
|
+
* @param locale - The picked language.
|
|
1395
|
+
*/
|
|
1396
|
+
onSelect: (locale: CheckoutLocale) => void;
|
|
1397
|
+
/** Classes added to the wrapper. */
|
|
1398
|
+
className?: string;
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* The language menu of the checkout: a button with a globe and the language code, always next to the close button,
|
|
1402
|
+
* that opens the six languages under their own names (each with its `lang`). Arrow keys move, Enter or Space picks,
|
|
1403
|
+
* Escape closes and gives the focus back to the button; a click outside closes it. Before payment the note says the
|
|
1404
|
+
* documents follow the language.
|
|
1405
|
+
*
|
|
1406
|
+
* Side effect: while open, a `pointerdown` listener on the document closes it on a click outside.
|
|
1407
|
+
*
|
|
1408
|
+
* @param props - See {@link LocaleSwitcherProps}.
|
|
1409
|
+
* @returns The language menu.
|
|
1410
|
+
*/
|
|
1411
|
+
declare function LocaleSwitcher({ locale, labels, receiptIssued, onSelect, className }: LocaleSwitcherProps): react.JSX.Element;
|
|
1412
|
+
|
|
1413
|
+
/**
|
|
1414
|
+
* The method step: the token first, then its network (left out when the token has one), then how to pay — from a
|
|
1415
|
+
* wallet in this browser or with a QR code on a phone. The connected wallet's network comes first and is marked, the
|
|
1416
|
+
* merchant's Popular methods next; a discount or markup of a method shows on it. Paying from a wallet needs the chain
|
|
1417
|
+
* adapter of the method's family (`adapters` of `NovaPaymentsProvider`). "Continue" locks the price for the connected
|
|
1418
|
+
* wallet (or connects one first), locks it without a payer for a Solana Pay QR code, or shows the QR code of the
|
|
1419
|
+
* payment page for an EVM method paid on a phone; a wallet that must confirm the invoice first (an EVM payment it sends
|
|
1420
|
+
* itself) goes to the step that confirms it before the price. A consent the seller asks (`checkout.consent`) is a box the buyer
|
|
1421
|
+
* ticks under the ways to pay; a required one keeps "Continue" off until it is ticked, and the quote carries it.
|
|
1422
|
+
*
|
|
1423
|
+
* @returns The method step.
|
|
1424
|
+
*/
|
|
1425
|
+
declare function MethodScreen(): react.JSX.Element | null;
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* The paid outcome: the amount, network, time and transaction, the steps done, a refund made later, the receipt to
|
|
1429
|
+
* download, the automatic payments offer of a subscription, and the way back to the seller (`successUrl`) with a
|
|
1430
|
+
* visible countdown and "Stay here" (WCAG 2.2.1). In a modal it offers Close instead: the page under it is the
|
|
1431
|
+
* seller's, and loading it again would close everything at once.
|
|
1432
|
+
*
|
|
1433
|
+
* Side effects: navigates to the seller's `successUrl` when the countdown ends.
|
|
1434
|
+
*
|
|
1435
|
+
* @returns The paid outcome.
|
|
1436
|
+
*/
|
|
1437
|
+
declare function PaidScreen(): react.JSX.Element | null;
|
|
1438
|
+
|
|
1439
|
+
/**
|
|
1440
|
+
* The pay step: the connected wallet (with "Change"), the exact amount to send with its network and invoice value,
|
|
1441
|
+
* the price lock with "Keep this price" in its last minute, the rate, the network fee (the merchant's or an estimate),
|
|
1442
|
+
* the recipient, and the main action — "Sign to pay" when the merchant pays the gas, "Pay" otherwise, "Switch to …"
|
|
1443
|
+
* on the wrong network, "Confirm this wallet to pay" before a transfer or a paymaster payment of a method the gasless
|
|
1444
|
+
* relay could pay (the wallet signs Quasar's free confirmation of the invoice first; the relay's authorization needs
|
|
1445
|
+
* none). Before the prompt it reads the wallet's balance (unless `config.balanceCheck` is `false`)
|
|
1446
|
+
* and, when it is short, offers the methods the wallet can pay and the seller's top-up link. `handlers.onSubmit` wraps
|
|
1447
|
+
* the pay button. A Solana payment off mainnet reminds the buyer to switch the wallet to its cluster (Solana wallets
|
|
1448
|
+
* choose their network themselves), with the steps of Phantom and Solflare. The note under the buttons says that the
|
|
1449
|
+
* payment goes straight to the merchant and, when the merchant checks paying wallets (`amlScreening` of the
|
|
1450
|
+
* checkout), that it does.
|
|
1451
|
+
*
|
|
1452
|
+
* Side effects: balance, fee and wallet capability reads from the network through the chain adapter (no request to
|
|
1453
|
+
* Quasar); wallet prompts; checkout requests to Quasar; on a Solana payment, `switchNetwork` of the Satellite store
|
|
1454
|
+
* moves the app's Solana connection to the payment's cluster (no wallet request).
|
|
1455
|
+
*
|
|
1456
|
+
* @returns The pay step.
|
|
1457
|
+
*/
|
|
1458
|
+
declare function PayScreen(): react.JSX.Element | null;
|
|
1459
|
+
|
|
1460
|
+
/**
|
|
1461
|
+
* The QR code step. For Solana, a Solana Pay transfer request a phone wallet scans (or opens with "Open in wallet
|
|
1462
|
+
* app"), with the exact amount, the recipient, the price lock and a warning against paying from an exchange; the page
|
|
1463
|
+
* waits for the payment, which Quasar finds by the reference key. For an EVM method, the QR code of the payment page
|
|
1464
|
+
* opens this checkout on the phone, before any price.
|
|
1465
|
+
*
|
|
1466
|
+
* @returns The QR code step.
|
|
1467
|
+
*/
|
|
1468
|
+
declare function QrScreen(): react.JSX.Element | null;
|
|
1469
|
+
|
|
1470
|
+
/** What a refund asks for: the amount and mode `start` takes (`RefundParams` of `@tuwaio/quasar-sdk`). */
|
|
1471
|
+
type RefundRequest = Parameters<RefundState['start']>[1];
|
|
1472
|
+
/**
|
|
1473
|
+
* Where a refund stands for the merchant: `amount` (what to refund), `requesting`, `connect` (a wallet of the
|
|
1474
|
+
* payment's network), `confirm`, `switching` and `wallet` (the wallet asks), `submitting`, `confirming` (the network
|
|
1475
|
+
* confirms it), `confirmed` or `failed`.
|
|
1476
|
+
*/
|
|
1477
|
+
type RefundStep = 'amount' | 'requesting' | 'connect' | 'confirm' | 'switching' | 'wallet' | 'submitting' | 'confirming' | 'confirmed' | 'failed';
|
|
1478
|
+
/**
|
|
1479
|
+
* Why a refund was not sent: the wallet holds too little (`notEnough`), the merchant declined, the wallet cannot send
|
|
1480
|
+
* it or sent it on another network, it failed, Quasar does not know the payer (`noRecipient`), or Quasar did not answer when
|
|
1481
|
+
* the window looked again before asking the wallet (`unreachable`), the wallet is the one that paid and would only pay the
|
|
1482
|
+
* fee (`fromBuyer`), or the merchant closed the wait while the request stays open in the wallet (`stillInWallet`).
|
|
1483
|
+
*/
|
|
1484
|
+
type RefundProblem = 'notEnough' | 'declined' | 'unsupported' | 'wrongNetwork' | 'failed' | 'noRecipient' | 'unreachable' | 'fromBuyer' | 'stillInWallet';
|
|
1485
|
+
/** What {@link useRefund} needs. */
|
|
1486
|
+
interface UseRefundParams {
|
|
1487
|
+
/** The refund store (`createRefundStore` of `@tuwaio/quasar-sdk/checkout`). */
|
|
1488
|
+
store: RefundStore;
|
|
1489
|
+
/** The paid invoice to refund. */
|
|
1490
|
+
invoiceId: string;
|
|
1491
|
+
/** Its number, for the transaction in Pulsar (the ID without one). */
|
|
1492
|
+
invoice?: string;
|
|
1493
|
+
/** The refund the app worked out: asked for at once, without the amount step. */
|
|
1494
|
+
params?: RefundRequest;
|
|
1495
|
+
/** Whether the window is open: when it opens again after a confirmed refund, it starts over for another one. */
|
|
1496
|
+
open?: boolean;
|
|
1497
|
+
/** The labels of the language. */
|
|
1498
|
+
labels: NovaPaymentsLabels;
|
|
1499
|
+
/** The language, for amounts. */
|
|
1500
|
+
locale: string;
|
|
1501
|
+
/**
|
|
1502
|
+
* Connects a wallet of the payment's chain family, for apps without Nova Connect (the `onConnectWallet` of
|
|
1503
|
+
* `NovaPaymentsProvider` otherwise). Inside `NovaConnectProvider` the refund opens its connect modal instead.
|
|
1504
|
+
*
|
|
1505
|
+
* @param family - The chain family of the payment.
|
|
1506
|
+
*/
|
|
1507
|
+
onConnectWallet?: (family: PaymentFamily) => void;
|
|
1508
|
+
}
|
|
1509
|
+
/** What {@link useRefund} returns. */
|
|
1510
|
+
interface RefundFlow {
|
|
1511
|
+
/** Where the refund stands. */
|
|
1512
|
+
step: RefundStep;
|
|
1513
|
+
/** The refund store's phase. */
|
|
1514
|
+
phase: RefundPhase;
|
|
1515
|
+
/**
|
|
1516
|
+
* What a refund would send, before it is asked for: a requested refund holds its amount until it is sent.
|
|
1517
|
+
*
|
|
1518
|
+
* @param request - What to refund.
|
|
1519
|
+
* @returns The preview; `null` when the store cannot show one; `refused` when Quasar would refuse it (`error` says why).
|
|
1520
|
+
*/
|
|
1521
|
+
preview: (request: RefundRequest) => Promise<RefundPreview | 'refused' | null>;
|
|
1522
|
+
/** The refund, once asked for. */
|
|
1523
|
+
refund: RefundState['refund'];
|
|
1524
|
+
/** Why the last request to Quasar failed. */
|
|
1525
|
+
error: CheckoutError | null;
|
|
1526
|
+
/** What the wallet sends, or `null` before the refund is asked for or without a payer. */
|
|
1527
|
+
transfer: PaymentInstructions | null;
|
|
1528
|
+
/** The CAIP-2 chain of the payment. */
|
|
1529
|
+
chainId: string | null;
|
|
1530
|
+
/** The name of its network. */
|
|
1531
|
+
network: string;
|
|
1532
|
+
/** The amount to send with its symbol. */
|
|
1533
|
+
amount: string;
|
|
1534
|
+
/** The connected wallet, when it is of the payment's chain family. */
|
|
1535
|
+
wallet: CheckoutWallet | null;
|
|
1536
|
+
/** Whether the EVM wallet is on another network than the payment's: {@link RefundFlow.switchNetwork} first. */
|
|
1537
|
+
wrongNetwork: boolean;
|
|
1538
|
+
/** What the wallet holds of the asset: `undefined` while read, `null` when unknown. */
|
|
1539
|
+
balance: bigint | null | undefined;
|
|
1540
|
+
/** The estimated network fee. */
|
|
1541
|
+
fee: NativeFee | null | undefined;
|
|
1542
|
+
/** Why the refund was not sent, until the next try. */
|
|
1543
|
+
problem: RefundProblem | null;
|
|
1544
|
+
/** The transaction the wallet sent; while Quasar has not taken it, {@link RefundFlow.send} hands it over again. */
|
|
1545
|
+
txKey: string | null;
|
|
1546
|
+
/** The explorer link of a transaction of the refund, when the chain has one. */
|
|
1547
|
+
transactionUrl: (hash: string) => string | undefined;
|
|
1548
|
+
/** The explorer link of an address on the chain of the refund, when the chain has one. */
|
|
1549
|
+
addressUrl: (address: string) => string | undefined;
|
|
1550
|
+
/** Whether the page can connect a wallet. */
|
|
1551
|
+
canConnect: boolean;
|
|
1552
|
+
/** Whether the connect modal is open. */
|
|
1553
|
+
connecting: boolean;
|
|
1554
|
+
/**
|
|
1555
|
+
* Asks Quasar for the refund.
|
|
1556
|
+
*
|
|
1557
|
+
* @param params - Amount, mode and reason.
|
|
1558
|
+
*/
|
|
1559
|
+
start: (params: RefundRequest) => Promise<void>;
|
|
1560
|
+
/** Asks the merchant to connect a wallet of the payment's chain family. */
|
|
1561
|
+
connect: () => void;
|
|
1562
|
+
/** Asks the EVM wallet to switch to the payment's network; sends nothing. */
|
|
1563
|
+
switchNetwork: () => Promise<void>;
|
|
1564
|
+
/** Sends the refund from the wallet (switching its network first) and hands its transaction to Quasar. */
|
|
1565
|
+
send: () => Promise<void>;
|
|
1566
|
+
/**
|
|
1567
|
+
* Closes the wait for the wallet. Its request stays open there: a transaction it sends later is still handed to Quasar, a
|
|
1568
|
+
* refusal is not shown, and {@link RefundFlow.send} asks it nothing more meanwhile.
|
|
1569
|
+
*/
|
|
1570
|
+
dismiss: () => void;
|
|
1571
|
+
/** Whether a send is under way, from the press on: the button shows it, and another press sends nothing. */
|
|
1572
|
+
sending: boolean;
|
|
1573
|
+
}
|
|
1574
|
+
/**
|
|
1575
|
+
* Refunds a payment from the merchant's connected wallet: asks Quasar for the refund through the store,
|
|
1576
|
+
* sends its transfer to the payer with the payments adapter of the chain family (switching the wallet to the payment's
|
|
1577
|
+
* network first, and never prompting a wallet that holds too little), hands the transaction to Quasar and lets the
|
|
1578
|
+
* store follow it until Quasar confirms it and issues the credit note. A transaction the wallet sent is handed over
|
|
1579
|
+
* again on the next {@link RefundFlow.send}, never sent twice. Before the wallet is asked the refund is read again, and nothing
|
|
1580
|
+
* goes out when it no longer waits or Quasar does not answer. With the app's Pulsar store (`pulsar` of
|
|
1581
|
+
* `NovaPaymentsProvider`) and an adapter that describes its transactions, the refund is also tracked by Pulsar, and
|
|
1582
|
+
* Nova Transactions shows its toast.
|
|
1583
|
+
*
|
|
1584
|
+
* Side effects: the store's calls; wallet prompts; balance and fee reads from the network; the Pulsar store.
|
|
1585
|
+
*
|
|
1586
|
+
* @param params - See {@link UseRefundParams}.
|
|
1587
|
+
* @returns See {@link RefundFlow}.
|
|
1588
|
+
*/
|
|
1589
|
+
declare function useRefund({ store, invoiceId, invoice, params, open, labels, locale, onConnectWallet, }: UseRefundParams): RefundFlow;
|
|
1590
|
+
|
|
1591
|
+
/** A refund of the store (`Refund` of `@tuwaio/quasar-sdk`). */
|
|
1592
|
+
type Refund = NonNullable<RefundState['refund']>;
|
|
1593
|
+
/** Props of {@link RefundDialog}. */
|
|
1594
|
+
interface RefundDialogProps {
|
|
1595
|
+
/** Whether the window is open. */
|
|
1596
|
+
open: boolean;
|
|
1597
|
+
/**
|
|
1598
|
+
* Opens or closes the window.
|
|
1599
|
+
*
|
|
1600
|
+
* @param open - Whether it is open.
|
|
1601
|
+
*/
|
|
1602
|
+
onOpenChange: (open: boolean) => void;
|
|
1603
|
+
/**
|
|
1604
|
+
* The refund store (`createRefundStore` of `@tuwaio/quasar-sdk/checkout`), whose calls the app runs on its server
|
|
1605
|
+
* with the secret key. One store per invoice: it keeps the refund while the window is closed.
|
|
1606
|
+
*/
|
|
1607
|
+
store: RefundStore;
|
|
1608
|
+
/** The paid invoice to refund. */
|
|
1609
|
+
invoiceId: string;
|
|
1610
|
+
/** Its number, shown in the title and in the transaction of Pulsar. */
|
|
1611
|
+
invoice?: string;
|
|
1612
|
+
/** The refund the app worked out (amount, mode, reason): asked for at once, without the amount step. */
|
|
1613
|
+
params?: RefundRequest;
|
|
1614
|
+
/** The invoice currency, for the amount step. Defaults to `USD`. */
|
|
1615
|
+
currency?: string;
|
|
1616
|
+
/** What is left to refund, with its currency, shown under the amount (`20.00 USD`). */
|
|
1617
|
+
refundable?: string;
|
|
1618
|
+
/** The language (a BCP 47 tag). Defaults to `en`. */
|
|
1619
|
+
locale?: string;
|
|
1620
|
+
/** Rows the app adds: to the confirm step (what the refund takes back) and to the refunded step. */
|
|
1621
|
+
details?: {
|
|
1622
|
+
confirm?: ReactNode;
|
|
1623
|
+
done?: ReactNode;
|
|
1624
|
+
};
|
|
1625
|
+
/** "Record refund": the app's form for a refund sent another way; offered when the wallet does not send it. */
|
|
1626
|
+
onRecord?: () => void;
|
|
1627
|
+
/**
|
|
1628
|
+
* Connects a wallet of the payment's chain family, for apps without Nova Connect; overrides the `onConnectWallet` of
|
|
1629
|
+
* `NovaPaymentsProvider`. Inside `NovaConnectProvider` (the app's, or Nova's own connection) the window opens its
|
|
1630
|
+
* connect modal instead.
|
|
1631
|
+
*
|
|
1632
|
+
* @param family - The chain family of the payment.
|
|
1633
|
+
*/
|
|
1634
|
+
onConnectWallet?: (family: PaymentFamily) => void;
|
|
1635
|
+
/**
|
|
1636
|
+
* Called once Quasar confirmed the refund and issued its credit note.
|
|
1637
|
+
*
|
|
1638
|
+
* @param refund - The confirmed refund (`Refund` of `@tuwaio/quasar-sdk`).
|
|
1639
|
+
*/
|
|
1640
|
+
onRefunded?: (refund: NonNullable<RefundState['refund']>) => void;
|
|
1641
|
+
}
|
|
1642
|
+
/** Props of {@link RefundButton}. */
|
|
1643
|
+
interface RefundButtonProps extends Omit<RefundDialogProps, 'open' | 'onOpenChange'> {
|
|
1644
|
+
/** The button's text. Defaults to the `refund.button` label. */
|
|
1645
|
+
label?: ReactNode;
|
|
1646
|
+
/** Classes of the button. */
|
|
1647
|
+
className?: string;
|
|
1648
|
+
/** Whether the button is disabled. */
|
|
1649
|
+
disabled?: boolean;
|
|
1650
|
+
}
|
|
1651
|
+
/**
|
|
1652
|
+
* A button that refunds a paid invoice from the merchant's connected wallet: it opens {@link RefundDialog}. Put it
|
|
1653
|
+
* inside {@link NovaPaymentsProvider}: it uses the provider's wallet connection (the app's Satellite store and Nova
|
|
1654
|
+
* Connect when the app has them, else Nova's own `ownConnection`) and its adapters. In an app whose wallets connect
|
|
1655
|
+
* without Nova Connect, pass `onConnectWallet` here or to the provider.
|
|
1656
|
+
*
|
|
1657
|
+
* @param props - See {@link RefundButtonProps}.
|
|
1658
|
+
* @returns The button and its window.
|
|
1659
|
+
*
|
|
1660
|
+
* @example
|
|
1661
|
+
* ```tsx
|
|
1662
|
+
* import { createRefundStore } from '@tuwaio/payments-sdk/checkout';
|
|
1663
|
+
* import { RefundButton } from '@tuwaio/payments-sdk';
|
|
1664
|
+
*
|
|
1665
|
+
* // refundInvoice, submitRefund and getRefund are Server Actions calling quasar.payments
|
|
1666
|
+
* const refunds = createRefundStore({ request: refundInvoice, submit: submitRefund, get: getRefund });
|
|
1667
|
+
*
|
|
1668
|
+
* <RefundButton store={refunds} invoiceId={invoice.id} invoice={invoice.number} currency="USD" />;
|
|
1669
|
+
* ```
|
|
1670
|
+
*/
|
|
1671
|
+
declare function RefundButton({ label, className, disabled, ...props }: RefundButtonProps): react.JSX.Element;
|
|
1672
|
+
/**
|
|
1673
|
+
* The window of a refund from the merchant's wallet: what to refund (skipped
|
|
1674
|
+
* with `params`), a wallet of the payment's network, the confirmation (what goes where, from which wallet with its
|
|
1675
|
+
* balance, the network fee, and the app's rows), the wallet's prompt, the transaction on its way, and the credit note.
|
|
1676
|
+
* A refund the wallet did not send says why, offers to send it again and the app's "Record refund". The refund
|
|
1677
|
+
* goes on while the window is closed: the store follows it.
|
|
1678
|
+
*
|
|
1679
|
+
* Side effects: those of `useRefund` (the store's calls, wallet prompts, balance and fee reads, the Pulsar store).
|
|
1680
|
+
*
|
|
1681
|
+
* @param props - See {@link RefundDialogProps}.
|
|
1682
|
+
* @returns The window.
|
|
1683
|
+
*/
|
|
1684
|
+
declare function RefundDialog({ open, onOpenChange, locale, onRefunded, ...props }: RefundDialogProps): react.JSX.Element;
|
|
1685
|
+
/** The step of a refund the window shows. @internal */
|
|
1686
|
+
declare function RefundSteps({ flow, labels, locale, close, currency, refundable, details, onRecord, }: Pick<RefundDialogProps, 'currency' | 'refundable' | 'details' | 'onRecord'> & {
|
|
1687
|
+
flow: RefundFlow;
|
|
1688
|
+
labels: NovaPaymentsLabels;
|
|
1689
|
+
locale: string;
|
|
1690
|
+
close: () => void;
|
|
1691
|
+
}): react.JSX.Element;
|
|
1692
|
+
/** Whether a refund has been on its way for long, from when it last changed. @internal */
|
|
1693
|
+
declare const isSlow: (refund: Pick<Refund, "createdAt" | "updatedAt"> | null | undefined) => boolean;
|
|
1694
|
+
/** A refusal of Quasar in the words of the window, or of the app when it said it in the reader's language. @internal */
|
|
1695
|
+
declare const refusalText: (error: {
|
|
1696
|
+
code: string;
|
|
1697
|
+
text?: string;
|
|
1698
|
+
}, text: NovaPaymentsLabels["refund"]) => string;
|
|
1699
|
+
/**
|
|
1700
|
+
* A refund whose transaction failed on-chain: why, then the same refund asked for again, priced now, or recorded.
|
|
1701
|
+
*
|
|
1702
|
+
* @internal
|
|
1703
|
+
*/
|
|
1704
|
+
declare function FailedStep({ flow, labels, locale, values, recordAction, close, }: {
|
|
1705
|
+
flow: RefundFlow;
|
|
1706
|
+
labels: NovaPaymentsLabels;
|
|
1707
|
+
locale: string;
|
|
1708
|
+
values: Record<string, string>;
|
|
1709
|
+
recordAction: ReactNode;
|
|
1710
|
+
close: () => void;
|
|
1711
|
+
}): react.JSX.Element;
|
|
1712
|
+
/**
|
|
1713
|
+
* What to refund: an amount of the invoice currency (everything left when empty) or everything received.
|
|
1714
|
+
*
|
|
1715
|
+
* @internal
|
|
1716
|
+
*/
|
|
1717
|
+
declare function AmountStep({ flow, labels, locale, currency, refundable, }: {
|
|
1718
|
+
flow: RefundFlow;
|
|
1719
|
+
labels: NovaPaymentsLabels;
|
|
1720
|
+
locale: string;
|
|
1721
|
+
currency: string;
|
|
1722
|
+
refundable?: string;
|
|
1723
|
+
}): react.JSX.Element;
|
|
1724
|
+
declare function ConfirmStep({ flow, labels, locale, values, details, recordAction, }: {
|
|
1725
|
+
flow: RefundFlow;
|
|
1726
|
+
labels: NovaPaymentsLabels;
|
|
1727
|
+
locale: string;
|
|
1728
|
+
values: Record<string, string>;
|
|
1729
|
+
details?: ReactNode;
|
|
1730
|
+
recordAction: ReactNode;
|
|
1731
|
+
}): react.JSX.Element;
|
|
1732
|
+
|
|
1733
|
+
/**
|
|
1734
|
+
* What the wallet asks for: a gasless signature, a transaction, a network switch, the permission of automatic
|
|
1735
|
+
* payments, the signature that confirms the paying wallet (`proof`), or Quasar takes the payment.
|
|
1736
|
+
*/
|
|
1737
|
+
type WalletPromptKind = 'sign' | 'confirm' | 'switch' | 'permission' | 'proof' | 'submitting';
|
|
1738
|
+
/** Props of {@link WalletPrompt}. */
|
|
1739
|
+
interface WalletPromptProps {
|
|
1740
|
+
/** What the wallet asks for. */
|
|
1741
|
+
kind: WalletPromptKind;
|
|
1742
|
+
/** The wallet's name, as it calls itself (`name` of the connected wallet). */
|
|
1743
|
+
walletName: string;
|
|
1744
|
+
/** The wallet's id, for the icon Nova has of it when the wallet gives none. */
|
|
1745
|
+
walletId: string;
|
|
1746
|
+
/** The icon the wallet gives itself (`icon` of the connected wallet), usually a `data:` URI. */
|
|
1747
|
+
walletIcon?: string;
|
|
1748
|
+
/** The amount with its symbol. */
|
|
1749
|
+
amount: string;
|
|
1750
|
+
/** The seller. */
|
|
1751
|
+
merchant: string;
|
|
1752
|
+
/** The network of the payment. */
|
|
1753
|
+
network: string;
|
|
1754
|
+
/** The recipient, shortened (not copyable: it is checked, never typed). */
|
|
1755
|
+
to: string;
|
|
1756
|
+
/** The countdown of the price lock; `null` once it ended. */
|
|
1757
|
+
priceTime: string | null;
|
|
1758
|
+
/** Asks the wallet again; only where a second request cannot pay twice (a signature). */
|
|
1759
|
+
onRetry?: () => void;
|
|
1760
|
+
/** What the window says instead of the text of its kind (the signature that confirms the wallet). */
|
|
1761
|
+
text?: string;
|
|
1762
|
+
/** The rows to check in the wallet instead of the payment's (the signature that confirms the wallet). */
|
|
1763
|
+
details?: {
|
|
1764
|
+
name: string;
|
|
1765
|
+
value: string;
|
|
1766
|
+
}[];
|
|
1767
|
+
/** A line under the text: how the wallet may present the request (the signature that confirms the wallet). */
|
|
1768
|
+
hint?: string;
|
|
1769
|
+
/** Closes the window. */
|
|
1770
|
+
onCancel: () => void;
|
|
1771
|
+
/**
|
|
1772
|
+
* The height in px of the step the window stands for, measured while the step showed and capped at the room of the
|
|
1773
|
+
* checkout pane. Below 640 px, where the checkout has no fixed height, the window keeps it as its minimum height, so
|
|
1774
|
+
* the sheet does not shrink while the wallet asks and grow back after. Wider screens have the fixed height of the
|
|
1775
|
+
* checkout and ignore it.
|
|
1776
|
+
*/
|
|
1777
|
+
stepHeight?: number | null;
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* The window that stands for the pay step while the wallet asks the buyer: what to sign or confirm, and what to check
|
|
1781
|
+
* in the wallet before — the amount, the recipient, the network and the time left of the price (WCAG 3.3.4); for the
|
|
1782
|
+
* signature that confirms the paying wallet, the invoice, the seller and the site the message names. It sits in the
|
|
1783
|
+
* flow of the screen, in place of the step: a screen that shows it (a custom screen of
|
|
1784
|
+
* `customization.components.screens` too) hides its step while it shows, with `display: none` and `inert` (the step
|
|
1785
|
+
* keeps its state), so the window fills the checkout pane, centered, without the scrollbar of a taller step, and
|
|
1786
|
+
* passes the step's height as `stepHeight`, so a phone keeps the height of the sheet. The heading takes the focus, so
|
|
1787
|
+
* screen readers say what happens; when the window closes and the step comes back, the focus returns to the button
|
|
1788
|
+
* that opened it ("Pay", "Switch to …") from the page or the dialog frame it fell back to, unless the buyer moved it
|
|
1789
|
+
* elsewhere. "Try again" re-asks only for a signature; for a transaction the buyer is sent to the wallet, where the
|
|
1790
|
+
* request still waits, so it cannot be paid twice.
|
|
1791
|
+
*
|
|
1792
|
+
* @param props - See {@link WalletPromptProps}.
|
|
1793
|
+
* @returns The window.
|
|
1794
|
+
*/
|
|
1795
|
+
declare function WalletPrompt({ kind, walletName, walletId, walletIcon, amount, merchant, network, to, priceTime, onRetry, text, details, hint, onCancel, stepHeight, }: WalletPromptProps): react.JSX.Element;
|
|
1796
|
+
|
|
1797
|
+
/**
|
|
1798
|
+
* Reads a value once per key: again when the key changes, never for a `null` key. An answer for an old key is
|
|
1799
|
+
* dropped. Used for the balances and fee estimates the pay step reads from the network.
|
|
1800
|
+
*
|
|
1801
|
+
* @param key - What the value depends on, as a string; `null` to read nothing.
|
|
1802
|
+
* @param load - Reads the value for the current key.
|
|
1803
|
+
* @returns The value; `undefined` while it is read (or without a key); `null` when the read failed.
|
|
1804
|
+
*/
|
|
1805
|
+
declare function useAsyncValue<T>(key: string | null, load: () => Promise<T> | T): T | null | undefined;
|
|
1806
|
+
/**
|
|
1807
|
+
* Reads a value like {@link useAsyncValue}, and again when the buyer comes back to the page (focus, visibility) or
|
|
1808
|
+
* `refresh` changes, keeping the last answer meanwhile: a balance the buyer tops up in the wallet opens the pay button
|
|
1809
|
+
* without a reload, and a read under way does not open it before the answer.
|
|
1810
|
+
*
|
|
1811
|
+
* Side effects: `focus` and `visibilitychange` listeners while there is a key.
|
|
1812
|
+
*
|
|
1813
|
+
* @param key - What the value depends on, as a string; `null` to read nothing.
|
|
1814
|
+
* @param load - Reads the value for the current key.
|
|
1815
|
+
* @param refresh - Reads again when it changes, for the same key.
|
|
1816
|
+
* @returns The value; `undefined` until the first answer for this key (or without a key); `null` when the read failed.
|
|
1817
|
+
*/
|
|
1818
|
+
declare function useRereadValue<T>(key: string | null, load: () => Promise<T> | T, refresh?: unknown): T | null | undefined;
|
|
1819
|
+
|
|
1820
|
+
/**
|
|
1821
|
+
* What the parts of the surrounding `PaymentCheckout` share, for components that replace its parts.
|
|
1822
|
+
*
|
|
1823
|
+
* @returns The checkout context.
|
|
1824
|
+
* @throws When called outside a `PaymentCheckout`.
|
|
1825
|
+
*/
|
|
1826
|
+
declare function useCheckoutContext(): CheckoutContextValue;
|
|
1827
|
+
/**
|
|
1828
|
+
* The context of the surrounding `PaymentCheckout`, or `null` outside one: for parts the checkout shares with
|
|
1829
|
+
* `RefundButton`, which take the checkout's customization only inside it.
|
|
1830
|
+
*
|
|
1831
|
+
* @returns The checkout context, or `null`.
|
|
1832
|
+
* @internal
|
|
1833
|
+
*/
|
|
1834
|
+
declare function useOptionalCheckoutContext(): CheckoutContextValue | null;
|
|
1835
|
+
|
|
1836
|
+
/** Parameters of {@link useCheckoutEvents}. */
|
|
1837
|
+
interface UseCheckoutEventsParams {
|
|
1838
|
+
/** The state of the checkout store. */
|
|
1839
|
+
state: CheckoutState;
|
|
1840
|
+
/** The screen shown. */
|
|
1841
|
+
screen: CheckoutScreen;
|
|
1842
|
+
/** `Date.now()` of the latest second tick of the checkout. */
|
|
1843
|
+
now: number;
|
|
1844
|
+
/** The handlers of `customization.handlers` of `PaymentCheckout`. */
|
|
1845
|
+
handlers?: PaymentCheckoutHandlers;
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Tells the app what happened in a checkout through its handlers: `onStatusChange` with the first phase and invoice
|
|
1849
|
+
* status and on every change, `onError` once per new error, and `onExpire` when the locked price runs out (at the
|
|
1850
|
+
* tick that crosses its end) and when the invoice expires, with whether a payment is on its way (one this page handed
|
|
1851
|
+
* over, one of the invoice Quasar reports, as on a reopened page, or one Quasar could not confirm yet and reads again).
|
|
1852
|
+
* Handlers that change between renders are called in their latest version.
|
|
1853
|
+
*
|
|
1854
|
+
* @param params - See {@link UseCheckoutEventsParams}.
|
|
1855
|
+
*/
|
|
1856
|
+
declare function useCheckoutEvents({ state, screen, now, handlers }: UseCheckoutEventsParams): void;
|
|
1857
|
+
|
|
1858
|
+
/** What {@link useCheckoutStore} takes. */
|
|
1859
|
+
interface UseCheckoutStoreOptions {
|
|
1860
|
+
/** The checkout token of the invoice. */
|
|
1861
|
+
token: string;
|
|
1862
|
+
/** The Quasar API. */
|
|
1863
|
+
baseUrl?: string;
|
|
1864
|
+
/** Calls to make instead of the HTTP ones, for tests and simulations; read when the store is created. */
|
|
1865
|
+
api?: CheckoutApi;
|
|
1866
|
+
/** The `EventSource` to follow the invoice with (`null`: read it every `pollMs`); read when the store is created. */
|
|
1867
|
+
EventSource?: EventSourceConstructor | null;
|
|
1868
|
+
/** How often to read the invoice without an event stream, in milliseconds. */
|
|
1869
|
+
pollMs?: number;
|
|
1870
|
+
/** Whether to load and follow the invoice; `false` keeps the idle store, which makes no requests. Defaults to `true`. */
|
|
1871
|
+
enabled?: boolean;
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* The checkout store of an invoice (`createCheckoutStore` from `@tuwaio/quasar-sdk/checkout`): created and loaded
|
|
1875
|
+
* after mount, destroyed on unmount or when `token` or `baseUrl` change. Until then it is a store in the `loading`
|
|
1876
|
+
* phase that makes no requests.
|
|
1877
|
+
*
|
|
1878
|
+
* Side effects: the store reads the checkout and follows the invoice (an `EventSource` on its `events` route, or a
|
|
1879
|
+
* request every `pollMs`) until the invoice is final.
|
|
1880
|
+
*
|
|
1881
|
+
* @param options - See {@link UseCheckoutStoreOptions}.
|
|
1882
|
+
* @returns The store.
|
|
1883
|
+
*/
|
|
1884
|
+
declare function useCheckoutStore(options: UseCheckoutStoreOptions): CheckoutStore;
|
|
1885
|
+
/**
|
|
1886
|
+
* Reads a checkout store and re-renders when the selected part changes (`useStore` of `zustand`).
|
|
1887
|
+
*
|
|
1888
|
+
* @param store - The store, from {@link useCheckoutStore}.
|
|
1889
|
+
* @param selector - What to read.
|
|
1890
|
+
* @returns The selected part of the state.
|
|
1891
|
+
*/
|
|
1892
|
+
declare function useCheckoutState<T>(store: CheckoutStore, selector: (state: CheckoutState) => T): T;
|
|
1893
|
+
|
|
1894
|
+
/**
|
|
1895
|
+
* The wallet connected through Satellite Connect (the active connection of `SatelliteConnectProvider` from
|
|
1896
|
+
* `@tuwaio/satellite-react`), in CAIP identifiers, named and shown as the wallet calls itself: the name and icon of
|
|
1897
|
+
* its wallet in the wallet lists of the store (`getConnectors()`, the wallet with exactly the connector type of the
|
|
1898
|
+
* connection), as Nova Connect lists it; `null` without a connection or without the provider, in which case the
|
|
1899
|
+
* checkout offers the QR code and the wallet connection only.
|
|
1900
|
+
*
|
|
1901
|
+
* Side effects: while mounted in the browser, a subscription to the wallet lists of the store (`watchConnectors` of
|
|
1902
|
+
* `@tuwaio/satellite-core`, when the store has it), so a wallet that announces itself later is named too.
|
|
1903
|
+
*
|
|
1904
|
+
* @returns The wallet, or `null`. The same object while the connection, the name and the icon stay the same.
|
|
1905
|
+
*/
|
|
1906
|
+
declare function useConnectedWallet(): CheckoutWallet | null;
|
|
1907
|
+
|
|
1908
|
+
/** What the labels customization of {@link NovaPaymentsProvider} gets with the labels it transforms. */
|
|
1909
|
+
interface NovaPaymentsLabelsContext {
|
|
1910
|
+
/** The language of the checkout. */
|
|
1911
|
+
locale: CheckoutLocale | string;
|
|
1912
|
+
}
|
|
1913
|
+
/** Customization of {@link NovaPaymentsProvider}. */
|
|
1914
|
+
type NovaPaymentsProviderCustomization = {
|
|
1915
|
+
/** Labels. */
|
|
1916
|
+
labels?: {
|
|
1917
|
+
/**
|
|
1918
|
+
* Changes the labels of a language after the built-in ones and `labels` are applied, for example to translate a
|
|
1919
|
+
* language the package does not have.
|
|
1920
|
+
*
|
|
1921
|
+
* @param labels - The labels of the language with `labels` applied.
|
|
1922
|
+
* @param context - The language.
|
|
1923
|
+
* @returns The labels to use.
|
|
1924
|
+
*/
|
|
1925
|
+
transform?: (labels: NovaPaymentsLabels, context: NovaPaymentsLabelsContext) => NovaPaymentsLabels;
|
|
1926
|
+
};
|
|
1927
|
+
};
|
|
1928
|
+
/**
|
|
1929
|
+
* The wallet connection Nova brings when the app has no `SatelliteConnectProvider` above {@link NovaPaymentsProvider}:
|
|
1930
|
+
* a Satellite store, its watchers and a Nova Connect modal, all its own. Create it once, at module level: new adapter
|
|
1931
|
+
* objects on every render would be passed to the store again.
|
|
1932
|
+
*
|
|
1933
|
+
* Nova keeps one store per Satellite adapter (the first of `adapter`) for the life of the page, since the wagmi config
|
|
1934
|
+
* and the wallets keep their connections too: a checkout closed and opened again, another page, or a second
|
|
1935
|
+
* `NovaPaymentsProvider` on the same adapters shows the wallet still connected. Nova's part of the package (its
|
|
1936
|
+
* store and the Nova Connect modal) loads on demand, the first time a provider uses its own connection.
|
|
1937
|
+
*/
|
|
1938
|
+
interface NovaPaymentsOwnConnection {
|
|
1939
|
+
/**
|
|
1940
|
+
* The Satellite adapters of Nova's store: `satelliteEVMAdapter(wagmiConfig, chains)` of `@tuwaio/satellite-evm`,
|
|
1941
|
+
* `satelliteSolanaAdapter({ rpcUrls })` of `@tuwaio/satellite-solana`.
|
|
1942
|
+
*/
|
|
1943
|
+
adapter: SatelliteConnectProviderProps['adapter'];
|
|
1944
|
+
/**
|
|
1945
|
+
* The watchers of that store, which follow the wallets: `<EVMConnectorsWatcher wagmiConfig={wagmiConfig} />` of
|
|
1946
|
+
* `@tuwaio/nova-connect/evm`, `<SolanaConnectorsWatcher />` of `@tuwaio/nova-connect/solana` (without `siwx`).
|
|
1947
|
+
*/
|
|
1948
|
+
watchers: ReactNode;
|
|
1949
|
+
/**
|
|
1950
|
+
* The payment adapters, on the same wagmi config as `adapter`: `paymentsEVMAdapter(wagmiConfig)`,
|
|
1951
|
+
* `paymentsSolanaAdapter({ rpcUrls })`.
|
|
1952
|
+
*/
|
|
1953
|
+
adapters: PaymentsAdapter[];
|
|
1954
|
+
/**
|
|
1955
|
+
* The props of Nova's own connect modal (`NovaConnectProvider` of `@tuwaio/nova-connect`): `appChains` and/or
|
|
1956
|
+
* `solanaRPCUrls` (the modals are rendered only with them), `labels`, `legal`, `withBalance`… Never `siwx`: Nova's
|
|
1957
|
+
* own connection pays and refunds, it does not sign anyone in.
|
|
1958
|
+
*/
|
|
1959
|
+
novaConnect: Omit<NovaConnectProviderPropsWithCustomization, 'children' | 'siwx'>;
|
|
1960
|
+
/**
|
|
1961
|
+
* Whether to reconnect the last wallet after a page load (default `false`). With `true`, Satellite's start-up runs
|
|
1962
|
+
* once per page load (`initializeAutoConnect` of the store): with `@tuwaio/satellite-core` 0.11.1 or later it
|
|
1963
|
+
* reconnects only the last wallet, without a permission prompt, and disconnects only connections this page opened;
|
|
1964
|
+
* earlier versions first disconnect every wallet of its adapters, which can drop the wallets of other tabs. Without it, Nova's connect modal hides "Remember this wallet", since nothing would reconnect the wallet, unless
|
|
1965
|
+
* `novaConnect.customization` sets `hidden` of `modals.connectModal.childComponents.rememberWallet`.
|
|
1966
|
+
*/
|
|
1967
|
+
autoConnect?: boolean;
|
|
1968
|
+
/**
|
|
1969
|
+
* Whether to keep the connected wallet in `localStorage` after the tab closes (default `false`: in `sessionStorage`
|
|
1970
|
+
* until the tab closes). See `rememberWallet` of `createSatelliteConnectStore` from `@tuwaio/satellite-core`. The
|
|
1971
|
+
* keys are shared with every Satellite store of the site: connecting a wallet that is not remembered moves the last
|
|
1972
|
+
* connection out of `localStorage`, and disconnecting removes it, so another Satellite app on the same origin
|
|
1973
|
+
* forgets the wallet it remembered.
|
|
1974
|
+
*/
|
|
1975
|
+
rememberWallet?: boolean;
|
|
1976
|
+
}
|
|
1977
|
+
/** Props of {@link NovaPaymentsProvider}. */
|
|
1978
|
+
interface NovaPaymentsProviderProps {
|
|
1979
|
+
/** The Quasar API (Quasar Cloud by default, the address of your node for the Community Edition). */
|
|
1980
|
+
baseUrl?: string;
|
|
1981
|
+
/** Texts to replace in every language. */
|
|
1982
|
+
labels?: NovaPaymentsLabelOverrides;
|
|
1983
|
+
/** Customization of the labels. */
|
|
1984
|
+
customization?: NovaPaymentsProviderCustomization;
|
|
1985
|
+
/**
|
|
1986
|
+
* The chain families the checkouts pay from the app's connected wallet on: `paymentsEVMAdapter` of
|
|
1987
|
+
* `@tuwaio/nova-payments/evm` (on the wagmi config of the app's Satellite EVM adapter), `paymentsSolanaAdapter` of
|
|
1988
|
+
* `@tuwaio/nova-payments/solana`. Without the adapter of a method's family, the buyer pays that method with a QR
|
|
1989
|
+
* code. When Nova uses its own connection, the `adapters` of `ownConnection` replace them. Without `adapters`, a
|
|
1990
|
+
* provider on the connection of a `NovaPaymentsProvider` above (the app's, or Nova's own) uses the adapters of that
|
|
1991
|
+
* provider; `[]` asks for QR codes only.
|
|
1992
|
+
*/
|
|
1993
|
+
adapters?: PaymentsAdapter[];
|
|
1994
|
+
/**
|
|
1995
|
+
* The app's Pulsar store (`injectExternalPendingTxs` of `createPulsarStore` from `@tuwaio/pulsar-core`). While a
|
|
1996
|
+
* checkout is open it tracks the payment itself; when it closes before Quasar settled a payment the wallet sent, the
|
|
1997
|
+
* payment goes to this store, which tracks it and keeps it in the history, and Nova Transactions shows its toast.
|
|
1998
|
+
*/
|
|
1999
|
+
pulsar?: PaymentsPulsar;
|
|
2000
|
+
/**
|
|
2001
|
+
* The wallet connection Nova brings when the app has none: used only when no `SatelliteConnectProvider` is above
|
|
2002
|
+
* (see {@link NovaPaymentsOwnConnection}). Inside the app's Satellite store, Nova uses the app's connection and never
|
|
2003
|
+
* adds a second one.
|
|
2004
|
+
*/
|
|
2005
|
+
ownConnection?: NovaPaymentsOwnConnection;
|
|
2006
|
+
/**
|
|
2007
|
+
* Connects a wallet of a chain family when there is no Nova Connect to open (an app that connects wallets its own
|
|
2008
|
+
* way): the default of every `PaymentCheckout`, `RefundButton` and `RefundDialog` below, which their own
|
|
2009
|
+
* `onConnectWallet` overrides.
|
|
2010
|
+
*
|
|
2011
|
+
* @param family - The chain family of the payment.
|
|
2012
|
+
*/
|
|
2013
|
+
onConnectWallet?: (family: PaymentFamily) => void;
|
|
2014
|
+
/** The app. */
|
|
2015
|
+
children: ReactNode;
|
|
2016
|
+
}
|
|
2017
|
+
/**
|
|
2018
|
+
* Gives the checkouts and refunds below it the Quasar API, the labels, the chain adapters and a wallet connection. A
|
|
2019
|
+
* checkout works without it, with Quasar Cloud, the built-in labels and QR payments only.
|
|
2020
|
+
*
|
|
2021
|
+
* The wallet connection is chosen once, on the first render (see {@link PaymentsConnectionMode} and
|
|
2022
|
+
* {@link usePaymentsConnection}): Nova brings its own connection only when the app has none.
|
|
2023
|
+
*
|
|
2024
|
+
* - Inside the app's `SatelliteConnectProvider` (from `@tuwaio/satellite-react`) and `NovaConnectProvider` (from
|
|
2025
|
+
* `@tuwaio/nova-connect`): the app's wallet, network, connect modal and SIWX, with the `adapters` prop. Nova mounts
|
|
2026
|
+
* nothing of its own.
|
|
2027
|
+
* - Inside the app's Satellite store without Nova Connect: the app's wallet; "Connect wallet" calls `onConnectWallet`.
|
|
2028
|
+
* Nova never adds a second store.
|
|
2029
|
+
* - Without a Satellite store, with `ownConnection`: Nova's own store, watchers and connect modal (never SIWX), with
|
|
2030
|
+
* the adapters of `ownConnection`. It runs Satellite's start-up only when `autoConnect` is set. That part loads on
|
|
2031
|
+
* demand: until it is loaded, nothing below the provider is rendered.
|
|
2032
|
+
* - Without either: QR payments, and `onConnectWallet`.
|
|
2033
|
+
*
|
|
2034
|
+
* A `NovaPaymentsProvider` inside another one's own connection sees that connection as the app's, so two stores never
|
|
2035
|
+
* stack, and without `adapters` it pays with those of the provider above. A later change of the providers above never
|
|
2036
|
+
* remounts the checkouts on another connection.
|
|
2037
|
+
*
|
|
2038
|
+
* Side effects: with its own connection, those of the Satellite store, kept in memory for the life of the page (the
|
|
2039
|
+
* last wallet in `sessionStorage`, or in `localStorage` with `rememberWallet`, under keys shared with every Satellite
|
|
2040
|
+
* store of the site), of the watchers and of Nova Connect. In development (`NODE_ENV` is `development`),
|
|
2041
|
+
* `console.warn` once when the providers above change after the first render, when `ownConnection` is given inside the
|
|
2042
|
+
* app's store without Nova Connect, and when `ownConnection` is given but the app's connection is used without
|
|
2043
|
+
* `adapters` (its own or those of a `NovaPaymentsProvider` above).
|
|
2044
|
+
*
|
|
2045
|
+
* @param props - See {@link NovaPaymentsProviderProps}.
|
|
2046
|
+
* @returns The provider.
|
|
2047
|
+
*
|
|
2048
|
+
* @example
|
|
2049
|
+
* ```tsx
|
|
2050
|
+
* import { NovaPaymentsProvider, PaymentCheckout } from '@tuwaio/payments-sdk';
|
|
2051
|
+
*
|
|
2052
|
+
* export function Checkout({ token }: { token: string }) {
|
|
2053
|
+
* return (
|
|
2054
|
+
* <NovaPaymentsProvider baseUrl="https://quasar.example.com" labels={{ steps: { pay: 'Payment' } }}>
|
|
2055
|
+
* <PaymentCheckout token={token} display="inline" />
|
|
2056
|
+
* </NovaPaymentsProvider>
|
|
2057
|
+
* );
|
|
2058
|
+
* }
|
|
2059
|
+
* ```
|
|
2060
|
+
*/
|
|
2061
|
+
declare function NovaPaymentsProvider({ baseUrl, labels, customization, adapters, pulsar, ownConnection, onConnectWallet, children, }: NovaPaymentsProviderProps): react.JSX.Element;
|
|
2062
|
+
|
|
2063
|
+
/**
|
|
2064
|
+
* Whose wallet connection the checkouts and refunds use, as `NovaPaymentsProvider` decided on its first render:
|
|
2065
|
+
*
|
|
2066
|
+
* - `app`: the app's. A Satellite store (`SatelliteConnectProvider` of `@tuwaio/satellite-react`) and
|
|
2067
|
+
* `NovaConnectProvider` of `@tuwaio/nova-connect` are above it: the wallet, its network, the connect modal and SIWX
|
|
2068
|
+
* are the app's, and Nova adds nothing.
|
|
2069
|
+
* - `appStore`: the app's Satellite store without Nova Connect: "Connect wallet" calls `onConnectWallet`.
|
|
2070
|
+
* - `own`: Nova's own. The app has no Satellite store and gave `ownConnection`: Nova runs its own store, watchers and
|
|
2071
|
+
* connect modal, without SIWX.
|
|
2072
|
+
* - `none`: no connection. The buyer pays with a QR code, or connects through `onConnectWallet`.
|
|
2073
|
+
*/
|
|
2074
|
+
type PaymentsConnectionMode = 'app' | 'appStore' | 'own' | 'none';
|
|
2075
|
+
/** The settings `NovaPaymentsProvider` gives the checkouts below it. */
|
|
2076
|
+
interface NovaPaymentsSettings {
|
|
2077
|
+
/** The Quasar API, if set. */
|
|
2078
|
+
baseUrl?: string;
|
|
2079
|
+
/** Texts to replace in every language. */
|
|
2080
|
+
labels?: NovaPaymentsLabelOverrides;
|
|
2081
|
+
/** Customization of the labels. */
|
|
2082
|
+
customization?: NovaPaymentsProviderCustomization;
|
|
2083
|
+
/**
|
|
2084
|
+
* The chain families the checkouts pay from a connected wallet on: the `adapters` prop, or those of `ownConnection`
|
|
2085
|
+
* when Nova runs its own connection.
|
|
2086
|
+
*/
|
|
2087
|
+
adapters?: PaymentsAdapter[];
|
|
2088
|
+
/** The app's Pulsar store, which takes over the payments a checkout closed on. */
|
|
2089
|
+
pulsar?: PaymentsPulsar;
|
|
2090
|
+
/** Whose wallet connection the checkouts use; unset without `NovaPaymentsProvider`. */
|
|
2091
|
+
connection?: PaymentsConnectionMode;
|
|
2092
|
+
/**
|
|
2093
|
+
* The app's handler that connects a wallet, for the checkouts and refunds below without Nova Connect.
|
|
2094
|
+
*
|
|
2095
|
+
* @param family - The chain family of the payment.
|
|
2096
|
+
*/
|
|
2097
|
+
onConnectWallet?: (family: PaymentFamily) => void;
|
|
2098
|
+
}
|
|
2099
|
+
/**
|
|
2100
|
+
* The context of `NovaPaymentsProvider`, created once and saved on `globalThis`
|
|
2101
|
+
* (`Symbol.for('tuwaio.nova-payments.context')`), so copies of the package share it. @internal
|
|
2102
|
+
*/
|
|
2103
|
+
declare const NovaPaymentsContext: Context<NovaPaymentsSettings>;
|
|
2104
|
+
|
|
2105
|
+
/**
|
|
2106
|
+
* The settings of the nearest `NovaPaymentsProvider`; empty without one.
|
|
2107
|
+
*
|
|
2108
|
+
* @returns The settings.
|
|
2109
|
+
*/
|
|
2110
|
+
declare function useNovaPayments(): NovaPaymentsSettings;
|
|
2111
|
+
|
|
2112
|
+
/**
|
|
2113
|
+
* The current time, updated every `intervalMs` while `active`.
|
|
2114
|
+
*
|
|
2115
|
+
* Side effect: an interval timer while active.
|
|
2116
|
+
*
|
|
2117
|
+
* @param intervalMs - How often to update, in milliseconds.
|
|
2118
|
+
* @param active - Whether to update (stop on a final state to save renders).
|
|
2119
|
+
* @returns `Date.now()` of the latest update.
|
|
2120
|
+
*/
|
|
2121
|
+
declare function useNow(intervalMs: number, active?: boolean): number;
|
|
2122
|
+
|
|
2123
|
+
/**
|
|
2124
|
+
* Tells the app once that the invoice is paid, when the checkout reaches the paid outcome.
|
|
2125
|
+
*
|
|
2126
|
+
* @param phase - Where the payment stands.
|
|
2127
|
+
* @param invoice - The invoice of the checkout.
|
|
2128
|
+
* @param onPaid - The app's callback, if any.
|
|
2129
|
+
*/
|
|
2130
|
+
declare function usePaidCallback(phase: CheckoutPhase, invoice: CheckoutView['invoice'] | undefined, onPaid: ((invoice: CheckoutView['invoice']) => void) | undefined, openedPaid?: boolean): void;
|
|
2131
|
+
/** What {@link useAutoReturn} needs. */
|
|
2132
|
+
interface UseAutoReturnParams {
|
|
2133
|
+
/** Where to send the buyer (the invoice's `successUrl`); `null` for no return. */
|
|
2134
|
+
url: string | null;
|
|
2135
|
+
/** Seconds before the return; `0` for no automatic return. */
|
|
2136
|
+
seconds: number;
|
|
2137
|
+
/** `Date.now()` of the latest second tick of the checkout. */
|
|
2138
|
+
now: number;
|
|
2139
|
+
/**
|
|
2140
|
+
* Sends the buyer to the link (default: `window.location.assign`).
|
|
2141
|
+
*
|
|
2142
|
+
* @param url - The link.
|
|
2143
|
+
*/
|
|
2144
|
+
navigate?: (url: string) => void;
|
|
2145
|
+
}
|
|
2146
|
+
/**
|
|
2147
|
+
* The visible countdown before the paid outcome sends the buyer back to the seller, with "Stay here" (WCAG 2.2.1).
|
|
2148
|
+
*
|
|
2149
|
+
* Side effects: navigates the page when the countdown ends.
|
|
2150
|
+
*
|
|
2151
|
+
* @param params - See {@link UseAutoReturnParams}.
|
|
2152
|
+
* @returns `left`: seconds before the return (`null` when there is none); `stay`: stops it.
|
|
2153
|
+
*/
|
|
2154
|
+
declare function useAutoReturn({ url, seconds, now, navigate, }: UseAutoReturnParams): {
|
|
2155
|
+
left: number | null;
|
|
2156
|
+
stay: () => void;
|
|
2157
|
+
};
|
|
2158
|
+
|
|
2159
|
+
/**
|
|
2160
|
+
* @file Why a wallet did not pay: the buyer declined, the wallet cannot do it, it is on another network, or it failed.
|
|
2161
|
+
*/
|
|
2162
|
+
/**
|
|
2163
|
+
* Why a wallet request did not go through: `declined` by the buyer, `unsupported` by the wallet, `wrongNetwork` when it
|
|
2164
|
+
* was on another network than the request, `switchFailed` when it did not switch, `notAuthorized` when it has not allowed
|
|
2165
|
+
* the account for the site (EIP-1193 4100), `alreadyPending` when another request of the site still waits in it,
|
|
2166
|
+
* `sentUnconfirmed` when it sent a payment that is not confirmed yet (it may still land), or `failed`.
|
|
2167
|
+
*/
|
|
2168
|
+
type PaymentWalletErrorKind = 'declined' | 'unsupported' | 'wrongNetwork' | 'switchFailed' | 'notAuthorized' | 'alreadyPending' | 'sentUnconfirmed' | 'failed';
|
|
2169
|
+
/** The error a payments adapter throws when it knows why the wallet did not pay. */
|
|
2170
|
+
declare class PaymentWalletError extends Error {
|
|
2171
|
+
readonly kind: PaymentWalletErrorKind;
|
|
2172
|
+
/**
|
|
2173
|
+
* @param kind - Why: see {@link PaymentWalletErrorKind}.
|
|
2174
|
+
* @param message - What to log.
|
|
2175
|
+
* @param options - The original error as `cause`.
|
|
2176
|
+
*/
|
|
2177
|
+
constructor(kind: PaymentWalletErrorKind, message: string, options?: {
|
|
2178
|
+
cause?: unknown;
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
/**
|
|
2182
|
+
* Why a wallet request failed, from the error the wallet library threw and the causes it wraps, whichever of them names
|
|
2183
|
+
* it: EIP-1193 code `4001` and viem's `UserRejectedRequestError`, and the "user rejected" messages of Wallet Standard
|
|
2184
|
+
* wallets, are `declined`. A request the wallet already has waiting (code `-32002`) is `alreadyPending`, also inside a
|
|
2185
|
+
* failed switch: the buyer answers it there. wagmi's `ChainNotConfiguredError` (the network of the payment is not in the
|
|
2186
|
+
* wagmi config of `paymentsEVMAdapter`; the buyer can still pay with the QR code) and `ConnectorNotConnectedError` (that
|
|
2187
|
+
* config has no connection of the wallet) are `unsupported`, as is a wallet that does not know the request (codes 4200,
|
|
2188
|
+
* -32601, -32004). `ConnectorChainMismatchError` and `ChainMismatchError` are `wrongNetwork`; `SwitchChainError` and
|
|
2189
|
+
* `SwitchChainNotSupportedError` are `switchFailed`; code `4100` is `notAuthorized`. Named apart so that the page never
|
|
2190
|
+
* says a payment failed, or that a fee was spent, about a request that never left the wallet.
|
|
2191
|
+
*
|
|
2192
|
+
* Side effects: in development (`NODE_ENV` is `development`), a failure it cannot name logs to the console, and a
|
|
2193
|
+
* `ConnectorNotConnectedError` logs a `console.error`:
|
|
2194
|
+
* the app gave `NovaPaymentsProvider` an EVM adapter built on another wagmi config than the one its wallet connection
|
|
2195
|
+
* (its Satellite EVM adapter) uses.
|
|
2196
|
+
*
|
|
2197
|
+
* @param error - What the wallet library threw.
|
|
2198
|
+
* @returns The kind.
|
|
2199
|
+
*/
|
|
2200
|
+
declare function walletErrorKind(error: unknown): PaymentWalletErrorKind;
|
|
2201
|
+
|
|
2202
|
+
/** Where the confirmation of the paying wallet stands: the wallet switches its network, then signs. */
|
|
2203
|
+
type PayerProofStep = 'idle' | 'switching' | 'signing';
|
|
2204
|
+
/** Why the wallet did not confirm: its kind of failure, or a network switch the buyer refused, no signature being asked. */
|
|
2205
|
+
type PayerProofProblem = PaymentWalletErrorKind | 'switchDeclined';
|
|
2206
|
+
/** What {@link usePayerProof} needs. */
|
|
2207
|
+
interface UsePayerProofParams {
|
|
2208
|
+
/** The adapter of the method's chain family; without `signMessage` the wallet cannot confirm the invoice. */
|
|
2209
|
+
adapter: PaymentsAdapter | undefined;
|
|
2210
|
+
/** The checkout store. */
|
|
2211
|
+
store: {
|
|
2212
|
+
getState: () => Pick<CheckoutState, 'confirmPayer' | 'requestQuote' | 'payer' | 'abandonConfirmation'>;
|
|
2213
|
+
};
|
|
2214
|
+
/** The connected wallet. */
|
|
2215
|
+
wallet: CheckoutWallet | null;
|
|
2216
|
+
/** The CAIP-2 network of the method: a smart wallet's signature counts there only. */
|
|
2217
|
+
chainId: string;
|
|
2218
|
+
}
|
|
2219
|
+
/** What {@link usePayerProof} returns. */
|
|
2220
|
+
interface PayerProofFlow {
|
|
2221
|
+
/** Where the confirmation stands. */
|
|
2222
|
+
step: PayerProofStep;
|
|
2223
|
+
/** Why the wallet did not switch or sign, until the next try; `switchDeclined`: the buyer refused the network switch. */
|
|
2224
|
+
problem: PayerProofProblem | null;
|
|
2225
|
+
/** The message Quasar issued for the wallet to sign (its site, network, nonce), once Quasar answered. */
|
|
2226
|
+
request: PayerProofMessage | null;
|
|
2227
|
+
/**
|
|
2228
|
+
* Confirms the invoice from the wallet: switches the wallet to the method's network when it is on another one, then
|
|
2229
|
+
* has it sign Quasar's message (`confirmPayer` of the checkout store).
|
|
2230
|
+
*
|
|
2231
|
+
* @param options - `quote: true` locks the price once the wallet confirmed (the step before the price).
|
|
2232
|
+
* @param options.quote - Whether to lock the price after it.
|
|
2233
|
+
* @returns Whether the wallet confirmed the invoice.
|
|
2234
|
+
*/
|
|
2235
|
+
confirm: (options?: {
|
|
2236
|
+
quote?: boolean;
|
|
2237
|
+
}) => Promise<boolean>;
|
|
2238
|
+
/**
|
|
2239
|
+
* Closes the wallet window. The request stays open in the wallet: a signature it gives later still confirms the
|
|
2240
|
+
* invoice (and locks the price), a refusal is not shown. A cancel during the network switch asks for no signature.
|
|
2241
|
+
* {@link PayerProofFlow.confirm} can be called again at once: the new request replaces the open one, and signing
|
|
2242
|
+
* twice moves no money.
|
|
2243
|
+
*/
|
|
2244
|
+
dismiss: () => void;
|
|
2245
|
+
}
|
|
2246
|
+
/**
|
|
2247
|
+
* Confirms that the connected wallet pays the invoice, for the step before the price and for a payment of a method the
|
|
2248
|
+
* gasless relay could pay: a free signature of Quasar's EIP-4361 message that moves no money, one per invoice and wallet.
|
|
2249
|
+
*
|
|
2250
|
+
* Side effects: wallet prompts (a network switch, the signature); `POST payer-proof/message` and `POST payer-proof`
|
|
2251
|
+
* through the checkout store, then `POST quote` with `quote: true`.
|
|
2252
|
+
*
|
|
2253
|
+
* @param params - See {@link UsePayerProofParams}.
|
|
2254
|
+
* @returns See {@link PayerProofFlow}.
|
|
2255
|
+
*/
|
|
2256
|
+
declare function usePayerProof({ adapter, store, wallet, chainId }: UsePayerProofParams): PayerProofFlow;
|
|
2257
|
+
|
|
2258
|
+
/**
|
|
2259
|
+
* @file The payment of a locked price: how the wallet pays it, what the buyer sends and the merchant receives, the
|
|
2260
|
+
* market rate behind it, and what a wallet lacks to pay it.
|
|
2261
|
+
*/
|
|
2262
|
+
|
|
2263
|
+
/**
|
|
2264
|
+
* How the wallet pays a quote: `relay` signs an EIP-3009 authorization that Quasar sends (the merchant pays the gas),
|
|
2265
|
+
* `paymaster` sends the quoted calls with the checkout's ERC-7677 paymaster (a smart wallet; the merchant pays the
|
|
2266
|
+
* gas), `transfer` sends the transfer and pays the gas.
|
|
2267
|
+
*/
|
|
2268
|
+
type PayPath = 'relay' | 'paymaster' | 'transfer';
|
|
2269
|
+
/**
|
|
2270
|
+
* How the wallet pays a quote. A smart wallet that takes a paymaster sends sponsored calls; any other wallet signs the
|
|
2271
|
+
* authorization; the buyer may choose to pay the gas instead.
|
|
2272
|
+
*
|
|
2273
|
+
* @param quote - The locked quote.
|
|
2274
|
+
* @param options - What the buyer and the wallet allow.
|
|
2275
|
+
* @param options.withGas - The buyer chose "Pay with gas instead".
|
|
2276
|
+
* @param options.canSponsorCalls - The wallet sends `wallet_sendCalls` with the `paymasterService` capability.
|
|
2277
|
+
* @returns The path.
|
|
2278
|
+
*/
|
|
2279
|
+
declare function payPath(quote: CheckoutQuote, options: {
|
|
2280
|
+
withGas: boolean;
|
|
2281
|
+
canSponsorCalls: boolean;
|
|
2282
|
+
}): PayPath;
|
|
2283
|
+
/** What a quote moves, in base units of its token. */
|
|
2284
|
+
interface QuoteAmounts {
|
|
2285
|
+
/** What the buyer sends. */
|
|
2286
|
+
send: string;
|
|
2287
|
+
/** What the merchant receives. */
|
|
2288
|
+
receives: string;
|
|
2289
|
+
/** The token's transfer fee on top, with its percent; `null` when the token keeps none. */
|
|
2290
|
+
fee: {
|
|
2291
|
+
amount: string;
|
|
2292
|
+
percent: string;
|
|
2293
|
+
} | null;
|
|
2294
|
+
}
|
|
2295
|
+
/**
|
|
2296
|
+
* What the buyer sends and the merchant receives for this payment: the same amount, unless the token keeps a fee on
|
|
2297
|
+
* every transfer. On the quote of a rest that is what is left of the invoice, not its total.
|
|
2298
|
+
*
|
|
2299
|
+
* @param quote - The locked quote.
|
|
2300
|
+
* @returns The amounts.
|
|
2301
|
+
*/
|
|
2302
|
+
declare function quoteAmounts(quote: CheckoutQuote): QuoteAmounts;
|
|
2303
|
+
/**
|
|
2304
|
+
* The market price of one token in the invoice currency behind a quote. Quasar asks for
|
|
2305
|
+
* `total × (1 + markup) × (1 − discount) / price` tokens, so the price is recovered without the method's markup or
|
|
2306
|
+
* discount, which the checkout shows apart. For display only: amounts are never derived from it.
|
|
2307
|
+
*
|
|
2308
|
+
* @param quote - The locked quote.
|
|
2309
|
+
* @param totalMinor - The invoice total in minor units (cents) the quote pays.
|
|
2310
|
+
* @returns The price, or `null` without a total or a token amount.
|
|
2311
|
+
*/
|
|
2312
|
+
declare function quoteRate(quote: CheckoutQuote, totalMinor: string | null): number | null;
|
|
2313
|
+
/** What a wallet lacks for a payment, in base units. */
|
|
2314
|
+
interface BalanceShortfall {
|
|
2315
|
+
/** What the wallet has. */
|
|
2316
|
+
have: string;
|
|
2317
|
+
/** What the payment needs. */
|
|
2318
|
+
need: string;
|
|
2319
|
+
/** The difference. */
|
|
2320
|
+
short: string;
|
|
2321
|
+
}
|
|
2322
|
+
/**
|
|
2323
|
+
* What a wallet lacks to pay a quote.
|
|
2324
|
+
*
|
|
2325
|
+
* @param balance - The wallet's balance of the quoted token, in base units.
|
|
2326
|
+
* @param quote - The locked quote.
|
|
2327
|
+
* @param fee - The network fee, when it is paid in the quoted token (the native coin); counted in what is needed.
|
|
2328
|
+
* @returns The shortfall, or `null` when the balance is enough.
|
|
2329
|
+
*/
|
|
2330
|
+
declare function balanceShortfall(balance: bigint, quote: CheckoutQuote, fee?: bigint): BalanceShortfall | null;
|
|
2331
|
+
/**
|
|
2332
|
+
* The CAIP-2 chain a quote is paid on.
|
|
2333
|
+
*
|
|
2334
|
+
* @param instructions - What the wallet sends.
|
|
2335
|
+
* @returns For example `eip155:8453` or `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`.
|
|
2336
|
+
*/
|
|
2337
|
+
declare function instructionsChainId(instructions: PaymentInstructions): string;
|
|
2338
|
+
|
|
2339
|
+
/**
|
|
2340
|
+
* @file Paying a locked price from the connected wallet, without React: the wallet prompt, then the hand-over to
|
|
2341
|
+
* Quasar.
|
|
2342
|
+
*/
|
|
2343
|
+
|
|
2344
|
+
/** What {@link payInvoice} needs. */
|
|
2345
|
+
interface PayInvoiceParams {
|
|
2346
|
+
/** The adapter of the quote's chain family. */
|
|
2347
|
+
adapter: PaymentsAdapter;
|
|
2348
|
+
/** The checkout store (only `submit` and `relay` are used). */
|
|
2349
|
+
store: {
|
|
2350
|
+
getState: () => Pick<CheckoutState, 'submit' | 'relay'>;
|
|
2351
|
+
};
|
|
2352
|
+
/** The locked quote. */
|
|
2353
|
+
quote: CheckoutQuote;
|
|
2354
|
+
/** The wallet the quote is locked to. */
|
|
2355
|
+
wallet: CheckoutWallet;
|
|
2356
|
+
/** How the wallet pays, from `payPath`. */
|
|
2357
|
+
path: PayPath;
|
|
2358
|
+
/** The checkout's ERC-7677 paymaster URL, for the `paymaster` path. */
|
|
2359
|
+
paymasterUrl: string | null;
|
|
2360
|
+
/** Called when the wallet answered, before the payment is handed to Quasar. */
|
|
2361
|
+
onWalletDone?: () => void;
|
|
2362
|
+
/**
|
|
2363
|
+
* Called with the ID of a sponsored batch as soon as the wallet took it, before it has a transaction.
|
|
2364
|
+
*
|
|
2365
|
+
* @param batchId - The ID of the batch.
|
|
2366
|
+
*/
|
|
2367
|
+
onBatchAccepted?: (batchId: string) => void;
|
|
2368
|
+
/**
|
|
2369
|
+
* Called with the transaction the wallet sent (its hash), before Quasar takes it; not for a gasless signature, whose
|
|
2370
|
+
* transaction Quasar sends.
|
|
2371
|
+
*
|
|
2372
|
+
* @param txKey - The transaction hash (EVM) or signature (Solana).
|
|
2373
|
+
*/
|
|
2374
|
+
onSent?: (txKey: string) => void;
|
|
2375
|
+
}
|
|
2376
|
+
/**
|
|
2377
|
+
* Pays a locked quote: `transfer` sends the transfer and hands its key to Quasar (`submit`), `relay` signs the
|
|
2378
|
+
* authorization for Quasar to send (`relay`), `paymaster` sends the sponsored calls and hands their transaction hash
|
|
2379
|
+
* to Quasar. A transaction the wallet sent is always handed over, whatever the page shows meanwhile, with the method it
|
|
2380
|
+
* was quoted for: the buyer may have gone on to a price on another network while the wallet asked.
|
|
2381
|
+
*
|
|
2382
|
+
* Side effects: a wallet prompt; requests to the checkout routes of Quasar.
|
|
2383
|
+
*
|
|
2384
|
+
* @param params - See {@link PayInvoiceParams}.
|
|
2385
|
+
* @returns Whether Quasar took the payment (the store's `error` says why not).
|
|
2386
|
+
* @throws {@link PaymentWalletError} `unsupported` when the adapter or the quote cannot take the path; the wallet's
|
|
2387
|
+
* error when it refuses or fails.
|
|
2388
|
+
*/
|
|
2389
|
+
declare function payInvoice({ adapter, store, quote, wallet, path, paymasterUrl, onWalletDone, onBatchAccepted, onSent, }: PayInvoiceParams): Promise<boolean>;
|
|
2390
|
+
|
|
2391
|
+
/**
|
|
2392
|
+
* How long a request the wallet never answered blocks a second one. A wallet that lost its request (a mobile session that
|
|
2393
|
+
* ended) gives no answer at all, and the buyer must not be trapped by it for good.
|
|
2394
|
+
*
|
|
2395
|
+
* @internal
|
|
2396
|
+
*/
|
|
2397
|
+
declare const OPEN_REQUEST_MS: number;
|
|
2398
|
+
|
|
2399
|
+
/** Where a payment from the wallet stands: `wallet` while the wallet asks the buyer, `submitting` while Quasar takes it. */
|
|
2400
|
+
type PaymentStatus = 'idle' | 'switching' | 'wallet' | 'submitting';
|
|
2401
|
+
|
|
2402
|
+
/**
|
|
2403
|
+
* Whether the wallet took a sponsored batch of this checkout that has no hash yet: nothing the store knows of, and still the
|
|
2404
|
+
* page must not say that nothing was sent.
|
|
2405
|
+
*
|
|
2406
|
+
* @param store - The checkout store.
|
|
2407
|
+
* @returns Whether such a batch may be on its way.
|
|
2408
|
+
* @internal
|
|
2409
|
+
*/
|
|
2410
|
+
declare function isPaymentAccepted(store: object): boolean;
|
|
2411
|
+
/** What {@link usePayment} needs. */
|
|
2412
|
+
interface UsePaymentParams {
|
|
2413
|
+
/** The adapter of the quote's chain family; without it the wallet cannot pay. */
|
|
2414
|
+
adapter: PaymentsAdapter | undefined;
|
|
2415
|
+
/** The checkout store. */
|
|
2416
|
+
store: PayInvoiceParams['store'];
|
|
2417
|
+
/** The locked quote. */
|
|
2418
|
+
quote: CheckoutQuote | null;
|
|
2419
|
+
/** The wallet the quote is locked to. */
|
|
2420
|
+
wallet: CheckoutWallet | null;
|
|
2421
|
+
/** How the wallet pays. */
|
|
2422
|
+
path: PayPath;
|
|
2423
|
+
/** The checkout's ERC-7677 paymaster URL. */
|
|
2424
|
+
paymasterUrl: string | null;
|
|
2425
|
+
/** The invoice: a sponsored batch the wallet took is kept in the tab under it until its hash comes. */
|
|
2426
|
+
invoiceId?: string;
|
|
2427
|
+
/**
|
|
2428
|
+
* Called with the payment the wallet sent (not a gasless signature, whose transaction Quasar sends).
|
|
2429
|
+
*
|
|
2430
|
+
* @param payment - The transaction and what it pays.
|
|
2431
|
+
*/
|
|
2432
|
+
onSent?: (payment: SentPayment) => void;
|
|
2433
|
+
}
|
|
2434
|
+
/** What {@link usePayment} returns. */
|
|
2435
|
+
interface Payment {
|
|
2436
|
+
/** Where the payment stands. */
|
|
2437
|
+
status: PaymentStatus;
|
|
2438
|
+
/** Why the wallet did not pay or switch, until the next try. */
|
|
2439
|
+
problem: PaymentWalletErrorKind | null;
|
|
2440
|
+
/** The wallet asked, for the window: it keeps its name when the buyer disconnects it while the request waits there. */
|
|
2441
|
+
askedWallet: CheckoutWallet | null;
|
|
2442
|
+
/** What the wallet was asked to send, for the window: a request that waits keeps its amount under a new price. */
|
|
2443
|
+
askedInstructions: PaymentInstructions | null;
|
|
2444
|
+
/** Pays the quote from the wallet; resolves when Quasar took it or the wallet refused. */
|
|
2445
|
+
pay: () => Promise<void>;
|
|
2446
|
+
/** Asks the wallet to switch to the quote's chain. */
|
|
2447
|
+
switchNetwork: () => Promise<void>;
|
|
2448
|
+
/**
|
|
2449
|
+
* Closes the wallet window. A request the wallet still shows stays open there: a transaction it sends later is
|
|
2450
|
+
* still handed to Quasar, a refusal is not shown.
|
|
2451
|
+
*/
|
|
2452
|
+
dismiss: () => void;
|
|
2453
|
+
}
|
|
2454
|
+
/**
|
|
2455
|
+
* Pays a locked quote from the connected wallet and says where it stands, for the pay step.
|
|
2456
|
+
*
|
|
2457
|
+
* Side effects: wallet prompts; requests to the checkout routes of Quasar.
|
|
2458
|
+
*
|
|
2459
|
+
* @param params - See {@link UsePaymentParams}.
|
|
2460
|
+
* @returns See {@link Payment}.
|
|
2461
|
+
*/
|
|
2462
|
+
declare function usePayment({ adapter, store, quote, wallet, path, paymasterUrl, invoiceId, onSent, }: UsePaymentParams): Payment;
|
|
2463
|
+
|
|
2464
|
+
/**
|
|
2465
|
+
* What the confirm and paid steps show of the payment: its network and amount (from the locked quote), the
|
|
2466
|
+
* transaction (Quasar's hash, else the submitted key) with its explorer link from the chain adapter, and the sender.
|
|
2467
|
+
*
|
|
2468
|
+
* @returns The facts; each is `null` (or `undefined` for the link) when unknown.
|
|
2469
|
+
*/
|
|
2470
|
+
declare function usePaymentFacts(): {
|
|
2471
|
+
network: string | null;
|
|
2472
|
+
amount: string | null;
|
|
2473
|
+
paidAmount: string | null;
|
|
2474
|
+
txKey: string | null;
|
|
2475
|
+
lastOfParts: boolean;
|
|
2476
|
+
explorerUrl: string | undefined;
|
|
2477
|
+
from: string | null;
|
|
2478
|
+
fromAddress: string | null;
|
|
2479
|
+
fromUrl: string | undefined;
|
|
2480
|
+
};
|
|
2481
|
+
|
|
2482
|
+
/** What {@link usePaymentHandOver} needs. */
|
|
2483
|
+
interface UsePaymentHandOverParams {
|
|
2484
|
+
/** The checkout store (its state is read when the payment is handed over). */
|
|
2485
|
+
store: {
|
|
2486
|
+
getState: () => Pick<CheckoutState, 'phase' | 'error' | 'checkout'>;
|
|
2487
|
+
};
|
|
2488
|
+
/** Whether the checkout is open (a modal); an inline checkout stays open while it is shown. */
|
|
2489
|
+
open: boolean;
|
|
2490
|
+
/**
|
|
2491
|
+
* The adapter of a chain family.
|
|
2492
|
+
*
|
|
2493
|
+
* @param family - The family.
|
|
2494
|
+
* @returns The adapter, if any.
|
|
2495
|
+
*/
|
|
2496
|
+
adapterFor: (family: PaymentFamily) => PaymentsAdapter | undefined;
|
|
2497
|
+
/** The app's Pulsar store, if any. */
|
|
2498
|
+
pulsar: PaymentsPulsar | undefined;
|
|
2499
|
+
/** The labels of the checkout language. */
|
|
2500
|
+
labels: NovaPaymentsLabels;
|
|
2501
|
+
/** The checkout language (a BCP 47 tag). */
|
|
2502
|
+
locale: string;
|
|
2503
|
+
}
|
|
2504
|
+
/**
|
|
2505
|
+
* Follows the payment the wallet sent until the checkout closes: while it is open the checkout tracks the payment
|
|
2506
|
+
* itself; when it closes (or goes away) before Quasar settled the payment, the payment is handed over to the app's
|
|
2507
|
+
* Pulsar store, where Nova Transactions shows its toast. A wallet that sends after the checkout closed hands its
|
|
2508
|
+
* payment over at once.
|
|
2509
|
+
*
|
|
2510
|
+
* Side effects: on hand-over, a pending transaction in the Pulsar store and its tracker.
|
|
2511
|
+
*
|
|
2512
|
+
* @param params - See {@link UsePaymentHandOverParams}.
|
|
2513
|
+
* @returns The function to call with the payment the wallet sent.
|
|
2514
|
+
*/
|
|
2515
|
+
declare function usePaymentHandOver({ store, open, adapterFor, pulsar, labels, locale, }: UsePaymentHandOverParams): (payment: SentPayment) => void;
|
|
2516
|
+
|
|
2517
|
+
/**
|
|
2518
|
+
* Whose wallet connection the checkouts and refunds use: the choice of the nearest {@link NovaPaymentsProvider}
|
|
2519
|
+
* (made on its first render), or, without one, what the app's providers above give (`app`, `appStore` or `none`). See
|
|
2520
|
+
* {@link PaymentsConnectionMode}.
|
|
2521
|
+
*
|
|
2522
|
+
* @returns The mode.
|
|
2523
|
+
*
|
|
2524
|
+
* @example
|
|
2525
|
+
* ```tsx
|
|
2526
|
+
* import { usePaymentsConnection } from '@tuwaio/payments-sdk';
|
|
2527
|
+
*
|
|
2528
|
+
* export function WalletNote() {
|
|
2529
|
+
* const connection = usePaymentsConnection();
|
|
2530
|
+
* return connection === 'own' ? <p>The checkout connects its own wallet.</p> : null;
|
|
2531
|
+
* }
|
|
2532
|
+
* ```
|
|
2533
|
+
*/
|
|
2534
|
+
declare function usePaymentsConnection(): PaymentsConnectionMode;
|
|
2535
|
+
|
|
2536
|
+
/**
|
|
2537
|
+
* The labels of a language: the built-in ones (English for a language without its own), then `labels` of
|
|
2538
|
+
* `NovaPaymentsProvider`, then its `customization.labels.transform`. The built-in labels of a language other than
|
|
2539
|
+
* English load on first use (see `loadLabels`); until they arrive the hook keeps the labels it showed before (English
|
|
2540
|
+
* the first time) and renders again once they are loaded.
|
|
2541
|
+
*
|
|
2542
|
+
* @param locale - The language of the checkout.
|
|
2543
|
+
* @returns The labels.
|
|
2544
|
+
*/
|
|
2545
|
+
declare function usePaymentsLabels(locale: string): NovaPaymentsLabels;
|
|
2546
|
+
|
|
2547
|
+
/** What {@link useWalletConnection} returns. */
|
|
2548
|
+
interface WalletConnection {
|
|
2549
|
+
/** Whether the page can connect a wallet: Nova Connect is set up, or the app handles it. */
|
|
2550
|
+
canConnect: boolean;
|
|
2551
|
+
/** Whether the connect modal of Nova Connect is open. */
|
|
2552
|
+
connecting: boolean;
|
|
2553
|
+
/**
|
|
2554
|
+
* Asks the buyer to connect a wallet of a chain family.
|
|
2555
|
+
*
|
|
2556
|
+
* @param family - The family of the chosen method.
|
|
2557
|
+
* @returns Whether the request went anywhere.
|
|
2558
|
+
*/
|
|
2559
|
+
connect: (family: PaymentFamily) => boolean;
|
|
2560
|
+
}
|
|
2561
|
+
/**
|
|
2562
|
+
* Connects a wallet for a payment: opens the connect modal of Nova Connect on the wallets of the method's chain family
|
|
2563
|
+
* when the checkout is inside `NovaConnectProvider` of `@tuwaio/nova-connect` (the app's, or Nova's own connection of
|
|
2564
|
+
* {@link NovaPaymentsProvider}), else calls the app's handler: `onConnectWallet`, or that of `NovaPaymentsProvider`.
|
|
2565
|
+
*
|
|
2566
|
+
* @param onConnectWallet - The app's handler, for apps that connect wallets without Nova Connect; overrides the
|
|
2567
|
+
* `onConnectWallet` of `NovaPaymentsProvider`.
|
|
2568
|
+
* @returns See {@link WalletConnection}.
|
|
2569
|
+
*/
|
|
2570
|
+
declare function useWalletConnection(onConnectWallet?: (family: PaymentFamily) => void): WalletConnection;
|
|
2571
|
+
|
|
2572
|
+
/**
|
|
2573
|
+
* @file The buyer details the checkout collects when the merchant's settings ask for them: which
|
|
2574
|
+
* fields, what is missing, and the countries to pick from.
|
|
2575
|
+
*/
|
|
2576
|
+
|
|
2577
|
+
/** A field of the buyer details form. */
|
|
2578
|
+
interface BuyerField {
|
|
2579
|
+
/** The field of `Buyer`. */
|
|
2580
|
+
name: keyof Buyer;
|
|
2581
|
+
/** Whether the invoice needs it. */
|
|
2582
|
+
required: boolean;
|
|
2583
|
+
/** The `autocomplete` token, so browsers fill it in (WCAG 1.3.5). */
|
|
2584
|
+
autoComplete: string;
|
|
2585
|
+
/** The input type. */
|
|
2586
|
+
type: 'email' | 'text' | 'country';
|
|
2587
|
+
}
|
|
2588
|
+
/** Why a field is refused: missing, not an email, not a country code. */
|
|
2589
|
+
type BuyerIssue = 'required' | 'email' | 'country';
|
|
2590
|
+
/** What the checkout collects: `email` or `full` details (the checkout view's `buyer.collect`). */
|
|
2591
|
+
type BuyerCollect = 'email' | 'full';
|
|
2592
|
+
/**
|
|
2593
|
+
* The fields of the form, in order.
|
|
2594
|
+
*
|
|
2595
|
+
* @param collect - What the checkout collects.
|
|
2596
|
+
* @param company - The buyer wants an invoice for a company: name, address line, country and tax ID are needed.
|
|
2597
|
+
* @returns The fields.
|
|
2598
|
+
*/
|
|
2599
|
+
declare function buyerFields(collect: BuyerCollect, company: boolean): BuyerField[];
|
|
2600
|
+
/**
|
|
2601
|
+
* What is missing or invalid in the details, field by field.
|
|
2602
|
+
*
|
|
2603
|
+
* @param buyer - The details as typed.
|
|
2604
|
+
* @param collect - What the checkout collects.
|
|
2605
|
+
* @param company - Whether the buyer wants a company invoice.
|
|
2606
|
+
* @returns The issue of each refused field; empty when the details can be sent.
|
|
2607
|
+
*/
|
|
2608
|
+
declare function buyerIssues(buyer: Partial<Record<keyof Buyer, string>>, collect: BuyerCollect, company: boolean): Partial<Record<keyof Buyer, BuyerIssue>>;
|
|
2609
|
+
/**
|
|
2610
|
+
* The details to send: trimmed, empty ones left out, the country in capitals.
|
|
2611
|
+
*
|
|
2612
|
+
* @param buyer - The details as typed.
|
|
2613
|
+
* @returns The `Buyer` for `setBuyer` of the checkout store.
|
|
2614
|
+
*/
|
|
2615
|
+
declare function cleanBuyer(buyer: Partial<Record<keyof Buyer, string>>): Buyer;
|
|
2616
|
+
/**
|
|
2617
|
+
* The countries to pick from, named in the language of the page (`Intl.DisplayNames`) and sorted by name.
|
|
2618
|
+
*
|
|
2619
|
+
* @param locale - BCP 47 language of the page.
|
|
2620
|
+
* @returns The country codes and names.
|
|
2621
|
+
*/
|
|
2622
|
+
declare function countryOptions(locale: string): {
|
|
2623
|
+
code: string;
|
|
2624
|
+
name: string;
|
|
2625
|
+
}[];
|
|
2626
|
+
|
|
2627
|
+
/**
|
|
2628
|
+
* @file Numbers, amounts, addresses and countdowns as the checkout shows them, in the language of the page.
|
|
2629
|
+
*/
|
|
2630
|
+
/**
|
|
2631
|
+
* A decimal string from an integer amount of minor units (cents), without floating point.
|
|
2632
|
+
*
|
|
2633
|
+
* @param minor - Minor units, as a decimal integer string (may be negative).
|
|
2634
|
+
* @param digits - Minor digits of the currency (default `2`).
|
|
2635
|
+
* @returns The decimal, for example `89.54` for `8954`.
|
|
2636
|
+
*/
|
|
2637
|
+
declare function minorToDecimal(minor: string, digits?: number): string;
|
|
2638
|
+
/**
|
|
2639
|
+
* A fiat amount with two decimals and the grouping of the language, without the currency (the checkout shows its
|
|
2640
|
+
* code next to it).
|
|
2641
|
+
*
|
|
2642
|
+
* @param amount - A decimal string or a number.
|
|
2643
|
+
* @param locale - BCP 47 language of the page.
|
|
2644
|
+
* @returns The formatted amount, for example `1,234.50` in English and `1.234,50` in German.
|
|
2645
|
+
*/
|
|
2646
|
+
declare function formatFiat(amount: string | number, locale: string): string;
|
|
2647
|
+
/**
|
|
2648
|
+
* A token amount from base units, exact: every decimal the amount has (at least two), never rounded, with the
|
|
2649
|
+
* grouping of the language. What the buyer sends must match the wallet to the last digit.
|
|
2650
|
+
*
|
|
2651
|
+
* @param baseUnits - Base units, as a decimal integer string.
|
|
2652
|
+
* @param decimals - Decimals of the token.
|
|
2653
|
+
* @param locale - BCP 47 language of the page.
|
|
2654
|
+
* @returns The formatted amount, for example `89.54` for `89540000` with 6 decimals.
|
|
2655
|
+
*/
|
|
2656
|
+
declare function formatTokenAmount(baseUnits: string, decimals: number, locale: string): string;
|
|
2657
|
+
/**
|
|
2658
|
+
* A network fee for a line of text: an estimate, so six decimals at most. A fee below that says nothing a reader can use
|
|
2659
|
+
* (the wallet sets its own and may well charge more), so it has no number.
|
|
2660
|
+
*
|
|
2661
|
+
* @param baseUnits - Base units, as a decimal integer string (not negative).
|
|
2662
|
+
* @param decimals - Decimals of the native token.
|
|
2663
|
+
* @param locale - BCP 47 language of the page.
|
|
2664
|
+
* @returns For example `0.000036` for 36082500481100 with 18 decimals; `null` for a fee below `0.000001`.
|
|
2665
|
+
*/
|
|
2666
|
+
declare function formatFeeAmount(baseUnits: string, decimals: number, locale: string): string | null;
|
|
2667
|
+
/**
|
|
2668
|
+
* A token amount as a wallet takes it when pasted: exact, with a dot, without grouping or trailing zeros.
|
|
2669
|
+
*
|
|
2670
|
+
* @param baseUnits - Base units, as a decimal integer string (not negative).
|
|
2671
|
+
* @param decimals - Decimals of the token.
|
|
2672
|
+
* @returns For example `89.54` for `89540000` with 6 decimals, `5` for `5000000`.
|
|
2673
|
+
*/
|
|
2674
|
+
declare function baseUnitsToDecimal(baseUnits: string, decimals: number): string;
|
|
2675
|
+
|
|
2676
|
+
/**
|
|
2677
|
+
* Time left as a countdown: `mm:ss` under an hour, `hh:mm:ss` under a day, `Nd hh:mm` beyond, where seconds say nothing
|
|
2678
|
+
* and would not fit beside the date in the summary.
|
|
2679
|
+
*
|
|
2680
|
+
* @param ms - Milliseconds left; a negative value counts as zero.
|
|
2681
|
+
* @returns The countdown.
|
|
2682
|
+
*/
|
|
2683
|
+
declare function formatCountdown(ms: number): string;
|
|
2684
|
+
|
|
2685
|
+
/**
|
|
2686
|
+
* @file What the outcome steps show: how to reach the seller, when to ask before leaving, what a refusal means, the
|
|
2687
|
+
* terms of automatic payments, what an underpaid invoice still needs, and what arrived on an invoice.
|
|
2688
|
+
*/
|
|
2689
|
+
|
|
2690
|
+
/**
|
|
2691
|
+
* Where "Contact <seller>" leads: an email to the seller's support address about the invoice, else the seller's site.
|
|
2692
|
+
*
|
|
2693
|
+
* @param merchant - The seller's support email and site.
|
|
2694
|
+
* @param merchant.supportEmail - The support email, if any.
|
|
2695
|
+
* @param merchant.website - The site (http(s) only), if any.
|
|
2696
|
+
* @param subject - The subject of the email, for example `Invoice INV-2026-42`.
|
|
2697
|
+
* @returns The link, or `null` when the seller gave neither.
|
|
2698
|
+
*/
|
|
2699
|
+
declare function contactHref(merchant: Pick<CheckoutMerchant, 'supportEmail' | 'website'>, subject: string): string | null;
|
|
2700
|
+
/**
|
|
2701
|
+
* What the checkout says about a payment that left the wallet, or may have, from the store's error: a transaction that
|
|
2702
|
+
* does not pay the invoice (`pay.mismatch`; `pay.mismatchTakenElsewhere` when Quasar credited it to another invoice;
|
|
2703
|
+
* `pay.mismatchHeldElsewhere` when another invoice holds it for a refund only, `held`;
|
|
2704
|
+
* `pay.mismatchOtherWallet` for a transfer from a wallet that did not confirm the invoice, `pay.mismatchOtherWalletHeld`
|
|
2705
|
+
* when Quasar recorded it as a held transfer the seller returns, `held`; `pay.mismatchChargeHeld` for an automatic charge
|
|
2706
|
+
* that landed after the buyer chose another way to pay), a payment Quasar closed after 24 hours without a result on chain
|
|
2707
|
+
* (`outcome.unconfirmedClosed`), a transaction another invoice handed over first (`outcome.unconfirmedTakenElsewhere`)
|
|
2708
|
+
* and a payment the network confirmed that Quasar has not recorded yet (`outcome.unconfirmedSettlementRetrying` while
|
|
2709
|
+
* Quasar settles it again daily, for 30 days, else `outcome.unconfirmedSettlementFailed`). Never "it failed", "only the
|
|
2710
|
+
* network fee was spent" or "nothing was charged" for them.
|
|
2711
|
+
*
|
|
2712
|
+
* @param error - The store's error, if any.
|
|
2713
|
+
* @param labels - The labels of the checkout language.
|
|
2714
|
+
* @param merchant - The seller's name.
|
|
2715
|
+
* @returns The text, or `null` for any other error, or none.
|
|
2716
|
+
*/
|
|
2717
|
+
declare function leftTheWalletText(error: CheckoutError | null | undefined, labels: NovaPaymentsLabels, merchant?: string): string | null;
|
|
2718
|
+
/**
|
|
2719
|
+
* Whether closing the checkout asks first: only while nothing has been sent. Once a transaction is on its way, or the
|
|
2720
|
+
* invoice is settled, the checkout closes without a question; also after a payment that left the wallet, or may have
|
|
2721
|
+
* ({@link leftTheWalletText}: a transaction that does not pay the invoice, a payment Quasar closed without a result on
|
|
2722
|
+
* chain within 24 hours, a transaction another invoice handed over first, a confirmed payment Quasar has not recorded
|
|
2723
|
+
* yet), so the question's "Nothing is sent yet" would not be true. Nor is it on the rest of an underpaid invoice, whose
|
|
2724
|
+
* price stays as it is.
|
|
2725
|
+
*
|
|
2726
|
+
* @param phase - Where the payment stands.
|
|
2727
|
+
* @param error - The store's last error, if any.
|
|
2728
|
+
* @param status - The state of the invoice, when known.
|
|
2729
|
+
* @returns `true` to ask.
|
|
2730
|
+
*/
|
|
2731
|
+
declare function needsLeaveConfirm(phase: CheckoutPhase, error?: CheckoutError | null, status?: string | null): boolean;
|
|
2732
|
+
/**
|
|
2733
|
+
* The text of a refusal on the method step, with what to do.
|
|
2734
|
+
*
|
|
2735
|
+
* @param error - The store's error.
|
|
2736
|
+
* @param labels - The labels of the checkout language.
|
|
2737
|
+
* @param merchant - The seller's name, for a payment that left the wallet, or may have ({@link leftTheWalletText}).
|
|
2738
|
+
* @returns The text.
|
|
2739
|
+
*/
|
|
2740
|
+
declare function methodErrorText(error: CheckoutError, labels: NovaPaymentsLabels, merchant?: string): string;
|
|
2741
|
+
/** The terms of an automatic payments offer, as the checkout shows them. */
|
|
2742
|
+
interface AutoPayTerms {
|
|
2743
|
+
/** The CAIP-2 chain of the charges. */
|
|
2744
|
+
chainId: string;
|
|
2745
|
+
/**
|
|
2746
|
+
* The wallet the charges are paid to: the merchant's, as the `payee` rule of the request names it (the app's
|
|
2747
|
+
* collector, which sends the charges, when the request names no payee).
|
|
2748
|
+
*/
|
|
2749
|
+
to: string;
|
|
2750
|
+
/** The most it takes in a period, in base units of the token. */
|
|
2751
|
+
limit: string;
|
|
2752
|
+
/** Decimals of the token. */
|
|
2753
|
+
decimals: number;
|
|
2754
|
+
/** Symbol of the token. */
|
|
2755
|
+
symbol: string;
|
|
2756
|
+
/** The length of a period, in seconds. */
|
|
2757
|
+
periodSeconds: number;
|
|
2758
|
+
/** When the permission ends, in milliseconds; `null` without an expiry rule. */
|
|
2759
|
+
expiresAt: number | null;
|
|
2760
|
+
}
|
|
2761
|
+
/**
|
|
2762
|
+
* What the connected wallet may ask its wallet for: the offer, or taking over an active permission that holds nothing.
|
|
2763
|
+
*
|
|
2764
|
+
* @param offer - The automatic-charge offer of the checkout.
|
|
2765
|
+
* @returns The method and the request, or `null` when nothing can be given now.
|
|
2766
|
+
*/
|
|
2767
|
+
declare function grantableOffer(offer: AutoChargeOffer | null): Extract<AutoChargeOffer, {
|
|
2768
|
+
status: 'available';
|
|
2769
|
+
}> | NonNullable<Extract<AutoChargeOffer, {
|
|
2770
|
+
status: 'active';
|
|
2771
|
+
}>['replacement']> | null;
|
|
2772
|
+
/**
|
|
2773
|
+
* The terms of an ERC-7715 automatic payments offer: the periodic limit in the token of the method, the period, the
|
|
2774
|
+
* expiry and the merchant's wallet the charges are paid to.
|
|
2775
|
+
*
|
|
2776
|
+
* @param offer - The view's `autoCharge`.
|
|
2777
|
+
* @param methods - The view's methods (for the token of the offer).
|
|
2778
|
+
* @returns The terms, or `null` when the offer is not available or its method is unknown.
|
|
2779
|
+
*/
|
|
2780
|
+
declare function autoPayTerms(offer: AutoChargeOffer | null, methods: CheckoutMethod[]): AutoPayTerms | null;
|
|
2781
|
+
/**
|
|
2782
|
+
* A period as words of the language: whole days in days, otherwise in hours.
|
|
2783
|
+
*
|
|
2784
|
+
* @param seconds - The period.
|
|
2785
|
+
* @param locale - BCP 47 language of the page.
|
|
2786
|
+
* @returns For example `30 days`, `2 hours`, `30 днів`.
|
|
2787
|
+
*/
|
|
2788
|
+
declare function formatPeriod(seconds: number, locale: string): string;
|
|
2789
|
+
/**
|
|
2790
|
+
* What an underpaid invoice still needs, in base units of the locked token.
|
|
2791
|
+
*
|
|
2792
|
+
* @param quote - The locked quote the payment was for.
|
|
2793
|
+
* @param amountPaid - What arrived, in base units of that token.
|
|
2794
|
+
* @returns The rest, or `null` when it is unknown or nothing is left.
|
|
2795
|
+
*/
|
|
2796
|
+
declare function underpaidRest(quote: Pick<CheckoutQuote, 'cryptoAmountExpected'> | null, amountPaid: string | null): string | null;
|
|
2797
|
+
/**
|
|
2798
|
+
* What the buyer is told about the rate of the rest of an underpaid invoice, in an asset that moves against the invoice
|
|
2799
|
+
* currency (`rateHeldUntil` of the quote): until when a payment settles by itself, or that the seller now decides.
|
|
2800
|
+
*
|
|
2801
|
+
* @param quote - The locked quote.
|
|
2802
|
+
* @param now - The time now, in milliseconds.
|
|
2803
|
+
* @param labels - The labels of the checkout language.
|
|
2804
|
+
* @param merchant - The seller's name.
|
|
2805
|
+
* @param locale - The language of the checkout.
|
|
2806
|
+
* @param ended - What is said past that time; the payment step's `pay.restRateEnded` speaks of the payment being made.
|
|
2807
|
+
* @returns The text, or `null` when the rate holds until the due date.
|
|
2808
|
+
*/
|
|
2809
|
+
declare function restRateText(quote: Pick<CheckoutQuote, 'rateHeldUntil'> | null, now: number, labels: NovaPaymentsLabels, merchant: string, locale: string, ended?: string): string | null;
|
|
2810
|
+
/**
|
|
2811
|
+
* The address of a wallet Quasar names: it keeps the wallet that paid first as an address or as a CAIP-10 account.
|
|
2812
|
+
*
|
|
2813
|
+
* @param wallet - The wallet, in either form.
|
|
2814
|
+
* @returns The address.
|
|
2815
|
+
*/
|
|
2816
|
+
declare function addressOfWallet(wallet: string): string;
|
|
2817
|
+
/**
|
|
2818
|
+
* Whether two wallets Quasar names are one: an EVM address in any letter case, any other exactly.
|
|
2819
|
+
*
|
|
2820
|
+
* @param a - A wallet, as an address or an account.
|
|
2821
|
+
* @param b - Another one.
|
|
2822
|
+
* @returns `true` for the same wallet.
|
|
2823
|
+
*/
|
|
2824
|
+
declare function isSameWallet(a: string, b: string): boolean;
|
|
2825
|
+
/**
|
|
2826
|
+
* What arrived on an invoice, when anything did: an expired invoice says so instead of "nothing was charged".
|
|
2827
|
+
*
|
|
2828
|
+
* @param amountPaid - What arrived, in base units of the locked token (`amountPaid` of the invoice).
|
|
2829
|
+
* @returns The amount, or `null` when nothing arrived.
|
|
2830
|
+
*/
|
|
2831
|
+
declare function receivedAmount(amountPaid: string | null): string | null;
|
|
2832
|
+
/**
|
|
2833
|
+
* Whether a refund sends more tokens than came in, or a noticeably different number of tokens than its amount took at the rate of the payment: half a
|
|
2834
|
+
* percent or more, so a stablecoin at par never asks.
|
|
2835
|
+
*
|
|
2836
|
+
* @param preview - What the refund would send.
|
|
2837
|
+
* @returns Whether the merchant should look first.
|
|
2838
|
+
*/
|
|
2839
|
+
declare function refundRateMoved(preview: Pick<RefundPreview, 'cryptoAmount' | 'atPaymentRate'> & Partial<Pick<RefundPreview, 'received'>>): boolean;
|
|
2840
|
+
/**
|
|
2841
|
+
* Whether the checkout needs its second tick: for the deadline, the price lock and the return countdown. A receipt or an
|
|
2842
|
+
* expired page left open would otherwise render everything once a second for nothing.
|
|
2843
|
+
*
|
|
2844
|
+
* @param phase - The checkout's phase.
|
|
2845
|
+
* @param autoReturnSeconds - The seconds before the paid outcome returns to the seller, when set.
|
|
2846
|
+
* @param labelsShown - Whether the labels of the language are there: their file shows with a render.
|
|
2847
|
+
* @returns Whether to tick.
|
|
2848
|
+
* @internal
|
|
2849
|
+
*/
|
|
2850
|
+
declare function needsTheClock(phase: string, autoReturnSeconds: number | undefined, labelsShown: boolean): boolean;
|
|
2851
|
+
|
|
2852
|
+
/**
|
|
2853
|
+
* @file The paying wallet's confirmation of the invoice: before an EVM payment the buyer's
|
|
2854
|
+
* wallet sends itself, it signs Quasar's message for free, so that Quasar credits its transfers to this invoice only.
|
|
2855
|
+
* When the checkout asks for it, what it says about a refusal, and which wallets sign with a passkey.
|
|
2856
|
+
*/
|
|
2857
|
+
|
|
2858
|
+
/** Why the wallet did not confirm: its kind of failure, or a network switch the buyer refused. */
|
|
2859
|
+
type ConfirmProblem = PaymentWalletErrorKind | 'switchDeclined';
|
|
2860
|
+
/**
|
|
2861
|
+
* Whether the wallet is a smart account that signs with a passkey (or a fingerprint), by its connector type.
|
|
2862
|
+
*
|
|
2863
|
+
* @param wallet - The connected wallet.
|
|
2864
|
+
* @returns `true` for Coinbase Smart Wallet, Base Account and Porto.
|
|
2865
|
+
*/
|
|
2866
|
+
declare function isSmartWallet(wallet: Pick<CheckoutWallet, 'connectorType'> | null | undefined): boolean;
|
|
2867
|
+
/**
|
|
2868
|
+
* Whether the wallet confirms the invoice before it pays from the pay step: while the checkout store says it must
|
|
2869
|
+
* (`required`, `confirming`), and for a method the gasless relay could pay (`unless_relayed`) when the wallet sends the
|
|
2870
|
+
* transfer or the paymaster's calls itself; the relay's signed authorization confirms the wallet on its own.
|
|
2871
|
+
*
|
|
2872
|
+
* @param payerProof - `payerProof` of the checkout store (left out by older stores).
|
|
2873
|
+
* @param path - How the wallet pays the quote.
|
|
2874
|
+
* @returns `true` to ask for the confirmation first.
|
|
2875
|
+
*/
|
|
2876
|
+
declare function needsPayerProof(payerProof: string | undefined, path: PayPath): boolean;
|
|
2877
|
+
/** The part of the checkout store {@link lockPrice} reads. */
|
|
2878
|
+
interface LockPriceStore {
|
|
2879
|
+
/** The store's state and actions. */
|
|
2880
|
+
getState: () => Pick<CheckoutState, 'requestQuote' | 'error'> & {
|
|
2881
|
+
readonly payerProof?: string;
|
|
2882
|
+
};
|
|
2883
|
+
}
|
|
2884
|
+
/**
|
|
2885
|
+
* Locks the price for the wallet the buyer continued with, or turns to the step that confirms the wallet first: while
|
|
2886
|
+
* the checkout store says the wallet must confirm the invoice (`payerProof` `required`), no price is asked; when Quasar
|
|
2887
|
+
* refuses the price with `payer_proof_required` (a wallet it wants confirmed, which the checkout did not announce), the
|
|
2888
|
+
* step shows too.
|
|
2889
|
+
*
|
|
2890
|
+
* Side effects: `POST quote` through the checkout store.
|
|
2891
|
+
*
|
|
2892
|
+
* @param store - The checkout store.
|
|
2893
|
+
* @param showConfirmWallet - Shows (`true`) or leaves (`false`) the step that confirms the wallet.
|
|
2894
|
+
* @returns The quote, or `null` when none was locked.
|
|
2895
|
+
*/
|
|
2896
|
+
declare function lockPrice(store: LockPriceStore, showConfirmWallet: (show: boolean) => void): Promise<CheckoutQuote | null>;
|
|
2897
|
+
/**
|
|
2898
|
+
* Whether the error is a refusal of the wallet's confirmation (`payer_proof_*`, `payer_chain_mismatch`,
|
|
2899
|
+
* `too_many_payers`): the pay step shows only these under the confirmation, its other errors have texts of their own.
|
|
2900
|
+
*
|
|
2901
|
+
* @param error - The checkout store's error, if any.
|
|
2902
|
+
* @returns `true` for a refusal of the confirmation.
|
|
2903
|
+
*/
|
|
2904
|
+
declare function isPayerProofError(error: CheckoutError | null | undefined): boolean;
|
|
2905
|
+
/**
|
|
2906
|
+
* Whether an error belongs on the step that confirms the wallet. The store's error may be about something else: a
|
|
2907
|
+
* transfer held from another wallet, or a price refused to the last wallet, opened the step with "Something went wrong"
|
|
2908
|
+
* before the wallet was asked anything.
|
|
2909
|
+
*
|
|
2910
|
+
* @param error - The checkout store's error, if any.
|
|
2911
|
+
* @returns `true` for a refusal of the confirmation or a failure of its requests.
|
|
2912
|
+
*/
|
|
2913
|
+
declare function isConfirmationError(error: CheckoutError | null | undefined): boolean;
|
|
2914
|
+
/**
|
|
2915
|
+
* What the step that confirms the wallet says about a refusal, with what to do: the wallet's (the buyer declined, the
|
|
2916
|
+
* wallet cannot sign messages, it failed) or Quasar's (`payer_proof_invalid`, `payer_proof_unavailable`,
|
|
2917
|
+
* `payer_chain_mismatch`, `too_many_payers`, `rate_limited`…). The buyer stays on the step and can try again.
|
|
2918
|
+
*
|
|
2919
|
+
* @param error - The checkout store's error, if any.
|
|
2920
|
+
* @param problem - Why the wallet did not sign, when the checkout knows it.
|
|
2921
|
+
* @param labels - The labels of the checkout language.
|
|
2922
|
+
* @param values - The wallet's name, the method's network and the seller's name.
|
|
2923
|
+
* @param values.wallet - The wallet's name.
|
|
2924
|
+
* @param values.network - The network of the method.
|
|
2925
|
+
* @param values.merchant - The seller's name.
|
|
2926
|
+
* @returns The text, or `null` with nothing to say (no error, or `payer_proof_required`, the reason the step shows).
|
|
2927
|
+
*/
|
|
2928
|
+
declare function payerProofErrorText(error: CheckoutError | null | undefined, problem: ConfirmProblem | null, labels: NovaPaymentsLabels, values: {
|
|
2929
|
+
wallet: string;
|
|
2930
|
+
network: string;
|
|
2931
|
+
merchant: string;
|
|
2932
|
+
}): string | null;
|
|
2933
|
+
|
|
2934
|
+
/**
|
|
2935
|
+
* @file A QR code as one SVG path, so the checkout draws it in its own colors.
|
|
2936
|
+
*/
|
|
2937
|
+
/**
|
|
2938
|
+
* A QR code as an SVG path: one 1×1 square per dark module, inside a quiet zone of four modules. Error correction `M`
|
|
2939
|
+
* (15 %) keeps payment links short enough to scan from a screen.
|
|
2940
|
+
*
|
|
2941
|
+
* @param text - What the code holds (a Solana Pay URL, a payment page).
|
|
2942
|
+
* @returns The size of the square view box in modules and the path.
|
|
2943
|
+
*/
|
|
2944
|
+
declare function qrPath(text: string): {
|
|
2945
|
+
size: number;
|
|
2946
|
+
path: string;
|
|
2947
|
+
};
|
|
2948
|
+
|
|
2949
|
+
/**
|
|
2950
|
+
* @file A refund as the merchant's wallet sends it: the transfer Quasar asks for, in the shape of a payment.
|
|
2951
|
+
*/
|
|
2952
|
+
|
|
2953
|
+
/** What Quasar asks the merchant to send for a refund (`instructions` of the refund store). */
|
|
2954
|
+
type RefundInstructions = NonNullable<RefundState['instructions']>;
|
|
2955
|
+
/**
|
|
2956
|
+
* The transfer of a refund as a payments adapter sends it (`sendTransfer`): the asset of the payment to the payer, on
|
|
2957
|
+
* the chain of the payment. The token is the contract or mint of the CAIP-19 asset, `native` for the coin of the chain.
|
|
2958
|
+
*
|
|
2959
|
+
* @param instructions - What Quasar asks to send.
|
|
2960
|
+
* @returns The transfer, or `null` without a recipient or on a chain no adapter pays on.
|
|
2961
|
+
*/
|
|
2962
|
+
declare function refundTransfer(instructions: RefundInstructions): PaymentInstructions | null;
|
|
2963
|
+
|
|
2964
|
+
/**
|
|
2965
|
+
* Subtotal and tax of the invoice from its lines: the lines carry net amounts, the total includes tax. The tax row
|
|
2966
|
+
* shows the rate when all taxed lines share one.
|
|
2967
|
+
*
|
|
2968
|
+
* @param invoice - The invoice of the checkout.
|
|
2969
|
+
* @returns The subtotal, the tax (`null` without tax), its rate (`null` with several) and the total, as decimals.
|
|
2970
|
+
*/
|
|
2971
|
+
declare function invoiceTotals(invoice: CheckoutView['invoice']): {
|
|
2972
|
+
subtotal: string;
|
|
2973
|
+
tax: string | null;
|
|
2974
|
+
rate: string | null;
|
|
2975
|
+
total: string;
|
|
2976
|
+
};
|
|
2977
|
+
|
|
2978
|
+
export { AmountStep, AutoPayScreen, BuyerScreen, CheckoutContext, CheckoutContextProvider, CheckoutFrame, CheckoutHeader, CheckoutPageRoot, CheckoutStepper, CheckoutSummary, CheckoutWallet, CompactSummary, ConfirmScreen, ConfirmStep, ConfirmWalletScreen, DEADLINE_ANNOUNCEMENTS, DeadlineTimer, Disclosure, FailedStep, LeaveDialog, LocaleSwitcher, MerchantBadge, MethodScreen, MobileSteps, NativeFee, NovaPaymentsContext, NovaPaymentsProvider, OPEN_REQUEST_MS, OrderLines, OrderTotal, OutcomeScreen, PaidScreen, PayScreen, PaymentCheckout, PaymentFamily, PaymentWalletError, PaymentsAdapter, QUOTE_WARNING_MS, QrScreen, RefundButton, RefundDialog, RefundSteps, ScreenBody, SellerDetailsContent, SummaryFooter, WalletPrompt, addressOfWallet, autoPayTerms, balanceShortfall, baseUnitsToDecimal, buyerFields, buyerIssues, checkoutClassName, checkoutScreen, checkoutSteps, cleanBuyer, contactHref, countryOptions, deadlineAnnouncement, deadlineState, formatCountdown, formatFeeAmount, formatFiat, formatPeriod, formatTokenAmount, grantableOffer, groupMethodsByToken, handOverPayment, instructionsChainId, invoiceTotals, isConfirmationError, isFinalPaymentFailure, isInvoicePaymentOnTheWay, isInvoicePaymentUnresolved, isMovedMoneyFailure, isPaidElsewhere, isPayerProofError, isPaymentAccepted, isPaymentOnTheWay, isQuoteEnding, isSameWallet, isSlow, isSmartWallet, leftTheWalletText, lockPrice, lockedPriceOnWallet, methodErrorText, minorToDecimal, needsLeaveConfirm, needsPayerProof, needsTheClock, paidSteps, payInvoice, payPath, payerProofErrorText, qrPath, quoteAmounts, quoteRate, receivedAmount, refundRateMoved, refundTransfer, refusalText, restRateText, screensPayingWallets, sentBeforeDeadline, shouldHandOver, takeOverOpens, unconfirmedFollowUp, unconfirmedTxKey, underpaidRest, useAsyncValue, useAutoReturn, useCheckoutContext, useCheckoutEvents, useCheckoutState, useCheckoutStore, useConnectedWallet, useNovaPayments, useNow, useOptionalCheckoutContext, usePaidCallback, usePayerProof, usePayment, usePaymentFacts, usePaymentHandOver, usePaymentsConnection, usePaymentsLabels, useRefund, useRereadValue, useWalletConnection, walletErrorKind, walletOnConfirmStep };
|
|
2979
|
+
export type { AutoPayTerms, BalanceShortfall, BuyerCollect, BuyerField, BuyerIssue, CheckoutContextValue, CheckoutHeaderProps, CheckoutNetworkOptionProps, CheckoutPartState, CheckoutPrimaryButtonProps, CheckoutQrCodeProps, CheckoutScreen, CheckoutScreenChoices, CheckoutScreenProps, CheckoutStatusIconProps, CheckoutStep, CheckoutStepperProps, CheckoutTokenGroup, CheckoutTokenOptionProps, ConfirmProblem, HandOverParams, LocaleSwitcherProps, LockPriceStore, NovaPaymentsLabelsContext, NovaPaymentsOwnConnection, NovaPaymentsProviderCustomization, NovaPaymentsProviderProps, NovaPaymentsSettings, OutcomeKind, PayInvoiceParams, PayPath, PayerProofFlow, PayerProofProblem, PayerProofStep, Payment, PaymentCheckoutChildCustomizations, PaymentCheckoutClassNames, PaymentCheckoutComponents, PaymentCheckoutConfig, PaymentCheckoutCustomization, PaymentCheckoutDisplay, PaymentCheckoutHandlers, PaymentCheckoutProps, PaymentStatus, PaymentWalletErrorKind, PaymentsConnectionMode, PaymentsPulsar, QuoteAmounts, RefundButtonProps, RefundDialogProps, RefundFlow, RefundInstructions, RefundProblem, RefundRequest, RefundStep, SentBeforeDeadlineParams, SentPayment, UnconfirmedFollowUp, UseAutoReturnParams, UseCheckoutEventsParams, UseCheckoutStoreOptions, UsePayerProofParams, UsePaymentHandOverParams, UsePaymentParams, UseRefundParams, WalletConnection, WalletPromptKind, WalletPromptProps };
|