quickbooks_types/models/
bill_payment.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4#[cfg(feature = "builder")]
5use crate::error::QBTypeError;
6use crate::{
7    common::{MetaData, NtRef},
8    LineField, QBCreatable, QBDeletable, QBFullUpdatable, QBItem, QBVoidable,
9};
10
11#[skip_serializing_none]
12#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
13#[serde(rename_all = "PascalCase", default)]
14#[cfg_attr(
15    feature = "builder",
16    derive(Builder),
17    builder(default, build_fn(error = "QBTypeError"), setter(into, strip_option))
18)]
19
20/// `BillPayment`
21///
22/// Represents a payment applied to vendor bills (accounts payable). Payments can be made by check or credit card; corresponding details are provided via `check_payment` or `credit_card_payment`.
23///
24/// API reference:
25/// <https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/billpayment>
26pub struct BillPayment {
27    /// The unique sync token of the entity, used for concurrency control
28    pub sync_token: Option<String>,
29    /// Domain of the transaction. `QBO` for `QuickBooks` Online.
30    pub domain: Option<String>,
31    /// Reference to the vendor for the transaction.
32    pub vendor_ref: Option<NtRef>,
33    /// Date of the transaction in YYYY-MM-DD format.
34    pub txn_date: Option<String>,
35    /// Total amount of the transaction.
36    pub total_amt: Option<f64>,
37    /// Type of payment for the transaction.
38    pub pay_type: Option<PayType>,
39    /// Private note for the transaction
40    pub private_note: Option<String>,
41    /// Indicates if the transaction is a sparse object
42    pub sparse: Option<bool>,
43    /// Line items for the transaction
44    pub line: Option<LineField>,
45    /// The unique ID of the entity
46    pub id: Option<String>,
47    /// Information about a check payment for the transaction. Not applicable to Estimate and `SalesOrder`. Used when `PayType` is `Check`
48    pub check_payment: Option<CheckBillPayment>,
49    /// Information about a credit card payment for the transaction. Not applicable to Estimate and `SalesOrder`. Used when `PayType` is `CreditCard`
50    pub credit_card_payment: Option<CreditCardBillPayment>,
51    /// Metadata about the transaction
52    pub meta_data: Option<MetaData>,
53}
54
55/// `CheckBillPayment`
56///
57/// Information about a check payment for the transaction.
58#[skip_serializing_none]
59#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
60#[serde(rename_all = "PascalCase")]
61pub struct CheckBillPayment {
62    pub print_status: Option<String>,
63    pub bank_account_ref: Option<NtRef>,
64}
65
66/// `CreditCardBillPayment`
67///
68/// Information about a credit card payment for the transaction.
69#[skip_serializing_none]
70#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
71pub struct CreditCardBillPayment {
72    #[serde(rename = "CCAccountRef")]
73    pub cc_account_ref: Option<NtRef>,
74}
75
76/// `PayType`
77///
78/// Method by which a bill payment is made.
79#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
80pub enum PayType {
81    #[default]
82    CreditCard,
83    Check,
84}
85
86impl QBCreatable for BillPayment {
87    fn can_create(&self) -> bool {
88        self.vendor_ref.is_some()
89            && self.total_amt.is_some()
90            && self.line.is_some()
91            && self.pay_type.as_ref().is_some_and(|e| match e {
92                PayType::CreditCard => self.credit_card_payment.is_some(),
93                PayType::Check => self.check_payment.is_some(),
94            })
95        // TODO Currency ref check
96    }
97}
98
99impl QBVoidable for BillPayment {}
100impl QBDeletable for BillPayment {}
101impl QBFullUpdatable for BillPayment {
102    fn can_full_update(&self) -> bool {
103        self.can_create() && self.has_read()
104    }
105}