use std::{
future::{Future, IntoFuture},
pin::Pin,
};
use serde::Serialize;
use crate::{
api::API, entities::labeled_price::LabeledPrice, errors::ConogramError, impl_into_future,
request::RequestT, utils::deserialize_utils::is_false,
};
#[derive(Debug, Clone, Serialize)]
pub struct CreateInvoiceLinkParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub business_connection_id: Option<String>,
pub title: String,
pub description: String,
pub payload: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub provider_token: Option<String>,
pub currency: String,
pub prices: Vec<LabeledPrice>,
#[serde(skip_serializing_if = "Option::is_none")]
pub subscription_period: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_tip_amount: Option<i64>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub suggested_tip_amounts: Vec<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub provider_data: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub photo_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub photo_size: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub photo_width: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub photo_height: Option<i64>,
#[serde(default, skip_serializing_if = "is_false")]
pub need_name: bool,
#[serde(default, skip_serializing_if = "is_false")]
pub need_phone_number: bool,
#[serde(default, skip_serializing_if = "is_false")]
pub need_email: bool,
#[serde(default, skip_serializing_if = "is_false")]
pub need_shipping_address: bool,
#[serde(default, skip_serializing_if = "is_false")]
pub send_phone_number_to_provider: bool,
#[serde(default, skip_serializing_if = "is_false")]
pub send_email_to_provider: bool,
#[serde(default, skip_serializing_if = "is_false")]
pub is_flexible: bool,
}
impl_into_future!(CreateInvoiceLinkRequest<'a>);
#[derive(Clone)]
pub struct CreateInvoiceLinkRequest<'a> {
api: &'a API,
params: CreateInvoiceLinkParams,
}
impl<'a> RequestT for CreateInvoiceLinkRequest<'a> {
type ParamsType = CreateInvoiceLinkParams;
type ReturnType = String;
fn get_name() -> &'static str {
"createInvoiceLink"
}
fn get_api_ref(&self) -> &API {
self.api
}
fn get_params_ref(&self) -> &Self::ParamsType {
&self.params
}
fn is_multipart() -> bool {
false
}
}
impl<'a> CreateInvoiceLinkRequest<'a> {
pub fn new(
api: &'a API,
title: impl Into<String>,
description: impl Into<String>,
payload: impl Into<String>,
currency: impl Into<String>,
prices: impl IntoIterator<Item = impl Into<LabeledPrice>>,
) -> Self {
Self {
api,
params: CreateInvoiceLinkParams {
title: title.into(),
description: description.into(),
payload: payload.into(),
currency: currency.into(),
prices: prices.into_iter().map(Into::into).collect(),
business_connection_id: Option::default(),
provider_token: Option::default(),
subscription_period: Option::default(),
max_tip_amount: Option::default(),
suggested_tip_amounts: Vec::default(),
provider_data: Option::default(),
photo_url: Option::default(),
photo_size: Option::default(),
photo_width: Option::default(),
photo_height: Option::default(),
need_name: bool::default(),
need_phone_number: bool::default(),
need_email: bool::default(),
need_shipping_address: bool::default(),
send_phone_number_to_provider: bool::default(),
send_email_to_provider: bool::default(),
is_flexible: bool::default(),
},
}
}
#[must_use]
pub fn business_connection_id(mut self, business_connection_id: impl Into<String>) -> Self {
self.params.business_connection_id = Some(business_connection_id.into());
self
}
#[must_use]
pub fn title(mut self, title: impl Into<String>) -> Self {
self.params.title = title.into();
self
}
#[must_use]
pub fn description(mut self, description: impl Into<String>) -> Self {
self.params.description = description.into();
self
}
#[must_use]
pub fn payload(mut self, payload: impl Into<String>) -> Self {
self.params.payload = payload.into();
self
}
#[must_use]
pub fn provider_token(mut self, provider_token: impl Into<String>) -> Self {
self.params.provider_token = Some(provider_token.into());
self
}
#[must_use]
pub fn currency(mut self, currency: impl Into<String>) -> Self {
self.params.currency = currency.into();
self
}
#[must_use]
pub fn prices(mut self, prices: impl IntoIterator<Item = impl Into<LabeledPrice>>) -> Self {
self.params.prices = prices.into_iter().map(Into::into).collect();
self
}
#[must_use]
pub fn subscription_period(mut self, subscription_period: impl Into<i64>) -> Self {
self.params.subscription_period = Some(subscription_period.into());
self
}
#[must_use]
pub fn max_tip_amount(mut self, max_tip_amount: impl Into<i64>) -> Self {
self.params.max_tip_amount = Some(max_tip_amount.into());
self
}
#[must_use]
pub fn suggested_tip_amounts(
mut self,
suggested_tip_amounts: impl IntoIterator<Item = impl Into<i64>>,
) -> Self {
self.params.suggested_tip_amounts =
suggested_tip_amounts.into_iter().map(Into::into).collect();
self
}
#[must_use]
pub fn provider_data(mut self, provider_data: impl Into<String>) -> Self {
self.params.provider_data = Some(provider_data.into());
self
}
#[must_use]
pub fn photo_url(mut self, photo_url: impl Into<String>) -> Self {
self.params.photo_url = Some(photo_url.into());
self
}
#[must_use]
pub fn photo_size(mut self, photo_size: impl Into<i64>) -> Self {
self.params.photo_size = Some(photo_size.into());
self
}
#[must_use]
pub fn photo_width(mut self, photo_width: impl Into<i64>) -> Self {
self.params.photo_width = Some(photo_width.into());
self
}
#[must_use]
pub fn photo_height(mut self, photo_height: impl Into<i64>) -> Self {
self.params.photo_height = Some(photo_height.into());
self
}
#[must_use]
pub fn need_name(mut self, need_name: impl Into<bool>) -> Self {
self.params.need_name = need_name.into();
self
}
#[must_use]
pub fn need_phone_number(mut self, need_phone_number: impl Into<bool>) -> Self {
self.params.need_phone_number = need_phone_number.into();
self
}
#[must_use]
pub fn need_email(mut self, need_email: impl Into<bool>) -> Self {
self.params.need_email = need_email.into();
self
}
#[must_use]
pub fn need_shipping_address(mut self, need_shipping_address: impl Into<bool>) -> Self {
self.params.need_shipping_address = need_shipping_address.into();
self
}
#[must_use]
pub fn send_phone_number_to_provider(
mut self,
send_phone_number_to_provider: impl Into<bool>,
) -> Self {
self.params.send_phone_number_to_provider = send_phone_number_to_provider.into();
self
}
#[must_use]
pub fn send_email_to_provider(mut self, send_email_to_provider: impl Into<bool>) -> Self {
self.params.send_email_to_provider = send_email_to_provider.into();
self
}
#[must_use]
pub fn is_flexible(mut self, is_flexible: impl Into<bool>) -> Self {
self.params.is_flexible = is_flexible.into();
self
}
}
impl API {
pub fn create_invoice_link(
&self,
title: impl Into<String>,
description: impl Into<String>,
payload: impl Into<String>,
currency: impl Into<String>,
prices: impl IntoIterator<Item = impl Into<LabeledPrice>>,
) -> CreateInvoiceLinkRequest {
CreateInvoiceLinkRequest::new(self, title, description, payload, currency, prices)
}
}