|
1 | 1 | # Payment Relay
|
| 2 | + |
| 3 | +The _Payment Relay_ base URL is found in the `relay` field of _Connect Payment_. |
| 4 | + |
| 5 | +The following Web API must be implemented by a _Payment Relay_: |
| 6 | + |
| 7 | +| URL | Method | Post Data | Response | Function | |
| 8 | +|--------------------|--------|-------------------------|-----------------------|--------------------------------| |
| 9 | +| _relay_/**pay** | POST | _Payment Response_ | _Payment Reply_ | Submit payment tx | |
| 10 | +| _relay_/**status** | POST | _Status Query_ | _Status Reply_ | Query payment status | |
| 11 | + |
| 12 | +Requests and responses are JSON payloads; JSON _must_ be UTF-8 encoded. |
| 13 | + |
| 14 | +All responses must include a `Cache-Control: no-store` header, to avoid |
| 15 | +leaking payment information into caches. Both endpoints additionally use |
| 16 | +the _POST_ method to avoid caching edge-cases (e.g. error responses.) |
| 17 | + |
| 18 | + |
| 19 | +### Payment Response |
| 20 | + |
| 21 | +This is the wallet's _response_ to the original _Payment Request_. |
| 22 | + |
| 23 | +```json |
| 24 | +{ |
| 25 | + "id": "PID-123", // Relay-unique Payment ID from Connect Payment |
| 26 | + "tx": "489c47f8a3ba3293737a.." // hex-encoded signed dogecoin transaction |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | + |
| 31 | +### Payment Reply |
| 32 | + |
| 33 | +This is the _Payment Relay's_ reply from the `pay` URL. |
| 34 | + |
| 35 | +```json |
| 36 | +{ |
| 37 | + "id": "PID-123", // Relay-unique Payment ID from Connect Payment |
| 38 | + "status": "accepted", // One of: accepted | declined |
| 39 | + "reason": "", // Reason for decline (message, optional) |
| 40 | + "required": 5, // number of block confirmations required (risk analysis) |
| 41 | + "confirmed": 0, // current number of block confirmations on-chain |
| 42 | + "due_sec": 300, // Estimated time in seconds until confirmed |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +If the transaction is malformed, or does not pay the requested amounts to |
| 47 | +the requested addresses, the POST will be rejected with a **400 Bad Request** |
| 48 | +http response. This represents a _programming error_ in the wallet. |
| 49 | + |
| 50 | +Payments may also be rejected with a `declined` status, in the case that |
| 51 | +the _Vendor_ or their nominated _Relay_ believes the transaction is too |
| 52 | +risky. This represents a _customer-specific_ problem. |
| 53 | + |
| 54 | +The final three fields, `required`, `confirmed` and `due_sec` are in common |
| 55 | +with the _Status Reply_ below. |
| 56 | + |
| 57 | + |
| 58 | +### Status Query |
| 59 | + |
| 60 | +This allows the wallet to query the current status of a payment. |
| 61 | + |
| 62 | +```json |
| 63 | +{ |
| 64 | + "id": "PID-123" // Relay-unique Payment ID from Connect Payment |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | + |
| 69 | +### Status Reply |
| 70 | + |
| 71 | +This is the _Payment Relay's_ reply from the `status` URL. |
| 72 | + |
| 73 | +```json |
| 74 | +{ |
| 75 | + "id": "PID-123", // Relay-unique Payment ID from Connect Payment |
| 76 | + "status": "accepted", // unpaid | accepted | confirmed |
| 77 | + "required": 5, // number of block confirmations required |
| 78 | + "confirmed": 4, // current number of block confirmations on-chain |
| 79 | + "due_sec": 30, // Estimated time in seconds until confirmed |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +Payments transition from `unpaid` to `accepted` after the signed transaction |
| 84 | +is submitted to the `pay` endpoint (provided payment was accepted.) |
| 85 | + |
| 86 | +After the required number of block confirmations have been seen on-chain, |
| 87 | +the payment status transitions to `confirmed`. |
| 88 | + |
| 89 | +When the payment status is `confirmed`, the `confirmed` field is always greater |
| 90 | +or equal to `required`, and the `due_sec` field is alway zero. |
| 91 | + |
| 92 | +Note: there are some edge-cases where the `confirmed` count can reduce, |
| 93 | +i.e. during a short-term blockchain fork. |
0 commit comments