The conditions for leaving the shop is the same as the conditions that disables your ability to undo purchases, and is tied to both distance from the shopkeeper as well as combat status. A few other effects and triggers will also classify you as leaving the shop.
Passive: After 2:00 elapse, you can enter debt to buy items, up to 145 (+ 7 per minute), which is displayed as negative gold in your treasury. Future's Market activates after 2:00 elapse.