quickbooks_types/models/
payment.rs

1use chrono::NaiveDate;
2use serde::{Deserialize, Serialize};
3use serde_with::skip_serializing_none;
4
5use super::common::{CreditCardPayment, MetaData, NtRef};
6#[cfg(feature = "builder")]
7use crate::error::QBTypeError;
8use crate::{
9    LineField, QBCreatable, QBDeletable, QBFullUpdatable, QBItem, QBPDFable, QBSendable, QBVoidable,
10};
11
12#[skip_serializing_none]
13#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
14#[serde(rename_all = "PascalCase", default)]
15#[cfg_attr(
16    feature = "builder",
17    derive(Builder),
18    builder(default, build_fn(error = "QBTypeError"), setter(into, strip_option))
19)]
20
21/// `Payment`
22///
23/// Represents receipt or application of funds against customer balances or invoices.
24///
25/// Creation requirements:
26/// - `QBCreatable::can_create()` returns true when both `total_amt` and `customer_ref` are present.
27///
28/// Update semantics:
29/// - `QBFullUpdatable::can_full_update()` returns true when `has_read()` (ID + sync token) and `can_create()` are both true.
30/// - `QBDeletable` and `QBVoidable` are implemented; both require `has_read()`.
31///
32/// API reference:
33/// <https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/payment>
34pub struct Payment {
35    /// The unique ID of the entity
36    pub id: Option<String>,
37    /// The unique sync token of the entity, used for concurrency control
38    pub sync_token: Option<String>,
39    /// Metadata about the entity
40    #[serde(skip_serializing)]
41    pub meta_data: Option<MetaData>,
42    /// Total amount of the payment
43    pub total_amt: Option<f64>,
44    /// Reference to the customer for the payment
45    pub customer_ref: Option<NtRef>,
46    /// Reference to the currency for the payment
47    pub currency_ref: Option<NtRef>,
48    /// Private note for the payment
49    pub private_note: Option<String>,
50    /// Reference to the payment method
51    pub payment_method_ref: Option<NtRef>,
52    /// Unapplied amount of the payment
53    pub unapplied_amt: Option<f64>,
54    /// Reference to the account where the payment is deposited
55    pub deposit_to_account_ref: Option<NtRef>,
56    /// Exchange rate for the payment
57    pub exchange_rate: Option<f64>,
58    /// Line items for the payment
59    pub line: Option<LineField>,
60    /// Source of the transaction
61    pub txn_source: Option<String>,
62    /// Reference to the accounts receivable account
63    #[serde(rename = "ARAccountRef")]
64    pub ar_account_ref: Option<NtRef>,
65    /// Date of the transaction in YYYY-MM-DD format
66    pub txn_date: Option<NaiveDate>,
67    /// Information about a credit card payment for the transaction
68    pub credit_card_payment: Option<CreditCardPayment>,
69    /// Type of location for the transaction
70    pub transaction_location_type: Option<String>,
71    /// Reference number for the payment
72    pub payment_ref_num: Option<String>,
73    /// Reference to the tax exemption for the payment
74    pub tax_exemption_ref: Option<NtRef>,
75}
76
77impl QBCreatable for Payment {
78    fn can_create(&self) -> bool {
79        self.total_amt.is_some() && self.customer_ref.is_some()
80    }
81}
82
83impl QBDeletable for Payment {}
84impl QBVoidable for Payment {}
85impl QBFullUpdatable for Payment {
86    fn can_full_update(&self) -> bool {
87        self.has_read() && self.can_create()
88    }
89}
90
91impl QBSendable for Payment {}
92impl QBPDFable for Payment {}