# Recent payment and budget changes

Changes from 27–29 Oct 2026 by Girish and Navnath Satav. All three commits are on `development` and `master`. Request shapes are in [AdMedia sync API](admedia-sync-api.md).

A billing credit writes `Advertiser_billing` and does not fund delivery. A budget adjustment writes `Advertiser_budget`, which is the balance ads spend. Both calls use the same amount and comment.

## 27 Oct — Girish `0a7aa70`

Payment, line-item funding, and rollover stopped writing `Advertiser_billing` and `Advertiser_budget` with Admin SQL and started calling the billing API.

Each post is recorded locally so it is not sent twice:

| Sync type            | Comment                               |
| -------------------- | ------------------------------------- |
| `PAYMENT`            | `dsp-payment-{paymentId}`             |
| `LINE_ITEM_FUNDING`  | `dsp-line-item-funding-{lineItemId}`  |
| `LINE_ITEM_ROLLOVER` | `dsp-line-item-rollover-{lineItemId}` |

`scripts/admedia-backfill-billing-sync.ts` marks existing funding and rollover comments `LINKED`. It does not call AdMedia and does not touch payment rows. Run it before a process that no longer reads `ADMIN_DATABASE_URL`, or those line items are credited again.

Rollover is one net adjustment: overspend minus unspent. A positive net is `credit`. A negative net is `debit`. A net that formats as `0.00` is not sent.

```json
{
  "amount": "12.50",
  "direction": "debit",
  "comment": "dsp-line-item-rollover-88"
}
```

A 4xx marks the sync row `FAILED`. Any other failure is not posted again until someone checks AdMedia.

## 27 Oct — Navnath `b13a89e`

Line-item funding only posted `POST /advertisers/{id}/billing/credits`. That does not add to `Advertiser_budget`. The same amount and comment are now also posted as a budget credit.

```json
{
  "amount": "50.00",
  "direction": "credit",
  "comment": "dsp-line-item-funding-88"
}
```

`clamped: true` is logged. The sync row is still marked linked. The amount is the card charge, not the full line-item budget.

## 29 Oct — Navnath `39c508b`

Wallet payments had the same gap. `syncPayment` posted a billing credit and did not adjust the budget. It now posts both, with comment `dsp-payment-{paymentId}`.

```json
{
  "amount": "100.00",
  "direction": "credit",
  "comment": "dsp-payment-42"
}
```

A paid payment with amount `0` or below is not sent. A payment that becomes `PAID` on the update path now calls `onPaymentPaid`, so that payment is synced.
