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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  package stripe
     8  
     9  import "encoding/json"
    10  
    11  // The status of the Test Clock.
    12  type TestHelpersTestClockStatus string
    13  
    14  // List of values that TestHelpersTestClockStatus can take
    15  const (
    16  	TestHelpersTestClockStatusAdvancing       TestHelpersTestClockStatus = "advancing"
    17  	TestHelpersTestClockStatusInternalFailure TestHelpersTestClockStatus = "internal_failure"
    18  	TestHelpersTestClockStatusReady           TestHelpersTestClockStatus = "ready"
    19  )
    20  
    21  // Deletes a test clock.
    22  type TestHelpersTestClockParams struct {
    23  	Params `form:"*"`
    24  	// Specifies which fields in the response should be expanded.
    25  	Expand []*string `form:"expand"`
    26  	// The initial frozen time for this test clock.
    27  	FrozenTime *int64 `form:"frozen_time"`
    28  	// The name for this test clock.
    29  	Name *string `form:"name"`
    30  }
    31  
    32  // AddExpand appends a new field to expand.
    33  func (p *TestHelpersTestClockParams) AddExpand(f string) {
    34  	p.Expand = append(p.Expand, &f)
    35  }
    36  
    37  // Returns a list of your test clocks.
    38  type TestHelpersTestClockListParams struct {
    39  	ListParams `form:"*"`
    40  	// Specifies which fields in the response should be expanded.
    41  	Expand []*string `form:"expand"`
    42  }
    43  
    44  // AddExpand appends a new field to expand.
    45  func (p *TestHelpersTestClockListParams) AddExpand(f string) {
    46  	p.Expand = append(p.Expand, &f)
    47  }
    48  
    49  // Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to Ready.
    50  type TestHelpersTestClockAdvanceParams struct {
    51  	Params `form:"*"`
    52  	// Specifies which fields in the response should be expanded.
    53  	Expand []*string `form:"expand"`
    54  	// The time to advance the test clock. Must be after the test clock's current frozen time. Cannot be more than two intervals in the future from the shortest subscription in this test clock. If there are no subscriptions in this test clock, it cannot be more than two years in the future.
    55  	FrozenTime *int64 `form:"frozen_time"`
    56  }
    57  
    58  // AddExpand appends a new field to expand.
    59  func (p *TestHelpersTestClockAdvanceParams) AddExpand(f string) {
    60  	p.Expand = append(p.Expand, &f)
    61  }
    62  
    63  // A test clock enables deterministic control over objects in testmode. With a test clock, you can create
    64  // objects at a frozen time in the past or future, and advance to a specific future time to observe webhooks and state changes. After the clock advances,
    65  // you can either validate the current state of your scenario (and test your assumptions), change the current state of your scenario (and test more complex scenarios), or keep advancing forward in time.
    66  type TestHelpersTestClock struct {
    67  	APIResource
    68  	// Time at which the object was created. Measured in seconds since the Unix epoch.
    69  	Created int64 `json:"created"`
    70  	Deleted bool  `json:"deleted"`
    71  	// Time at which this clock is scheduled to auto delete.
    72  	DeletesAfter int64 `json:"deletes_after"`
    73  	// Time at which all objects belonging to this clock are frozen.
    74  	FrozenTime int64 `json:"frozen_time"`
    75  	// Unique identifier for the object.
    76  	ID string `json:"id"`
    77  	// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
    78  	Livemode bool `json:"livemode"`
    79  	// The custom name supplied at creation.
    80  	Name string `json:"name"`
    81  	// String representing the object's type. Objects of the same type share the same value.
    82  	Object string `json:"object"`
    83  	// The status of the Test Clock.
    84  	Status TestHelpersTestClockStatus `json:"status"`
    85  }
    86  
    87  // TestHelpersTestClockList is a list of TestClocks as retrieved from a list endpoint.
    88  type TestHelpersTestClockList struct {
    89  	APIResource
    90  	ListMeta
    91  	Data []*TestHelpersTestClock `json:"data"`
    92  }
    93  
    94  // UnmarshalJSON handles deserialization of a TestHelpersTestClock.
    95  // This custom unmarshaling is needed because the resulting
    96  // property may be an id or the full struct if it was expanded.
    97  func (t *TestHelpersTestClock) UnmarshalJSON(data []byte) error {
    98  	if id, ok := ParseID(data); ok {
    99  		t.ID = id
   100  		return nil
   101  	}
   102  
   103  	type testHelpersTestClock TestHelpersTestClock
   104  	var v testHelpersTestClock
   105  	if err := json.Unmarshal(data, &v); err != nil {
   106  		return err
   107  	}
   108  
   109  	*t = TestHelpersTestClock(v)
   110  	return nil
   111  }