<!-- ZenPays documentation · https://docs.zenpayz.com/docs/rest-api/endpoints/billing/invoices/pay-invoice -->

# Pay Invoice

Initiate payment for an invoice. Creates a payment intent that the customer can use to complete the payment.

:::note
This is a **public endpoint** — no authentication headers are required.
:::

<EndpointHeader verb="POST" path="/merchant/api/v1/invoices/:invoiceId/pay" />

## Request

### Path Parameters

<ParamTable
  rows={[
    { name: "invoiceId", type: "string", required: true, desc: "The invoice ID (e.g. `inv_a1b2c3d4e5f6g7h8`)" },
  ]}
/>

## Response

### Success (200 OK)

```json
{
  "success": true,
  "data": {
    "invoiceId": "inv_a1b2c3d4e5f6g7h8",
    "paymentIntentId": "pi_x1y2z3w4v5u6t7s8",
    "amount": 275.00,
    "currency": "USD",
    "checkoutUrl": "https://checkout.zenpayz.com/pay/pi_x1y2z3w4v5u6t7s8"
  },
  "message": "Payment initiated successfully",
  "error": null,
  "meta": {
    "request_id": "req_xxxxx",
    "timestamp": "2024-01-15T10:30:00.000Z",
    "processing_time_ms": 120,
    "api_version": "v1",
    "endpoint": "POST /invoices/:invoiceId/pay",
    "user_type": "merchant"
  }
}
```

### Error Responses

<ErrorTable
  rows={[
    { code: "INVOICE_NOT_FOUND", status: "404", message: "Invoice does not exist" },
    { code: "INVOICE_ALREADY_PAID", status: "409", message: "Invoice has already been fully paid" },
    { code: "INVOICE_CANCELLED", status: "409", message: "Cannot pay a cancelled invoice" },
  ]}
/>

<CodeRail>

## Examples

<Tabs groupId="language">
  <TabItem value="curl" label="cURL" default>

```bash
curl -X POST https://api.zenpayz.com/merchant/api/v1/invoices/inv_a1b2c3d4e5f6g7h8/pay \
  -H "Content-Type: application/json"
```

  </TabItem>
  <TabItem value="javascript" label="JavaScript">

```javascript
const response = await fetch('https://api.zenpayz.com/merchant/api/v1/invoices/inv_a1b2c3d4e5f6g7h8/pay', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
});

const result = await response.json();
console.log(result.data.checkoutUrl); // Redirect customer to this URL
```

  </TabItem>
  <TabItem value="sdk" label="SDK">

```javascript
const payment = await zenpays.invoices.pay('inv_a1b2c3d4e5f6g7h8');

console.log(payment.checkoutUrl); // Redirect customer to this URL
```

  </TabItem>
</Tabs>

</CodeRail>

## Related Endpoints

- [Public Invoice](/docs/rest-api/endpoints/billing/invoices/public-invoice)
- [Get Invoice](/docs/rest-api/endpoints/billing/invoices/get-invoice)
- [Generate Payment Link](/docs/rest-api/endpoints/billing/invoices/generate-payment-link)
