-
Notifications
You must be signed in to change notification settings - Fork 0
/
pricing_preview.go
139 lines (125 loc) · 7.49 KB
/
pricing_preview.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Code generated by the Paddle SDK Generator; DO NOT EDIT.
package paddle
import "context"
// PricePreviewItem: List of items to preview price calculations for.
type PricePreviewItem struct {
// PriceID: Paddle ID for the price to add to this transaction, prefixed with `pri_`.
PriceID string `json:"price_id,omitempty"`
// Quantity: Quantity of the item to preview.
Quantity int `json:"quantity,omitempty"`
}
// UnitTotalsFormatted: Breakdown of the charge for one unit in the format of a given currency.
type UnitTotalsFormatted struct {
// Subtotal: Unit price.
Subtotal string `json:"subtotal,omitempty"`
/*
Discount: Total discount as a result of any discounts applied.
Except for percentage discounts, Paddle applies tax to discounts based on the line item `price.tax_mode`. If `price.tax_mode` for a line item is `internal`, Paddle removes tax from the discount applied.
*/
Discount string `json:"discount,omitempty"`
// Tax: Total tax on the subtotal.
Tax string `json:"tax,omitempty"`
// Total: Total after discount and tax.
Total string `json:"total,omitempty"`
}
// TotalsFormatted: The financial breakdown of a charge in the format of a given currency.
type TotalsFormatted struct {
// Subtotal: The amount times the quantity.
Subtotal string `json:"subtotal,omitempty"`
/*
Discount: The amount discounted due to a discount code or ID being applied.
Except for percentage discounts, Paddle applies tax to discounts based on the line item `price.tax_mode`. If `price.tax_mode` for a line item is `internal`, Paddle removes tax from the discount applied.
*/
Discount string `json:"discount,omitempty"`
// Tax: The amount of tax due on the subtotal.
Tax string `json:"tax,omitempty"`
// Total: The subtotal - discount + tax.
Total string `json:"total,omitempty"`
}
// PricePreviewDiscounts: Array of discounts applied to this preview line item. Empty if no discounts applied.
type PricePreviewDiscounts struct {
// Discount: Related discount entity for this preview line item.
Discount Discount `json:"discount,omitempty"`
// Total: Total amount discounted as a result of this discount.
Total string `json:"total,omitempty"`
// FormattedTotal: Total amount discounted as a result of this discount in the format of a given currency. '
FormattedTotal string `json:"formatted_total,omitempty"`
}
// PricePreviewLineItem: Information about line items for this preview. Includes totals calculated by Paddle. Considered the source of truth for line item totals.
type PricePreviewLineItem struct {
// Price: Related price entity for this preview line item.
Price Price `json:"price,omitempty"`
// Quantity: Quantity of this preview line item.
Quantity int `json:"quantity,omitempty"`
// TaxRate: Rate used to calculate tax for this preview line item.
TaxRate string `json:"tax_rate,omitempty"`
// UnitTotals: Breakdown of the charge for one unit in the lowest denomination of a currency (e.g. cents for USD).
UnitTotals UnitTotals `json:"unit_totals,omitempty"`
// FormattedUnitTotals: Breakdown of the charge for one unit in the format of a given currency.
FormattedUnitTotals UnitTotalsFormatted `json:"formatted_unit_totals,omitempty"`
// Totals: Breakdown of a charge in the lowest denomination of a currency (e.g. cents for USD).
Totals Totals `json:"totals,omitempty"`
// FormattedTotals: The financial breakdown of a charge in the format of a given currency.
FormattedTotals TotalsFormatted `json:"formatted_totals,omitempty"`
// Product: Related product entity for this preview line item price.
Product Product `json:"product,omitempty"`
// Discounts: Array of discounts applied to this preview line item. Empty if no discounts applied.
Discounts []PricePreviewDiscounts `json:"discounts,omitempty"`
}
// PricePreviewDetails: Calculated totals for a price preview, including discounts, tax, and currency conversion.
type PricePreviewDetails struct {
// LineItems: Information about line items for this preview. Includes totals calculated by Paddle. Considered the source of truth for line item totals.
LineItems []PricePreviewLineItem `json:"line_items,omitempty"`
}
type PricePreview struct {
// CustomerID: Paddle ID of the customer that this preview is for, prefixed with `ctm_`.
CustomerID *string `json:"customer_id,omitempty"`
// AddressID: Paddle ID of the address that this preview is for, prefixed with `add_`. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
AddressID *string `json:"address_id,omitempty"`
// BusinessID: Paddle ID of the business that this preview is for, prefixed with `biz_`.
BusinessID *string `json:"business_id,omitempty"`
// CurrencyCode: Supported three-letter ISO 4217 currency code.
CurrencyCode CurrencyCode `json:"currency_code,omitempty"`
// DiscountID: Paddle ID of the discount applied to this preview, prefixed with `dsc_`.
DiscountID *string `json:"discount_id,omitempty"`
// Address: Address for this preview. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
Address *AddressPreview `json:"address,omitempty"`
// CustomerIPAddress: IP address for this transaction preview. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
CustomerIPAddress *string `json:"customer_ip_address,omitempty"`
// Items: List of items to preview price calculations for.
Items []PricePreviewItem `json:"items,omitempty"`
// Details: Calculated totals for a price preview, including discounts, tax, and currency conversion.
Details PricePreviewDetails `json:"details,omitempty"`
// AvailablePaymentMethods: List of available payment methods for Paddle Checkout given the price and location information passed.
AvailablePaymentMethods PaymentMethodType `json:"available_payment_methods,omitempty"`
}
// PricingPreviewClient is a client for the Pricing preview resource.
type PricingPreviewClient struct {
doer Doer
}
// PricePreviewRequest is given as an input to PricePreview.
type PricePreviewRequest struct {
// Items: List of items to preview price calculations for.
Items []PricePreviewItem `json:"items,omitempty"`
// CustomerID: Paddle ID of the customer that this preview is for, prefixed with `ctm_`.
CustomerID *string `json:"customer_id,omitempty"`
// AddressID: Paddle ID of the address that this preview is for, prefixed with `add_`. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
AddressID *string `json:"address_id,omitempty"`
// BusinessID: Paddle ID of the business that this preview is for, prefixed with `biz_`.
BusinessID *string `json:"business_id,omitempty"`
// CurrencyCode: Supported three-letter ISO 4217 currency code.
CurrencyCode *CurrencyCode `json:"currency_code,omitempty"`
// DiscountID: Paddle ID of the discount applied to this preview, prefixed with `dsc_`.
DiscountID *string `json:"discount_id,omitempty"`
// Address: Address for this preview. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
Address *AddressPreview `json:"address,omitempty"`
// CustomerIPAddress: IP address for this transaction preview. Send one of `address_id`, `customer_ip_address`, or the `address` object when previewing.
CustomerIPAddress *string `json:"customer_ip_address,omitempty"`
}
// PricePreview performs the POST operation on a Pricing preview resource.
func (c *PricingPreviewClient) PricePreview(ctx context.Context, req *PricePreviewRequest) (res *PricePreview, err error) {
if err := c.doer.Do(ctx, "POST", "/pricing-preview", req, &res); err != nil {
return nil, err
}
return res, nil
}