is_paid() ) { return self::CONFIRMED; } if ( method_exists( $order, 'get_date_paid' ) ) { $paid = $order->get_date_paid(); if ( ! empty( $paid ) ) { return self::CONFIRMED; } } $status = method_exists( $order, 'get_status' ) ? (string) $order->get_status() : ''; if ( 0 === strpos( $status, 'wc-' ) ) { $status = substr( $status, 3 ); } // Processing / completed are payment-confirmed lifecycle states (incl. COD). if ( in_array( $status, array( 'processing', 'completed' ), true ) ) { return self::CONFIRMED; } return self::PRELIMINARY; } /** * @param string|null $state Stored state. * @return bool */ public static function is_preliminary( $state ) { return self::PRELIMINARY === (string) $state; } /** * @param string|null $state Stored state. * @return bool */ public static function is_confirmed( $state ) { $state = (string) $state; // Legacy rows without the column are treated as confirmed. return '' === $state || self::CONFIRMED === $state; } /** * Read from a persisted row (column preferred; coverage_json fallback). * * @param array $row Order risk row. * @return string */ public static function from_row( array $row ) { if ( isset( $row['payment_result_state'] ) && '' !== (string) $row['payment_result_state'] ) { return (string) $row['payment_result_state']; } if ( ! empty( $row['coverage_json'] ) ) { $coverage = json_decode( (string) $row['coverage_json'], true ); if ( is_array( $coverage ) && ! empty( $coverage['payment_result_state'] ) ) { return (string) $coverage['payment_result_state']; } } return self::CONFIRMED; } /** * Merchant-facing note for preliminary results. * * @return string */ public static function preliminary_note() { return __( 'Payment pending — preliminary result', 'marginbeacon' ); } /** * Prevent instantiation. */ private function __construct() {} }