We derive explicit formulas for barrier options of European type and touch-and-out options assuming that under a chosen equivalent martingale measure the stock returns follow a Lévy process from a wide class, which contains Brownian motions (BM), normal inverse Gaussian processes (NIG), hyperbolic processes (HP), normal tilted stable Lévy processes (NTS Lévy), processes of the KoBoL family and any finite mixture of independent BM, NIG, HP, NTS Lévy and KoBoL processes. In contrast to the Gaussian case, for a barrier option, a rebate must be specified not only at the barrier but for all values of the stock on the other side of the barrier. We consider options with a constant or exponentially decaying rebate and options which pay a fixed rebate when the first barrier has been crossed but the second one has not. We obtain pricing formulas by solving boundary problems for the generalized Black--Scholes equation. We use the representation of the $q$-order harmonic measure of a set relative to a point in terms of the $q$-potential measure, the Wiener--Hopf factorization method and elements of the theory of pseudodifferential operators.