moved answerPreCheckoutQuery from types to requests

This commit is contained in:
P0lunin 2019-09-15 14:40:24 +03:00
parent 8ffb4db4cc
commit de0b9f4ab8
4 changed files with 84 additions and 9 deletions

View 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
}
}

View file

@ -89,6 +89,7 @@ mod tests {
}
}
pub mod answer_pre_checkout_query;
pub mod edit_message_live_location;
pub mod forward_message;
pub mod get_file;

View 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>,
}

View file

@ -1,6 +1,5 @@
use self::not_implemented_types::*;
pub use self::{
answer_pre_checkout_query::AnswerPreCheckoutQuery,
answer_shipping_query::AnswerShippingQuery,
animation::Animation,
audio::Audio,
@ -51,7 +50,6 @@ pub use self::{
};
mod animation;
mod answer_pre_checkout_query;
mod answer_shipping_query;
mod audio;
mod callback_query;