pub struct Payments { /* private fields */ }Expand description
Payment operations for transaction processing and refunds
Implementations§
Source§impl Payments
impl Payments
Sourcepub fn create(&self, input: CreatePayment) -> Result<Payment>
pub fn create(&self, input: CreatePayment) -> Result<Payment>
Create a new payment
§Example
use stateset_embedded::{Commerce, CreatePayment, PaymentMethodType, CardBrand, OrderId, CurrencyCode};
use rust_decimal_macros::dec;
let commerce = Commerce::new("./store.db")?;
let payment = commerce.payments().create(CreatePayment {
order_id: Some(OrderId::new()),
payment_method: PaymentMethodType::CreditCard,
amount: dec!(149.99),
currency: Some(CurrencyCode::USD),
card_brand: Some(CardBrand::Visa),
card_last4: Some("4242".into()),
billing_email: Some("customer@example.com".into()),
..Default::default()
})?;Sourcepub fn get_by_number(&self, payment_number: &str) -> Result<Option<Payment>>
pub fn get_by_number(&self, payment_number: &str) -> Result<Option<Payment>>
Get a payment by payment number (e.g., “PAY-20231215123456”)
Sourcepub fn get_by_external_id(&self, external_id: &str) -> Result<Option<Payment>>
pub fn get_by_external_id(&self, external_id: &str) -> Result<Option<Payment>>
Get a payment by external ID (e.g., Stripe payment intent ID)
Sourcepub fn list(&self, filter: PaymentFilter) -> Result<Vec<Payment>>
pub fn list(&self, filter: PaymentFilter) -> Result<Vec<Payment>>
List payments with optional filtering
Sourcepub fn for_order(&self, order_id: OrderId) -> Result<Vec<Payment>>
pub fn for_order(&self, order_id: OrderId) -> Result<Vec<Payment>>
Get all payments for an order
Sourcepub fn for_invoice(&self, invoice_id: Uuid) -> Result<Vec<Payment>>
pub fn for_invoice(&self, invoice_id: Uuid) -> Result<Vec<Payment>>
Get all payments for an invoice
Sourcepub fn mark_processing(&self, id: PaymentId) -> Result<Payment>
pub fn mark_processing(&self, id: PaymentId) -> Result<Payment>
Mark payment as processing
Sourcepub fn mark_completed(&self, id: PaymentId) -> Result<Payment>
pub fn mark_completed(&self, id: PaymentId) -> Result<Payment>
Mark payment as completed
This records the payment timestamp and marks the transaction as successful.
Sourcepub fn mark_failed(
&self,
id: PaymentId,
reason: &str,
code: Option<&str>,
) -> Result<Payment>
pub fn mark_failed( &self, id: PaymentId, reason: &str, code: Option<&str>, ) -> Result<Payment>
Mark payment as failed
§Arguments
id- Payment IDreason- Human-readable failure reasoncode- Optional error code from payment processor
Sourcepub fn create_refund(&self, input: CreateRefund) -> Result<Refund>
pub fn create_refund(&self, input: CreateRefund) -> Result<Refund>
Create a refund for a payment
§Example
use stateset_embedded::{Commerce, CreateRefund, PaymentId};
use rust_decimal_macros::dec;
let commerce = Commerce::new("./store.db")?;
// Full refund (omit amount for full refund)
let refund = commerce.payments().create_refund(CreateRefund {
payment_id: PaymentId::new(),
reason: Some("Customer request".into()),
..Default::default()
})?;
// Partial refund
let refund = commerce.payments().create_refund(CreateRefund {
payment_id: PaymentId::new(),
amount: Some(dec!(50.00)),
reason: Some("Partial refund for damaged item".into()),
..Default::default()
})?;Sourcepub fn get_refunds(&self, payment_id: PaymentId) -> Result<Vec<Refund>>
pub fn get_refunds(&self, payment_id: PaymentId) -> Result<Vec<Refund>>
Get all refunds for a payment
Sourcepub fn complete_refund(&self, id: Uuid) -> Result<Refund>
pub fn complete_refund(&self, id: Uuid) -> Result<Refund>
Complete a refund
This marks the refund as processed and updates the payment’s refunded amount.
Sourcepub fn create_payment_method(
&self,
input: CreatePaymentMethod,
) -> Result<PaymentMethod>
pub fn create_payment_method( &self, input: CreatePaymentMethod, ) -> Result<PaymentMethod>
Create a stored payment method for a customer
§Example
use stateset_embedded::{Commerce, CreatePaymentMethod, PaymentMethodType, CardBrand, CustomerId};
let commerce = Commerce::new("./store.db")?;
let method = commerce.payments().create_payment_method(CreatePaymentMethod {
customer_id: CustomerId::new(),
method_type: PaymentMethodType::CreditCard,
is_default: Some(true),
card_brand: Some(CardBrand::Visa),
card_last4: Some("4242".into()),
card_exp_month: Some(12),
card_exp_year: Some(2025),
cardholder_name: Some("Alice Smith".into()),
..Default::default()
})?;Sourcepub fn get_payment_methods(
&self,
customer_id: CustomerId,
) -> Result<Vec<PaymentMethod>>
pub fn get_payment_methods( &self, customer_id: CustomerId, ) -> Result<Vec<PaymentMethod>>
Get all payment methods for a customer
Sourcepub fn delete_payment_method(&self, id: Uuid) -> Result<()>
pub fn delete_payment_method(&self, id: Uuid) -> Result<()>
Delete a payment method
Sourcepub fn set_default_payment_method(
&self,
customer_id: CustomerId,
method_id: Uuid,
) -> Result<()>
pub fn set_default_payment_method( &self, customer_id: CustomerId, method_id: Uuid, ) -> Result<()>
Set a payment method as the default for a customer
Sourcepub fn count(&self, filter: PaymentFilter) -> Result<u64>
pub fn count(&self, filter: PaymentFilter) -> Result<u64>
Count payments matching a filter