use super::Transaction;
use crate::{client, endpoints::Endpoint, Result};
#[derive(Debug)]
#[must_use]
pub struct Request<'a, C>
where
C: client::Inner,
{
client: &'a C,
endpoint: String,
expand_merchant: bool,
}
impl<C> Endpoint for Request<'_, C>
where
C: client::Inner,
{
const METHOD: reqwest::Method = reqwest::Method::GET;
fn endpoint(&self) -> &str {
&self.endpoint
}
fn query(&self) -> Option<&dyn erased_serde::Serialize> {
if self.expand_merchant {
Some(&("expand[]", "merchant"))
} else {
None
}
}
}
impl<'a, C> Request<'a, C>
where
C: client::Inner,
{
pub(crate) fn new(client: &'a C, transaction_id: &'a str) -> Self {
let endpoint = format!("/transactions/{transaction_id}");
Self {
client,
endpoint,
expand_merchant: false,
}
}
pub const fn expand_merchant(mut self) -> Self {
self.expand_merchant = true;
self
}
pub async fn send(self) -> Result<Transaction> {
self.client.handle_request(&self).await
}
}