Skip to content

Commit

Permalink
Merge pull request #2906 from woocommerce/PCP-4014-Zero-Value-Free-Gi…
Browse files Browse the repository at this point in the history
…ft-Item-Causing-“CANNOT-BE-NEGATIVE”-Error

Fix negative unit amount adjustments in item sanitization
  • Loading branch information
InpsydeNiklas authored Dec 23, 2024
2 parents 64d791d + 9c44783 commit e948c43
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/ppcp-api-client/src/Helper/PurchaseUnitSanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ private function sanitize_item_amount_mismatch(): void {
// Get a more intelligent adjustment mechanism.
$increment = ( new MoneyFormatter() )->minimum_increment( $item['unit_amount']['currency_code'] );

// not floor items that will be negative then.
if ( (float) $item['unit_amount']['value'] < $increment ) {
continue;
}

$this->purchase_unit['items'][ $index ]['unit_amount'] = ( new Money(
( (float) $item['unit_amount']['value'] ) - $increment,
$item['unit_amount']['currency_code']
Expand Down

0 comments on commit e948c43

Please sign in to comment.