charge_mode() ) { PriceChargeMode::Full => $running, PriceChargeMode::OnSite => Money::zero( $running->currency() ), PriceChargeMode::Deposit => $this->deposit_amount( $ctx, $running ), }; } /** * Deposit amount capped at the grand total. * * @param PriceContext $ctx Context. * @param Money $total Grand total. * * @since 0.1.0 */ public function deposit_amount( PriceContext $ctx, Money $total ): Money { if ( DepositType::None === $ctx->deposit_type() ) { return $total; } if ( DepositType::Percent === $ctx->deposit_type() ) { return $total->percent( $ctx->deposit_value() ); } $fixed = new Money( $ctx->deposit_value(), $total->currency() ); if ( $fixed->amount_minor() > $total->amount_minor() ) { return $total; } return $fixed; } }