> For the complete documentation index, see [llms.txt](https://developer.paddle.com/llms.txt).

# Paddle.TransactionPreview()

Use to generate a transaction preview for prices and location information supplied.

---

Use `Paddle.TransactionPreview()` to return a transaction preview object for items and location information supplied.

[Transaction previews](https://developer.paddle.com/api-reference/transactions/preview-transaction.md) are previews of [transaction entities](https://developer.paddle.com/api-reference/transactions/overview.md), holding calculated totals for prices — including discounts, taxes, and currency conversion. They're typically used for building advanced, cart-style pricing pages where users can build their own plans. For simpler pricing pages, consider the [`Paddle.PricePreview()`](https://developer.paddle.com/paddle-js/methods/paddle-pricepreview.md) method instead.

Unlike [pricing previews](https://developer.paddle.com/paddle-js/methods/paddle-pricepreview.md) returned when using [`Paddle.PricePreview()`](https://developer.paddle.com/paddle-js/methods/paddle-pricepreview.md), transaction previews return both line item and grand totals for items passed. This means that they have the same validation logic as transactions, too. For example, all items must have the same billing period.

Accepts the same request body as [the preview a transaction operation](https://developer.paddle.com/api-reference/transactions/preview-transaction.md) in the Paddle API, except fields must be formatted as `camelCase` rather than `snake_case`.

Returns a promise that contains an object that matches the response from the preview a transaction operation. Field names are `camelCase` rather than `snake_case`.

{% callout type="note" %}
When location information is omitted, Paddle.js automatically detects visitor location using their IP address and returns localized prices.
{% /callout %}

## Parameters

```yaml
title: Paddle.TransactionPreview() parameters
type: object
properties:
  request:
    type: object
    description: >-
      Transaction preview request body. Must include an `items` array. Include location information to return localized
      prices, or omit to let Paddle.js automatically detect location.
```

Check [the preview a transaction operation](https://developer.paddle.com/api-reference/transactions/preview-transaction.md) documentation to learn about the fields you can send in a request. Convert `snake_case` field names to `camelCase`, as is convention for JavaScript.

## Examples

This example includes a request with two items where the country code is the United States and the currency code is `USD`. One of the items is excluded from the totals using the `includeInTotals` field. It also passes a discount.

The request is passed to `Paddle.TransactionPreview()`, which returns a promise. It prints the response to the console.

{% tabs sync="paddlejs-preference" %}
{% tab-item title="Using a script tag" %}

```js
var request = {
  items: [
    {
      quantity: 20,
      priceId: "pri_01gsz8z1q1n00f12qt82y31smh",
    },
    {
      quantity: 1,
      priceId: "pri_01gsz98e27ak2tyhexptwc58yk",
      includeInTotals: false,
    },
  ],
  discountId: "dsc_01gtgztp8fpchantd5g1wrksa3",
  address: {
    countryCode: "US",
  },
  currencyCode: "USD",
};

Paddle.TransactionPreview(request)
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });
```

{% /tab-item %}
{% tab-item title="Using a JavaScript package manager" %}

```ts
import { initializePaddle } from "@paddle/paddle-js";

const paddle = await initializePaddle({
  token: "live_7d279f61a3499fed520f7cd8c08",
});

const request = {
  items: [
    {
      quantity: 20,
      priceId: "pri_01gsz8z1q1n00f12qt82y31smh",
    },
    {
      quantity: 1,
      priceId: "pri_01gsz98e27ak2tyhexptwc58yk",
      includeInTotals: false,
    },
  ],
  discountId: "dsc_01gtgztp8fpchantd5g1wrksa3",
  address: {
    countryCode: "US",
  },
  currencyCode: "USD",
};

paddle
  ?.TransactionPreview(request)
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });
```

{% /tab-item %}
{% /tabs %}