Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d9d3556579 | |||
| c2bd02e9ec |
@@ -26,6 +26,10 @@ Released with 2meet-data-optimizer 1.3.0 (hardening 2.3).
|
|||||||
status `refunded`; untracked orders get none). Repeated events still leave
|
status `refunded`; untracked orders get none). Repeated events still leave
|
||||||
one row per order and vendor. dev36: partial refund then completion records
|
one row per order and vendor. dev36: partial refund then completion records
|
||||||
the refunded amount. (PR-092)
|
the refunded amount. (PR-092)
|
||||||
|
- Amounts follow Marketplace::get_order_profit() (what the vendor is paid,
|
||||||
|
which subtracts the full tax after refunds); the subtotal is floored at 0,
|
||||||
|
so a fully refunded taxed order no longer records a negative commission.
|
||||||
|
(PR-112)
|
||||||
|
|
||||||
### Upgrading
|
### Upgrading
|
||||||
|
|
||||||
|
|||||||
@@ -149,6 +149,10 @@ class TMDO_WC_Orders_Interceptor extends TMDO_Interceptor_Base {
|
|||||||
if ( ! get_option( 'hp_vendor_include_taxes' ) ) {
|
if ( ! get_option( 'hp_vendor_include_taxes' ) ) {
|
||||||
$subtotal -= (float) $order->get_total_tax();
|
$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 );
|
$vendor_payout = max( 0.0, $subtotal * $vendor_share - $fee );
|
||||||
$commission = $subtotal - $vendor_payout;
|
$commission = $subtotal - $vendor_payout;
|
||||||
$commission_rate = round( ( 1 - $vendor_share ) * 100, 2 ); // Platform percentage, as set in Marketplace.
|
$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 );
|
$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 {
|
public function test_a_refund_of_an_untracked_order_records_nothing(): void {
|
||||||
$this->refund( 50.0, 'pending' );
|
$this->refund( 50.0, 'pending' );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user