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

# Credit notes

> Estimate, issue, and void credit notes against finalized invoices.

| Command                                                                                                                                     | Description                             |
| ------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- |
| `credit-notes create`                                                                                                                       | Issue a credit note against an invoice. |
| `credit-notes estimate`                                                                                                                     | Estimate without issuing.               |
| `credit-notes get <lago_id>`                                                                                                                | Retrieve a credit note.                 |
| `credit-notes list`                                                                                                                         | List credit notes.                      |
| `credit-notes update <lago_id>`                                                                                                             | Update refund status.                   |
| `credit-notes download <lago_id>`                                                                                                           | Trigger the PDF.                        |
| `credit-notes void <lago_id>`                                                                                                               | Void. Confirmation-gated.               |
| `credit-notes metadata`, `merge-credit-note-metadata`, `delete-credit-note-metadata-key`, `delete-all-credit-note-metadata <lago_id> [key]` | Metadata.                               |

## create

A credit note splits into a credit part (wallet balance the customer can use on future invoices) and a refund part (money back through the payment provider). Both are cents.

| Flag                                             | Description                                                                                                        |
| ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
| `--invoice-id`                                   | The invoice's `lago_id`.                                                                                           |
| `--reason`                                       | `duplicated_charge`, `product_unsatisfactory`, `order_change`, `order_cancellation`, `fraudulent_charge`, `other`. |
| `--items`                                        | JSON array of `{"fee_id","amount_cents"}`. Fee IDs come from `invoices get`.                                       |
| `--credit-amount-cents`, `--refund-amount-cents` | How the total splits.                                                                                              |
| `--description`                                  | Free text on the document.                                                                                         |

Run `estimate` with the same items first. It returns the taxes and totals the credit note would carry.

<RequestExample>
  ```bash estimate theme={"dark"}
  lago credit-notes estimate --input '{
    "credit_note": {
      "invoice_id": "4d904d90-4d90-4d90-4d90-4d904d904d90",
      "items": [{"fee_id": "6f906f90-6f90-6f90-6f90-6f906f906f90", "amount_cents": 5000}]
    }
  }'
  ```

  ```bash create theme={"dark"}
  lago credit-notes create \
    --invoice-id 4d904d90-4d90-4d90-4d90-4d904d904d90 \
    --reason duplicated_charge \
    --credit-amount-cents 5000 --refund-amount-cents 0 \
    --items '[{"fee_id":"6f906f90-6f90-6f90-6f90-6f906f906f90","amount_cents":5000}]'
  ```

  ```bash get theme={"dark"}
  lago credit-notes get 7a907a90-7a90-7a90-7a90-7a907a907a90
  lago credit-notes get 7a907a90-7a90-7a90-7a90-7a907a907a90 --output json \
    --query 'credit_note.{status: credit_status, total: total_amount_cents}'
  lago credit-notes download 7a907a90-7a90-7a90-7a90-7a907a907a90
  ```

  ```bash list theme={"dark"}
  lago credit-notes list --limit 20
  ```

  ```bash void theme={"dark"}
  lago credit-notes void 7a907a90-7a90-7a90-7a90-7a907a907a90 --confirm 7a907a90-7a90-7a90-7a90-7a907a907a90
  ```
</RequestExample>

