Paddle.TransactionPreview()
Generates 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 are previews of transaction entities, 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()
method instead.
Unlike pricing previews returned when using Paddle.PricePreview()
, transaction previews return overall 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 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
.
Requires a client-side token for authentication. If you're passing the older
seller
parameter toPaddle.Initialize()
, replace this withtoken
to usePaddle.TransactionPreview()
.
Parameters
Transaction preview request body. Must include an items
array.
Check the preview a transaction operation 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.
12345678910111213141516171819201var request = {
2 items: [
3 {
4 quantity: 20,
5 priceId: "pri_01gsz8z1q1n00f12qt82y31smh"
6 },
7 {
8 quantity: 1,
9 priceId: "pri_01gsz98e27ak2tyhexptwc58yk",
10 includeInTotals: false
11 }
12 ],
13 discountId: "dsc_01gtgztp8fpchantd5g1wrksa3",
14 address: {
15 countryCode: "US"
16 },
17 currencyCode: "USD"
18}
19
20Paddle.TransactionPreview(request)