crypto_pay_api/webhook/
mod.rs

1mod config;
2mod handler;
3
4pub use config::{WebhookHandlerConfig, WebhookHandlerConfigBuilder};
5pub use handler::WebhookHandler;
6
7use crate::client::CryptoBot;
8
9impl CryptoBot {
10    /// Creates a new webhook handler builder
11    ///
12    /// # Example
13    /// ```no_run
14    /// use crypto_pay_api::prelude::*;
15    /// use std::time::Duration;
16    ///
17    /// #[tokio::main]
18    /// async fn main() -> Result<(), CryptoBotError> {
19    ///     let client = CryptoBot::builder().api_token("YOUR_API_TOKEN").build().unwrap();
20    ///
21    ///     let webhook_handler = client.webhook_handler()
22    ///         .expiration_time(Duration::from_secs(60 * 10))
23    ///         .build();
24    ///     Ok(())
25    /// }
26    /// ```
27    pub fn webhook_handler(&self) -> WebhookHandlerConfigBuilder<'_> {
28        WebhookHandlerConfigBuilder::new_with_client(&self.api_token)
29    }
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35    use std::time::Duration;
36
37    #[test]
38    fn test_webhook_handler_creation() {
39        let client = CryptoBot::test_client();
40
41        // Test with default config
42        let handler = client.webhook_handler().build();
43
44        assert_eq!(handler.api_token, client.api_token);
45        assert_eq!(handler.config.expiration_time, Some(Duration::from_secs(600)));
46
47        // Test with custom config
48        let handler = client
49            .webhook_handler()
50            .expiration_time(Duration::from_secs(300))
51            .build();
52
53        assert_eq!(handler.api_token, client.api_token);
54        assert_eq!(handler.config.expiration_time, Some(Duration::from_secs(300)));
55    }
56}