Commit 59bddfe5b2 for woocommerce

commit 59bddfe5b22cf6645384035ff49d6009f7e5d7da
Author: Mayisha <33387139+Mayisha@users.noreply.github.com>
Date:   Tue Dec 16 09:49:30 2025 +0600

    PayPal Standard: Add order amount validation for purchase unit (#62385)

    * add order amount validation for paypal purchase unit

    * fix comment

    * move check outside

    * fix phpstan

diff --git a/plugins/woocommerce/changelog/62385-fix-paypal-standard-zero-or-negative-order-total b/plugins/woocommerce/changelog/62385-fix-paypal-standard-zero-or-negative-order-total
new file mode 100644
index 0000000000..18c89fce4f
--- /dev/null
+++ b/plugins/woocommerce/changelog/62385-fix-paypal-standard-zero-or-negative-order-total
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Added validation for PayPal Standard purchase unit amount in create-order requests to prevent errors when order totals are invalid.
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php b/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php
index 450a2c9ba0..f925928c7a 100644
--- a/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php
+++ b/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php
@@ -618,6 +618,13 @@ class WC_Gateway_Paypal_Request {
 			throw new Exception( 'Currency is not supported by PayPal. Order ID: ' . esc_html( $order->get_id() ) );
 		}

+		$purchase_unit_amount = $this->get_paypal_order_purchase_unit_amount( $order );
+		if ( $purchase_unit_amount['value'] <= 0 ) {
+			// If we cannot build purchase unit amount (e.g. negative or zero order total),
+			// we should not proceed with the create-order request.
+			throw new Exception( 'Cannot build PayPal order purchase unit amount. Order total is not valid. Order ID: ' . esc_html( (string) $order->get_id() ) . ', Total: ' . esc_html( (string) $purchase_unit_amount['value'] ) );
+		}
+
 		$order_items = $this->get_paypal_order_items( $order );
 		if ( empty( $order_items ) ) {
 			// If we cannot build order items (e.g. negative item amounts),
@@ -657,7 +664,7 @@ class WC_Gateway_Paypal_Request {
 			'purchase_units' => array(
 				array(
 					'custom_id'  => $this->get_paypal_order_custom_id( $order ),
-					'amount'     => $this->get_paypal_order_purchase_unit_amount( $order ),
+					'amount'     => $purchase_unit_amount,
 					'invoice_id' => $this->limit_length( $this->gateway->get_option( 'invoice_prefix' ) . $order->get_order_number(), WC_Gateway_Paypal_Constants::PAYPAL_INVOICE_ID_MAX_LENGTH ),
 					'items'      => $order_items,
 					'payee'      => array(