|
1 | 1 | # Updating a Request |
2 | 2 |
|
3 | | -After a request is created, it can be updated: |
| 3 | +After a request is created, it can be updated by the authorized parties. Each update requires a signature and is persisted to the Request Network. |
4 | 4 |
|
5 | | -<table data-full-width="true"><thead><tr><th>Name</th><th>Description</th><th>Role Authorized</th></tr></thead><tbody><tr><td><strong>accept</strong></td><td>accept a request, indicating that it will be paid</td><td>payer</td></tr><tr><td><strong>cancel</strong></td><td>cancel a request</td><td>payee, payer</td></tr><tr><td><strong>reduceExpectedAmount</strong></td><td>reduce the expected amount</td><td>payee</td></tr><tr><td><strong>increaseExpectedAmount</strong></td><td>increase the expected amount</td><td>payer</td></tr><tr><td><strong>addStakeholders</strong></td><td>grant 1 or more third parties access to view an encrypted request</td><td>payee, payer, third party</td></tr></tbody></table> |
| 5 | +## Summary of Actions |
6 | 6 |
|
7 | | -Feature exists. More docs coming soon... |
| 7 | +| Action | Description | Authorized Role | |
| 8 | +| :--- | :--- | :--- | |
| 9 | +| **accept** | Accept a request, indicating that it will be paid | Payer | |
| 10 | +| **cancel** | Cancel a request | Payee or Payer | |
| 11 | +| **reduceExpectedAmount** | Reduce the expected amount | Payee | |
| 12 | +| **increaseExpectedAmount** | Increase the expected amount | Payer | |
| 13 | +| **addStakeholders** | Grant 1 or more third parties access to view an encrypted request | Payee, Payer, or Third Party | |
| 14 | + |
| 15 | +## Examples |
| 16 | + |
| 17 | +### Initialize the Request Client |
| 18 | + |
| 19 | +First, retrieve the request you want to update. You must provide a `signatureProvider` to sign the update transactions. |
| 20 | + |
| 21 | +```javascript |
| 22 | +const { RequestNetwork, Types } = require("@requestnetwork/request-client.js"); |
| 23 | + |
| 24 | +const requestClient = new RequestNetwork({ |
| 25 | + nodeConnectionConfig: { baseURL: "https://sepolia.gateway.request.network/" }, |
| 26 | + signatureProvider: epkSignatureProvider, // Required for updates |
| 27 | +}); |
| 28 | + |
| 29 | +const request = await requestClient.fromRequestId('YOUR_REQUEST_ID'); |
| 30 | +``` |
| 31 | + |
| 32 | +### Accept a Request (Payer) |
| 33 | + |
| 34 | +The payer can accept a request to signal their intention to pay. |
| 35 | + |
| 36 | +```javascript |
| 37 | +const updatedRequestData = await request.accept({ |
| 38 | + type: Types.Identity.TYPE.ETHEREUM_ADDRESS, |
| 39 | + value: payerIdentity, |
| 40 | +}); |
| 41 | + |
| 42 | +// Wait for the update to be persisted |
| 43 | +await request.waitForConfirmation(); |
| 44 | +``` |
| 45 | + |
| 46 | +### Cancel a Request (Payee or Payer) |
| 47 | + |
| 48 | +Either the payee or the payer can cancel a request. |
| 49 | + |
| 50 | +```javascript |
| 51 | +const updatedRequestData = await request.cancel({ |
| 52 | + type: Types.Identity.TYPE.ETHEREUM_ADDRESS, |
| 53 | + value: signerIdentity, |
| 54 | +}); |
| 55 | + |
| 56 | +await request.waitForConfirmation(); |
| 57 | +``` |
| 58 | + |
| 59 | +### Increase Expected Amount (Payer) |
| 60 | + |
| 61 | +The payer can increase the expected amount (e.g., adding a tip or adjusting for additional services). |
| 62 | + |
| 63 | +```javascript |
| 64 | +const updatedRequestData = await request.increaseExpectedAmountRequest( |
| 65 | + '100000000000000000', // Amount to add in base units (e.g., 0.1 ETH) |
| 66 | + { |
| 67 | + type: Types.Identity.TYPE.ETHEREUM_ADDRESS, |
| 68 | + value: payerIdentity, |
| 69 | + } |
| 70 | +); |
| 71 | + |
| 72 | +await request.waitForConfirmation(); |
| 73 | +``` |
| 74 | + |
| 75 | +### Reduce Expected Amount (Payee) |
| 76 | + |
| 77 | +The payee can reduce the expected amount (e.g., applying a discount). |
| 78 | + |
| 79 | +```javascript |
| 80 | +const updatedRequestData = await request.reduceExpectedAmountRequest( |
| 81 | + '100000000000000000', // Amount to subtract in base units |
| 82 | + { |
| 83 | + type: Types.Identity.TYPE.ETHEREUM_ADDRESS, |
| 84 | + value: payeeIdentity, |
| 85 | + } |
| 86 | +); |
| 87 | + |
| 88 | +await request.waitForConfirmation(); |
| 89 | +``` |
0 commit comments