mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
moved answerPreCheckoutQuery from types to requests
This commit is contained in:
parent
8ffb4db4cc
commit
de0b9f4ab8
4 changed files with 84 additions and 9 deletions
83
src/core/requests/answer_pre_checkout_query.rs
Normal file
83
src/core/requests/answer_pre_checkout_query.rs
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
use crate::core::{
|
||||||
|
requests::{RequestContext, Request, RequestFuture, ResponseResult},
|
||||||
|
network
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Clone)]
|
||||||
|
/// Once the user has confirmed their payment and shipping details, the Bot API
|
||||||
|
/// sends the final confirmation in the form of an [`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.
|
||||||
|
pub struct AnswerPreCheckoutQuery<'a> {
|
||||||
|
#[serde(skip_serializing)]
|
||||||
|
ctx: RequestContext<'a>,
|
||||||
|
|
||||||
|
/// Unique identifier for the query to be answered
|
||||||
|
pub pre_checkout_query_id: String,
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
pub ok: bool,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
/// 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.
|
||||||
|
pub error_message: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Request<'a> for AnswerPreCheckoutQuery<'a> {
|
||||||
|
type ReturnValue = bool;
|
||||||
|
|
||||||
|
fn send(self) -> RequestFuture<'a, ResponseResult<Self::ReturnValue>> {
|
||||||
|
Box::pin(async move {
|
||||||
|
network::request_json(
|
||||||
|
&self.ctx.client,
|
||||||
|
&self.ctx.token,
|
||||||
|
"answerPreCheckoutQuery",
|
||||||
|
&self
|
||||||
|
).await
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> AnswerPreCheckoutQuery<'a> {
|
||||||
|
pub(crate) fn new(
|
||||||
|
ctx: RequestContext<'a>,
|
||||||
|
pre_checkout_query_id: String,
|
||||||
|
ok: bool
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
ctx,
|
||||||
|
pre_checkout_query_id,
|
||||||
|
ok,
|
||||||
|
error_message: None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pre_checkout_query_id<T>(mut self, pre_checkout_query_id: T) -> Self
|
||||||
|
where T: Into<String>
|
||||||
|
{
|
||||||
|
self.pre_checkout_query_id = pre_checkout_query_id.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ok<T>(mut self, ok: T) -> Self
|
||||||
|
where T: Into<bool>
|
||||||
|
{
|
||||||
|
self.ok = ok.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn error_message<T>(mut self, error_message: T) -> Self
|
||||||
|
where T: Into<String>
|
||||||
|
{
|
||||||
|
self.error_message = Some(error_message.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,6 +89,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod answer_pre_checkout_query;
|
||||||
pub mod edit_message_live_location;
|
pub mod edit_message_live_location;
|
||||||
pub mod forward_message;
|
pub mod forward_message;
|
||||||
pub mod get_file;
|
pub mod get_file;
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
|
||||||
pub struct AnswerPreCheckoutQuery {
|
|
||||||
pub pre_checkout_query_id: String,
|
|
||||||
pub ok: bool,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub error_message: Option<String>,
|
|
||||||
}
|
|
|
@ -1,6 +1,5 @@
|
||||||
use self::not_implemented_types::*;
|
use self::not_implemented_types::*;
|
||||||
pub use self::{
|
pub use self::{
|
||||||
answer_pre_checkout_query::AnswerPreCheckoutQuery,
|
|
||||||
answer_shipping_query::AnswerShippingQuery,
|
answer_shipping_query::AnswerShippingQuery,
|
||||||
animation::Animation,
|
animation::Animation,
|
||||||
audio::Audio,
|
audio::Audio,
|
||||||
|
@ -51,7 +50,6 @@ pub use self::{
|
||||||
};
|
};
|
||||||
|
|
||||||
mod animation;
|
mod animation;
|
||||||
mod answer_pre_checkout_query;
|
|
||||||
mod answer_shipping_query;
|
mod answer_shipping_query;
|
||||||
mod audio;
|
mod audio;
|
||||||
mod callback_query;
|
mod callback_query;
|
||||||
|
|
Loading…
Reference in a new issue