$failure */ public static function build( array $failure ): string { $reason = sanitize_key( (string) ( $failure['reason'] ?? '' ) ); $status = (int) ( $failure['status'] ?? 0 ); $is_local = ! empty( $failure['is_local'] ); if ( 'webhook_url_unreachable' === $reason ) { $message = 'Payment could not be started because the webhook is unreachable.'; if ( $is_local ) { $message .= ' Local environments are often not publicly reachable.'; } return self::append_status( $message, $status ); } if ( 'webhook_url_invalid' === $reason ) { return self::append_status( 'Payment could not be started because the webhook is invalid.', $status ); } if ( 'invalid_phone_number' === $reason ) { return self::append_status( 'Payment could not be started because the phone number is invalid.', $status ); } if ( 'fraud_rejection' === $reason ) { return self::append_status( 'Payment could not be started because the payment was rejected.', $status ); } return ''; } private static function append_status( string $message, int $status ): string { if ( $status <= 0 ) { return $message; } return sprintf( '%s (%d)', $message, $status ); } }