<ResponseExample>
  ```json estimate theme={"dark"}
  {
    "estimated_credit_note": {
      "lago_invoice_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
      "invoice_number": "LAG-1234",
      "currency": "USD",
      "taxes_amount_cents": 20,
      "precise_taxes_amount_cents": 20.1,
      "taxes_rate": 20,
      "sub_total_excluding_taxes_amount_cents": 100,
      "max_creditable_amount_cents": 100,
      "max_refundable_amount_cents": 0,
      "max_offsettable_amount_cents": 0,
      "coupons_adjustment_amount_cents": 20,
      "precise_coupons_adjustment_amount_cents": 20.1,
      "items": [
        {
          "amount_cents": 100,
          "lago_fee_id": "1a901a90-1a90-1a90-1a90-1a901a901a90"
        }
      ],
      "applied_taxes": [
        {
          "lago_tax_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
          "tax_name": "TVA",
          "tax_code": "french_standard_vat",
          "tax_rate": 20,
          "tax_description": "French standard VAT",
          "base_amount_cents": 100,
          "amount_cents": 2000,
          "amount_currency": "USD"
        }
      ]
    }
  }
  ```

  ```text create theme={"dark"}
  LAGO_ID  1a901a90-1a90-1a90-1a90-1a901a901a90
  ```

  ```json get theme={"dark"}
  {
    "credit_note": {
      "lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
      "billing_entity_code": "acme_corp",
      "sequential_id": 2,
      "number": "LAG-1234-CN2",
      "lago_invoice_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
      "invoice_number": "LAG-1234",
      "purchase_order_number": "PO-123",
      "issuing_date": "2022-12-06",
      "credit_status": "available",
      "refund_status": "pending",
      "reason": "duplicated_charge",
      "description": "Free text",
      "currency": "USD",
      "total_amount_cents": 120,
      "taxes_amount_cents": 20,
      "taxes_rate": 20,
      "sub_total_excluding_taxes_amount_cents": 100,
      "balance_amount_cents": 100,
      "credit_amount_cents": 5000,
      "refund_amount_cents": 0,
      "offset_amount_cents": 0,
      "coupons_adjustment_amount_cents": 20,
      "created_at": "2022-09-14T16:35:31Z",
      "updated_at": "2022-09-14T16:35:31Z",
      "file_url": "https://getlago.com/credit_note/file",
      "items": [
        {
          "lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
          "amount_cents": 100,
          "amount_currency": "USD",
          "fee": {
            "lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
            "lago_charge_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
            "lago_charge_filter_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
            "lago_fixed_charge_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
            "lago_invoice_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
            "lago_true_up_fee_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
            "lago_true_up_parent_fee_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
            "lago_subscription_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
            "lago_customer_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
            "external_customer_id": "external_id",
            "external_subscription_id": "external_id",
            "amount_cents": 100,
            "precise_amount": "1.0001",
            "precise_total_amount": "1.0212",
            "amount_currency": "USD",
            "taxes_amount_cents": 20,
            "taxes_precise_amount": "0.20123",
            "taxes_rate": 20,
            "units": "0.32",
            "precise_unit_amount": "312.5",
            "total_aggregated_units": "0.32",
            "total_amount_cents": 120,
            "total_amount_currency": "USD",
            "events_count": 23,
            "pay_in_advance": true,
            "invoiceable": true,
            "from_date": "2022-04-29T08:59:51Z",
            "to_date": "2022-05-29T08:59:51Z",
            "payment_status": "pending",
            "created_at": "2022-08-24T14:58:59Z",
            "succeeded_at": "2022-08-24T14:58:59Z",
            "failed_at": "2022-08-24T14:58:59Z",
            "refunded_at": "2022-08-24T14:58:59Z",
            "event_transaction_id": "transaction_1234567890",
            "description": "Fee description",
            "precise_coupons_amount_cents": "0.0",
            "sub_total_excluding_taxes_amount_cents": 100,
            "sub_total_excluding_taxes_precise_amount_cents": "100.0",
            "amount_details": {},
            "self_billed": false,
            "item": {},
            "applied_taxes": [],
            "pricing_unit_details": {},
            "presentation_breakdowns": []
          }
        }
      ],
      "applied_taxes": [
        {
          "lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
          "lago_tax_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
          "tax_name": "TVA",
          "tax_code": "french_standard_vat",
          "tax_rate": 20,
          "tax_description": "French standard VAT",
          "amount_cents": 2000,
          "amount_currency": "USD",
          "created_at": "2022-09-14T16:35:31Z"
        }
      ],
      "self_billed": false,
      "customer": {
        "lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
        "sequential_id": 1,
        "slug": "LAG-1234-001",
        "external_id": "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba",
        "billing_entity_code": "acme_corp",
        "address_line1": "5230 Penfield Ave",
        "address_line2": null,
        "applicable_timezone": "America/Los_Angeles",
        "city": "Woodland Hills",
        "country": "US",
        "currency": "USD",
        "email": "dinesh@piedpiper.test",
        "legal_name": "Coleman-Blair",
        "legal_number": "49-008-2965",
        "logo_url": "http://hooli.com/logo.png",
        "name": "Gavin Belson",
        "firstname": "Gavin",
        "lastname": "Belson",
        "account_type": "customer",
        "customer_type": "company",
        "phone": "1-171-883-3711 x245",
        "state": "CA",
        "tax_identification_number": "EU123456789",
        "timezone": "America/Los_Angeles",
        "url": "http://hooli.com",
        "zipcode": "91364",
        "net_payment_term": 30,
        "external_salesforce_id": "0015p00001JQx1QAAT",
        "created_at": "2022-04-29T08:59:51Z",
        "updated_at": "2022-04-29T08:59:51Z",
        "finalize_zero_amount_invoice": "inherit",
        "skip_invoice_custom_sections": false,
        "billing_configuration": {
          "invoice_grace_period": 3,
          "subscription_invoice_issuing_date_anchor": "next_period_start",
          "subscription_invoice_issuing_date_adjustment": "keep_anchor",
          "payment_provider": "stripe",
          "payment_provider_code": "stripe-eu-1",
          "provider_customer_id": "cus_12345",
          "sync": true,
          "sync_with_provider": true,
          "document_locale": "fr",
          "provider_payment_methods": [
            "card",
            "sepa_debit",
            "us_bank_account",
            "bacs_debit",
            "link",
            "boleto",
            "crypto",
            "customer_balance"
          ]
        },
        "shipping_address": {
          "address_line1": "5230 Penfield Ave",
          "address_line2": null,
          "city": "Woodland Hills",
          "country": "US",
          "state": "CA",
          "zipcode": "91364"
        },
        "metadata": [
          {
            "lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
            "key": "Purchase Order",
            "value": "123456789",
            "display_in_invoice": true,
            "created_at": "2022-04-29T08:59:51Z"
          }
        ],
        "integration_customers": [
          {
            "lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
            "type": "netsuite",
            "integration_code": "netsuite-eu-1",
            "external_customer_id": "cus_12345",
            "sync_with_provider": true,
            "subsidiary_id": "2",
            "targeted_object": "contacts",
            "email": "dinesh@piedpiper.test"
          }
        ]
      },
      "metadata": {
        "external_id": "ext-123",
        "synced_at": "2024-01-15",
        "source": null
      },
      "error_details": null
    }
  }
  ```
</ResponseExample>
