pub struct Credit { /* private fields */ }Expand description
Credit Management interface.
Implementations§
Source§impl Credit
impl Credit
Sourcepub fn create_credit_account(
&self,
input: CreateCreditAccount,
) -> Result<CreditAccount>
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()
})?;Sourcepub fn get_credit_account(&self, id: CreditId) -> Result<Option<CreditAccount>>
pub fn get_credit_account(&self, id: CreditId) -> Result<Option<CreditAccount>>
Get a credit account by ID.
Sourcepub fn get_credit_account_by_customer(
&self,
customer_id: CustomerId,
) -> Result<Option<CreditAccount>>
pub fn get_credit_account_by_customer( &self, customer_id: CustomerId, ) -> Result<Option<CreditAccount>>
Get a credit account by customer ID.
Sourcepub fn update_credit_account(
&self,
id: CreditId,
input: UpdateCreditAccount,
) -> Result<CreditAccount>
pub fn update_credit_account( &self, id: CreditId, input: UpdateCreditAccount, ) -> Result<CreditAccount>
Update a credit account.
Sourcepub fn list_credit_accounts(
&self,
filter: CreditAccountFilter,
) -> Result<Vec<CreditAccount>>
pub fn list_credit_accounts( &self, filter: CreditAccountFilter, ) -> Result<Vec<CreditAccount>>
List credit accounts with optional filtering.
Sourcepub fn adjust_credit_limit(
&self,
customer_id: CustomerId,
new_limit: Decimal,
reason: &str,
) -> Result<CreditAccount>
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"
)?;Sourcepub fn suspend_credit_account(
&self,
customer_id: CustomerId,
reason: &str,
) -> Result<CreditAccount>
pub fn suspend_credit_account( &self, customer_id: CustomerId, reason: &str, ) -> Result<CreditAccount>
Suspend a credit account.
Sourcepub fn reactivate_credit_account(
&self,
customer_id: CustomerId,
) -> Result<CreditAccount>
pub fn reactivate_credit_account( &self, customer_id: CustomerId, ) -> Result<CreditAccount>
Reactivate a suspended credit account.
Sourcepub fn check_credit(
&self,
customer_id: CustomerId,
order_amount: Decimal,
) -> Result<CreditCheckResult>
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");
}
}Sourcepub fn reserve_credit(
&self,
customer_id: CustomerId,
order_id: OrderId,
amount: Decimal,
) -> Result<CreditAccount>
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.
Sourcepub fn release_credit_reservation(
&self,
customer_id: CustomerId,
order_id: OrderId,
) -> Result<CreditAccount>
pub fn release_credit_reservation( &self, customer_id: CustomerId, order_id: OrderId, ) -> Result<CreditAccount>
Release a credit reservation (e.g., order cancelled).
Sourcepub fn charge_credit(
&self,
customer_id: CustomerId,
order_id: OrderId,
amount: Decimal,
) -> Result<CreditAccount>
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).
Sourcepub fn place_hold(&self, input: PlaceCreditHold) -> Result<CreditHold>
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);Sourcepub fn list_holds(&self, filter: CreditHoldFilter) -> Result<Vec<CreditHold>>
pub fn list_holds(&self, filter: CreditHoldFilter) -> Result<Vec<CreditHold>>
List credit holds with optional filtering.
Sourcepub fn release_hold(&self, input: ReleaseCreditHold) -> Result<CreditHold>
pub fn release_hold(&self, input: ReleaseCreditHold) -> Result<CreditHold>
Release a credit hold.
Sourcepub fn get_active_holds(
&self,
customer_id: CustomerId,
) -> Result<Vec<CreditHold>>
pub fn get_active_holds( &self, customer_id: CustomerId, ) -> Result<Vec<CreditHold>>
Get all active holds for a customer.
Sourcepub fn get_holds_for_order(&self, order_id: OrderId) -> Result<Vec<CreditHold>>
pub fn get_holds_for_order(&self, order_id: OrderId) -> Result<Vec<CreditHold>>
Get all holds for an order.
Sourcepub fn submit_application(
&self,
input: SubmitCreditApplication,
) -> Result<CreditApplication>
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);Sourcepub fn get_application(&self, id: Uuid) -> Result<Option<CreditApplication>>
pub fn get_application(&self, id: Uuid) -> Result<Option<CreditApplication>>
Get a credit application by ID.
Sourcepub fn list_applications(
&self,
filter: CreditApplicationFilter,
) -> Result<Vec<CreditApplication>>
pub fn list_applications( &self, filter: CreditApplicationFilter, ) -> Result<Vec<CreditApplication>>
List credit applications with optional filtering.
Sourcepub fn review_application(
&self,
input: ReviewCreditApplication,
) -> Result<CreditApplication>
pub fn review_application( &self, input: ReviewCreditApplication, ) -> Result<CreditApplication>
Review and approve/deny a credit application.
Sourcepub fn withdraw_application(&self, id: Uuid) -> Result<CreditApplication>
pub fn withdraw_application(&self, id: Uuid) -> Result<CreditApplication>
Withdraw a credit application.
Sourcepub fn record_transaction(
&self,
input: RecordCreditTransaction,
) -> Result<CreditTransaction>
pub fn record_transaction( &self, input: RecordCreditTransaction, ) -> Result<CreditTransaction>
Record a credit transaction.
Sourcepub fn list_transactions(
&self,
filter: CreditTransactionFilter,
) -> Result<Vec<CreditTransaction>>
pub fn list_transactions( &self, filter: CreditTransactionFilter, ) -> Result<Vec<CreditTransaction>>
List credit transactions with optional filtering.
Sourcepub fn apply_payment(
&self,
customer_id: CustomerId,
amount: Decimal,
reference_id: Option<Uuid>,
) -> Result<CreditAccount>
pub fn apply_payment( &self, customer_id: CustomerId, amount: Decimal, reference_id: Option<Uuid>, ) -> Result<CreditAccount>
Apply a payment to reduce customer balance.
Sourcepub fn get_customer_summary(
&self,
customer_id: CustomerId,
) -> Result<Option<CustomerCreditSummary>>
pub fn get_customer_summary( &self, customer_id: CustomerId, ) -> Result<Option<CustomerCreditSummary>>
Get credit summary for a customer.
Sourcepub fn get_aging_report(&self) -> Result<Vec<(CustomerId, CreditAgingBucket)>>
pub fn get_aging_report(&self) -> Result<Vec<(CustomerId, CreditAgingBucket)>>
Get credit aging report.
Sourcepub fn get_over_limit_customers(&self) -> Result<Vec<CreditAccount>>
pub fn get_over_limit_customers(&self) -> Result<Vec<CreditAccount>>
Get all customers over their credit limit.