stripe/resources/
test_clock_ext.rs

1// pub struct TestClockRetrieve {}
2
3use serde::Serialize;
4
5use crate::{
6    params::Paginable, Client, List, Response, TestHelpersTestClock, TestHelpersTestClockId,
7    Timestamp,
8};
9
10#[derive(Clone, Debug, Serialize, Default)]
11pub struct CreateTestClock<'a> {
12    /// The initial frozen time for this test clock.
13    pub frozen_time: Timestamp,
14
15    /// The name for this test clock.
16    pub name: &'a str,
17}
18
19impl<'a> CreateTestClock<'a> {
20    pub fn new() -> Self {
21        Self { frozen_time: Default::default(), name: Default::default() }
22    }
23}
24
25#[derive(Clone, Debug, Serialize, Default)]
26pub struct AdvanceTestClock {
27    /// The time to advance the test clock. Must be after the test clock’s current frozen time.
28    /// Cannot be more than two intervals in the future from the shortest subscription in this test clock.
29    /// If there are no subscriptions in this test clock, it cannot be more than two years in the future.
30    pub frozen_time: Timestamp,
31}
32
33#[derive(Clone, Debug, Serialize, Default)]
34pub struct ListTestClocks {
35    /// A cursor for use in pagination.
36    ///
37    /// `ending_before` is an object ID that defines your place in the list. For instance,
38    /// if you make a list request and receive 100 objects, starting with `obj_bar`,
39    /// your subsequent call can include `ending_before=obj_bar` in order to fetch the previous
40    /// page of the list.
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub ending_before: Option<TestHelpersTestClockId>,
43
44    /// A cursor for use in pagination.
45    ///
46    /// `starting_after` is an object ID that defines your place in the list. For instance,
47    /// if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent
48    /// call can include `starting_after=obj_foo` in order to fetch the next page of the list.
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub starting_after: Option<TestHelpersTestClockId>,
51
52    /// A limit on the number of objects to be returned. Limit can range between 1 and 100,
53    /// and the default is 10.
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub limit: Option<u64>,
56}
57
58impl ListTestClocks {
59    pub fn new() -> Self {
60        Self {
61            ending_before: Default::default(),
62            starting_after: Default::default(),
63            limit: Default::default(),
64        }
65    }
66}
67
68impl Paginable for ListTestClocks {
69    type O = TestHelpersTestClock;
70
71    fn set_last(&mut self, item: Self::O) {
72        self.starting_after = Some(item.id);
73    }
74}
75
76impl TestHelpersTestClock {
77    /// Creates a new test clock that can be attached to new customers and quotes.
78    ///
79    /// For more details see <https://docs.stripe.com/api/test_clocks/create>
80    pub fn create(client: &Client, params: &CreateTestClock<'_>) -> Response<TestHelpersTestClock> {
81        client.post_form("/test_helpers/test_clocks", params)
82    }
83
84    /// Retrieves a test clock.
85    ///
86    /// For more details see <https://docs.stripe.com/api/test_clocks/retrieve>
87    pub fn retrieve(
88        client: &Client,
89        id: &TestHelpersTestClockId,
90    ) -> Response<TestHelpersTestClock> {
91        client.get(&format!("/test_helpers/test_clocks/{}", id))
92    }
93
94    /// Returns a list of your test clocks.
95    ///
96    /// For more details see <https://docs.stripe.com/api/test_clocks/list>
97    pub fn list(client: &Client, params: &ListTestClocks) -> Response<List<TestHelpersTestClock>> {
98        client.get_query("/test_helpers/test_clocks", params)
99    }
100
101    /// Deletes a test clock.
102    ///
103    /// For more details see <https://docs.stripe.com/api/test_clocks/delete>
104    pub fn delete(client: &Client, id: &TestHelpersTestClockId) -> Response<TestHelpersTestClock> {
105        client.delete(&format!("/test_helpers/test_clocks/{}", id))
106    }
107
108    /// Starts advancing a test clock to a specified time in the future. Advancement is done when status changes to `Ready`.
109    ///
110    /// For more details see <https://docs.stripe.com/api/test_clocks/advance>
111    pub fn advance(
112        client: &Client,
113        test_clock_id: &TestHelpersTestClockId,
114        params: &AdvanceTestClock,
115    ) -> Response<TestHelpersTestClock> {
116        client.post_form(&format!("test_helpers/test_clocks/{}/advance", test_clock_id), params)
117    }
118}