use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::models::PaginationParams;
#[derive(Debug, Clone, Default)]
pub struct ListPaymentsRequest {
pub pagination: PaginationParams,
pub external_customer_id: Option<String>,
pub invoice_id: Option<Uuid>,
}
impl ListPaymentsRequest {
pub fn new() -> Self {
Self::default()
}
pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
self.pagination = pagination;
self
}
pub fn with_external_customer_id(mut self, external_customer_id: String) -> Self {
self.external_customer_id = Some(external_customer_id);
self
}
pub fn with_invoice_id(mut self, invoice_id: Uuid) -> Self {
self.invoice_id = Some(invoice_id);
self
}
pub fn to_query_params(&self) -> Vec<(&str, String)> {
let mut params = self.pagination.to_query_params();
if let Some(external_customer_id) = &self.external_customer_id {
params.push(("external_customer_id", external_customer_id.clone()));
}
if let Some(invoice_id) = &self.invoice_id {
params.push(("invoice_id", invoice_id.to_string()));
}
params
}
}
#[derive(Debug, Clone)]
pub struct GetPaymentRequest {
pub lago_id: Uuid,
}
impl GetPaymentRequest {
pub fn new(lago_id: Uuid) -> Self {
Self { lago_id }
}
}
#[derive(Debug, Clone)]
pub struct ListCustomerPaymentsRequest {
pub external_customer_id: String,
pub pagination: PaginationParams,
pub invoice_id: Option<Uuid>,
}
impl ListCustomerPaymentsRequest {
pub fn new(external_customer_id: String) -> Self {
Self {
external_customer_id,
pagination: PaginationParams::default(),
invoice_id: None,
}
}
pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
self.pagination = pagination;
self
}
pub fn with_invoice_id(mut self, invoice_id: Uuid) -> Self {
self.invoice_id = Some(invoice_id);
self
}
pub fn to_query_params(&self) -> Vec<(&str, String)> {
let mut params = self.pagination.to_query_params();
if let Some(invoice_id) = &self.invoice_id {
params.push(("invoice_id", invoice_id.to_string()));
}
params
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CreatePaymentInput {
pub invoice_id: String,
pub amount_cents: i64,
pub reference: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub paid_at: Option<String>,
}
impl CreatePaymentInput {
pub fn new(invoice_id: String, amount_cents: i64, reference: String) -> Self {
Self {
invoice_id,
amount_cents,
reference,
paid_at: None,
}
}
pub fn with_paid_at(mut self, paid_at: String) -> Self {
self.paid_at = Some(paid_at);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreatePaymentRequest {
pub payment: CreatePaymentInput,
}
impl CreatePaymentRequest {
pub fn new(input: CreatePaymentInput) -> Self {
Self { payment: input }
}
}