github.com/stripe/stripe-go/v76@v76.25.0/product.go (about)

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  package stripe
     8  
     9  import (
    10  	"encoding/json"
    11  	"github.com/stripe/stripe-go/v76/form"
    12  )
    13  
    14  // The type of the product. The product is either of type `good`, which is eligible for use with Orders and SKUs, or `service`, which is eligible for use with Subscriptions and Plans.
    15  type ProductType string
    16  
    17  // List of values that ProductType can take
    18  const (
    19  	ProductTypeGood    ProductType = "good"
    20  	ProductTypeService ProductType = "service"
    21  )
    22  
    23  // Delete a product. Deleting a product is only possible if it has no prices associated with it. Additionally, deleting a product with type=good is only possible if it has no SKUs associated with it.
    24  type ProductParams struct {
    25  	Params `form:"*"`
    26  	// Whether the product is currently available for purchase. Defaults to `true`.
    27  	Active *bool `form:"active"`
    28  	// The ID of the [Price](https://stripe.com/docs/api/prices) object that is the default price for this product.
    29  	DefaultPrice *string `form:"default_price"`
    30  	// Data used to generate a new [Price](https://stripe.com/docs/api/prices) object. This Price will be set as the default price for this product.
    31  	DefaultPriceData *ProductDefaultPriceDataParams `form:"default_price_data"`
    32  	// The product's description, meant to be displayable to the customer. Use this field to optionally store a long form explanation of the product being sold for your own rendering purposes.
    33  	Description *string `form:"description"`
    34  	// Specifies which fields in the response should be expanded.
    35  	Expand []*string `form:"expand"`
    36  	// A list of up to 15 marketing features for this product. These are displayed in [pricing tables](https://stripe.com/docs/payments/checkout/pricing-table).
    37  	Features []*ProductFeatureParams `form:"features"`
    38  	// An identifier will be randomly generated by Stripe. You can optionally override this ID, but the ID must be unique across all products in your Stripe account.
    39  	ID *string `form:"id"`
    40  	// A list of up to 8 URLs of images for this product, meant to be displayable to the customer.
    41  	Images []*string `form:"images"`
    42  	// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`.
    43  	Metadata map[string]string `form:"metadata"`
    44  	// The product's name, meant to be displayable to the customer.
    45  	Name *string `form:"name"`
    46  	// The dimensions of this product for shipping purposes.
    47  	PackageDimensions *ProductPackageDimensionsParams `form:"package_dimensions"`
    48  	// Whether this product is shipped (i.e., physical goods).
    49  	Shippable *bool `form:"shippable"`
    50  	// An arbitrary string to be displayed on your customer's credit card or bank statement. While most banks display this information consistently, some may display it incorrectly or not at all.
    51  	//
    52  	// This may be up to 22 characters. The statement description may not include `<`, `>`, `\`, `"`, `'` characters, and will appear on your customer's statement in capital letters. Non-ASCII characters are automatically stripped.
    53  	//  It must contain at least one letter. May only be set if `type=service`.
    54  	StatementDescriptor *string `form:"statement_descriptor"`
    55  	// A [tax code](https://stripe.com/docs/tax/tax-categories) ID.
    56  	TaxCode *string `form:"tax_code"`
    57  	// The type of the product. Defaults to `service` if not explicitly specified, enabling use of this product with Subscriptions and Plans. Set this parameter to `good` to use this product with Orders and SKUs. On API versions before `2018-02-05`, this field defaults to `good` for compatibility reasons.
    58  	Type *string `form:"type"`
    59  	// A label that represents units of this product. When set, this will be included in customers' receipts, invoices, Checkout, and the customer portal. May only be set if `type=service`.
    60  	UnitLabel *string `form:"unit_label"`
    61  	// A URL of a publicly-accessible webpage for this product.
    62  	URL *string `form:"url"`
    63  }
    64  
    65  // AddExpand appends a new field to expand.
    66  func (p *ProductParams) AddExpand(f string) {
    67  	p.Expand = append(p.Expand, &f)
    68  }
    69  
    70  // AddMetadata adds a new key-value pair to the Metadata.
    71  func (p *ProductParams) AddMetadata(key string, value string) {
    72  	if p.Metadata == nil {
    73  		p.Metadata = make(map[string]string)
    74  	}
    75  
    76  	p.Metadata[key] = value
    77  }
    78  
    79  // A list of up to 15 marketing features for this product. These are displayed in [pricing tables](https://stripe.com/docs/payments/checkout/pricing-table).
    80  type ProductFeatureParams struct {
    81  	// The marketing feature name. Up to 80 characters long.
    82  	Name *string `form:"name"`
    83  }
    84  
    85  // The dimensions of this product for shipping purposes.
    86  type ProductPackageDimensionsParams struct {
    87  	// Height, in inches. Maximum precision is 2 decimal places.
    88  	Height *float64 `form:"height"`
    89  	// Length, in inches. Maximum precision is 2 decimal places.
    90  	Length *float64 `form:"length"`
    91  	// Weight, in ounces. Maximum precision is 2 decimal places.
    92  	Weight *float64 `form:"weight"`
    93  	// Width, in inches. Maximum precision is 2 decimal places.
    94  	Width *float64 `form:"width"`
    95  }
    96  
    97  // Returns a list of your products. The products are returned sorted by creation date, with the most recently created products appearing first.
    98  type ProductListParams struct {
    99  	ListParams `form:"*"`
   100  	// Only return products that are active or inactive (e.g., pass `false` to list all inactive products).
   101  	Active *bool `form:"active"`
   102  	// Only return products that were created during the given date interval.
   103  	Created *int64 `form:"created"`
   104  	// Only return products that were created during the given date interval.
   105  	CreatedRange *RangeQueryParams `form:"created"`
   106  	// Specifies which fields in the response should be expanded.
   107  	Expand []*string `form:"expand"`
   108  	// Only return products with the given IDs. Cannot be used with [starting_after](https://stripe.com/docs/api#list_products-starting_after) or [ending_before](https://stripe.com/docs/api#list_products-ending_before).
   109  	IDs []*string `form:"ids"`
   110  	// Only return products that can be shipped (i.e., physical, not digital products).
   111  	Shippable *bool `form:"shippable"`
   112  	// Only return products of this type.
   113  	Type *string `form:"type"`
   114  	// Only return products with the given url.
   115  	URL *string `form:"url"`
   116  }
   117  
   118  // AddExpand appends a new field to expand.
   119  func (p *ProductListParams) AddExpand(f string) {
   120  	p.Expand = append(p.Expand, &f)
   121  }
   122  
   123  // When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
   124  type ProductDefaultPriceDataCurrencyOptionsCustomUnitAmountParams struct {
   125  	// Pass in `true` to enable `custom_unit_amount`, otherwise omit `custom_unit_amount`.
   126  	Enabled *bool `form:"enabled"`
   127  	// The maximum unit amount the customer can specify for this item.
   128  	Maximum *int64 `form:"maximum"`
   129  	// The minimum unit amount the customer can specify for this item. Must be at least the minimum charge amount.
   130  	Minimum *int64 `form:"minimum"`
   131  	// The starting unit amount which can be updated by the customer.
   132  	Preset *int64 `form:"preset"`
   133  }
   134  
   135  // Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`.
   136  type ProductDefaultPriceDataCurrencyOptionsTierParams struct {
   137  	// The flat billing amount for an entire tier, regardless of the number of units in the tier.
   138  	FlatAmount *int64 `form:"flat_amount"`
   139  	// Same as `flat_amount`, but accepts a decimal value representing an integer in the minor units of the currency. Only one of `flat_amount` and `flat_amount_decimal` can be set.
   140  	FlatAmountDecimal *float64 `form:"flat_amount_decimal,high_precision"`
   141  	// The per unit billing amount for each individual unit for which this tier applies.
   142  	UnitAmount *int64 `form:"unit_amount"`
   143  	// Same as `unit_amount`, but accepts a decimal value in cents (or local equivalent) with at most 12 decimal places. Only one of `unit_amount` and `unit_amount_decimal` can be set.
   144  	UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"`
   145  	// Specifies the upper bound of this tier. The lower bound of a tier is the upper bound of the previous tier adding one. Use `inf` to define a fallback tier.
   146  	UpTo    *int64 `form:"up_to"`
   147  	UpToInf *bool  `form:"-"` // See custom AppendTo
   148  }
   149  
   150  // AppendTo implements custom encoding logic for ProductDefaultPriceDataCurrencyOptionsTierParams.
   151  func (p *ProductDefaultPriceDataCurrencyOptionsTierParams) AppendTo(body *form.Values, keyParts []string) {
   152  	if BoolValue(p.UpToInf) {
   153  		body.Add(form.FormatKey(append(keyParts, "up_to")), "inf")
   154  	}
   155  }
   156  
   157  // Prices defined in each available currency option. Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies).
   158  type ProductDefaultPriceDataCurrencyOptionsParams struct {
   159  	// When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
   160  	CustomUnitAmount *ProductDefaultPriceDataCurrencyOptionsCustomUnitAmountParams `form:"custom_unit_amount"`
   161  	// Only required if a [default tax behavior](https://stripe.com/docs/tax/products-prices-tax-categories-tax-behavior#setting-a-default-tax-behavior-(recommended)) was not provided in the Stripe Tax settings. Specifies whether the price is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. Once specified as either `inclusive` or `exclusive`, it cannot be changed.
   162  	TaxBehavior *string `form:"tax_behavior"`
   163  	// Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`.
   164  	Tiers []*ProductDefaultPriceDataCurrencyOptionsTierParams `form:"tiers"`
   165  	// A positive integer in cents (or local equivalent) (or 0 for a free price) representing how much to charge.
   166  	UnitAmount *int64 `form:"unit_amount"`
   167  	// Same as `unit_amount`, but accepts a decimal value in cents (or local equivalent) with at most 12 decimal places. Only one of `unit_amount` and `unit_amount_decimal` can be set.
   168  	UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"`
   169  }
   170  
   171  // The recurring components of a price such as `interval` and `interval_count`.
   172  type ProductDefaultPriceDataRecurringParams struct {
   173  	// Specifies billing frequency. Either `day`, `week`, `month` or `year`.
   174  	Interval *string `form:"interval"`
   175  	// The number of intervals between subscription billings. For example, `interval=month` and `interval_count=3` bills every 3 months. Maximum of three years interval allowed (3 years, 36 months, or 156 weeks).
   176  	IntervalCount *int64 `form:"interval_count"`
   177  }
   178  
   179  // Data used to generate a new [Price](https://stripe.com/docs/api/prices) object. This Price will be set as the default price for this product.
   180  type ProductDefaultPriceDataParams struct {
   181  	// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
   182  	Currency *string `form:"currency"`
   183  	// Prices defined in each available currency option. Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies).
   184  	CurrencyOptions map[string]*ProductDefaultPriceDataCurrencyOptionsParams `form:"currency_options"`
   185  	// The recurring components of a price such as `interval` and `interval_count`.
   186  	Recurring *ProductDefaultPriceDataRecurringParams `form:"recurring"`
   187  	// Only required if a [default tax behavior](https://stripe.com/docs/tax/products-prices-tax-categories-tax-behavior#setting-a-default-tax-behavior-(recommended)) was not provided in the Stripe Tax settings. Specifies whether the price is considered inclusive of taxes or exclusive of taxes. One of `inclusive`, `exclusive`, or `unspecified`. Once specified as either `inclusive` or `exclusive`, it cannot be changed.
   188  	TaxBehavior *string `form:"tax_behavior"`
   189  	// A positive integer in cents (or local equivalent) (or 0 for a free price) representing how much to charge. One of `unit_amount` or `unit_amount_decimal` is required.
   190  	UnitAmount *int64 `form:"unit_amount"`
   191  	// Same as `unit_amount`, but accepts a decimal value in cents (or local equivalent) with at most 12 decimal places. Only one of `unit_amount` and `unit_amount_decimal` can be set.
   192  	UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"`
   193  }
   194  
   195  // Search for products you've previously created using Stripe's [Search Query Language](https://stripe.com/docs/search#search-query-language).
   196  // Don't use search in read-after-write flows where strict consistency is necessary. Under normal operating
   197  // conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up
   198  // to an hour behind during outages. Search functionality is not available to merchants in India.
   199  type ProductSearchParams struct {
   200  	SearchParams `form:"*"`
   201  	// Specifies which fields in the response should be expanded.
   202  	Expand []*string `form:"expand"`
   203  	// A cursor for pagination across multiple pages of results. Don't include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
   204  	Page *string `form:"page"`
   205  }
   206  
   207  // AddExpand appends a new field to expand.
   208  func (p *ProductSearchParams) AddExpand(f string) {
   209  	p.Expand = append(p.Expand, &f)
   210  }
   211  
   212  // A list of up to 15 marketing features for this product. These are displayed in [pricing tables](https://stripe.com/docs/payments/checkout/pricing-table).
   213  type ProductFeature struct {
   214  	// The marketing feature name. Up to 80 characters long.
   215  	Name string `json:"name"`
   216  }
   217  
   218  // The dimensions of this product for shipping purposes.
   219  type ProductPackageDimensions struct {
   220  	// Height, in inches.
   221  	Height float64 `json:"height"`
   222  	// Length, in inches.
   223  	Length float64 `json:"length"`
   224  	// Weight, in ounces.
   225  	Weight float64 `json:"weight"`
   226  	// Width, in inches.
   227  	Width float64 `json:"width"`
   228  }
   229  
   230  // Products describe the specific goods or services you offer to your customers.
   231  // For example, you might offer a Standard and Premium version of your goods or service; each version would be a separate Product.
   232  // They can be used in conjunction with [Prices](https://stripe.com/docs/api#prices) to configure pricing in Payment Links, Checkout, and Subscriptions.
   233  //
   234  // Related guides: [Set up a subscription](https://stripe.com/docs/billing/subscriptions/set-up-subscription),
   235  // [share a Payment Link](https://stripe.com/docs/payment-links),
   236  // [accept payments with Checkout](https://stripe.com/docs/payments/accept-a-payment#create-product-prices-upfront),
   237  // and more about [Products and Prices](https://stripe.com/docs/products-prices/overview)
   238  type Product struct {
   239  	APIResource
   240  	// Whether the product is currently available for purchase.
   241  	Active bool `json:"active"`
   242  	// Time at which the object was created. Measured in seconds since the Unix epoch.
   243  	Created int64 `json:"created"`
   244  	// The ID of the [Price](https://stripe.com/docs/api/prices) object that is the default price for this product.
   245  	DefaultPrice *Price `json:"default_price"`
   246  	Deleted      bool   `json:"deleted"`
   247  	// The product's description, meant to be displayable to the customer. Use this field to optionally store a long form explanation of the product being sold for your own rendering purposes.
   248  	Description string `json:"description"`
   249  	// A list of up to 15 marketing features for this product. These are displayed in [pricing tables](https://stripe.com/docs/payments/checkout/pricing-table).
   250  	Features []*ProductFeature `json:"features"`
   251  	// Unique identifier for the object.
   252  	ID string `json:"id"`
   253  	// A list of up to 8 URLs of images for this product, meant to be displayable to the customer.
   254  	Images []string `json:"images"`
   255  	// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
   256  	Livemode bool `json:"livemode"`
   257  	// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
   258  	Metadata map[string]string `json:"metadata"`
   259  	// The product's name, meant to be displayable to the customer.
   260  	Name string `json:"name"`
   261  	// String representing the object's type. Objects of the same type share the same value.
   262  	Object string `json:"object"`
   263  	// The dimensions of this product for shipping purposes.
   264  	PackageDimensions *ProductPackageDimensions `json:"package_dimensions"`
   265  	// Whether this product is shipped (i.e., physical goods).
   266  	Shippable bool `json:"shippable"`
   267  	// Extra information about a product which will appear on your customer's credit card statement. In the case that multiple products are billed at once, the first statement descriptor will be used.
   268  	StatementDescriptor string `json:"statement_descriptor"`
   269  	// A [tax code](https://stripe.com/docs/tax/tax-categories) ID.
   270  	TaxCode *TaxCode `json:"tax_code"`
   271  	// The type of the product. The product is either of type `good`, which is eligible for use with Orders and SKUs, or `service`, which is eligible for use with Subscriptions and Plans.
   272  	Type ProductType `json:"type"`
   273  	// A label that represents units of this product. When set, this will be included in customers' receipts, invoices, Checkout, and the customer portal.
   274  	UnitLabel string `json:"unit_label"`
   275  	// Time at which the object was last updated. Measured in seconds since the Unix epoch.
   276  	Updated int64 `json:"updated"`
   277  	// A URL of a publicly-accessible webpage for this product.
   278  	URL string `json:"url"`
   279  }
   280  
   281  // ProductList is a list of Products as retrieved from a list endpoint.
   282  type ProductList struct {
   283  	APIResource
   284  	ListMeta
   285  	Data []*Product `json:"data"`
   286  }
   287  
   288  // ProductSearchResult is a list of Product search results as retrieved from a search endpoint.
   289  type ProductSearchResult struct {
   290  	APIResource
   291  	SearchMeta
   292  	Data []*Product `json:"data"`
   293  }
   294  
   295  // UnmarshalJSON handles deserialization of a Product.
   296  // This custom unmarshaling is needed because the resulting
   297  // property may be an id or the full struct if it was expanded.
   298  func (p *Product) UnmarshalJSON(data []byte) error {
   299  	if id, ok := ParseID(data); ok {
   300  		p.ID = id
   301  		return nil
   302  	}
   303  
   304  	type product Product
   305  	var v product
   306  	if err := json.Unmarshal(data, &v); err != nil {
   307  		return err
   308  	}
   309  
   310  	*p = Product(v)
   311  	return nil
   312  }