@depay/widgets 8.0.2 → 8.0.4
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 +97 -42
- package/dist/esm/index.bundle.js +16 -41
- package/dist/esm/index.js +86 -63
- package/dist/umd/index.bundle.js +16 -41
- package/dist/umd/index.js +86 -63
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -328,29 +328,43 @@ Alternatively you can pass a method to track that performs the tracking request
|
|
|
328
328
|
DePayWidgets.Payment({
|
|
329
329
|
|
|
330
330
|
track: {
|
|
331
|
-
method: (payment)=>{
|
|
332
|
-
|
|
331
|
+
method: async (payment)=>{
|
|
332
|
+
let response = await fetch('/track/payments', {
|
|
333
333
|
method: 'POST',
|
|
334
334
|
body: JSON.stringify(payment),
|
|
335
335
|
headers: { "Content-Type": "application/json", "X-CSRF-TOKEN": document.querySelector('[name=csrf-token]').content }
|
|
336
336
|
})
|
|
337
|
+
if(response.status != 200) {
|
|
338
|
+
throw 'TRACKING FAILED'
|
|
339
|
+
}
|
|
337
340
|
}
|
|
338
341
|
}
|
|
339
342
|
})
|
|
340
343
|
```
|
|
341
344
|
|
|
342
|
-
|
|
345
|
+
```javascript
|
|
346
|
+
DePayWidgets.Payment({
|
|
347
|
+
|
|
348
|
+
track: {
|
|
349
|
+
method: (payment)=>axios('/track/payments', payment)
|
|
350
|
+
}
|
|
351
|
+
})
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
In case you pass a tracking method it needs to return a promise.
|
|
343
355
|
|
|
344
|
-
|
|
356
|
+
If that promise resolves, the widget assumes the tracking initialization was successful. If the promise rejects it will retry the tracking initialization over and over again.
|
|
357
|
+
|
|
358
|
+
Make sure to evaluate within your tracking method if the response succeeded or not and throw an error accordingly.
|
|
359
|
+
|
|
360
|
+
Your endpoint also needs to make sure to forward this to the [payment tracking api](https://depay.com/documentation/api#payments).
|
|
345
361
|
|
|
346
362
|
Also make sure to add `token`, `amount` and `confirmations` when forwarding the request to the payments api.
|
|
347
363
|
Those values are supposed to be set by your backend not the widget nor the fronted because any user could set these values to their liking otherwise, having you confirm payment amounts and tokens that you didn't intend to receive!
|
|
348
364
|
|
|
349
365
|
Make sure you read the [Payment Tracking API](https://depay.com/documentation/api#payments) for further details on how to integrate payment tracking.
|
|
350
366
|
|
|
351
|
-
Payment tracking requests will be attempted
|
|
352
|
-
|
|
353
|
-
A failed payment tracking will also call the [error callback](#error) with `{code: "TRACKING_FAILED"}`.
|
|
367
|
+
Payment tracking requests will be attempted indefinitely. After 2 minutes a warning dialog will be presented to users asking them to ensure an internet connection so that the payment tracking can be performed.
|
|
354
368
|
|
|
355
369
|
##### Asynchronous Validation
|
|
356
370
|
|
|
@@ -385,11 +399,48 @@ It will use the endpoint or the method to request a release every 5 seconds.
|
|
|
385
399
|
You need to make sure to respond to this request with a status `404` in case the user is not to be released just yet (payment and processing on your side are not complete yet)
|
|
386
400
|
or `200` if the payment has been completed and the processing on your side is done and the user can be released and forwarded withing your payment flow.
|
|
387
401
|
|
|
388
|
-
In case you want to redirect the user to the next step in your system the poll endpoint needs to respond with a body containing json like: `{ forward_to: 'https://example.com/next_step_url' }`.
|
|
402
|
+
In case you want to redirect the user to the next step in your system, the poll endpoint needs to respond with a body containing json like: `{ forward_to: 'https://example.com/next_step_url' }`.
|
|
389
403
|
|
|
390
404
|
It is not enough to rely on setting `forward_to` initially with the tracking request, you will also need to respond with `forward_to` when implementing polling
|
|
391
405
|
as the entire reason for polling is to cover cases where websockets fail and the initial `forward_to` can not be communicated to the client.
|
|
392
406
|
|
|
407
|
+
If you use a method for additional polling, make sure you return a promise. Polling will continue as long as you resolve this promise with anything that resolves to true:
|
|
408
|
+
|
|
409
|
+
```javascript
|
|
410
|
+
DePayWidgets.Payment({
|
|
411
|
+
|
|
412
|
+
track: {
|
|
413
|
+
poll: {
|
|
414
|
+
method: async (payment)=>{
|
|
415
|
+
let response = await fetch('/payments/123/release', {
|
|
416
|
+
method: 'POST',
|
|
417
|
+
body: JSON.stringify(payment),
|
|
418
|
+
headers: { "Content-Type": "application/json", "X-CSRF-TOKEN": document.querySelector('[name=csrf-token]').content }
|
|
419
|
+
})
|
|
420
|
+
if(response.status == 200) {
|
|
421
|
+
let json = await response.json()
|
|
422
|
+
return json // { "forward_to": "https://mywebsite.com/payments/123/confirmation" }
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
})
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
```javascript
|
|
431
|
+
DePayWidgets.Payment({
|
|
432
|
+
|
|
433
|
+
track: {
|
|
434
|
+
poll: {
|
|
435
|
+
method: async (payment)=>{
|
|
436
|
+
let response = await axios('/payments/123/release', payment)
|
|
437
|
+
return response // { "forward_to": "https://mywebsite.com/payments/123/confirmation" }
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
})
|
|
442
|
+
```
|
|
443
|
+
|
|
393
444
|
#### connected
|
|
394
445
|
|
|
395
446
|
`connected`
|
|
@@ -1743,7 +1794,18 @@ BODY
|
|
|
1743
1794
|
}
|
|
1744
1795
|
```
|
|
1745
1796
|
|
|
1746
|
-
The `/login` endpoint needs to recover the address for `message` and `signature
|
|
1797
|
+
The `/login` endpoint needs to recover the address for `message` and `signature`.
|
|
1798
|
+
|
|
1799
|
+
e.g. your backend could use node + ethers.js to recover the signature
|
|
1800
|
+
|
|
1801
|
+
```javascript
|
|
1802
|
+
const ethers = require('ethers')
|
|
1803
|
+
const hashedMessage = ethers.utils.hashMessage(inputs.message)
|
|
1804
|
+
const address = ethers.utils.recoverAddress(hashedMessage, inputs.signature)
|
|
1805
|
+
return address
|
|
1806
|
+
```
|
|
1807
|
+
|
|
1808
|
+
make sure you return the recovered address back to the widget:
|
|
1747
1809
|
|
|
1748
1810
|
```
|
|
1749
1811
|
POST /login
|
|
@@ -1751,6 +1813,7 @@ RESPONSE
|
|
|
1751
1813
|
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
|
|
1752
1814
|
```
|
|
1753
1815
|
|
|
1816
|
+
|
|
1754
1817
|
Which will resolve the `DePayWidgets.Login` request to the resolved account:
|
|
1755
1818
|
|
|
1756
1819
|
```javascript
|
|
@@ -1851,39 +1914,6 @@ export default (props)=>{
|
|
|
1851
1914
|
|
|
1852
1915
|
```
|
|
1853
1916
|
|
|
1854
|
-
|
|
1855
|
-
## Development
|
|
1856
|
-
|
|
1857
|
-
### Quick start
|
|
1858
|
-
|
|
1859
|
-
```
|
|
1860
|
-
yarn install
|
|
1861
|
-
yarn dev
|
|
1862
|
-
```
|
|
1863
|
-
|
|
1864
|
-
### Testing
|
|
1865
|
-
|
|
1866
|
-
#### Debug Cypress
|
|
1867
|
-
|
|
1868
|
-
Starts cypress in `--headed` and `--no-exit`
|
|
1869
|
-
|
|
1870
|
-
```
|
|
1871
|
-
test:cypress:debug
|
|
1872
|
-
```
|
|
1873
|
-
|
|
1874
|
-
Test and debug single cypress file:
|
|
1875
|
-
|
|
1876
|
-
```
|
|
1877
|
-
yarn test:cypress:debug --spec "cypress/e2e/Payment/amount.js"
|
|
1878
|
-
```
|
|
1879
|
-
|
|
1880
|
-
### Release new versions to npm
|
|
1881
|
-
|
|
1882
|
-
```
|
|
1883
|
-
npm login
|
|
1884
|
-
npm publish
|
|
1885
|
-
```
|
|
1886
|
-
|
|
1887
1917
|
## Web3 Payments
|
|
1888
1918
|
|
|
1889
1919
|
The future is [Web3 Payments](https://depay.com/web3-payments).
|
|
@@ -1917,3 +1947,28 @@ Feel free to use & contribute to our codebase at. We're happy to have you look u
|
|
|
1917
1947
|
### Multichain
|
|
1918
1948
|
|
|
1919
1949
|
[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.
|
|
1950
|
+
|
|
1951
|
+
## Development
|
|
1952
|
+
|
|
1953
|
+
### Quick start
|
|
1954
|
+
|
|
1955
|
+
```
|
|
1956
|
+
yarn install
|
|
1957
|
+
yarn dev
|
|
1958
|
+
```
|
|
1959
|
+
|
|
1960
|
+
### Testing
|
|
1961
|
+
|
|
1962
|
+
#### Debug Cypress
|
|
1963
|
+
|
|
1964
|
+
Starts cypress in `--headed` and `--no-exit`
|
|
1965
|
+
|
|
1966
|
+
```
|
|
1967
|
+
test:cypress:debug
|
|
1968
|
+
```
|
|
1969
|
+
|
|
1970
|
+
Test and debug single cypress file:
|
|
1971
|
+
|
|
1972
|
+
```
|
|
1973
|
+
yarn test:cypress:debug --spec "cypress/e2e/Payment/amount.js"
|
|
1974
|
+
```
|