@tokelia/pay-widget 13.0.45-tokelia.3

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/README.md ADDED
@@ -0,0 +1,1049 @@
1
+ # tokelia-pay widget
2
+
3
+ Derivado de [@depay/widgets](https://github.com/DePayFi/widgets) (MIT).
4
+
5
+ ## 📦 Installation
6
+
7
+ ```bash
8
+ npm install @tokelia/pay-widget
9
+ ```
10
+
11
+ CDN (jsDelivr, sirve el bundle publicado en npm):
12
+
13
+ ```html
14
+ <script src="https://cdn.jsdelivr.net/npm/@tokelia/pay-widget@13/dist/umd/index.bundle.js"></script>
15
+ ```
16
+
17
+ Global UMD: `TokeliaPay`. Por ejemplo `TokeliaPay.Payment({ integration, apiUrl, ... })`.
18
+
19
+ ### Opciones propias de tokelia-pay
20
+
21
+ | Opción | Tipo | Descripción |
22
+ |---|---|---|
23
+ | `apiUrl` | `string` | Base del servicio tokelia-pay (sin barra final). Obligatoria con `integration`. |
24
+ | `endpoints` | `EndpointOptions` | Plantillas por endpoint (`configuration`, `attempts`, `attempt`, `fiatRate`, `routesAll`, `routesBest`, `validationSocket`) para sobrescribir las rutas por defecto. Ver `src/index.d.ts`. |
25
+ | `publicKey` | `string` | PEM para verificar la cabecera `x-signature` de la configuración. Sin ella no se verifica. |
26
+ | `walletConnectProjectId` | `string` | Project ID de Reown Cloud para WalletConnect. Sin él, WalletConnect no está disponible (MetaMask, Coinbase Wallet y las wallets de navegador funcionan igual). |
27
+ | `providers` | `{[cadena]: string[]}` | RPC por cadena. Si no se pasa, el widget usa las URL de `chains` que entrega el servicio (proxy JSON-RPC del checkout). |
28
+
29
+ Rutas por defecto (relativas a `apiUrl`, montadas por tokelia-pay bajo `/v1/public`):
30
+
31
+ - `configuration`: `/v1/public/checkouts/{id}`
32
+ - `attempts`: `/v1/public/checkouts/{id}/attempts`
33
+ - `attempt`: `/v1/public/attempts/{id}`
34
+ - `fiatRate`: `/v1/public/rates/usd/{currency}`
35
+ - `routesAll`: `/v1/public/checkouts/{id}/routes/all`
36
+ - `routesBest`: `/v1/public/checkouts/{id}/routes/best`
37
+
38
+ Sin `apiUrl` (modo no gestionado con `accept`) hay que pasar `endpoints.routesAll` y `endpoints.routesBest`: el widget no calcula rutas por sí mismo ni consulta a DePay.
39
+
40
+ ### Redes de pruebas
41
+
42
+ `basesepolia` (Base Sepolia, chainId 84532) está soportada para QA con el router de tokelia-pay. El resumen del pago muestra la etiqueta "Red de pruebas". El servicio solo la activa para inquilinos en `mode: "test"`.
43
+
44
+ ## Import in your JavaScript files
45
+
46
+ ```javascript
47
+ import TokeliaPay from '@tokelia/pay-widget'
48
+ ```
49
+
50
+ ## Server-Side Rendering (SSR)
51
+
52
+ If you're using SSR frameworks like Next.js, make sure to only load DePay Widgets on the client side.
53
+
54
+ Guide: https://dev.to/elisabethleonhardt/how-to-use-client-side-only-packages-with-ssr-in-gatsby-and-nextjs-3pfa
55
+
56
+ ## Demos
57
+
58
+ Configurator UI: https://app.depay.com/integrations/new
59
+
60
+ Technical Demo: https://depayfi.github.io/widgets/demo.bundle.html
61
+
62
+ ## Support
63
+
64
+ ### Platforms
65
+
66
+ Este paquete es solo EVM (Ethereum Virtual Machine).
67
+ Se distribuye como un único build; no hay empaquetado específico por plataforma (sin variantes EVM/SVM).
68
+
69
+ ### Blockchains
70
+
71
+ - [Ethereum](https://ethereum.org)
72
+ - [BNB Smart Chain](https://www.binance.org/smartChain)
73
+ - [Polygon](https://polygon.technology)
74
+ - [Arbitrum](https://arbitrum.io)
75
+ - [Optimism](https://www.optimism.io)
76
+ - [Base](https://base.org)
77
+ - [Base Sepolia](https://docs.base.org/base-chain/quickstart/network-information) (testnet)
78
+ - [Avalanche](https://www.avax.network)
79
+ - [Gnosis](https://gnosis.io)
80
+
81
+ ### Wallets
82
+
83
+ DePay supports [most crypto wallets](https://depay.com/wallets).
84
+
85
+ ## Payment Widget
86
+
87
+ Enable seamless wallet-to-wallet crypto payments.
88
+
89
+ ### Managed Integration using Integration ID
90
+
91
+ ```javascript
92
+ TokeliaPay.Payment({
93
+ integration: 'YOUR_INTEGRATION_ID'
94
+ })
95
+ ```
96
+
97
+ Managed integration configurations fetched from app.depay.com.
98
+
99
+ > [!IMPORTANT]
100
+ > Local configurations override remote settings.
101
+
102
+ > [!CAUTION]
103
+ > Use either `integration` (managed) or `accept` (unmanaged), never both.
104
+
105
+ #### Payload for Dynamic Backend Configurations
106
+
107
+ ```javascript
108
+ TokeliaPay.Payment({
109
+ integration: 'YOUR_INTEGRATION_ID',
110
+ payload: { dynamicKey: 'dynamicValue' }
111
+ })
112
+ ```
113
+
114
+ Forwards the payload to your backend for dynamic payment setup, like:
115
+
116
+ ```json
117
+ {
118
+ "dynamicKey": "dynamicValue"
119
+ }
120
+ ```
121
+
122
+ ### Unmanaged Configuration
123
+
124
+ > [!IMPORTANT]
125
+ > Unmanaged configurations do not provide any callbacks for server-side actions or integrations. They are limited to initiating and executing payments only. If you need callbacks for your integrations, use [managed integrations](https://depay.com/docs/payments/integrate/widget).
126
+
127
+ ```javascript
128
+ TokeliaPay.Payment({
129
+ accept: [{
130
+ blockchain: 'ethereum',
131
+ amount: 1,
132
+ token: 'TOKEN_ADDRESS',
133
+ receiver: 'RECEIVER_ADDRESS'
134
+ }]
135
+ })
136
+ ```
137
+
138
+ Multi-blockchain payments:
139
+
140
+ ```javascript
141
+ TokeliaPay.Payment({
142
+ accept: [
143
+ { // 20 USDT on ethereum
144
+ blockchain: 'ethereum',
145
+ amount: 20,
146
+ token: '0xdac17f958d2ee523a2206206994597c13d831ec7',
147
+ receiver: '0x4e260bB2b25EC6F3A59B478fCDe5eD5B8D783B02'
148
+ },{ // 20 BUSD on bsc
149
+ blockchain: 'bsc',
150
+ amount: 20,
151
+ token: '0xe9e7cea3dedca5984780bafc599bd69add087d56',
152
+ receiver: '0x552C2a5a774CcaEeC036d41c983808E3c76477e6'
153
+ },{ // 20 USDC on polygon
154
+ blockchain: 'polygon',
155
+ amount: 20,
156
+ token: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
157
+ receiver: '0x552C2a5a774CcaEeC036d41c983808E3c76477e6'
158
+ }
159
+ ]
160
+ });
161
+ ```
162
+
163
+ ### Configuration Options
164
+
165
+ #### accept
166
+
167
+ > [!CAUTION]
168
+ > Use either `integration` (managed) or `accept` (unmanaged), never both.
169
+
170
+ ```javascript
171
+ TokeliaPay.Payment({
172
+ accept: [{
173
+ blockchain: 'ethereum',
174
+ amount: 1,
175
+ token: 'TOKEN_ADDRESS',
176
+ receiver: 'RECEIVER_ADDRESS'
177
+ }]
178
+ })
179
+ ```
180
+
181
+ `blockchain`
182
+
183
+ The blockchain you want to receive the payment on.
184
+
185
+ `token`
186
+
187
+ The address of the token you want to receive.
188
+
189
+ `amount` (Optional)
190
+
191
+ The amount of tokens you want to receive. Needs to be passed as a human readable number e.g. `20`.
192
+
193
+ The `BigNumber` of that amount will be calculated internally including finding the right amount of decimals for the given token.
194
+ So please just pass the amount in a human readable form as Number/Decimal: e.g. `20` for 20 USDT or `20.25` etc.
195
+
196
+ If you do not pass an amount, the user will be able to select an amount within the widget.
197
+
198
+ `receiver`
199
+
200
+ The address receiving the payment. Always double check that you've set the right address.
201
+
202
+
203
+ #### amount
204
+
205
+ ##### fixed currency amounts
206
+
207
+ If you want the widget to fix a payment amount in a currency, use `currency` and `fix`:
208
+
209
+ `currency`:
210
+
211
+ Example (charge US$5.20):
212
+
213
+ ```
214
+ {
215
+ amount: {
216
+ currency: 'USD',
217
+ fix: 5.20
218
+ }
219
+ }
220
+ ```
221
+
222
+ Make sure to not pass any amounts to `accept` if you use fix currency amounts.
223
+
224
+ The widget will still display local currency conversions to users. If you want to change this see `currency` configuration.
225
+
226
+ ##### amount selection (changeable amounts)
227
+
228
+ When you want to control how the amount selection behaves, pass the `amount` configuration object,
229
+ alongside values for `start`, `min` and `step`.
230
+
231
+ `start`: The amount that is initially selected.
232
+
233
+ `min`: The minimum amount selectable.
234
+
235
+ `step`: The number by which to increment/decrement changes to the amount.
236
+
237
+ #### fee
238
+
239
+ You can configure a fee which will be applied to every payment with its own dedicated fee receiver address.
240
+
241
+ The fee will be taken from the target token and target amount (after swap, depending on your `accept` configuration).
242
+
243
+ `amount`: Either percentage (e.g. `5%`, or absolute amount as BigNumber string ('100000000000000000') or pure number (2.5)
244
+
245
+ `receiver`: The address that is supposed to receive the fee.
246
+
247
+ ```javascript
248
+ TokeliaPay.Payment({
249
+ accept: [
250
+ {...
251
+
252
+ fee: {
253
+ amount: '3%',
254
+ receiver: '0x4e260bB2b25EC6F3A59B478fCDe5eD5B8D783B02'
255
+ }
256
+ }
257
+ ],
258
+ });
259
+ ```
260
+
261
+ ##### fee2
262
+
263
+ You can configure up to 2 fees that will be paid out as part of the payment:
264
+
265
+ ```javascript
266
+ TokeliaPay.Payment({
267
+ accept: [
268
+ {...
269
+
270
+ fee: {...},
271
+ fee2: {,
272
+ amount: '5%',
273
+ receiver: '0x08B277154218CCF3380CAE48d630DA13462E3950'
274
+ }
275
+ }
276
+ ],
277
+ });
278
+ ```
279
+
280
+ ##### protocolFee
281
+
282
+ The fee paid to the protocol:
283
+
284
+ ```javascript
285
+ TokeliaPay.Payment({
286
+
287
+ protocolFee: '1.5%',
288
+
289
+ });
290
+ ```
291
+
292
+ #### title
293
+
294
+ `title`
295
+
296
+ Allows you to change the title of the widget:
297
+
298
+ ```javascript
299
+ TokeliaPay.Payment({
300
+
301
+ title: 'Donation'
302
+
303
+ //...
304
+ })
305
+ ```
306
+
307
+ #### wallets
308
+
309
+ You can sort and allow (list) wallets displayed during the initial wallet selection step as follows:
310
+
311
+ ##### wallets.sort
312
+
313
+ ```
314
+ {
315
+ wallets: {
316
+ sort: [
317
+ 'Uniswap',
318
+ 'Coinbase'
319
+ ]
320
+ }
321
+ }
322
+ ```
323
+
324
+ This configuration would display Uniswap and Coinbase first, then would list all the others.
325
+
326
+ ##### wallets.allow
327
+
328
+ ```
329
+ {
330
+ wallets: {
331
+ allow: [
332
+ 'Uniswap',
333
+ 'Coinbase',
334
+ 'Rainbow'
335
+ ]
336
+ }
337
+ }
338
+ ```
339
+
340
+ This configuration would only display Uniswap, Coinbase and Rainbow. No other options/wallets are displayed.
341
+
342
+ #### wallet
343
+
344
+ `wallet`
345
+
346
+ Allows to pass an already connected wallet instance (to skip the "Connect Wallet" flow):
347
+
348
+ ```javascript
349
+ let { wallet } = TokeliaPay.Connect({})
350
+
351
+ TokeliaPay.Payment({
352
+
353
+ wallet: wallet
354
+
355
+ })
356
+ ```
357
+
358
+ #### walletConnectProjectId
359
+
360
+ `walletConnectProjectId`
361
+
362
+ Project ID de [Reown Cloud](https://cloud.reown.com) para habilitar WalletConnect. Sin él, WalletConnect no está disponible (MetaMask, Coinbase Wallet y las wallets de navegador siguen funcionando igual):
363
+
364
+ ```javascript
365
+ TokeliaPay.Payment({
366
+
367
+ walletConnectProjectId: 'YOUR_PROJECT_ID'
368
+
369
+ })
370
+ ```
371
+
372
+ #### providers
373
+
374
+ Allows to set providers to be used for making RPC calls to the individual blockchains:
375
+
376
+ ```javascript
377
+ TokeliaPay.Payment({
378
+
379
+ providers: {
380
+ ethereum: ['http://localhost:8545'],
381
+ bsc: ['http://localhost:8545'],
382
+ polygon: ['http://localhost:8545']
383
+ }
384
+ })
385
+ ```
386
+
387
+ Si no se pasa `providers` para una cadena, el widget usa las URL de `chains[*].rpcUrls` que entrega el checkout de tokelia-pay (el proxy JSON-RPC del servicio).
388
+
389
+ #### currency
390
+
391
+ Allows you to enforce displayed local currency (instead of automatically detecting it):
392
+
393
+ ```javascript
394
+
395
+ TokeliaPay.Payment({
396
+
397
+ currency: 'USD'
398
+
399
+ })
400
+
401
+ ```
402
+
403
+ #### allow (list)
404
+
405
+ Allows only the configured tokens to be eligible as means of payment:
406
+
407
+ ```javacript
408
+ TokeliaPay.Payment({
409
+
410
+ allow: {
411
+ ethereum: [
412
+ '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // ETH
413
+ '0xdac17f958d2ee523a2206206994597c13d831ec7', // USDT
414
+ '0x6b175474e89094c44da98b954eedeac495271d0f' // DAI
415
+ ],
416
+ bsc: [
417
+ '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // BNB
418
+ '0xe9e7cea3dedca5984780bafc599bd69add087d56', // BUSD
419
+ '0x55d398326f99059ff775485246999027b3197955' // BSC-USD
420
+ ],
421
+ polygon: [
422
+ '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // MATIC
423
+ '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', // USDC
424
+ ]
425
+ }
426
+
427
+ })
428
+
429
+ ```
430
+
431
+ #### deny
432
+
433
+ Allows to deny tokens so that they will not be suggested as means of payment:
434
+
435
+ ```javacript
436
+ TokeliaPay.Payment({
437
+
438
+ deny: {
439
+ ethereum: [
440
+ '0x82dfDB2ec1aa6003Ed4aCBa663403D7c2127Ff67', // akSwap
441
+ '0x1368452Bfb5Cd127971C8DE22C58fBE89D35A6BF', // JNTR/e
442
+ '0xC12D1c73eE7DC3615BA4e37E4ABFdbDDFA38907E', // KICK
443
+ ],
444
+ bsc: [
445
+ '0x119e2ad8f0c85c6f61afdf0df69693028cdc10be', // Zepe
446
+ '0xb0557906c617f0048a700758606f64b33d0c41a6', // Zepe
447
+ '0x5190b01965b6e3d786706fd4a999978626c19880', // TheEver
448
+ '0x68d1569d1a6968f194b4d93f8d0b416c123a599f', // AABek
449
+ '0xa2295477a3433f1d06ba349cde9f89a8b24e7f8d', // AAX
450
+ '0xbc6675de91e3da8eac51293ecb87c359019621cf', // AIR
451
+ '0x5558447b06867ffebd87dd63426d61c868c45904', // BNBW
452
+ '0x569b2cf0b745ef7fad04e8ae226251814b3395f9', // BSCTOKEN
453
+ '0x373233a38ae21cf0c4f9de11570e7d5aa6824a1e', // ALPACA
454
+ '0x7269163f2b060fb90101f58cf724737a2759f0bb', // PUPDOGE
455
+ '0xb16600c510b0f323dee2cb212924d90e58864421', // FLUX
456
+ '0x2df0b14ee90671021b016dab59f2300fb08681fa', // SAFEMOON.is
457
+ '0xd22202d23fe7de9e3dbe11a2a88f42f4cb9507cf', // MNEB
458
+ '0xfc646d0b564bf191b3d3adf2b620a792e485e6da', // PIZA
459
+ '0xa58950f05fea2277d2608748412bf9f802ea4901', // WSG
460
+ '0x12e34cdf6a031a10fe241864c32fb03a4fdad739' // FREE
461
+ ]
462
+ }
463
+ })
464
+ ```
465
+
466
+ #### container
467
+
468
+ `container`
469
+
470
+ Allows you to pass a container element that is supposed to contain the widget:
471
+
472
+ ```javascript
473
+ TokeliaPay.Payment({
474
+ container: document.getElementById('my-container')
475
+ })
476
+ ```
477
+
478
+ Make sure to set the css value `position: relative;` for the container element. Otherwise it can not contain the widget.
479
+
480
+ React example:
481
+
482
+ ```javascript
483
+ let CustomComponentWithWidget = (props)=>{
484
+ let container = useRef()
485
+
486
+ useEffect(()=>{
487
+ if(container.current) {
488
+ TokeliaPay.Payment({ ...defaultArguments, document,
489
+ container: container.current
490
+ })
491
+ }
492
+ }, [container])
493
+
494
+ return(
495
+ <div ref={container} style={{ position: 'relative', border: '1px solid black', width: "600px", height: "600px" }}></div>
496
+ )
497
+ }
498
+ ```
499
+
500
+ #### style
501
+
502
+ `style`
503
+
504
+ Allows you to change the style of the widget.
505
+
506
+ ```javascript
507
+ TokeliaPay.Payment({
508
+ style: {
509
+ colors: {
510
+ primary: '#ffd265',
511
+ text: '#e1b64a',
512
+ buttonText: '#000000',
513
+ },
514
+ fontFamily: '"Cardo", serif !important',
515
+ css: `
516
+ @import url("https://fonts.googleapis.com/css2?family=Cardo:wght@400;700&display=swap");
517
+
518
+ .ReactDialogBackground {
519
+ background: rgba(0,0,0,0.8);
520
+ }
521
+ `
522
+ }
523
+ })
524
+ ```
525
+
526
+ ##### colors
527
+
528
+ `colors`
529
+
530
+ Allows you to set color values:
531
+
532
+ ```javascript
533
+ TokeliaPay.Payment({
534
+
535
+ style: {
536
+ colors: {
537
+ primary: '#ffd265',
538
+ text: '#ffd265',
539
+ buttonText: '#000000',
540
+ icons: '#ffd265'
541
+ }
542
+ }
543
+ })
544
+ ```
545
+
546
+ ##### colorsDarkMode
547
+
548
+ You can pass colors applicable to dark mode:
549
+
550
+ ```javascript
551
+ TokeliaPay.Payment({
552
+
553
+ style: {
554
+ colorsDarkMode: {
555
+ primary: '#000265',
556
+ text: '#000265',
557
+ buttonText: '#FFFFFF',
558
+ icons: '#000265'
559
+ }
560
+ }
561
+ })
562
+ ```
563
+
564
+ ##### fontFamily
565
+
566
+ `fontFamily`
567
+
568
+ Allows you to set the font-family:
569
+
570
+ ```javascript
571
+ TokeliaPay.Payment({
572
+
573
+ style: {
574
+ fontFamily: '"Cardo", serif !important'
575
+ }
576
+ })
577
+ ```
578
+
579
+ ##### css
580
+
581
+ `css`
582
+
583
+ Allows you to inject CSS:
584
+
585
+ ```javascript
586
+ TokeliaPay.Payment({
587
+
588
+ style: {
589
+ css: `
590
+ @import url("https://fonts.googleapis.com/css2?family=Cardo:wght@400;700&display=swap");
591
+
592
+ .ReactDialogBackground {
593
+ background: rgba(0,0,0,0.8);
594
+ }
595
+ `
596
+ }
597
+ })
598
+ ```
599
+
600
+ ###### cssDarkMode
601
+
602
+ Allows you to inject css to adjust darkMode:
603
+
604
+ ```javascript
605
+ TokeliaPay.Payment({
606
+
607
+ style: {
608
+ cssDarkMode: `
609
+ @import url("https://fonts.googleapis.com/css2?family=Cardo:wght@400;700&display=swap");
610
+
611
+ .ReactDialogBackground {
612
+ background: rgba(0,0,0,0.8);
613
+ }
614
+ `
615
+ }
616
+ })
617
+ ```
618
+
619
+ #### unmount
620
+
621
+ `unmount`
622
+
623
+ Allows you to unmount (the React safe way) the entire widget from the outside:
624
+
625
+ ```javascript
626
+ let { unmount } = await TokeliaPay.Payment({})
627
+
628
+ unmount()
629
+ ```
630
+
631
+ ### Client Side Callbacks
632
+
633
+ > [!CAUTION]
634
+ > Client-side callbacks and client-side flow management are not recommended. Payment flows can involve device handovers (e.g., desktop to mobile) or app-to-app transitions on mobile, which break client-side control. In case of failed transactions, the widget provides a built-in way for users to retry their payments, so you don’t need to implement this functionality yourself. For this reason, relying solely on client-side callbacks for flow handling is not recommended. Instead, you can manage and control the user flow through [managed integrations](https://depay.com/docs/payments/integrate/widget).
635
+
636
+ Despite the previous warning, the widget still offers the following callbacks:
637
+
638
+ #### before
639
+
640
+ `before`
641
+
642
+ A function that will be called before the payment is handed over to the wallet.
643
+
644
+ Allows you to stop the payment if this method returns false.
645
+
646
+ ```javascript
647
+ TokeliaPay.Payment({
648
+
649
+ before: async (payment, from)=> {
650
+ alert('Something went wrong')
651
+ return false // stops payment
652
+ }
653
+ })
654
+ ```
655
+
656
+ #### sent
657
+
658
+ `sent`
659
+
660
+ A function that will be called once the payment has been sent to the network (but still needs to be mined/confirmed).
661
+
662
+ The widget will call this function with a transaction as single argument (see: [depay-web3-wallets](https://github.com/depayfi/depay-web3-wallets#transaction) for more details about the structure)
663
+
664
+ ```javascript
665
+ TokeliaPay.Payment({
666
+
667
+ sent: (transaction)=> {
668
+ // called when payment transaction has been sent to the network
669
+ }
670
+ })
671
+ ```
672
+
673
+ #### succeeded
674
+
675
+ `succeeded`
676
+
677
+ A function that will be called once the payment has succeeded on the network (checked client-side).
678
+
679
+ The widget will call this function passing a transaction as single argument (see: [depay-web3-wallets](https://github.com/depayfi/depay-web3-wallets#transaction) for more details)
680
+
681
+ ```javascript
682
+ TokeliaPay.Payment({
683
+
684
+ succeeded: (transaction, payment)=> {
685
+ // called when payment transaction has been confirmed once by the network
686
+ // might be called multiple times
687
+
688
+ // "payment" contains information about what the user selected as payment
689
+ }
690
+ })
691
+ ```
692
+
693
+ #### validated
694
+
695
+ `validated`
696
+
697
+ A function that will be called once the payment has been validated by DePay.
698
+
699
+ ```javascript
700
+ TokeliaPay.Payment({
701
+
702
+ validated: (successful, transaction, payment)=> {
703
+ // successful (true or false)
704
+
705
+ // "payment" contains information about what the user selected as payment
706
+ }
707
+ })
708
+ ```
709
+
710
+ #### failed
711
+
712
+ `failed`
713
+
714
+ A function that will be called if the payment execution failed on the blockchain (after it has been sent/submitted).
715
+
716
+ The widget will call this function passing a transaction as single argument (see: [depay-web3-wallets](https://github.com/depayfi/depay-web3-wallets#transaction) for more details)
717
+
718
+ ```javascript
719
+ TokeliaPay.Payment({
720
+
721
+ failed: (transaction, error, payment)=> {
722
+ // called when payment transaction failed on the blockchain
723
+ // handled by the widget, no need to display anything
724
+ // might be called multiple times
725
+
726
+ // "payment" contains information about what the user selected as payment
727
+ }
728
+ })
729
+ ```
730
+
731
+ #### critical
732
+
733
+ `critical`
734
+
735
+ A function that will be called if the widget throws a critical internal error that it can't handle and display on its own:
736
+
737
+ ```javascript
738
+ TokeliaPay.Payment({
739
+
740
+ critical: (error)=> {
741
+ // render and display the error with error.toString()
742
+ }
743
+ })
744
+ ```
745
+
746
+ #### error
747
+
748
+ `error`
749
+
750
+ A function that will be called if the widget throws a non-critical internal error that it can and will handle and display on its own:
751
+
752
+ ```javascript
753
+ TokeliaPay.Payment({
754
+
755
+ error: (error)=> {
756
+ // maybe do some internal tracking with error.toString()
757
+ // no need to display anything as widget takes care of displaying the error
758
+ }
759
+ })
760
+ ```
761
+
762
+ ## Connect Widget
763
+
764
+ DePay Connect allows you to have your users connect their crypto wallet to your dApp or website.
765
+
766
+ Returns connected `account` and `wallet` in return.
767
+
768
+ ```javascript
769
+ let { account, wallet } = await TokeliaPay.Connect()
770
+ ```
771
+
772
+ See [web3-wallets](https://github.com/depayfi/web3-wallets) for more details about the returned `wallet`.
773
+
774
+ ### Rejections
775
+
776
+ 1. Rejects if user just closes the dialog without connecting any wallet:
777
+
778
+ ```javascript
779
+
780
+ TokeliaPay.Connect().then(()=>{}).catch((error)=>{
781
+ error // "USER_CLOSED_DIALOG"
782
+ })
783
+
784
+ ```
785
+
786
+ ## Login Widget
787
+
788
+ DePay Login allows you to perform web3 wallet logins with ease.
789
+
790
+ Returns `account` if successfully signed and recovered log in message.
791
+
792
+ ```javascript
793
+ let message = "Sign to login"
794
+ let { account, wallet } = await TokeliaPay.Login({ message })
795
+ ```
796
+
797
+ Connects wallet and instructs connected wallet to sign `message`, afterwards sends `signature` and `message` to `POST /login` (or `endpoint` if defined):
798
+
799
+ ```
800
+ POST /login
801
+ BODY
802
+ {
803
+ "message": "Sign to login",
804
+ "signature": "0x123456" // raw signature
805
+ }
806
+ ```
807
+
808
+ The `/login` endpoint needs to recover the address for `message` and `signature`.
809
+
810
+ e.g. your backend could use node + ethers.js to recover the signature
811
+
812
+ ```javascript
813
+ const ethers = require('ethers')
814
+ const hashedMessage = ethers.utils.hashMessage(inputs.message)
815
+ const address = ethers.utils.recoverAddress(hashedMessage, inputs.signature)
816
+ return address
817
+ ```
818
+
819
+ make sure you return the recovered address back to the widget:
820
+
821
+ ```
822
+ POST /login
823
+ RESPONSE
824
+ "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
825
+ ```
826
+
827
+
828
+ Which will resolve the `TokeliaPay.Login` request to the resolved account:
829
+
830
+ ```javascript
831
+ account // 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
832
+ ```
833
+
834
+ You can also pass a `recover` function that takes care of signature recovery:
835
+
836
+ ```javascript
837
+ TokeliaPay.Login({ message, recover: ({ message, signature })=>{
838
+ return new Promise((resolve, reject)=>{
839
+ fetch('https://example.com/login', {
840
+ method: 'POST',
841
+ body: JSON.stringify({ message, signature })
842
+ })
843
+ .then((response)=>{
844
+ if(response.status == 200) {
845
+ response.text().then((account)=>{
846
+ resolve(account)
847
+ }).catch(reject)
848
+ } else {
849
+ response.text().then((text)=>{
850
+ reject(text || 'Recovering login signature failed!')
851
+ }).catch(reject)
852
+ }
853
+ })
854
+ })
855
+ }
856
+ })
857
+ ```
858
+
859
+ ### Sign message containing the account address
860
+
861
+ In case you want to include the wallet account identifier in the to be signed message, pass a callback function returning a string to `message`:
862
+
863
+ ```javascript
864
+ let { account } = await TokeliaPay.Login({
865
+ message: (account)=>`Click to log in to DePay and to accept DePay's Terms of Service: https://depay.com/legal/terms\n${dateTime}\n${account}`
866
+ })
867
+ console.log("Logged in via signature", account)
868
+ ```
869
+
870
+ ### Rejections
871
+
872
+ 1. Rejects if user just closes the dialog without connecting any wallet:
873
+
874
+ ```javascript
875
+
876
+ TokeliaPay.Login().then(()=>{}).catch((error)=>{
877
+ error // "USER_CLOSED_DIALOG"
878
+ })
879
+
880
+ ```
881
+
882
+ ## Select Widget
883
+
884
+ DePay Select widget allows you to open a dialog that allows you to select things like tokens, etc.
885
+
886
+ ### Select Token
887
+
888
+ Resolves with what has been selected by the user.
889
+
890
+ ```javascript
891
+ let token = await TokeliaPay.Select({ what: 'token' })
892
+
893
+ // {
894
+ // address: "0xa0bed124a09ac2bd941b10349d8d224fe3c955eb"
895
+ // blockchain: "ethereum"
896
+ // decimals: 18
897
+ // logo: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb/logo.png"
898
+ // name: "DePay"
899
+ // symbol: "DEPAY",
900
+ // routable: true // information if token is routable through DePay Payment router
901
+ // }
902
+ ```
903
+
904
+ ### Select NFT
905
+
906
+ Resolves with what has been selected by the user.
907
+
908
+ This only resolves to a single contract on a single blockchain.
909
+
910
+ As NFT collections could span over multiple blockchains, users would need to make one selection per contract address & blockchain.
911
+
912
+ ```javascript
913
+ let collection = await TokeliaPay.Select({ what: 'nft' })
914
+
915
+ // {
916
+ // address: "0xba30E5F9Bb24caa003E9f2f0497Ad287FDF95623",
917
+ // blockchain: "ethereum",
918
+ // createdAt: "2021-06-18T21:32:25.355263+00:00",
919
+ // image: "https://i.seadn.io/gae/l1wZXP2hHFUQ3turU5VQ9PpgVVasyQ79-ChvCgjoU5xKkBA50OGoJqKZeMOR-qLrzqwIfd1HpYmiv23JWm0EZ14owiPYaufqzmj1?w=500&auto=format",
920
+ // link: "https://opensea.io/collection/bored-ape-kennel-club",
921
+ // name: "BoredApeKennelClub",
922
+ // type: "721",
923
+ // }
924
+ ```
925
+
926
+ If the NFT contract is of type 1155 the return will also contain the NFTs id for the given contract address:
927
+
928
+ ```javascript
929
+ // {
930
+ // address: "0x495f947276749Ce646f68AC8c248420045cb7b5e",
931
+ // blockchain: "ethereum",
932
+ // id: "35347623114821255323888368639026081793120226253597860997754787918389704654849",
933
+ // image: "https://i.seadn.io/gae/IIFck1wOESXNMfCN6nEhFIXReUaSyI68MXNPjvFapbjQXc42ARIcG8k-nEKJjXs1GdCY75ej4qArfy7LDbgGOFSR6zzBIOG-yEw04Q?w=500&auto=format",
934
+ // link: "https://opensea.io/assets/ethereum/0x495f947276749ce646f68ac8c248420045cb7b5e/35347623114821255323888368639026081793120226253597860997754787918389704654849",
935
+ // name: "Genesis Block - 100,000 BC",
936
+ // type: "1155"
937
+ // }
938
+ ```
939
+
940
+ If NFT is a list of mints on solana:
941
+
942
+ If the NFT contract is of type 1155 the return will also contain the NFTs id for the given contract address:
943
+
944
+ ```javascript
945
+ // {
946
+ // addresses: ["4RYP3yX52g3BawgS4ShHwJqbrm8FcUF8PPA4oP1eP6Cv", "5GAse3WFPMCmbrw5x1RVdRaBttReBrgFLkw7yyqbSqtn"],
947
+ // blockchain: "solana",
948
+ // image: "https://img-cdn.magiceden.dev/rs:fill:400:400:0:0/plain/https%3A%2F%2Farweave.net%2FevHbhPvYxPn3NgtzeHg3WPS-QFwGdibQwTvY8chccrA%3Fext%3Dpng",
949
+ // link: "https://magiceden.io/marketplace/depay",
950
+ // name: "SOL - AD 2020",
951
+ // type: "metaplex"
952
+ // }
953
+ ```
954
+
955
+ ## Examples
956
+
957
+ ### React
958
+
959
+ #### Payment Widget
960
+
961
+ ```javascript
962
+
963
+ import React from 'react'
964
+ import TokeliaPay from '@tokelia/pay-widget'
965
+
966
+ export default (props)=>{
967
+
968
+ let unmount
969
+
970
+ const openPaymentWidget = async ()=>{
971
+ (
972
+ { unmount } = await TokeliaPay.Payment({...})
973
+ )
974
+ }
975
+
976
+ useEffect(() => {
977
+ return ()=>{
978
+ // make sure an open widgets gets closed/unmounted as part of this component
979
+ if(unmount) { unmount() }
980
+ }
981
+ }, [])
982
+
983
+ return(
984
+ <button onClick={ openPaymentWidget } type="button">
985
+ Pay
986
+ </button>
987
+ )
988
+ }
989
+
990
+ ```
991
+
992
+ ## Web3 Payments
993
+
994
+ The future is [Web3 Payments](https://depay.com/web3-payments).
995
+
996
+ Blockchains hold the potential to faster, simpler and smarter payments.
997
+
998
+ Web3 Payments are borderless, peer-to-peer, and support multiple tokens and blockchains.
999
+
1000
+ Accept any asset type that your customers already have in their wallet. [DePay](https://depay.com) is blockchain agnostic and can at any time be extended on any blockchain-specific plugin. Interoperability, scalability & flexibility are the cornerstones of our protocol. Accepting any asset that users already have in their wallets no matter which blockchain these are held on, reduces friction when performing decentralized payments.
1001
+
1002
+ ### Chain Agnostic (Multichain)
1003
+
1004
+ Interoperability is the key principle on which our infrastructure is built. [DePay](https://depay.com) is extensible around any blockchain, ensuring a competitive cross-chain future.
1005
+
1006
+ ### Permissionless
1007
+
1008
+ Interoperability is the key principle on which our infrastructure is built. [DePay](https://depay.com) is extensible around any blockchain, ensuring a competitive cross-chain future.
1009
+
1010
+ ### Trustless
1011
+
1012
+ Most Web3 Payment providers & processors receive payments to wallets that they manage themselves. Only in a further intermediate step are the payments paid out to sellers. [DePay](https://depay.com) does not act as an intermediary. Every intermediate step is replaced by smart contracts which are connected to decentralized liquidity pools. As a result, trust is no longer required.
1013
+
1014
+ ### Easy to use
1015
+
1016
+ Our ambition was to create an even easier user experience than you're used to from shopping in current non-crypto e-commerce stores. We think we've done a good job of that.
1017
+
1018
+ ### Open Source
1019
+
1020
+ Feel free to use & contribute to our codebase at. We're happy to have you look under our hood. The [DePay](https://depay.com) protocol will always remain open source.
1021
+
1022
+ ### Multichain
1023
+
1024
+ [DePay](https://depay.com) calculates payment routes on multiple blockchains simultaneously despite what your wallet is currently connected to. Our software automatically detects & switches the network if required.
1025
+
1026
+ ## Development
1027
+
1028
+ ### Quick start
1029
+
1030
+ ```
1031
+ yarn install
1032
+ yarn dev
1033
+ ```
1034
+
1035
+ ### Testing
1036
+
1037
+ #### Debug Cypress
1038
+
1039
+ Starts cypress in `--headed` and `--no-exit`
1040
+
1041
+ ```
1042
+ test:cypress:debug
1043
+ ```
1044
+
1045
+ Test and debug single cypress file:
1046
+
1047
+ ```
1048
+ yarn test:cypress:debug --spec "cypress/e2e/bundle.js"
1049
+ ```