use payjp_client_core::{PayjpClient, BlockingClient, PayjpRequest, RequestBuilder, PayjpMethod};
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
struct ListStatementBuilder {
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
offset: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
since: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
until: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
owner: Option<ListStatementOwner>,
#[serde(skip_serializing_if = "Option::is_none")]
source_transfer: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
tenant: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
term: Option<String>,
#[serde(rename = "type")]
#[serde(skip_serializing_if = "Option::is_none")]
type_: Option<payjp_core::StatementType>,
}
impl ListStatementBuilder {
fn new() -> Self {
Self {
limit: None,offset: None,since: None,until: None,owner: None,source_transfer: None,tenant: None,term: None,type_: None,
}
}
}
#[derive(Copy,Clone,Eq, PartialEq,)]pub enum ListStatementOwner {
Merchant,
Tenant,
}
impl ListStatementOwner {
pub fn as_str(self) -> &'static str {
use ListStatementOwner::*;
match self {
Merchant => "merchant",
Tenant => "tenant",
}
}
}
impl std::str::FromStr for ListStatementOwner {
type Err = payjp_types::ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use ListStatementOwner::*;
match s {
"merchant" => Ok(Merchant),
"tenant" => Ok(Tenant),
_ => Err(payjp_types::ParseError)
}
}
}
impl std::fmt::Display for ListStatementOwner {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl std::fmt::Debug for ListStatementOwner {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl serde::Serialize for ListStatementOwner {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
serializer.serialize_str(self.as_str())
}
}
#[cfg(feature = "deserialize")]
impl<'de> serde::Deserialize<'de> for ListStatementOwner {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
use std::str::FromStr;
let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for ListStatementOwner"))
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
pub struct ListStatement {
inner: ListStatementBuilder,
}
impl ListStatement {
pub fn new() -> Self {
Self {
inner: ListStatementBuilder::new()
}
}
pub fn limit(mut self, limit: impl Into<i64>) -> Self {
self.inner.limit = Some(limit.into());
self
}
pub fn offset(mut self, offset: impl Into<i64>) -> Self {
self.inner.offset = Some(offset.into());
self
}
pub fn since(mut self, since: impl Into<i64>) -> Self {
self.inner.since = Some(since.into());
self
}
pub fn until(mut self, until: impl Into<i64>) -> Self {
self.inner.until = Some(until.into());
self
}
pub fn owner(mut self, owner: impl Into<ListStatementOwner>) -> Self {
self.inner.owner = Some(owner.into());
self
}
pub fn source_transfer(mut self, source_transfer: impl Into<String>) -> Self {
self.inner.source_transfer = Some(source_transfer.into());
self
}
pub fn tenant(mut self, tenant: impl Into<String>) -> Self {
self.inner.tenant = Some(tenant.into());
self
}
pub fn term(mut self, term: impl Into<String>) -> Self {
self.inner.term = Some(term.into());
self
}
pub fn type_(mut self, type_: impl Into<payjp_core::StatementType>) -> Self {
self.inner.type_ = Some(type_.into());
self
}
}
impl Default for ListStatement {
fn default() -> Self {
Self::new()
}
}impl ListStatement {
pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send(client).await
}
pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send_blocking(client)
}
pub fn paginate(&self) -> payjp_client_core::ListPaginator<payjp_types::List<payjp_core::Statement>> {
payjp_client_core::ListPaginator::new_list("/statements", &self.inner)
}
}
impl PayjpRequest for ListStatement {
type Output = payjp_types::List<payjp_core::Statement>;
fn build(&self) -> RequestBuilder {
RequestBuilder::new(PayjpMethod::Get, "/statements").query(&self.inner)
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
pub struct RetrieveStatement {
statement: payjp_core::StatementId,
}
impl RetrieveStatement {
pub fn new(statement:impl Into<payjp_core::StatementId>) -> Self {
Self {
statement: statement.into(),
}
}
}
impl RetrieveStatement {
pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send(client).await
}
pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send_blocking(client)
}
}
impl PayjpRequest for RetrieveStatement {
type Output = payjp_core::Statement;
fn build(&self) -> RequestBuilder {
let statement = &self.statement;
RequestBuilder::new(PayjpMethod::Get, format!("/statements/{statement}"))
}
}
#[derive(Copy,Clone,Debug,)]#[derive(serde::Serialize)]
struct StatementUrlsStatementBuilder {
#[serde(skip_serializing_if = "Option::is_none")]
platformer: Option<bool>,
}
impl StatementUrlsStatementBuilder {
fn new() -> Self {
Self {
platformer: None,
}
}
}
#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
pub struct StatementUrlsStatement {
inner: StatementUrlsStatementBuilder,
statement: payjp_core::StatementId,
}
impl StatementUrlsStatement {
pub fn new(statement:impl Into<payjp_core::StatementId>) -> Self {
Self {
statement: statement.into(),inner: StatementUrlsStatementBuilder::new()
}
}
pub fn platformer(mut self, platformer: impl Into<bool>) -> Self {
self.inner.platformer = Some(platformer.into());
self
}
}
impl StatementUrlsStatement {
pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send(client).await
}
pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
self.customize().send_blocking(client)
}
}
impl PayjpRequest for StatementUrlsStatement {
type Output = payjp_shared::StatementUrl;
fn build(&self) -> RequestBuilder {
let statement = &self.statement;
RequestBuilder::new(PayjpMethod::Post, format!("/statements/{statement}/statement_urls")).form(&self.inner)
}
}