conogram/methods/
answer_pre_checkout_query.rs

1use std::{
2    future::{Future, IntoFuture},
3    pin::Pin,
4};
5
6use serde::Serialize;
7
8use crate::{api::API, errors::ConogramError, impl_into_future, request::RequestT};
9
10#[derive(Debug, Clone, Serialize)]
11pub struct AnswerPreCheckoutQueryParams {
12    pub pre_checkout_query_id: String,
13    pub ok: bool,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub error_message: Option<String>,
16}
17
18impl_into_future!(AnswerPreCheckoutQueryRequest<'a>);
19
20///Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an [Update](https://core.telegram.org/bots/api/#update) with the field *pre\_checkout\_query*. Use this method to respond to such pre-checkout queries. On success, *True* is returned. **Note:** The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
21#[derive(Clone)]
22pub struct AnswerPreCheckoutQueryRequest<'a> {
23    api: &'a API,
24    params: AnswerPreCheckoutQueryParams,
25}
26
27impl<'a> RequestT for AnswerPreCheckoutQueryRequest<'a> {
28    type ParamsType = AnswerPreCheckoutQueryParams;
29    type ReturnType = bool;
30    fn get_name() -> &'static str {
31        "answerPreCheckoutQuery"
32    }
33    fn get_api_ref(&self) -> &API {
34        self.api
35    }
36    fn get_params_ref(&self) -> &Self::ParamsType {
37        &self.params
38    }
39    fn is_multipart() -> bool {
40        false
41    }
42}
43impl<'a> AnswerPreCheckoutQueryRequest<'a> {
44    pub fn new(
45        api: &'a API,
46        pre_checkout_query_id: impl Into<String>,
47        ok: impl Into<bool>,
48    ) -> Self {
49        Self {
50            api,
51            params: AnswerPreCheckoutQueryParams {
52                pre_checkout_query_id: pre_checkout_query_id.into(),
53                ok: ok.into(),
54                error_message: Option::default(),
55            },
56        }
57    }
58
59    ///Unique identifier for the query to be answered
60    #[must_use]
61    pub fn pre_checkout_query_id(mut self, pre_checkout_query_id: impl Into<String>) -> Self {
62        self.params.pre_checkout_query_id = pre_checkout_query_id.into();
63        self
64    }
65
66    ///Specify *True* if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use *False* if there are any problems.
67    #[must_use]
68    pub fn ok(mut self, ok: impl Into<bool>) -> Self {
69        self.params.ok = ok.into();
70        self
71    }
72
73    ///Required if *ok* is *False*. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.
74    #[must_use]
75    pub fn error_message(mut self, error_message: impl Into<String>) -> Self {
76        self.params.error_message = Some(error_message.into());
77        self
78    }
79}
80
81impl API {
82    ///Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an [Update](https://core.telegram.org/bots/api/#update) with the field *pre\_checkout\_query*. Use this method to respond to such pre-checkout queries. On success, *True* is returned. **Note:** The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
83    pub fn answer_pre_checkout_query(
84        &self,
85        pre_checkout_query_id: impl Into<String>,
86        ok: impl Into<bool>,
87    ) -> AnswerPreCheckoutQueryRequest {
88        AnswerPreCheckoutQueryRequest::new(self, pre_checkout_query_id, ok)
89    }
90}
91
92// Divider: all content below this line will be preserved after code regen