---
title: "Paid on the close"
url: https://services.dev/docs/grow/outcome
captured: [grow-outcome.txt]
---
# Paid on the close

URL: https://services.dev/docs/grow/outcome

> AI works a deal, and the buyer pays nothing until its own customer pays it. Two lines make a Service outcome-priced, the outcome with its proof and the share the price takes, and check prints what a win leaves you, what a loss costs and the win rate where they meet.

Some work is worth paying for only when it works. A Service meets that with two lines: `outcome` names the amount and what proves it, and `price.share` takes a share of it. Nothing is charged on effort. This is Grow 6.

## Add the outcome

```ts title="grow/outcome.ts"
import { Service } from 'services.dev'

// Grow 6, paid on the close: AI works a deal, and the buyer pays 5% of the closed value once its own customer
// pays the invoice the close sends. Nothing is charged on effort, and a lost deal charges nothing.
export default Service({
  name: 'Deal',
  description: 'A deal, worked to close.',
  input: { account: 'party', value: 'money: list value', offer: 'url' },
  output: { closed_value: 'money', pay_link: 'url' },
  deliver: { source: 'ai', meet: 'ai', close: { by: 'ai', next: job => (job.output.closed_value ? 'won' : 'lost') } },
  ends: { won: { charge: true }, lost: { charge: false } },
  outcome: { amount: 'closed_value', proof: 'payment', match: { customer: 'account', metadata: 'deal' } },
  price: { usd: 0, share: '5%', of: 'closed_value', on: 'won', ai: 40 },
})
```

| Key | What it does |
|---|---|
| `outcome.amount` | The output field the share is of |
| `outcome.proof` | What proves it: here the buyer's customer paying the buyer's own invoice, read from the buyer's Stripe account |
| `outcome.match` | How a payment finds the job: its customer is the account, and its `metadata.deal` is this job |
| `price.share` | The share, taken at the end `on` names, once the proof lands |
| `price.ai` | What you spend on AI for one job, won or lost |

## Check it

`check` prints the bet before the first order: what a win leaves you, what a loss costs, and the win rate where the two break even:

```bash
npx services.dev check
```

```txt title="magic values: account.email = replies@example.test, metadata.sandbox.proof = "paid""
services/deal.ts · 9 lines · nothing on effort; 5% of closed_value at won, proven by the account's payment, held 60 days by bank, 120 by card.
  steps   source · ai → meet · ai → close · ai
  ends    won · charged · lost · $0
  outcome proof payment, read from the buyer's own Stripe account · matched on the account's customer and metadata.deal · window 60d by bank, 120d by card
  ledger  +$1,500.00 at won on $30,000 · AI $9.12 (example) · you $1,490.88
  lost    +$0.00 · AI up to $40.00 · you −$40.00
  odds    a lost deal costs $40.00, a won one leaves $1,490.88 · breaks even at 2.6% won (about 1 in 38)
✓ ready to sell · 1 Service · nothing charged before won
```

## Run one deal

The close sends the buyer's own invoice, and its payment proves the win:

```txt
→ POST /deals {"account":{"name":"Litware Clinics","email":"replies@example.test"},"value":30000,"offer":"https://harbor.example/route-planner","max_usd":1500,"payment_method":"pm_…","key":"litware"}
```

```txt title="201 · job_7Hx1 · deal · working · mandated · up to $1,500.00, charged at won · magic values: account.email = replies@example.test, metadata.sandbox.proof = "paid""
← 201 · job_7Hx1 · deal · working · mandated · up to $1,500.00, charged at won
```

```bash
npx services.dev tick 7d && npx services.dev deals get job_7Hx1
```

```txt title="magic values: account.email = replies@example.test, metadata.sandbox.proof = "paid""
job_7Hx1 · won · $1,500.00 charged, held to 2026-12-19
  closed    $30,000.00 · by AI · pay_link in_…X101, the buyer's own invoice with metadata.deal job_7Hx1
  proof     in_…X101 paid $30,000.00 · matched on the customer and metadata.deal
  ledger    +$1,500.00 · AI $9.12 of $40.00 · you $1,490.88 before the take
```

[The sales example](https://services.dev/docs/examples/sales.md) grows this to api.forsale: setters, closers and nurturers from a Pool, a floor only the seller sets, and every way a deal goes.

## Next

[Every month](https://services.dev/docs/grow/subscription.md): a plan that orders Translation on a schedule and on every change.

---

- Up: [Your first paid job](https://services.dev/docs.md)
- Previous: [A date the world sets](https://services.dev/docs/grow/clock.md)
- Next: [Every month](https://services.dev/docs/grow/subscription.md)
