fix(2meet-data-optimizer-woocommerce-addon): record no negative commission for a fully refunded taxed order

- the amounts follow Marketplace::get_order_profit() (what the vendor is
  paid), which subtracts the full order tax after refunds; a fully refunded
  taxed order came out at subtotal = commission = -tax. The subtotal is now
  floored at 0 (security review M2); partial refunds keep matching what
  Marketplace pays
- Verify: WCOrdersInterceptorTest (full refund with tax), integration 28, unit 11, phpcs
- PR: PR-112 (2.3 acceptance security review)
This commit is contained in:
2026-09-27 17:23:16 +08:00
parent 22afabc649
commit c2bd02e9ec
2 changed files with 21 additions and 0 deletions
@@ -149,6 +149,10 @@ class TMDO_WC_Orders_Interceptor extends TMDO_Interceptor_Base {
if ( ! get_option( 'hp_vendor_include_taxes' ) ) {
$subtotal -= (float) $order->get_total_tax();
}
// Marketplace subtracts the full tax even after a refund; a fully
// refunded taxed order would otherwise record a negative amount.
$subtotal = max( 0.0, $subtotal );
$vendor_payout = max( 0.0, $subtotal * $vendor_share - $fee );
$commission = $subtotal - $vendor_payout;
$commission_rate = round( ( 1 - $vendor_share ) * 100, 2 ); // Platform percentage, as set in Marketplace.
@@ -204,6 +204,23 @@ class WCOrdersInterceptorTest extends TestCase {
$this->assertEqualsWithDelta( 0.0, (float) $row['vendor_payout'], 0.0001 );
}
/**
* Amounts follow Marketplace::get_order_profit() (what the vendor is paid,
* which subtracts the full tax after refunds), but a fully refunded taxed
* order must not record a negative subtotal or commission.
*/
public function test_a_fully_refunded_taxed_order_records_no_negative_amounts(): void {
$this->place_order( $this->marketplace_meta(), 110.0, 10.0 );
$this->refund( 110.0, 'refunded' );
( new TMDO_WC_Orders_Interceptor() )->action_order_refunded( self::ORDER_ID, 1 );
$row = $this->commission_row();
$this->assertEqualsWithDelta( 0.0, (float) $row['subtotal'], 0.0001 );
$this->assertEqualsWithDelta( 0.0, (float) $row['commission'], 0.0001 );
$this->assertEqualsWithDelta( 0.0, (float) $row['vendor_payout'], 0.0001 );
}
public function test_a_refund_of_an_untracked_order_records_nothing(): void {
$this->refund( 50.0, 'pending' );