# Preview an invoice

Learn how to create a preview of an invoice.

You can create a preview of an invoice for your customer while they’re considering a purchase. [Create a preview](https://docs.stripe.com/api/invoices/create_preview.md) to calculate the total invoice amount, retrieve each invoice line, and include any relevant taxes or discounts. Creating a preview allows you to show the total payment amount to your customer without the need to create an invoice.

For example, if you operate a company that provides repair services to businesses, you might present your customers with multiple items that each have different prices and billing schedules:

- Item 1: 299 USD one-time service fee
- Item 2: 29 USD repair material A
- Item 3: 99 USD repair material B
- Item 4: 49 USD per month support plan

Customers might want to know how much different combinations of your goods and services cost. If they intend to purchase items 1 and 3 while applying the `WINTERSALE` promo code for 15% off, run the following API call:

```curl
curl https://api.stripe.com/v1/invoices/create_preview \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "invoice_items[0][price]={{SERVICE_FEE_PRICE_ID}}" \
  -d "invoice_items[0][quantity]=1" \
  -d "invoice_items[1][price]={{MATERIAL_B_PRICE_ID}}" \
  -d "invoice_items[1][quantity]=1" \
  -d "discounts[0][promotion_code]=promo_WINTERSALE"
```

Stripe returns an [invoice](https://docs.stripe.com/api/invoices/object.md) preview with each of the lines, with the discount applied, and the total amount:

```json
{
  "id": "{{INVOICE_ID}}",
  "object": "invoice",
  "account_country": "US",
  "account_name": null,
  "account_tax_ids": null,
  "amount_due": 33830,
  "amount_overpaid": 0,
  "amount_paid": 0,
  "amount_remaining": 33830,
  "amount_shipping": 0,
  "application": null,
  "attempt_count": 0,
  "attempted": false,
  "auto_advance": false,
  "automatic_tax": {
    "disabled_reason": null,
    "enabled": false,
    "liability": null,
    "provider": null,
    "status": null
  },
  "automatically_finalizes_at": null,
  "billing_reason": "upcoming",
  "collection_method": "charge_automatically",
  "created": 1793926511,
  "currency": "usd",
  "custom_fields": null,
  "customer": "cus_VZkwoBt9JeA10b",
  "customer_account": null,
  "customer_address": null,
  "customer_email": null,
  "customer_name": null,
  "customer_phone": null,
  "customer_shipping": null,
  "customer_tax_exempt": "none",
  "customer_tax_ids": [],
  "default_payment_method": null,
  "default_source": null,
  "default_tax_rates": [],
  "description": null,
  "discounts": [
    "di_1UYbQxClCIKljWvs0sejpmk2"
  ],
  "due_date": null,
  "effective_at": null,
  "ending_balance": 0,
  "footer": null,
  "from_invoice": null,
  "hosted_invoice_url": null,
  "invoice_pdf": null,
  "issuer": {
    "type": "self"
  },
  "last_finalization_error": null,
  "latest_revision": null,
  "lines": {
    "object": "list",
    "data": [
      {
        "id": "il_tmp_171a54ClCIKljWvsd42c7f4e",
        "object": "line_item",
        "amount": 9900,
        "currency": "usd",
        "description": "Item 3",
        "discount_amounts": [
          {
            "amount": 1485,
            "discount": "di_1UYbQxClCIKljWvs0sejpmk2"
          }
        ],
        "discountable": true,
        "discounts": [],
        "invoice": "{{INVOICE_ID}}",
        "livemode": false,
        "metadata": {},
        "parent": {
          "invoice_item_details": {
            "invoice_item": "ii_1UYbQxClCIKljWvsIkn0CwLN",
            "proration": false,
            "proration_details": {
              "credited_items": null
            },
            "subscription": null
          },
          "subscription_item_details": null,
          "type": "invoice_item_details"
        },
        "period": {
          "end": 1793926511,
          "start": 1793926511
        },
        "pretax_credit_amounts": [
          {
            "amount": 1485,
            "discount": "di_1UYbQxClCIKljWvs0sejpmk2",
            "type": "discount"
          }
        ],
        "pricing": {
          "price_details": {
            "price": "{{MATERIAL_B_PRICE_ID}}",
            "product": "prod_VZkwO0PzYHJ2FX"
          },
          "type": "price_details",
          "unit_amount_decimal": "9900"
        },
        "quantity": 1,
        "quantity_decimal": "1",
        "subtotal": 9900,
        "taxes": []
      },
      {
        "id": "il_tmp_1fc7a7ClCIKljWvsfd97b7ac",
        "object": "line_item",
        "amount": 29900,
        "currency": "usd",
        "description": "Item 1",
        "discount_amounts": [
          {
            "amount": 4485,
            "discount": "di_1UYbQxClCIKljWvs0sejpmk2"
          }
        ],
        "discountable": true,
        "discounts": [],
        "invoice": "{{INVOICE_ID}}",
        "livemode": false,
        "metadata": {},
        "parent": {
          "invoice_item_details": {
            "invoice_item": "ii_1UYbQxClCIKljWvstH2C8C9E",
            "proration": false,
            "proration_details": {
              "credited_items": null
            },
            "subscription": null
          },
          "subscription_item_details": null,
          "type": "invoice_item_details"
        },
        "period": {
          "end": 1793926511,
          "start": 1793926511
        },
        "pretax_credit_amounts": [
          {
            "amount": 4485,
            "discount": "di_1UYbQxClCIKljWvs0sejpmk2",
            "type": "discount"
          }
        ],
        "pricing": {
          "price_details": {
            "price": "{{SERVICE_FEE_PRICE_ID}}",
            "product": "prod_VZkwyWYobe0cC4"
          },
          "type": "price_details",
          "unit_amount_decimal": "29900"
        },
        "quantity": 1,
        "quantity_decimal": "1",
        "subtotal": 29900,
        "taxes": []
      }
    ],
    "has_more": false,
    "total_count": 2,
    "url": "/v1/invoices/{{INVOICE_ID}}/lines"
  },
  "livemode": false,
  "metadata": {},
  "next_payment_attempt": null,
  "number": null,
  "on_behalf_of": null,
  "parent": null,
  "payment_settings": {
    "default_mandate": null,
    "payment_method_options": null,
    "payment_method_types": null
  },
  "period_end": 1793926511,
  "period_start": 1793926511,
  "post_payment_credit_notes_amount": 0,
  "pre_payment_credit_notes_amount": 0,
  "receipt_number": null,
  "rendering": null,
  "shipping_cost": null,
  "shipping_details": null,
  "starting_balance": 0,
  "statement_descriptor": null,
  "status": "draft",
  "status_transitions": {
    "finalized_at": null,
    "marked_uncollectible_at": null,
    "paid_at": null,
    "voided_at": null
  },
  "subtotal": 39800,
  "subtotal_excluding_tax": 39800,
  "test_clock": null,
  "total": 33830,
  "total_discount_amounts": [
    {
      "amount": 5970,
      "discount": "di_1UYbQxClCIKljWvs0sejpmk2"
    }
  ],
  "total_excluding_tax": 33830,
  "total_pretax_credit_amounts": [
    {
      "amount": 5970,
      "discount": "di_1UYbQxClCIKljWvs0sejpmk2",
      "type": "discount"
    }
  ],
  "total_taxes": [],
  "webhooks_delivered_at": null
}
```

Additionally, the resulting invoice preview can be retrieved through the [/v1/invoices/:id](https://docs.stripe.com/api/invoices/retrieve.md) endpoint for the following 72 hours:

```curl
curl https://api.stripe.com/v1/invoices/{{INVOICE_ID}} \
  -u "<<YOUR_SECRET_KEY>>:"
```

## Include Stripe Tax

To preview tax amounts from Stripe Tax, set `automatic_tax[enabled] = true` and pass the customer’s address in `customer_details[address]`.

Alternatively, you can pass in an IP address in `customer_details[tax][ip_address]` instead if you don’t have the customer’s address. In most cases, Stripe can resolve an IP address to a physical area, but its precision varies and might not reflect your customer’s actual location. We don’t recommend relying on a customer’s IP address to determine their address beyond an initial estimate.

```curl
curl https://api.stripe.com/v1/invoices/create_preview \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "customer_details[address][line1]=920 5th Ave" \
  -d "customer_details[address][city]=Seattle" \
  -d "customer_details[address][state]=WA" \
  -d "customer_details[address][postal_code]=98104" \
  -d "customer_details[address][country]=US" \
  -d "automatic_tax[enabled]=true" \
  -d "invoice_items[0][price]={{SERVICE_FEE_PRICE_ID}}" \
  -d "invoice_items[0][quantity]=1" \
  -d "invoice_items[1][price]={{MATERIAL_B_PRICE_ID}}" \
  -d "invoice_items[1][quantity]=1" \
  -d "discounts[0][promotion_code]=promo_WINTERSALE"
```

## Preview invoices with subscriptions

To preview the first invoice with a recurring price, use the [subscription_details.items](https://docs.stripe.com/api/invoices/create_preview.md#create_create_preview-subscription_details-items) parameter:

```curl
curl https://api.stripe.com/v1/invoices/create_preview \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "subscription_details[items][0][price]={{SUPPORT_PLAN_PRICE_ID}}" \
  -d "subscription_details[items][0][quantity]=1" \
  -d "invoice_items[0][price]={{SERVICE_FEE_PRICE_ID}}" \
  -d "invoice_items[0][quantity]=1" \
  -d "invoice_items[1][price]={{MATERIAL_B_PRICE_ID}}" \
  -d "invoice_items[1][quantity]=1" \
  -d "discounts[0][promotion_code]=promo_WINTERSALE"
```

To preview changes to an existing subscription, provide the [subscription or subscription schedule ID](https://docs.stripe.com/billing/subscriptions/subscription-schedules.md#preview-an-invoice).

## Preview the recurring charges only

Your customer might want a recurring subscription along with one-off items, or temporary credits or discounts to use with their purchase. If they want to know what the recurring charges are after any adjustments, use the [preview_mode](https://docs.stripe.com/api/invoices/create_preview.md#create_create_preview-preview_mode) parameter to offer them a preview of the total.

For example, if `WINTERSALE` is a one-time 15% discount and the customer wants to purchase items 1, 3, and 4, you can retrieve the recurring charge amount with this API call:

```curl
curl https://api.stripe.com/v1/invoices/create_preview \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d preview_mode=recurring \
  -d "subscription_details[items][0][price]={{SUPPORT_PLAN_PRICE_ID}}" \
  -d "subscription_details[items][0][quantity]=1" \
  -d "invoice_items[0][price]={{SERVICE_FEE_PRICE_ID}}" \
  -d "invoice_items[0][quantity]=1" \
  -d "invoice_items[1][price]={{MATERIAL_B_PRICE_ID}}" \
  -d "invoice_items[1][quantity]=1" \
  -d "discounts[0][promotion_code]=promo_WINTERSALE"
```

The resulting invoice only contains the 49 USD per month support plan with no discounts. Similarly, you can combine `preview_mode` with `subscription` or `subscription_schedule` to display the expected recurring charge, excluding one-off items and discounts.

## Invoice Line pagination

For invoices with more than 10 lines, you can [retrieve a paginated view of the lines](https://docs.stripe.com/api/invoice-line-item/retrieve.md):

```curl
curl https://api.stripe.com/v1/invoices/{{INVOICE_ID}}/lines \
  -u "<<YOUR_SECRET_KEY>>:"
```
