# payInvoice

Pay one OPEN invoice on the card on file: `number`, and from getInvoicePayment read just before `expectedAmountCents` (its `amountRemainingCents`) and `expectedCardLast4` (its `card.last4`). When asked first, its card names the invoice number, the exact dollars, the card ("Visa ending 4242") and that it is non-refundable. Refused when the amount or the card changed (read again), it is already paid, or no card is on file. `status`: PAID, PENDING (bank debit settling), REQUIRES_ACTION (send `hostedInvoiceUrl`) or DECLINED (`message`; another card goes on the Billing page). Never a staff member acting as the customer. Needs the spending permission.

- Call: `POST https://server.goliathdata.com/api/v1/call` with `{ "operationId": "payInvoice", "variables": {...} }`
- Scope: `ADMIN`
- Type: mutation
- Idempotency: honors `Idempotency-Key` (24 h)
- Rate-limited: no

## Variables

- `number`: `String!` (required)
- `expectedAmountCents`: `Int!` (required)
- `expectedCardLast4`: `String!` (required)

## Response (data, an example)

```json
{
  "billingMutation": {
    "payInvoice": {
      "status": "PAID",
      "invoiceNumber": "…",
      "amountCents": 0,
      "message": "…",
      "hostedInvoiceUrl": "…",
      "card": {
        "brand": "…",
        "last4": "…"
      }
    }
  }
}
```

## Example

```bash
curl https://server.goliathdata.com/api/v1/call \
  -H "Authorization: Bearer $GOLIATH_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "operationId": "payInvoice",
    "variables": {
      "number": "<String>",
      "expectedAmountCents": 10,
      "expectedCardLast4": "<String>"
    }
  }'
```
