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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  package stripe
     8  
     9  // The method for mapping a meter event to a customer.
    10  type BillingMeterCustomerMappingType string
    11  
    12  // List of values that BillingMeterCustomerMappingType can take
    13  const (
    14  	BillingMeterCustomerMappingTypeByID BillingMeterCustomerMappingType = "by_id"
    15  )
    16  
    17  // Specifies how events are aggregated.
    18  type BillingMeterDefaultAggregationFormula string
    19  
    20  // List of values that BillingMeterDefaultAggregationFormula can take
    21  const (
    22  	BillingMeterDefaultAggregationFormulaCount BillingMeterDefaultAggregationFormula = "count"
    23  	BillingMeterDefaultAggregationFormulaSum   BillingMeterDefaultAggregationFormula = "sum"
    24  )
    25  
    26  // The time window to pre-aggregate usage events for, if any.
    27  type BillingMeterEventTimeWindow string
    28  
    29  // List of values that BillingMeterEventTimeWindow can take
    30  const (
    31  	BillingMeterEventTimeWindowDay  BillingMeterEventTimeWindow = "day"
    32  	BillingMeterEventTimeWindowHour BillingMeterEventTimeWindow = "hour"
    33  )
    34  
    35  // The meter's status.
    36  type BillingMeterStatus string
    37  
    38  // List of values that BillingMeterStatus can take
    39  const (
    40  	BillingMeterStatusActive   BillingMeterStatus = "active"
    41  	BillingMeterStatusInactive BillingMeterStatus = "inactive"
    42  )
    43  
    44  // Retrieve a list of billing meters.
    45  type BillingMeterListParams struct {
    46  	ListParams `form:"*"`
    47  	// Specifies which fields in the response should be expanded.
    48  	Expand []*string `form:"expand"`
    49  	// Filter results to only include meters with the given status.
    50  	Status *string `form:"status"`
    51  }
    52  
    53  // AddExpand appends a new field to expand.
    54  func (p *BillingMeterListParams) AddExpand(f string) {
    55  	p.Expand = append(p.Expand, &f)
    56  }
    57  
    58  // Fields that specify how to map a meter event to a customer.
    59  type BillingMeterCustomerMappingParams struct {
    60  	// The key in the usage event payload to use for mapping the event to a customer.
    61  	EventPayloadKey *string `form:"event_payload_key"`
    62  	// The method for mapping a meter event to a customer. Must be `by_id`.
    63  	Type *string `form:"type"`
    64  }
    65  
    66  // The default settings to aggregate a meter's events with.
    67  type BillingMeterDefaultAggregationParams struct {
    68  	// Specifies how events are aggregated. Allowed values are `count` to count the number of events, `sum` to sum each event's value, or `last` to use the last event's value.
    69  	Formula *string `form:"formula"`
    70  }
    71  
    72  // Fields that specify how to calculate a usage event's value.
    73  type BillingMeterValueSettingsParams struct {
    74  	// The key in the usage event payload to use as the value for this meter. For example, if the event payload contains usage on a `bytes_used` field, then set the event_payload_key to "bytes_used".
    75  	EventPayloadKey *string `form:"event_payload_key"`
    76  }
    77  
    78  // Creates a billing meter
    79  type BillingMeterParams struct {
    80  	Params `form:"*"`
    81  	// Fields that specify how to map a meter event to a customer.
    82  	CustomerMapping *BillingMeterCustomerMappingParams `form:"customer_mapping"`
    83  	// The default settings to aggregate a meter's events with.
    84  	DefaultAggregation *BillingMeterDefaultAggregationParams `form:"default_aggregation"`
    85  	// The meter's name.
    86  	DisplayName *string `form:"display_name"`
    87  	// The name of the usage event to record usage for. Corresponds with the `event_name` field on usage events.
    88  	EventName *string `form:"event_name"`
    89  	// The time window to pre-aggregate usage events for, if any.
    90  	EventTimeWindow *string `form:"event_time_window"`
    91  	// Specifies which fields in the response should be expanded.
    92  	Expand []*string `form:"expand"`
    93  	// Fields that specify how to calculate a usage event's value.
    94  	ValueSettings *BillingMeterValueSettingsParams `form:"value_settings"`
    95  }
    96  
    97  // AddExpand appends a new field to expand.
    98  func (p *BillingMeterParams) AddExpand(f string) {
    99  	p.Expand = append(p.Expand, &f)
   100  }
   101  
   102  // Deactivates a billing meter
   103  type BillingMeterDeactivateParams struct {
   104  	Params `form:"*"`
   105  	// Specifies which fields in the response should be expanded.
   106  	Expand []*string `form:"expand"`
   107  }
   108  
   109  // AddExpand appends a new field to expand.
   110  func (p *BillingMeterDeactivateParams) AddExpand(f string) {
   111  	p.Expand = append(p.Expand, &f)
   112  }
   113  
   114  // Reactivates a billing meter
   115  type BillingMeterReactivateParams struct {
   116  	Params `form:"*"`
   117  	// Specifies which fields in the response should be expanded.
   118  	Expand []*string `form:"expand"`
   119  }
   120  
   121  // AddExpand appends a new field to expand.
   122  func (p *BillingMeterReactivateParams) AddExpand(f string) {
   123  	p.Expand = append(p.Expand, &f)
   124  }
   125  
   126  type BillingMeterCustomerMapping struct {
   127  	// The key in the usage event payload to use for mapping the event to a customer.
   128  	EventPayloadKey string `json:"event_payload_key"`
   129  	// The method for mapping a meter event to a customer.
   130  	Type BillingMeterCustomerMappingType `json:"type"`
   131  }
   132  type BillingMeterDefaultAggregation struct {
   133  	// Specifies how events are aggregated.
   134  	Formula BillingMeterDefaultAggregationFormula `json:"formula"`
   135  }
   136  type BillingMeterStatusTransitions struct {
   137  	// The time the meter was deactivated, if any. Measured in seconds since Unix epoch.
   138  	DeactivatedAt int64 `json:"deactivated_at"`
   139  }
   140  type BillingMeterValueSettings struct {
   141  	// The key in the usage event payload to use as the value for this meter.
   142  	EventPayloadKey string `json:"event_payload_key"`
   143  }
   144  
   145  // A billing meter is a resource that allows you to track usage of a particular event. For example, you might create a billing meter to track the number of API calls made by a particular user. You can then use the billing meter to charge the user for the number of API calls they make.
   146  type BillingMeter struct {
   147  	APIResource
   148  	// Time at which the object was created. Measured in seconds since the Unix epoch.
   149  	Created            int64                           `json:"created"`
   150  	CustomerMapping    *BillingMeterCustomerMapping    `json:"customer_mapping"`
   151  	DefaultAggregation *BillingMeterDefaultAggregation `json:"default_aggregation"`
   152  	// The meter's name.
   153  	DisplayName string `json:"display_name"`
   154  	// The name of the usage event to record usage for. Corresponds with the `event_name` field on usage events.
   155  	EventName string `json:"event_name"`
   156  	// The time window to pre-aggregate usage events for, if any.
   157  	EventTimeWindow BillingMeterEventTimeWindow `json:"event_time_window"`
   158  	// Unique identifier for the object.
   159  	ID string `json:"id"`
   160  	// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
   161  	Livemode bool `json:"livemode"`
   162  	// String representing the object's type. Objects of the same type share the same value.
   163  	Object string `json:"object"`
   164  	// The meter's status.
   165  	Status            BillingMeterStatus             `json:"status"`
   166  	StatusTransitions *BillingMeterStatusTransitions `json:"status_transitions"`
   167  	// Time at which the object was last updated. Measured in seconds since the Unix epoch.
   168  	Updated       int64                      `json:"updated"`
   169  	ValueSettings *BillingMeterValueSettings `json:"value_settings"`
   170  }
   171  
   172  // BillingMeterList is a list of Meters as retrieved from a list endpoint.
   173  type BillingMeterList struct {
   174  	APIResource
   175  	ListMeta
   176  	Data []*BillingMeter `json:"data"`
   177  }