mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Update PaymentsStatusHandlingTrait.php
Improve error handling in `PaymentsStatusHandlingTrait` to avoid null reference errors - Added safety checks for purchase_units, payments, captures, and authorizations - Ensured that methods are only called when necessary data exists - Skipped processing if data is missing, preventing potential fatal errors without logging - Enhanced code robustness for production environment
This commit is contained in:
parent
31afc7263e
commit
eb2250b0e6
1 changed files with 20 additions and 4 deletions
|
@ -34,10 +34,26 @@ trait PaymentsStatusHandlingTrait {
|
|||
Order $order,
|
||||
WC_Order $wc_order
|
||||
): void {
|
||||
if ( $order->intent() === 'CAPTURE' ) {
|
||||
$this->handle_capture_status( $order->purchase_units()[0]->payments()->captures()[0], $wc_order );
|
||||
} elseif ( $order->intent() === 'AUTHORIZE' ) {
|
||||
$this->handle_authorization_status( $order->purchase_units()[0]->payments()->authorizations()[0], $wc_order );
|
||||
if ($order->intent() === 'CAPTURE') {
|
||||
$purchase_units = $order->purchase_units();
|
||||
|
||||
if (!empty($purchase_units) && isset($purchase_units[0])) {
|
||||
$payments = $purchase_units[0]->payments();
|
||||
|
||||
if ($payments && !empty($payments->captures())) {
|
||||
$this->handle_capture_status($payments->captures()[0], $wc_order);
|
||||
}
|
||||
}
|
||||
} elseif ($order->intent() === 'AUTHORIZE') {
|
||||
$purchase_units = $order->purchase_units();
|
||||
|
||||
if (!empty($purchase_units) && isset($purchase_units[0])) {
|
||||
$payments = $purchase_units[0]->payments();
|
||||
|
||||
if ($payments && !empty($payments->authorizations())) {
|
||||
$this->handle_authorization_status($payments->authorizations()[0], $wc_order);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue