pub struct WithholdingGenerator { /* private fields */ }Expand description
Generates withholding tax records for cross-border vendor payments.
For each payment where vendor_country != source_country:
- Looks up the treaty rate for the
(source_country, vendor_country)pair. - If a treaty exists, applies the treaty rate.
- If no treaty exists, applies the default withholding rate.
- Computes
withheld_amount = base_amount * applied_rate.
Domestic payments (where vendor_country == source_country) are excluded
from withholding and produce no records.
§Standard Treaty Rates
The with_standard_treaties
method loads a US-centric treaty network with service withholding rates for
major trading partners (GB, DE, JP, FR, SG, IN, BR).
Implementations§
Source§impl WithholdingGenerator
impl WithholdingGenerator
Sourcepub fn new(seed: u64, default_rate: Decimal) -> Self
pub fn new(seed: u64, default_rate: Decimal) -> Self
Creates a new withholding generator with the given seed and default rate.
The default rate is applied when no treaty rate exists for a given
country pair. A common value is 0.30 (30%).
Sourcepub fn add_treaty_rate(
&mut self,
source_country: &str,
vendor_country: &str,
rate: Decimal,
)
pub fn add_treaty_rate( &mut self, source_country: &str, vendor_country: &str, rate: Decimal, )
Adds a treaty rate for a specific country pair.
The rate is stored for the (source_country, vendor_country) direction.
Treaty rates are directional: a US-DE treaty rate applies when the US is
the source and DE is the vendor, but not vice versa.
Sourcepub fn with_standard_treaties(self) -> Self
pub fn with_standard_treaties(self) -> Self
Loads the standard US treaty network for service withholding rates.
Treaty rates (service withholding, US perspective):
- US-GB: 0% (services)
- US-DE: 0% (services)
- US-JP: 0% (services)
- US-FR: 0% (services)
- US-SG: 0% (services)
- US-IN: 15% (services)
- US-BR: 15% (services)
Sourcepub fn generate(
&mut self,
payments: &[(String, String, String, Decimal)],
source_country: &str,
) -> Vec<WithholdingTaxRecord>
pub fn generate( &mut self, payments: &[(String, String, String, Decimal)], source_country: &str, ) -> Vec<WithholdingTaxRecord>
Generate withholding records for cross-border payments.
Each payment is a tuple of (payment_id, vendor_id, vendor_country, amount).
Domestic payments (where vendor_country == source_country) are excluded.
For each cross-border payment:
- If a treaty rate exists for
(source_country, vendor_country), the treaty rate is applied. - Otherwise the
default_rateis applied. withheld_amount = base_amount * applied_rate.