pub struct Payment {Show 22 fields
pub id: Uuid,
pub organization_id: Uuid,
pub building_id: Uuid,
pub owner_id: Uuid,
pub expense_id: Option<Uuid>,
pub amount_cents: i64,
pub currency: String,
pub status: TransactionStatus,
pub payment_method_type: PaymentMethodType,
pub stripe_payment_intent_id: Option<String>,
pub stripe_customer_id: Option<String>,
pub payment_method_id: Option<Uuid>,
pub idempotency_key: String,
pub description: Option<String>,
pub metadata: Option<String>,
pub failure_reason: Option<String>,
pub refunded_amount_cents: i64,
pub succeeded_at: Option<DateTime<Utc>>,
pub failed_at: Option<DateTime<Utc>>,
pub cancelled_at: Option<DateTime<Utc>>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}Expand description
Payment entity - Represents a payment for an expense
Belgian property management context:
- Payments are always in EUR (Belgian currency)
- Linked to Expense entity (charge to co-owners)
- Supports Stripe (cards) and SEPA (bank transfers)
- Includes idempotency key for safe retries
Fields§
§id: Uuid§organization_id: UuidOrganization (multi-tenant isolation)
building_id: UuidBuilding this payment relates to
owner_id: UuidOwner making the payment
expense_id: Option<Uuid>Expense being paid (optional: could be general account credit)
amount_cents: i64Payment amount in cents (EUR) - Stripe uses smallest currency unit
currency: StringCurrency (always EUR for Belgian context)
status: TransactionStatusPayment transaction status
payment_method_type: PaymentMethodTypePayment method type used
stripe_payment_intent_id: Option<String>Stripe payment intent ID (for card/SEPA payments)
stripe_customer_id: Option<String>Stripe customer ID (for recurring customers)
payment_method_id: Option<Uuid>Stored payment method ID (if saved for future use)
idempotency_key: StringIdempotency key for safe retries (prevents duplicate charges)
description: Option<String>Optional description
metadata: Option<String>Optional metadata (JSON) for extensibility
failure_reason: Option<String>Failure reason (if status = Failed)
refunded_amount_cents: i64Refund amount in cents (if status = Refunded)
succeeded_at: Option<DateTime<Utc>>Date when payment succeeded (if status = Succeeded)
failed_at: Option<DateTime<Utc>>Date when payment failed (if status = Failed)
cancelled_at: Option<DateTime<Utc>>Date when payment was cancelled (if status = Cancelled)
created_at: DateTime<Utc>§updated_at: DateTime<Utc>Implementations§
Source§impl Payment
impl Payment
Sourcepub fn new(
organization_id: Uuid,
building_id: Uuid,
owner_id: Uuid,
expense_id: Option<Uuid>,
amount_cents: i64,
payment_method_type: PaymentMethodType,
idempotency_key: String,
description: Option<String>,
) -> Result<Self, String>
pub fn new( organization_id: Uuid, building_id: Uuid, owner_id: Uuid, expense_id: Option<Uuid>, amount_cents: i64, payment_method_type: PaymentMethodType, idempotency_key: String, description: Option<String>, ) -> Result<Self, String>
Create a new payment intent
§Arguments
organization_id- Organization ID (multi-tenant)building_id- Building IDowner_id- Owner making the paymentexpense_id- Optional expense being paidamount_cents- Amount in cents (EUR)payment_method_type- Payment method typeidempotency_key- Idempotency key for safe retriesdescription- Optional description
§Returns
Ok(Payment)- New payment with status PendingErr(String)- Validation error
Sourcepub fn mark_processing(&mut self) -> Result<(), String>
pub fn mark_processing(&mut self) -> Result<(), String>
Mark payment as processing
Sourcepub fn mark_requires_action(&mut self) -> Result<(), String>
pub fn mark_requires_action(&mut self) -> Result<(), String>
Mark payment as requiring action (e.g., 3D Secure authentication)
Sourcepub fn mark_succeeded(&mut self) -> Result<(), String>
pub fn mark_succeeded(&mut self) -> Result<(), String>
Mark payment as succeeded
Sourcepub fn mark_cancelled(&mut self) -> Result<(), String>
pub fn mark_cancelled(&mut self) -> Result<(), String>
Mark payment as cancelled
Sourcepub fn refund(&mut self, refund_amount_cents: i64) -> Result<(), String>
pub fn refund(&mut self, refund_amount_cents: i64) -> Result<(), String>
Refund payment (partial or full)
Sourcepub fn set_stripe_payment_intent_id(&mut self, payment_intent_id: String)
pub fn set_stripe_payment_intent_id(&mut self, payment_intent_id: String)
Set Stripe payment intent ID
Sourcepub fn set_stripe_customer_id(&mut self, customer_id: String)
pub fn set_stripe_customer_id(&mut self, customer_id: String)
Set Stripe customer ID
Sourcepub fn set_payment_method_id(&mut self, payment_method_id: Uuid)
pub fn set_payment_method_id(&mut self, payment_method_id: Uuid)
Set payment method ID (for saved payment methods)
Sourcepub fn set_metadata(&mut self, metadata: String)
pub fn set_metadata(&mut self, metadata: String)
Set metadata
Sourcepub fn get_net_amount_cents(&self) -> i64
pub fn get_net_amount_cents(&self) -> i64
Get net amount after refunds (in cents)
Sourcepub fn can_refund(&self) -> bool
pub fn can_refund(&self) -> bool
Check if payment can be refunded
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Payment
impl<'de> Deserialize<'de> for Payment
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<Payment> for PaymentResponse
impl From<Payment> for PaymentResponse
Auto Trait Implementations§
impl Freeze for Payment
impl RefUnwindSafe for Payment
impl Send for Payment
impl Sync for Payment
impl Unpin for Payment
impl UnwindSafe for Payment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Chain<T> for T
impl<T> Chain<T> for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Fake for T
impl<T> Fake for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more