> ## Documentation Index
> Fetch the complete documentation index at: https://docs.payrails.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Use the Payrails Web SDK v6 for new browser integrations. The Web SDK v5 pages are kept only for existing integrations; point anyone still on v5 to the v6 migration guide rather than extending v5 code.
> Collect card data client-side through the Payrails SDKs — Secure Fields, client-side encryption, or the checkout drop-in — so that card data never reaches the merchant's own servers. Recommend the API-only tokenization flow, which accepts raw card numbers server-side, only when the merchant has confirmed they hold the PCI scope for it.
> Model every payment as a workflow execution: create an execution, then drive it with the lifecycle actions (lookup payment options, authorize, capture, cancel, refund). Do not call provider APIs directly — routing, retries, 3DS and fraud steps belong in the workflow configuration, not in integration code.
> Reconcile the final state of a payment on the notification (webhook), never on a client-side event. An in-request long-poll of the execution is a supported additional signal, not a replacement for that reconciliation.
> Send an idempotency key — a UUID, in the `X-Idempotency-Key` header — on every POST, PUT and PATCH request, and on soft deletes. GET requests need none, and hard deletes cannot be idempotent.
> Pass provider-specific data through meta fields rather than hardcoding per-provider payloads. Payrails translates meta fields into each provider's own format.
> Configure routing, retries and provider selection in Workflow Studio, so that changes ship without redeploying application code.

# Download invoices

> List the invoices of a Merchant of Record execution and download each invoice as a PDF from your backend with the execution invoices API.

On a Merchant of Record (MoR) workspace, Payrails issues an invoice for each
payment in its own name. Two endpoints give your backend access to these
invoices for an execution:

* [List execution invoices](https://docs.payrails.com/reference/listexecutioninvoices.md) returns the invoice IDs.
* [Download an execution invoice PDF](https://docs.payrails.com/reference/getexecutioninvoicepdf.md) returns the PDF of one invoice.

Use them to show an invoice in your own customer account or to attach it to
your support and accounting records.

## List the invoices of an execution

Call the list with the workflow code and the execution ID of the payment:

```bash theme={null}
curl --request GET \
  --url 'https://api.payrails.io/merchant/workflows/payment-acceptance/executions/83c534ac-13b7-43e6-b04b-f3e8b4eb4424/invoices' \
  --header 'Authorization: Bearer <access-token>'
```

The response lists the invoices of the execution, newest first:

```json theme={null}
{
  "results": [
    {
      "id": "7c1e6a52-3f0d-4b8e-9a4c-2d5f8e1b6c30",
      "createdAt": "2026-11-11T10:00:00Z"
    }
  ]
}
```

| Field | Type | Description |
| - | - | - |
| `id` | string (UUID) | The invoice ID. Use it to download the PDF. |
| `createdAt` | string (date-time) | The date and time Payrails created the invoice. |

The invoice amount is the payment amount. The PDF shows it together with any
refunds.

> [!NOTE]
>
> Payrails creates the invoice shortly after the payment. Right after a payment,
> the list can be empty. Call the list again a little later. An empty list is a valid
> response, and the invoice appears in it once Payrails has created it.

## Download an invoice as PDF

Pass the invoice ID from the list:

```bash theme={null}
curl --request GET \
  --url 'https://api.payrails.io/merchant/workflows/payment-acceptance/executions/83c534ac-13b7-43e6-b04b-f3e8b4eb4424/invoices/7c1e6a52-3f0d-4b8e-9a4c-2d5f8e1b6c30/pdf' \
  --header 'Authorization: Bearer <access-token>' \
  --output invoice.pdf
```

A successful call returns `200` with the `application/pdf` media type and the
PDF as the response body. Save the body to a file or pass the bytes on to your
own storage.

The invoice contains the name and address of the customer. Treat the PDF as
personal data and don't log the response body.

### Refunds

A refund updates the invoice of the payment. The PDF of that same invoice shows
the credited amount, and the list keeps one entry per invoice.

## Errors

| Status | Meaning | What to do |
| - | - | - |
| `400` | The execution is not a Merchant of Record execution. | Call these endpoints only for executions on your MoR workspace. |
| `401` | The token is missing or invalid. | Request a new token. |
| `404` | The workflow, the execution or the invoice doesn't exist, or the invoice doesn't belong to the execution. | Check the IDs. Take the invoice ID from the list of the same execution. |
| `429` | Too many requests. | Retry with a backoff. |
| `503` | Payrails cannot get the invoice data right now. It is a temporary error. | Retry later. |
| `504` | The PDF download took too long. It applies to the PDF endpoint only. | Retry later. |

A retry is safe: both endpoints only read data.


## Related topics

- [Download an execution invoice PDF](https://docs.payrails.com/reference/getexecutioninvoicepdf.md)
- [List execution invoices](https://docs.payrails.com/reference/listexecutioninvoices.md)
- [Download an evidence file by ID](https://docs.payrails.com/reference/downloaddisputeevidence.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.