@depay/widgets 8.0.2 → 8.0.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 CHANGED
@@ -328,20 +328,36 @@ 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
- return fetch('/track/payments', {
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
- In case you pass a tracking method it needs to return a promise.
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.
355
+
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.
343
359
 
344
- Your endpoint needs to make sure to forward this to the [payment tracking api](https://depay.com/documentation/api#payments).
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!
@@ -385,11 +401,48 @@ It will use the endpoint or the method to request a release every 5 seconds.
385
401
  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
402
  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
403
 
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' }`.
404
+ 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
405
 
390
406
  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
407
  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
408
 
409
+ 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:
410
+
411
+ ```javascript
412
+ DePayWidgets.Payment({
413
+
414
+ track: {
415
+ poll: {
416
+ method: async (payment)=>{
417
+ let response = await fetch('/payments/123/release', {
418
+ method: 'POST',
419
+ body: JSON.stringify(payment),
420
+ headers: { "Content-Type": "application/json", "X-CSRF-TOKEN": document.querySelector('[name=csrf-token]').content }
421
+ })
422
+ if(response.status == 200) {
423
+ let json = await response.json()
424
+ return json // { "forward_to": "https://mywebsite.com/payments/123/confirmation" }
425
+ }
426
+ }
427
+ }
428
+ }
429
+ })
430
+ ```
431
+
432
+ ```javascript
433
+ DePayWidgets.Payment({
434
+
435
+ track: {
436
+ poll: {
437
+ method: async (payment)=>{
438
+ let response = await axios('/payments/123/release', payment)
439
+ return response // { "forward_to": "https://mywebsite.com/payments/123/confirmation" }
440
+ }
441
+ }
442
+ }
443
+ })
444
+ ```
445
+
393
446
  #### connected
394
447
 
395
448
  `connected`
@@ -1851,39 +1904,6 @@ export default (props)=>{
1851
1904
 
1852
1905
  ```
1853
1906
 
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
1907
  ## Web3 Payments
1888
1908
 
1889
1909
  The future is [Web3 Payments](https://depay.com/web3-payments).
@@ -1917,3 +1937,28 @@ Feel free to use & contribute to our codebase at. We're happy to have you look u
1917
1937
  ### Multichain
1918
1938
 
1919
1939
  [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.
1940
+
1941
+ ## Development
1942
+
1943
+ ### Quick start
1944
+
1945
+ ```
1946
+ yarn install
1947
+ yarn dev
1948
+ ```
1949
+
1950
+ ### Testing
1951
+
1952
+ #### Debug Cypress
1953
+
1954
+ Starts cypress in `--headed` and `--no-exit`
1955
+
1956
+ ```
1957
+ test:cypress:debug
1958
+ ```
1959
+
1960
+ Test and debug single cypress file:
1961
+
1962
+ ```
1963
+ yarn test:cypress:debug --spec "cypress/e2e/Payment/amount.js"
1964
+ ```