Quickstart
Install
Clearwake runs on the Python standard library. You need Python 3.12 or newer and git. Docker is needed only for the network cut run. Clone with submodules, because the receipt and policy code is in vendor/verdock-core.
git clone --recurse-submodules https://github.com/Sriharsan/clearwake-paypal.git
cd clearwake-paypal
python -m clearwake --port 8810Open http://127.0.0.1:8810/console for the three screens (buyer agent, control room with the dispute ledger, receipt verifier). With no keys set, everything is a local run on the local provider: no PayPal call and no network call. Speak to it from a phone with python -m clearwake --phone.
Run scripts for Windows and for macOS or Linux are in the repository root.
Quickstart
Guard PayPal's Agent Toolkit
Clearwake adds what the toolkit leaves to you: limits, one request id per money move, a read of PayPal's record before any retry, and a signed receipt.
pip install git+https://github.com/Sriharsan/clearwake-paypal
from clearwake import guard
tools = guard(paypal_toolkit_tools, policy="policy.yaml")paypal_toolkit_tools is the tool list your agent framework got from PayPal's toolkit. guard() returns a list of the same length and order. Read and write tools come back as the same objects. The 8 tools that move money come back wrapped, with the same name, description and schema. The wheel carries what it runs on, so the install needs no git submodules and no vendor folder. It needs Python 3.10 or newer and nothing else.
python -m clearwake.guard_api policy > policy.yamlThe policy is the file shown under Policy file below. Limits in it are in cents. A prompt, a buyer message or a model reply cannot change it.
by_name = {tool.name: tool for tool in tools}
dispute = by_name["get_dispute"].invoke({"dispute_id": "D-1"})
reply = by_name["accept_dispute_claim"].invoke({"dispute_id": "D-1", "note": "Accepted"})
print(reply)
print(tools.verify())What each kind of tool gets
| Tools | Count | What guard does |
|---|---|---|
Read and write tools, such as get_dispute, list_transactions, create_invoice | 39 | Nothing. The same objects, unchanged, no receipt. |
accept_dispute_claim and create_refund | 2 | Reads PayPal's record first and takes the amount from it. Above the policy limit: held for a person, nothing sent. Above the approval line: a person approves that exact move. One request id from the hash of the move. After a lost reply the next call reads PayPal's record and never repeats a move that applied. A signed receipt for every call. |
pay_order, send_invoice, send_invoice_reminder, record_payment_for_invoice, record_refund_for_invoice, activate_recurring_series | 6 | Held for a person unless the policy names the tool as an operation. A request id and a signed receipt either way. The guard cannot read their amount from one record, so a policy line with max_amount_minor for them holds the call. |
A call that is stopped returns JSON text: {"clearwake_guard": {"state": ..., "detail": ..., "sent": false, "request_id": ...}}. A call that went through returns PayPal's own reply unchanged. A call that lost its reply raises the original error to the agent. Approve a held move with tools.approve(approval_id, by="your name"); tools.pending() lists the open requests. tools.verify() checks the receipt log offline against its own public key.
Or point your agent at Clearwake's MCP server
Install it as above (pip install git+https://github.com/Sriharsan/clearwake-paypal). Claude, ChatGPT, Cursor or any MCP client can then use Clearwake in place of PayPal's MCP server. It lists the same 28 PayPal tools with the same names and schemas. The money tools are guarded, the read tools pass through. The default backend is the local provider: no account, no network, nothing real to move.
claude mcp add paypal-guarded -- python -m clearwake.mcp_server{
"mcpServers": {
"paypal-guarded": {
"command": "python",
"args": ["-m", "clearwake.mcp_server"]
}
}
}To put it in front of PayPal's own MCP server on the sandbox, add "--backend", "paypal" to the args and set CLEARWAKE_SANDBOX_ACK=I_CONFIRM_SANDBOX_ONLY, PAYPAL_ENVIRONMENT=SANDBOX and a sandbox PAYPAL_ACCESS_TOKEN in the client's environment. Clearwake refuses to start without them. Details and the install check are in docs/MCP_SERVER.md.
Tested against the real list of 47 tools recorded in docs/paypal_mcp_tools.json, with no network (tests/test_guard_api.py). The wrapped tools were not run against the live PayPal sandbox, and the toolkit as recorded sends no PayPal-Request-Id, so protection against a repeat comes from the ledger and from reading PayPal's record before any retry. The rest of the guard is described in docs/TOOLKIT_GUARD.md, and the Break it page replays the recorded attacks.
Quickstart
Add sandbox keys
Create a sandbox app in the PayPal developer dashboard and put its client id and secret in a .env file at the repository root. Git ignores that file. Clearwake reads only these names from it, and a value already set in your environment wins.
CLEARWAKE_SANDBOX_ACK=I_CONFIRM_SANDBOX_ONLY
PAYPAL_CLIENT_ID=
PAYPAL_CLIENT_SECRET=
PAYPAL_BASE_URL=https://api-m.sandbox.paypal.com
PAYPAL_SANDBOX_CAPTURE_ID=
CLEARWAKE_REFUND_AMOUNT=1.00PAYPAL_BASE_URLmust be exactly the sandbox host. Clearwake refuses to start against anything else, so production cannot be reached by a typo.CLEARWAKE_SANDBOX_ACKmust be the exact text shown. Without it the sandbox gateway will not load.PAYPAL_SANDBOX_CAPTURE_IDis the id of a COMPLETED sandbox capture that the refund cases use. A PENDING capture is refused.- Optional, for the dispatch proof setup only:
HF_TOKEN. Optional for a local model:CLEARWAKE_LOCAL_AI_ACK,CLEARWAKE_LOCAL_MODEL_DIGEST,CLEARWAKE_LOCAL_LEDGER.
Never paste a key into a chat, a screenshot or an issue. The sandbox setup scripts (scripts/sandbox_setup.py, .ps1, .sh) write only the capture id back to .env.
Quickstart
Sandbox checklist
Tick these off before a real sandbox run. Your ticks stay in this browser only.
Quickstart
Run the cases
Every run has a letter, a to o, and the command takes the letter. The table names each run with its PayPal id and date. Run them on local records first. Then run one against the real sandbox.
| Letter | Run | PayPal id | Recorded |
|---|---|---|---|
a | Buy inside the mandate | order approved by the sandbox buyer | local run, sandbox with --order |
b | Refuse a purchase outside the mandate | none, no payment is made | local run |
c | Refund under the limit | 6SN41486G5579815G | 31 Oct 2026 |
d | Refund above the approval line, approved | 2NB27940EC188891M | 31 Oct 2026 |
e | Lost reply, reconciled | not written to the run file | 31 Oct 2026 |
i | Item not received, tracking sent | PP-R-SLI-10195419 | 31 Oct 2026 |
j | Agent order disputed as unauthorised | none, local dispute | local run |
k | Near deadline, escalated with the countdown | none, local dispute | local run |
l | Batch of ten disputes in parallel | none, local disputes | local run |
m | Network cut mid batch | 6PX35920F4587564U and two more | 31 Oct 2026 |
n | Dispute settled by offer | PP-R-OBG-10196144 | 3 Nov 2026 |
o | Dispatch proof sent as evidence | PP-R-UKF-10195772 | 3 Nov 2026 |
python scripts/cases.pyNow the real sandbox. The settled by offer run (letter n) settles one dispute in conversation, and the dispute must be open at the INQUIRY stage. The sandbox buyer opens it in PayPal's Resolution Center, because the app's token cannot open a dispute for the buyer.
python scripts/cases.py --sandbox --only n --dispute PP-R-OBG-10196144Replace the dispute id with your own. Every result line says how it ran: real sandbox, injected fault in sandbox, local run or offline. Results are saved to data/runs/.
| Flag | What it does |
|---|---|
--sandbox | Use the real PayPal sandbox where PayPal allows it. Needs the keys in .env. |
--only n | Run only these cases. A comma list works: --only n,o. |
--dispute ID | Run the dispute cases on this sandbox dispute. |
--order ORDER_ID | Buy inside the mandate (letter a) in the sandbox: verify an order the sandbox buyer approved. |
--model ollama | Use a local open weights model for the agents. The default is scripted rules. |
Guide
Settle in conversation
While a dispute is at the INQUIRY stage, seller and buyer can still talk. A case settled here is not escalated to a claim, so PayPal charges no Standard Dispute Fee. Clearwake reads the dispute, lets the policy pick the amount, and sends one offer.
- The model may only choose a name:
settle_by_offer,refund_within_limit,fight_with_evidenceorescalate. The amount comes from the case and the policy, never from the model or the buyer's text. - The policy decides. In
policy/merchant.yaml,make_offerhas a limit of 500 minor units (USD 5.00) and needs approval above 300 (USD 3.00). - Clearwake calls
POST /v1/customer/disputes/{id}/make-offerwith a stablePayPal-Request-Id. PayPal refunds only if the buyer accepts. In the sandbox the buyer accepts in the Resolution Center. - Clearwake reads the dispute back. Only PayPal's record can mark it settled: UNDER_REVIEW is PENDING, RESOLVED is VERIFIED.
Send the offer alone. PayPal refuses an offer after a seller message. This was seen on the real sandbox as 422 ACTION_NOT_ALLOWED_IN_CURRENT_DISPUTE_STATE. Clearwake now sends the offer without a message first, and a refusal is written to the receipts as it happened.
clearwake.dispute.decision settle_by_offer, offer 250 (USD 2.50), stage INQUIRY
clearwake.dispute.offer_sent success true
clearwake.dispute.settlement success false UNDER_REVIEW stage INQUIRY state PENDING
clearwake.dispute.settlement success true RESOLVED stage INQUIRY RESOLVED_BUYER_FAVOUR state VERIFIEDResult: PASS. USD 2.50 refunded to the buyer (refund 0TB11858A85953644), never a claim. These lines are from site/receipts/case-n-settle.ndjson.
Guide
Evidence before the deadline
Clearwake reads the dispute's seller_response_due_date and the links PayPal offers, and acts only on what PayPal offers. If the case is near the deadline, it escalates to the approval inbox with the time left instead of guessing.
- Evidence comes from the record only: the PayPal order, the tracking, the mandate receipt, the dispatch receipt. The buyer's message is read as a claim to check.
- Evidence goes to
POST /v1/customer/disputes/{id}/provide-evidenceas multipart. Partinputis JSON{"evidences": [...]}. Each photo is anevidence-filepart. - Send one merged evidence entry. PayPal needs an
item_idwhen there are several entries, and a disputed item can carry none. Two entries (tracking and dispatch proof) were refused withITEM_ID_IS_MANDATORY_FOR_MULTIPLE_EVIDENCES. - If the case has already moved to UNDER_REVIEW and PayPal no longer offers
provide_evidence(item not received, dispute PP-R-SLI-10195419, stage CHARGEBACK, 31 Oct 2026), Clearwake sends the tracking note throughprovide-supporting-infoinstead. - Then it reads the dispute back. Evidence counts as sent only when PayPal's record shows it:
clearwake.dispute.evidence_checkedwithdispatch_evidence_seentrue.
submission 1 provide-evidence 400 INVALID_REQUEST ITEM_ID_IS_MANDATORY_FOR_MULTIPLE_EVIDENCES, nothing applied
submission 2 provide-evidence response lost, held as UNKNOWN, reading the dispute showed nothing had landed
submission 3 provide-evidence same PayPal-Request-Id, merged entry, HTTP 200 in 4.2 s
read PROOF_OF_FULFILLMENT, SUBMITTED_BY_SELLER, 3 Nov 2026 10:13 UTC, status WAITING_FOR_BUYER_RESPONSE, stage INQUIRYGuide
Dispatch proof
When a buyer says only 2 of 3 items arrived, the best answer is a signed record of what went in the parcel. At packing, you photograph the open parcel. SAM 3 runs on your own machine and counts the items. Clearwake signs one receipt into your receipt chain.
One time setup of SAM 3
- On Hugging Face, request access to
facebook/sam3(needed) andfacebook/sam3.1(optional). Both are gated. - Add
HF_TOKEN=and your read token to.env. It is read only by the setup script and never printed. - Run the setup. It installs CPU PyTorch and Meta's code into
tools/sam/.venvand downloads 3.5 GB of weights next to the repository.
.\tools\sam\setup.ps1After the download, counting sets HF_HUB_OFFLINE=1 and works with the network unplugged. SAM 3 counts still photos. SAM 3.1 is Meta's video tracker and Clearwake does not claim it for photos.
Pack an order
python scripts/dispatch.py pack --order ORDER_ID --capture CAPTURE_ID \
--item notebook-a5=3:book --photo packing.jpg --sealed \
--counter sam --save-count
python scripts/dispatch.py show --order ORDER_ID--item is SKU=QUANTITY:PROMPT. The prompt is the word SAM looks for, and it matters: on the test photo, "book" found 3 notebooks and "notebook" found none. Every prompt run is listed in docs/RESULTS.md. Use --photo-note to say what a photo is when it is not your parcel. It is signed into the receipt.
The receipt clearwake.dispatch.recorded holds the order and capture ids, ordered and counted per item, the prompts, the SHA-256 of each photo, whether the parcel was sealed, the counter, the model, the device, the milliseconds, and the policy hash.
Strong or weak
When the dispute arrives, the Evidence agent checks the receipt. It is strong only if all of these hold: the receipt log verifies, counted equals ordered for every item, the parcel is sealed, a photo hash is on record, the tracking shows SHIPPED or DELIVERED, the order lines match, and the number the buyer wrote matches the order.
A weak proof is never sent. The policy settles by offer or escalates instead.
order 7RV99265V1496281G capture 4AN16499K3427771T
counted 3 of 3 notebook-a5, scores 0.70, 0.62, 0.59
timing 15.1 s to load, 55.7 s to count, no GPU
receipt 8b92abb9e53a6244
photo CC0 packing photo of the recorded runGuide
Mandate receipts
When an agent places an order for its owner, the buyer agent writes a signed mandate receipt into its own chain, with its own key. If the order is later disputed as unauthorised, the merchant's Evidence agent attaches that receipt, and anyone can verify it offline.
The buyer agent has a mandate: an owner, a budget, a per item cap, the merchants it may buy from and the categories it may buy. It refuses anything outside it. The receipt action is clearwake.buyer.mandate and its params are:
| Param | Meaning |
|---|---|
order_id | The PayPal order the agent paid for |
merchant | The merchant id from the catalog |
item | The product id |
price_minor, currency | What it cost, in integer minor units |
budget_minor, per_item_cap_minor | The owner's limits that applied |
allowed_categories | The categories the mandate allowed |
python scripts/cases.py --only a,b,jBuy inside the mandate (a) signs the receipt. Refuse outside the mandate (b) makes no payment. The unauthorised order check (j) disputes an agent order and attaches the receipt, which verifies offline. All three run on local records. To run the buy inside the mandate against the sandbox, add --sandbox --order ORDER_ID with an order the sandbox buyer approved.
Guide
Reconcile an UNKNOWN
If PayPal does not answer, the action may or may not have happened. Clearwake does not guess and does not resend money. It holds the action as UNKNOWN, writes clearwake.refund.unknown, and keeps the reservation so the limits stay safe.
- Read PayPal first. Read the capture or refund record (
GET /v2/payments/captures/{id},GET /v2/payments/refunds/{id}) or the dispute (GET /v1/customer/disputes/{id}). - Compare it with what you expected. Only an observed record that compares VERIFIED moves an UNKNOWN to VERIFIED. No record means it stays UNKNOWN.
- Only if the policy says
retry: safe(evidence, messages), send again with the samePayPal-Request-Id, so PayPal answers with the first result and does not apply it twice. Refunds and offers areretry: never.
| State | Meaning |
|---|---|
VERIFIED | Every compared field matches PayPal's record |
MISMATCH | At least one compared field differs |
UNKNOWN | No record, or a field is missing. Do not retry blind |
PENDING | PayPal reports a status still in progress |
The same case ran on the real sandbox as an injected fault: the real refund was sent and its reply withheld. Result: 1 refund at PayPal, the second call sent nothing, reconciled to VERIFIED. Dispatch proof submission 2 and submission 3 above show the same rule for evidence.
Guide
Run with the network cut
The network cut run (letter m) runs the agents on an internal Docker network. The egress gateway is the only service with a route out, and it allows only api-m.sandbox.paypal.com. The script then cuts the gateway's outside network in the middle of a batch.
python scripts/airgap.py
python scripts/airgap.py --boundary-only--boundary-only runs only the boundary checks and leaves the stack up. It makes no sandbox call and sends no refund. Inside the container, CLEARWAKE_EGRESS=host:port points the PayPal transport at the gateway, and ambient proxy settings are never read.
- Builds the image and starts the gateway and Ollama.
- Checks the boundary: no direct route out, a host off the allowlist is refused and receipted, the local model answers inside.
- Runs the network cut run against the sandbox. After the first refund is verified, the gateway is disconnected. Refunds are held as
clearwake.offline.held, not UNKNOWN, because the request never left. - Reconnects. Clearwake reads PayPal first, then sends the held refunds with their original request ids.
- Verifies every receipt log in a container started with
--network none.
boundary no direct route out (DNS fails); CONNECT example.com:443 through the gateway: 403, receipted
before refund 6PX35920F4587564U USD 1.00 VERIFIED
22:37:01 gateway disconnected: two USD 1.00 refunds held, offline, still held on a resume call
22:37:17 reconnected: capture read first, refunds 76C086475Y724052F and 9C434129FA2384059 VERIFIED
receipts 34 gateway lines and 12 merchant lines verified with --network noneEvery number on the hosted site is read from a recorded run. The network cut as a local run uses a network switch in place of Docker, and its output says so.
Guide
Verify receipts offline
A receipt log is plain text, one JSON object per line. You need the file and the public key you trust. No network and no account.
cd vendor/verdock-core
python -m verdock_core verify ../../site/receipts/case-n-settle.ndjson \
--public-key 93980b0de422af30f7bfaaab14c16c06209e71b296119e84d6b02c4c8517e6f9line 1: ok
line 2: ok
line 3: ok
line 4: ok
line 5: ok
verified: 5 lines, chain intact, signed by the trusted keyThe same check runs in your browser with WebCrypto. The file never leaves your machine. This card uses the site's own verify.js on the recorded settled by offer log.
Settled by offer log, PP-R-OBG-10196144, real sandbox, 3 Nov 2026
Public key 93980b0de422af30f7bfaaab14c16c06209e71b296119e84d6b02c4c8517e6f9
Not checked yet
The "change one value" button flips success on line 2 in memory only. The signature no longer matches and the chain breaks at that line.
Reference
Policy file
The policy is a file the server reads at start. A model never reads or edits it, and no prompt, buyer message or chat can change it. It is YAML (a small subset) or JSON, parsed and checked by vendor/verdock-core/verdock_core/policy.py. Unknown keys are rejected. Amounts are integers in minor units (cents). Floats, yes, no, null, anchors and flow lists are rejected.
| Key | Type | Meaning |
|---|---|---|
version | integer | Required. Must be 1. |
operations.NAME.level | text | Required. Assist, Draft, Execute with Approval or Execute within Limits. Assist and Draft never execute. |
operations.NAME.max_amount_minor | integer | Optional. Above it the action is refused. |
operations.NAME.approval_above_minor | integer | Optional. Above it a person must approve that exact action. |
operations.NAME.currency | 3 capitals | Optional. Another currency is refused. |
operations.NAME.retry | text | Optional. never (default) or safe. |
caps.per_customer_per_day_minor | integer | Optional. A daily total per customer. |
egress.allow_hosts | list of hosts | Optional. The only hosts the egress gateway may reach. Without it nothing may leave. |
Each decision returns one of: within limits, approval required by level, approval required above threshold, above limit, currency mismatch, invalid amount, draft only or unknown operation.
The policy hash is the SHA-256 of the checked policy as JSON with sorted keys and no spaces. It is written into the params of every receipt as policy_hash, so a receipt shows which rules were in force. Changing any level, limit, currency, retry rule or cap changes the hash.
The code also has a hard cap of USD 5.00 per refund (LIMIT in clearwake/paypal.py) that no file can raise. The refund workroom reads a second file, policy/autonomy.json: refund.limit.max up to 5.00, approval_expires_seconds from 30 to 900, and retry must be never.
version: 1
operations:
refund:
level: Execute within Limits
max_amount_minor: 500
approval_above_minor: 200
currency: USD
retry: never
accept_claim:
level: Execute within Limits
max_amount_minor: 500
approval_above_minor: 200
currency: USD
retry: never
provide_evidence:
level: Execute within Limits
retry: safe
make_offer:
level: Execute within Limits
max_amount_minor: 500
approval_above_minor: 300
currency: USD
retry: never
send_message:
level: Execute within Limits
retry: safe
propose_resolution:
level: Draft
retry: never
caps:
per_customer_per_day_minor: 600
egress:
allow_hosts:
- api-m.sandbox.paypal.comReference
Receipt format
Signed, hash chained action receipts in the format of draft-sahu-agent-action-receipts-00. One line of JSON per action. Ed25519 and SHA-256.
| Field | Type | Meaning |
|---|---|---|
step_id | text | What step this is, for example PP-R-OBG-10196144:offer |
action_id | text | What happened, for example clearwake.dispute.offer_sent |
params | any JSON | The facts. Keys are sorted at every depth when signing. |
success | true or false | Whether the action held up when checked |
ts_ms | integer | Milliseconds since the Unix epoch |
actor | object | Optional. agent and user, both text |
prev_hash | 64 hex | SHA-256 of the exact bytes of the line before. Absent on line 1. |
public_key | 64 hex | The Ed25519 public key, 32 bytes |
signature | 128 hex | The Ed25519 signature, 64 bytes |
- Integers only. A non integer number anywhere in a line is rejected, so the Python and browser verifiers always agree. Money is in minor units.
- Signed bytes: compact JSON of
step_id,action_id,params,success,ts_ms,actor(agent, then user) andprev_hash, in that order, leaving out any that are absent. - Other members are added. They are not signed, but the next line's
prev_hashcovers them. - Limit: a log with its newest lines removed still verifies. Keep the head digest somewhere else to catch that.
{
"step_id": "PP-R-OBG-10196144:offer",
"action_id": "clearwake.dispute.offer_sent",
"params": {
"dispute": "PP-R-OBG-10196144",
"offer_minor": 250,
"currency": "USD",
"policy_hash": "396af6170103c7e2570b7c4f159e18543160e14127a05f873135a366bd7af271"
},
"success": true,
"ts_ms": 1793704312548,
"actor": { "agent": "clearwake-merchant", "user": "merchant" },
"prev_hash": "30f0a49a4b61f8e0fe415c65785bba948e7db71143623a4c60a3e2ed7490d579",
"public_key": "93980b0de422af30f7bfaaab14c16c06209e71b296119e84d6b02c4c8517e6f9",
"signature": "f2e8845b5eb4754352117aab1c95e3f922dd6bef3a7d51c8b19028a3410e819f
d1f060a31f6cd86e50b9f36490e1869a488b0839716f07e6c24925bc86762a0a"
}One line of the file, pretty printed. In the file it is one line, and the signature is one 128 character string.
Reference
Events
Each action_id below is written by the code in clearwake/. A failed check is written with success false.
| action_id | Written when |
|---|---|
clearwake.decider.proposal | The model or scripted rule proposes a refund path |
clearwake.policy.refused | The policy refuses: above limit, wrong currency |
clearwake.invariant.refused | A swarm limit stops an amount (capture total, daily cap) |
clearwake.refund.blocked | The capture read before the refund failed. Nothing sent |
clearwake.approval.requested | An action waits in the approval inbox |
clearwake.approval.used | A person's approval was used once, for that exact action |
clearwake.refund.checked | PayPal's refund record was read and compared |
clearwake.refund.unknown | The refund response was lost. Held, not retried |
clearwake.offline.held | The request never left the network. Held |
clearwake.offline.reconciled | After reconnecting, PayPal's record was read first |
clearwake.dispute.proposal | A proposal for a dispute past the INQUIRY stage |
clearwake.dispute.decision | The policy decision at INQUIRY: settle, fight or escalate |
clearwake.dispute.escalated | Sent to the owner with the seconds left |
clearwake.dispute.offer_sent | An offer went to PayPal |
clearwake.dispute.message_checked | The sent message was looked for in PayPal's record |
clearwake.dispute.settlement | PayPal's record read after an offer: PENDING or VERIFIED |
clearwake.dispute.refused_by_paypal | PayPal refused an offer or evidence. Nothing applied |
clearwake.dispute.dispatch_checked | The dispatch receipt was checked against the claim |
clearwake.dispute.evidence_checked | The evidence was looked for in PayPal's record |
clearwake.dispute.supporting_info | A tracking note went in as supporting info |
clearwake.dispute.checked | The dispute was read back after an action |
clearwake.dispatch.recorded | A parcel was counted and signed at packing |
clearwake.buyer.mandate | The buyer agent signed a purchase inside its mandate |
Reference
API reference
The calls Clearwake makes, each with a request you can copy and the response that was recorded on the real sandbox. Replay shows a recorded response again. It sends nothing. Responses list only the fields that were read back in the run, not the full body. Set ACCESS_TOKEN from POST /v1/oauth2/token with your client id and secret, use a new UUID for REQUEST_ID, and set the other shell variables a request names (NOTE, NOTES, TRACKING) before you run it. Bodies are written as here documents, so each variable expands inside the JSON.
- GET /v2/payments/captures/{id}
- POST /v2/payments/captures/{id}/refund
- GET /v1/customer/disputes/{id}
- POST /v1/customer/disputes/{id}/make-offer
- POST /v1/customer/disputes/{id}/provide-evidence
- POST /v1/customer/disputes/{id}/provide-supporting-info
- POST /v2/checkout/orders/{id}/track
GET /v2/payments/captures/{id}
Read a capture. Clearwake does this before every refund, and again to reconcile. A capture that is not COMPLETED is refused.
curl https://api-m.sandbox.paypal.com/v2/payments/captures/$CAPTURE_ID \
-H "Authorization: Bearer $ACCESS_TOKEN"
from clearwake import envfile
from clearwake.paypal import SandboxGateway
envfile.load(".env")
gw = SandboxGateway.from_environment()
capture = gw.capture("1PH921107B839311S")
print(capture["status"])GET /v2/payments/captures/1PH921107B839311S
status COMPLETED (31 Oct 2026, setup)
status PARTIALLY_REFUNDED (after two refunds of USD 1.00)
GET /v2/payments/captures/96H267908A407644D
status PENDING
Clearwake: capture status PENDING. Nothing was sent.Replay shows a recorded response again. No request is sent to PayPal.
POST /v2/payments/captures/{id}/refund
One refund, in USD, at most 5.00. The request id is created once and reused on any retry the policy allows. Refunds are never retried.
curl -X POST https://api-m.sandbox.paypal.com/v2/payments/captures/$CAPTURE_ID/refund \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-H "PayPal-Request-Id: $REQUEST_ID" \
-H "Prefer: return=representation" \
--data-binary @- <<EOF
{"amount":{"value":"1.00","currency_code":"USD"},"custom_id":"$REQUEST_ID"}
EOF
import uuid
from clearwake import envfile
from clearwake.paypal import SandboxGateway
envfile.load(".env")
gw = SandboxGateway.from_environment()
request_id = str(uuid.uuid4())
refund = gw.refund("1PH921107B839311S", "1.00", "USD", request_id)
print(refund["id"], refund["status"])
print(gw.refund_record(refund["id"])) # read PayPal back before calling it donePOST .../refund amount USD 1.00
refund 6PX35920F4587564U
GET /v2/payments/refunds/6PX35920F4587564U
Clearwake state VERIFIED (network cut, 31 Oct 2026)
Earlier check, 31 Oct 2026
refunds 79R527888E694933F and 7A545589JM079780C, USD 1.00 each
read back COMPLETED, linked to the captureReplay shows a recorded response again. No request is sent to PayPal.
GET /v1/customer/disputes/{id}
Read a dispute. Clearwake acts only on the actions PayPal lists in its links, so this read decides what happens next.
curl https://api-m.sandbox.paypal.com/v1/customer/disputes/$DISPUTE_ID \
-H "Authorization: Bearer $ACCESS_TOKEN"
from clearwake import envfile
from clearwake.paypal import SandboxGateway
envfile.load(".env")
gw = SandboxGateway.from_environment()
dispute = gw.dispute("PP-R-UKF-10195772")
print(dispute["status"], dispute.get("dispute_life_cycle_stage"))
print([link["rel"] for link in dispute.get("links", [])])GET /v1/customer/disputes/PP-R-UKF-10195772 (3 Nov 2026)
status OPEN
dispute_life_cycle_stage INQUIRY
links offered provide_evidence, send_message, make_offer,
escalate, accept_claim
GET /v1/customer/disputes/PP-R-SLI-10195419 (31 Oct 2026)
status UNDER_REVIEW
dispute_life_cycle_stage CHARGEBACK
links offered provide_supporting_info onlyReplay shows a recorded response again. No request is sent to PayPal.
POST /v1/customer/disputes/{id}/make-offer
Offer the buyer a refund to settle at the INQUIRY stage. Send it alone: PayPal refuses an offer after a seller message. PayPal refunds only if the buyer accepts.
curl -X POST https://api-m.sandbox.paypal.com/v1/customer/disputes/$DISPUTE_ID/make-offer \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-H "PayPal-Request-Id: $REQUEST_ID" \
--data-binary @- <<EOF
{"note":"$NOTE","offer_type":"REFUND","offer_amount":{"currency_code":"USD","value":"2.50"}}
EOF
import uuid
from clearwake import envfile
from clearwake.paypal import SandboxGateway
envfile.load(".env")
gw = SandboxGateway.from_environment()
note = "We offer you USD 2.50 back to settle this case."
gw.make_offer("PP-R-OBG-10196144", note, "2.50", "USD", str(uuid.uuid4()))
# then read the dispute back: only PayPal's record says it is settled
print(gw.dispute("PP-R-OBG-10196144")["status"])POST .../make-offer after a seller message (3 Nov 2026, first run)
422 UNPROCESSABLE_ENTITY ACTION_NOT_ALLOWED_IN_CURRENT_DISPUTE_STATE
nothing applied
POST .../make-offer, the offer alone, USD 2.50
accepted
GET /v1/customer/disputes/PP-R-OBG-10196144
status UNDER_REVIEW stage INQUIRY Clearwake state PENDING
status RESOLVED stage INQUIRY
outcome RESOLVED_BUYER_FAVOUR Clearwake state VERIFIED
refund 0TB11858A85953644Replay shows a recorded response again. No request is sent to PayPal.
POST /v1/customer/disputes/{id}/provide-evidence
Evidence as multipart: part input is JSON, each photo is an evidence-file part. Send one merged entry, because PayPal needs an item_id when there are several.
cat > input.json <<EOF
{"evidences":[{"evidence_type":"PROOF_OF_FULFILLMENT","evidence_info":{"tracking_info":[{"carrier_name":"UPS","tracking_number":"$TRACKING"}]},"notes":"$NOTES","documents":[{"name":"packing.jpg"}]}]}
EOF
curl -X POST https://api-m.sandbox.paypal.com/v1/customer/disputes/$DISPUTE_ID/provide-evidence \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "PayPal-Request-Id: $REQUEST_ID" \
-F "input=<input.json;type=application/json" \
-F "evidence-file=@packing.jpg;type=image/jpeg"
import uuid
from clearwake import envfile
from clearwake.paypal import SandboxGateway
envfile.load(".env")
gw = SandboxGateway.from_environment()
tracking = "1Z999AA10123456784" # your carrier tracking number
notes = "Shipped by UPS. The packing photo is attached."
request_id = str(uuid.uuid4()) # keep it, and reuse it on a retry
entry = {"evidence_type": "PROOF_OF_FULFILLMENT",
"evidence_info": {"tracking_info": [{"carrier_name": "UPS", "tracking_number": tracking}]},
"notes": notes, "documents": [{"name": "packing.jpg"}]}
gw.provide_evidence("PP-R-UKF-10195772", [entry], request_id,
files=[("packing.jpg", open("packing.jpg", "rb").read(), "image/jpeg")]) # packing.jpg is your photo, next to the scriptsubmission 1 two evidence entries
400 INVALID_REQUEST ITEM_ID_IS_MANDATORY_FOR_MULTIPLE_EVIDENCES
nothing applied
submission 2 one merged entry
response lost. Clearwake state UNKNOWN. The dispute showed nothing had landed.
submission 3 same PayPal-Request-Id
HTTP 200 in 4.2 s
GET /v1/customer/disputes/PP-R-UKF-10195772
evidence PROOF_OF_FULFILLMENT, source SUBMITTED_BY_SELLER, 3 Nov 2026 10:13 UTC
document packing-photo-893632548b14c5d5.jpg
status WAITING_FOR_BUYER_RESPONSE stage INQUIRYReplay shows a recorded response again. No request is sent to PayPal.
POST /v1/customer/disputes/{id}/provide-supporting-info
Notes only, no files. PayPal offers this once a dispute is under review and no longer offers provide-evidence.
cat > input.json <<EOF
{"notes":"$NOTES"}
EOF
curl -X POST https://api-m.sandbox.paypal.com/v1/customer/disputes/$DISPUTE_ID/provide-supporting-info \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "PayPal-Request-Id: $REQUEST_ID" \
-F "input=<input.json;type=application/json"
import uuid
from clearwake import envfile
from clearwake.paypal import SandboxGateway
envfile.load(".env")
gw = SandboxGateway.from_environment()
notes = "Shipped by UPS. Tracking 1Z999AA10123456784 shows the parcel as delivered."
gw.provide_supporting_info("PP-R-SLI-10195419", notes, str(uuid.uuid4()))POST .../provide-supporting-info (item not received, PP-R-SLI-10195419, 31 Oct 2026)
GET /v1/customer/disputes/PP-R-SLI-10195419
note shown as SUBMITTED_BY_SELLER at 2026-10-31T10:31:38Z
Clearwake state VERIFIEDReplay shows a recorded response again. No request is sent to PayPal.
POST /v2/checkout/orders/{id}/track
Add tracking to an order. Clearwake reads trackers back from the order when it builds evidence.
curl -X POST https://api-m.sandbox.paypal.com/v2/checkout/orders/$ORDER_ID/track \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-H "PayPal-Request-Id: $REQUEST_ID" \
--data-binary @- <<EOF
{"capture_id":"$CAPTURE_ID","tracking_number":"$TRACKING","carrier":"UPS","notify_payer":false}
EOF
import uuid
from clearwake import envfile
from clearwake.paypal import SandboxGateway
envfile.load(".env")
gw = SandboxGateway.from_environment()
order_id, capture_id = "7RV99265V1496281G", "4AN16499K3427771T" # from your sandbox order
tracking_number = "1Z999AA10123456784"
gw.add_tracking(order_id, capture_id, tracking_number, "UPS", str(uuid.uuid4()))
print(gw.order(order_id))POST .../track, carrier UPS (31 Oct and 3 Nov 2026)
GET /v2/checkout/orders/7RV99265V1496281G
tracker shown by PayPal as SHIPPEDReplay shows a recorded response again. No request is sent to PayPal.
Every path the transport allows
Every call goes to https://api-m.sandbox.paypal.com. The transport in clearwake/paypal.py allows only these paths: HTTPS, no query string, no redirects, no proxy except the egress gateway, a 15 second timeout, and a response of at most 262,144 bytes. Any other path is refused before it is sent. POST calls carry a PayPal-Request-Id.
| Method and path | Used for |
|---|---|
POST /v1/oauth2/token | Client credentials token |
GET /v2/payments/captures/{id} | Capture read before every refund, and to reconcile |
POST /v2/payments/captures/{id}/refund | One refund, USD, at most 5.00 |
GET /v2/payments/refunds/{id} | Read the refund back |
POST /v2/checkout/orders | One time setup order (sandbox) |
GET /v2/checkout/orders/{id} | Order lines and trackers |
POST /v2/checkout/orders/{id}/capture | Capture a setup order |
POST /v2/checkout/orders/{id}/track | Add tracking to an order |
GET /v1/customer/disputes | List disputes |
GET /v1/customer/disputes/{id} | Read a dispute and the actions PayPal offers |
POST /v1/customer/disputes/{id}/make-offer | Offer a refund to settle at INQUIRY |
POST /v1/customer/disputes/{id}/send-message | Message the buyer at INQUIRY |
POST /v1/customer/disputes/{id}/provide-evidence | Evidence from the record, multipart, one merged entry |
POST /v1/customer/disputes/{id}/provide-supporting-info | Notes once a dispute is under review |
POST /v1/customer/disputes/{id}/accept-claim | Accept and refund inside the limit |
POST /v1/customer/disputes/{id}/adjudicate | Sandbox only: finish a test dispute |
Reference
Error explorer
Search a PayPal error or a Clearwake outcome. Each entry says where it was seen, the cause and the fix. Only errors seen in real runs or raised by the code are here.
422 ACTION_NOT_ALLOWED_IN_CURRENT_DISPUTE_STATEReal sandbox, settled by offer, PP-R-OBG-10196144, 3 Nov 2026
- Cause
- An offer was sent after a seller message. PayPal allows an offer only in an inquiry that waits for the seller.
- Fix
- Send the offer alone, first. Clearwake does this now and writes the refusal to the receipts as clearwake.dispute.refused_by_paypal.
400 INVALID_REQUEST ITEM_ID_IS_MANDATORY_FOR_MULTIPLE_EVIDENCESReal sandbox, dispatch proof, PP-R-UKF-10195772, 3 Nov 2026
- Cause
- Two evidence entries were sent, and the disputed item shows no item id.
- Fix
- Send one merged entry with the tracking, the notes and the documents together.
400 No permissions to set target_client_idReal sandbox, 31 Oct 2026
- Cause
- Creating a dispute for the buyer with a buyer assertion. The app's token has disputes/create, update-seller and read-seller, not update-buyer.
- Fix
- The sandbox buyer opens disputes in the Resolution Center. Clearwake handles them from there.
400 TRANSACTION_NOT_ELIGIBLEReal sandbox, 31 Oct 2026
- Cause
- The same create call without the assertion.
- Fix
- Same as above.
capture status PENDINGReal sandbox, network cut, second run, 31 Oct 2026
- Cause
- The configured capture was PENDING, and the capture read before the refund refused it.
- Fix
- Put a COMPLETED capture in PAYPAL_SANDBOX_CAPTURE_ID.
Capture preflight failed. Nothing was sent.Real sandbox, 31 Oct 2026, first run of the three refund runs
- Cause
- Clearwake will not fetch a token in the moment before a POST. The capture read failed, so the refund was held.
- Fix
- Run it again. Nothing reached PayPal, so there is nothing to reconcile.
Offline: the request did not leave this network.Network cut run, 31 Oct 2026
- Cause
- The egress gateway refused the tunnel or nothing could be reached. The request never left.
- Fix
- It is held as clearwake.offline.held. After reconnecting, Clearwake reads PayPal first, then sends with the original request id.
The sandbox response is uncertain. No automatic retry was sent.Lost reply: reconciled refund of 31 Oct 2026, and dispatch proof submission 2 of 3 Nov 2026
- Cause
- The request may or may not have been applied.
- Fix
- State UNKNOWN. Read PayPal first. Retry only if the policy says retry: safe, with the same PayPal-Request-Id.
403 from the egress gatewayNetwork cut run, example.com through the gateway
- Cause
- The host is not in egress.allow_hosts.
- Fix
- Expected. Only api-m.sandbox.paypal.com passes.
PAYPAL_BASE_URL must be exactly the sandbox hostcode Raised at start by the code
- Cause
- The base url is not https://api-m.sandbox.paypal.com.
- Fix
- Set PAYPAL_BASE_URL to the sandbox host. Clearwake never runs against anything else.
Explicit sandbox-only acknowledgement is requiredcode Raised at start by the code
- Cause
- CLEARWAKE_SANDBOX_ACK is not set to I_CONFIRM_SANDBOX_ONLY.
- Fix
- Set it in .env.
UNKNOWNcode Clearwake outcome
- Cause
- There is no observed record, or a compared field is missing. The action may or may not have happened.
- Fix
- Do not retry blind. Read PayPal's record and compare.
MISMATCHcode Clearwake outcome
- Cause
- At least one compared field differs from PayPal's record.
- Fix
- Treat it as not done as expected. Read the record and decide with the owner.
PENDINGcode Clearwake outcome
- Cause
- PayPal reports a status still in progress, for example a dispute UNDER_REVIEW after an offer.
- Fix
- Wait and read again. Only RESOLVED counts as settled.
above limitcode Policy decision
- Cause
- The amount is higher than max_amount_minor for that operation.
- Fix
- Nothing is sent. Change the file and restart, or let the owner decide.
approval required above thresholdcode Policy decision
- Cause
- The amount is above approval_above_minor.
- Fix
- It waits in the approval inbox. One approval, one exact action.
Reference
Recorded sandbox log
Every row is a recorded run unless it says otherwise. IDs are PayPal sandbox ids. Test money only. Sources: docs/SANDBOX_RUN.md, docs/RESULTS.md.
| Date | Case | What PayPal answered |
|---|---|---|
| 31 Oct | Setup | Order 1DW875094F275773J, USD 20.00, approved by the sandbox buyer. Capture 1PH921107B839311S COMPLETED. |
| 31 Oct | Four case check | 4 of 4 PASS. Refunds 79R527888E694933F and 7A545589JM079780C, USD 1.00 each, read back COMPLETED. Capture PARTIALLY_REFUNDED. |
| 31 Oct | c | Refund 6SN41486G5579815G VERIFIED. |
| 31 Oct | d | Refund 2NB27940EC188891M VERIFIED after approval. |
| 31 Oct | e, injected fault in sandbox | Real refund sent, reply withheld. 1 refund at PayPal, second call sent nothing, reconciled to VERIFIED. |
| 31 Oct | i | Dispute PP-R-SLI-10195419 was UNDER_REVIEW, stage CHARGEBACK. Only provide_supporting_info was offered. Note shown as SUBMITTED_BY_SELLER at 10:31:38Z. VERIFIED. |
| 31 Oct | Create a dispute by API | 400 No permissions to set target_client_id. Without the assertion, 400 TRANSACTION_NOT_ELIGIBLE. |
| 31 Oct | m, network cut | Refund 6PX35920F4587564U VERIFIED. Cut at 22:37:01, two refunds held. Restored at 22:37:17, 76C086475Y724052F and 9C434129FA2384059 VERIFIED. |
| 3 Nov | n, first run | Message, then offer: 422 ACTION_NOT_ALLOWED_IN_CURRENT_DISPUTE_STATE. Nothing applied. |
| 3 Nov | n, offer alone | Offer USD 2.50 accepted. UNDER_REVIEW, then RESOLVED (RESOLVED_BUYER_FAVOUR) at INQUIRY. Refund 0TB11858A85953644. PASS. |
| 3 Nov | o, submission 1 | 400 INVALID_REQUEST ITEM_ID_IS_MANDATORY_FOR_MULTIPLE_EVIDENCES. Nothing applied. |
| 3 Nov | o, submission 2 | Response lost. UNKNOWN. The dispute showed nothing had landed. |
| 3 Nov | o, submission 3 | Same request id. HTTP 200 in 4.2 s. PROOF_OF_FULFILLMENT with packing-photo-893632548b14c5d5.jpg. PASS. |
The ten case batch of 11 Nov 2026 ran on the real PayPal sandbox: its agents decided with a local model (qwen3.5:4b, 24 model calls, 0 scripted decisions) and PayPal reads RESOLVED at INQUIRY on four of the ten. The settled by offer run and the dispatch proof run passed on the real sandbox on 3 Nov 2026 with rule based deciders. The near deadline run is a local run. The receipts of the network cut, the settlement and the dispatch proof are in site/receipts/ and verify in your browser above.
Reference
Changelog
Milestones from docs/HACKATHON_UPDATES.md and the git history, oldest first, up to 12 Nov 2026. Dates are commit dates. Every commit is dated after the submission period opened on 1 October 2026.
| Date | Commit | Change |
|---|---|---|
| 2026-10-30 | 5586442 | Clearwake: shared refund workroom extending the pinned Relayloom core |
| 2026-10-30 | 1fbf0be | Add real PayPal sandbox setup and four case sandbox check |
| 2026-10-30 | b68f331 | Add autonomy policy with recorded approvals |
| 2026-10-31 | f690c63 | Refuse to run unless PAYPAL_BASE_URL is exactly the PayPal sandbox |
| 2026-10-31 | e0fdf83 | Pin the shared verdock-core engine v0.1.0 as a submodule |
| 2026-10-31 | d86176b | Case runner for a to l and a capture preflight before every swarm refund |
| 2026-10-31 | 582c222 | Answer disputes under review with supporting info PayPal offers, verified by read-back |
| 2026-10-31 | 2776a66 | Settle disputes in conversation before they become claims, held offline when the network is cut |
| 2026-10-31 | 864e6e8 | Network isolated run for the network cut, the settled by offer and network cut runs in the runner, and the fee leak gauge |
| 2026-10-31 | 12ebb23 | Public site for Vercel: the fee leak with sources, the recorded sandbox run and an in-browser receipt verifier |
| 2026-11-01 | 426a0f5 | Dispatch proof: signed packing record, strong or weak check against a buyer's claim, evidence with the photo, the dispatch proof run |
| 2026-11-03 | 0f884b6 | Dispatch proof run for real: SAM 3 counted a CC0 test photo on the CPU and PayPal's sandbox accepted the evidence with the photo |
| 2026-11-03 | 0ad7ba5 | Settle offer goes first and alone: PayPal refuses an offer after a seller message |
| 2026-11-03 | 1ebda16 | Record the real settled by offer run: settlement paid, case RESOLVED at INQUIRY; report paid settlement as pending until PayPal reads RESOLVED |
| 2026-11-03 | a70a542 | Publish the real settled by offer receipts on the site |
| 2026-11-09 | ce2d0c7 | Redesign: Figtree type, an editorial site (home, control room, developers) and a restyled console |
| 2026-11-10 | 4cd343a | The console is the product: AG Grid dispute ledger with countdown and CSV on site and console, hosted mode, baseline against Clearwake over 200 episodes, Channel3 price reference with a credit cap |
| 2026-11-10 | fcdb979 | Ten item not received cases with Add Tracking and paired receipts, plain words rules, voice and phone mode, measured merchant AI |
| 2026-11-11 | a836987 | Real ten case sandbox batch, owner and agents scene on case 3, MCP guard, APIMatic and Postman records |
| 2026-11-11 | 2df50eb | Drop in guard for toolkit agents, the Break it page, the final check gate and a Render blueprint without keys |
| 2026-11-11 | 184e743 | Holographic portraits for the owner and both agents, wake on batch case 3, Control Room ledger first, APIMatic portal link and Context Plugin record |
| 2026-11-11 | 6afaa06 | Anatomy diagram of one real dispute |
| 2026-11-11 | 40771bd | Home numbers: six sourced facts led by the baseline, handled with no error, and settled at INQUIRY |
| 2026-11-11 | cd82f9b | Anatomy as an exploded view: assembled unit in the centre, six layers split left and right, layer switch |
| 2026-11-11 | a7157d9 | Numbers first on every page, 4 of 4 inside the owner's limit, console tally generated from run files, nine slide deck |
| 2026-11-11 | 4515c44 | Network cut diagram rebuilt, console tally served as a static file |
| 2026-11-12 | 8c69d2c | Old names replaced across code, tests, scripts and docs; recorded files written before the change still load |
Reference
Spec, collection and SDKs
The console API is described in OpenAPI 3.1. Download the spec, open the API portal, or generate a client with APIMatic.