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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  package stripe
     8  
     9  import "encoding/json"
    10  
    11  // A discount represents the actual application of a [coupon](https://stripe.com/docs/api#coupons) or [promotion code](https://stripe.com/docs/api#promotion_codes).
    12  // It contains information about when the discount began, when it will end, and what it is applied to.
    13  //
    14  // Related guide: [Applying discounts to subscriptions](https://stripe.com/docs/billing/subscriptions/discounts)
    15  type Discount struct {
    16  	// The Checkout session that this coupon is applied to, if it is applied to a particular session in payment mode. Will not be present for subscription mode.
    17  	CheckoutSession string `json:"checkout_session"`
    18  	// A coupon contains information about a percent-off or amount-off discount you
    19  	// might want to apply to a customer. Coupons may be applied to [subscriptions](https://stripe.com/docs/api#subscriptions), [invoices](https://stripe.com/docs/api#invoices),
    20  	// [checkout sessions](https://stripe.com/docs/api/checkout/sessions), [quotes](https://stripe.com/docs/api#quotes), and more. Coupons do not work with conventional one-off [charges](https://stripe.com/docs/api#create_charge) or [payment intents](https://stripe.com/docs/api/payment_intents).
    21  	Coupon *Coupon `json:"coupon"`
    22  	// The ID of the customer associated with this discount.
    23  	Customer *Customer `json:"customer"`
    24  	Deleted  bool      `json:"deleted"`
    25  	// If the coupon has a duration of `repeating`, the date that this discount will end. If the coupon has a duration of `once` or `forever`, this attribute will be null.
    26  	End int64 `json:"end"`
    27  	// The ID of the discount object. Discounts cannot be fetched by ID. Use `expand[]=discounts` in API calls to expand discount IDs in an array.
    28  	ID string `json:"id"`
    29  	// The invoice that the discount's coupon was applied to, if it was applied directly to a particular invoice.
    30  	Invoice string `json:"invoice"`
    31  	// The invoice item `id` (or invoice line item `id` for invoice line items of type='subscription') that the discount's coupon was applied to, if it was applied directly to a particular invoice item or invoice line item.
    32  	InvoiceItem string `json:"invoice_item"`
    33  	// String representing the object's type. Objects of the same type share the same value.
    34  	Object string `json:"object"`
    35  	// The promotion code applied to create this discount.
    36  	PromotionCode *PromotionCode `json:"promotion_code"`
    37  	// Date that the coupon was applied.
    38  	Start int64 `json:"start"`
    39  	// The subscription that this coupon is applied to, if it is applied to a particular subscription.
    40  	Subscription string `json:"subscription"`
    41  	// The subscription item that this coupon is applied to, if it is applied to a particular subscription item.
    42  	SubscriptionItem string `json:"subscription_item"`
    43  }
    44  
    45  // UnmarshalJSON handles deserialization of a Discount.
    46  // This custom unmarshaling is needed because the resulting
    47  // property may be an id or the full struct if it was expanded.
    48  func (d *Discount) UnmarshalJSON(data []byte) error {
    49  	if id, ok := ParseID(data); ok {
    50  		d.ID = id
    51  		return nil
    52  	}
    53  
    54  	type discount Discount
    55  	var v discount
    56  	if err := json.Unmarshal(data, &v); err != nil {
    57  		return err
    58  	}
    59  
    60  	*d = Discount(v)
    61  	return nil
    62  }