Skip to main content

Credit

Struct Credit 

Source
pub struct Credit { /* private fields */ }
Expand description

Credit Management interface.

Implementations§

Source§

impl Credit

Source

pub fn create_credit_account( &self, input: CreateCreditAccount, ) -> Result<CreditAccount>

Create a credit account for a customer.

§Example
use stateset_embedded::{Commerce, CreateCreditAccount, CustomerId, RiskRating};
use rust_decimal_macros::dec;

let commerce = Commerce::new(":memory:")?;

let account = commerce.credit().create_credit_account(CreateCreditAccount {
    customer_id: CustomerId::new(),
    credit_limit: dec!(25000.00),
    payment_terms: Some("Net 45".into()),
    risk_rating: Some(RiskRating::Low),
    notes: Some("Established customer since 2020".into()),
    ..Default::default()
})?;
Source

pub fn get_credit_account(&self, id: CreditId) -> Result<Option<CreditAccount>>

Get a credit account by ID.

Source

pub fn get_credit_account_by_customer( &self, customer_id: CustomerId, ) -> Result<Option<CreditAccount>>

Get a credit account by customer ID.

Source

pub fn update_credit_account( &self, id: CreditId, input: UpdateCreditAccount, ) -> Result<CreditAccount>

Update a credit account.

Source

pub fn list_credit_accounts( &self, filter: CreditAccountFilter, ) -> Result<Vec<CreditAccount>>

List credit accounts with optional filtering.

Source

pub fn adjust_credit_limit( &self, customer_id: CustomerId, new_limit: Decimal, reason: &str, ) -> Result<CreditAccount>

Adjust a customer’s credit limit.

§Example
use stateset_embedded::{Commerce, CustomerId};
use rust_decimal_macros::dec;

let commerce = Commerce::new(":memory:")?;

let account = commerce.credit().adjust_credit_limit(
    CustomerId::new(),
    dec!(50000.00),
    "Annual review - increased based on payment history"
)?;
Source

pub fn suspend_credit_account( &self, customer_id: CustomerId, reason: &str, ) -> Result<CreditAccount>

Suspend a credit account.

Source

pub fn reactivate_credit_account( &self, customer_id: CustomerId, ) -> Result<CreditAccount>

Reactivate a suspended credit account.

Source

pub fn check_credit( &self, customer_id: CustomerId, order_amount: Decimal, ) -> Result<CreditCheckResult>

Check credit availability for an order.

§Example
use stateset_embedded::{Commerce, CustomerId};
use rust_decimal_macros::dec;

let commerce = Commerce::new(":memory:")?;

let result = commerce.credit().check_credit(
    CustomerId::new(), // customer ID
    dec!(5000.00),     // order amount
)?;

if result.approved {
    println!("Credit approved");
} else {
    println!("Credit denied: {:?}", result.reason);
    if result.requires_approval {
        println!("Can be approved by credit manager");
    }
}
Source

pub fn reserve_credit( &self, customer_id: CustomerId, order_id: OrderId, amount: Decimal, ) -> Result<CreditAccount>

Reserve credit for an order.

Reduces available credit until the order is invoiced or cancelled.

Source

pub fn release_credit_reservation( &self, customer_id: CustomerId, order_id: OrderId, ) -> Result<CreditAccount>

Release a credit reservation (e.g., order cancelled).

Source

pub fn charge_credit( &self, customer_id: CustomerId, order_id: OrderId, amount: Decimal, ) -> Result<CreditAccount>

Charge credit (convert reservation to balance when order is invoiced).

Source

pub fn place_hold(&self, input: PlaceCreditHold) -> Result<CreditHold>

Place a credit hold on a customer or order.

§Example
use stateset_embedded::{Commerce, PlaceCreditHold, CreditHoldType, CustomerId, OrderId};
use rust_decimal_macros::dec;

let commerce = Commerce::new(":memory:")?;

let hold = commerce.credit().place_hold(PlaceCreditHold {
    customer_id: CustomerId::new(),
    order_id: Some(OrderId::new()),
    hold_type: CreditHoldType::OverLimit,
    hold_amount: dec!(2500.00),
    reason: "Order exceeds available credit".into(),
    placed_by: Some("credit_system".into()),
})?;

println!("Hold placed: {:?}", hold.id);
Source

pub fn get_hold(&self, id: Uuid) -> Result<Option<CreditHold>>

Get a credit hold by ID.

Source

pub fn list_holds(&self, filter: CreditHoldFilter) -> Result<Vec<CreditHold>>

List credit holds with optional filtering.

Source

pub fn release_hold(&self, input: ReleaseCreditHold) -> Result<CreditHold>

Release a credit hold.

Source

pub fn get_active_holds( &self, customer_id: CustomerId, ) -> Result<Vec<CreditHold>>

Get all active holds for a customer.

Source

pub fn get_holds_for_order(&self, order_id: OrderId) -> Result<Vec<CreditHold>>

Get all holds for an order.

Source

pub fn submit_application( &self, input: SubmitCreditApplication, ) -> Result<CreditApplication>

Submit a credit application.

§Example
use stateset_embedded::{Commerce, CustomerId, SubmitCreditApplication};
use rust_decimal_macros::dec;

let commerce = Commerce::new(":memory:")?;

let app = commerce.credit().submit_application(SubmitCreditApplication {
    customer_id: CustomerId::new(),
    requested_limit: dec!(50000.00),
    business_name: Some("Acme Corp".into()),
    years_in_business: Some(10),
    annual_revenue: Some(dec!(5000000.00)),
    bank_reference: Some("First National Bank".into()),
    ..Default::default()
})?;

println!("Application {} submitted", app.application_number);
Source

pub fn get_application(&self, id: Uuid) -> Result<Option<CreditApplication>>

Get a credit application by ID.

Source

pub fn list_applications( &self, filter: CreditApplicationFilter, ) -> Result<Vec<CreditApplication>>

List credit applications with optional filtering.

Source

pub fn review_application( &self, input: ReviewCreditApplication, ) -> Result<CreditApplication>

Review and approve/deny a credit application.

Source

pub fn withdraw_application(&self, id: Uuid) -> Result<CreditApplication>

Withdraw a credit application.

Source

pub fn record_transaction( &self, input: RecordCreditTransaction, ) -> Result<CreditTransaction>

Record a credit transaction.

Source

pub fn list_transactions( &self, filter: CreditTransactionFilter, ) -> Result<Vec<CreditTransaction>>

List credit transactions with optional filtering.

Source

pub fn apply_payment( &self, customer_id: CustomerId, amount: Decimal, reference_id: Option<Uuid>, ) -> Result<CreditAccount>

Apply a payment to reduce customer balance.

Source

pub fn get_customer_summary( &self, customer_id: CustomerId, ) -> Result<Option<CustomerCreditSummary>>

Get credit summary for a customer.

Source

pub fn get_aging_report(&self) -> Result<Vec<(CustomerId, CreditAgingBucket)>>

Get credit aging report.

Source

pub fn get_over_limit_customers(&self) -> Result<Vec<CreditAccount>>

Get all customers over their credit limit.

Trait Implementations§

Source§

impl Debug for Credit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more