Skip to main content

WithholdingGenerator

Struct WithholdingGenerator 

Source
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

Source

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%).

Source

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.

Source

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)
Source

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_rate is applied.
  • withheld_amount = base_amount * applied_rate.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more