How can reflection and refraction be explained at the level of the photon? And how does a light beam's frequency remain constant after refraction? Why do photons of light bounce back at the angle at which they strike a reflecting surface, and not go in all directions? Why does a photon get deviated from its path if the density of a medium increases?
 A: A photon is not a little classical dot that moves from the source to the detector along a straight path. A photon is a quantum mechanical object that does not even have a position, let alone a path.
A single photon takes all possible paths at once. The phase of the photon evolves along each path at a fixed rate that is its frequency. When it encounters a mirror it takes every possible path to and from the mirror. In an ordinary mirror the phases of most paths cancel out and only the phases of the paths near the minimum-time path do not cancel. However, in unusual situations like a diffraction grating, the non-minimal paths can be made to add up as well creating strong reflection along non-classical directions.
In a refractive medium the phase rate stays constant but the speed of each path slows down. This again leads to most paths canceling except for the paths near the minimum time path. This results in focusing of a lens and other similar effects.
So photons behave with one principle: a photon takes all possible paths, each at the classical speed of light in that medium, and accumulates phase along that path at a fixed rate, and the total effect is determined by adding the contribution of each path (complex addition). This one principle explains all of the classical behavior as well as the non classical behavior.
For a more in-depth explanation see Feynman’s lectures on this topic: http://www.vega.org.uk/video/subseries/8
