It probably depends where you buy them from.
Make sure you take a picture of the fish while still in the bags if you get any dead on arrival but generally I've had no problems, nor did I get any dead or diseased fish, or disease outbreaks. Where I buy them from they arrive in great condition.
You need to be prepared to drip acclimate them, not to stress them with sudden bright lights, etc..Get the camera ready just in case...It's as safe as buying fish directly from the shop if the place you buy is decent. Fish can travel if well packed.
Have a container/bucket where you can put them in to acclimate. Have your ammonia and Ph test on hand too, if the difference between yours and the fish water is great as in Ph, make sure you acclimate(drip water from the main tank) until they equalize. If there's lots of ammonia in their water, make sure to remove some water from the container while dripping new one from your tank as often as you can without stressing the fish, so eventually the ammonia will be gone. You can put a drop of prime if you have it to nutralize any ammonia. And top up the tank with dechlorinated, temperature matched water while acclimating, so you don't have to turn off the filter/heater in the main tank.
Once done, net them in the tank, turn off the tank lights and feed them a bit. If the tank has other fish, make sure to feed the other fish before putting new ones in case some larger fish of yours think food is coming.
So basically, reduce stress as much as you can by properly acclimating them, keeping them in the dark and feeding them a bit after. And of course a well cycled tank to put them in with proper tank mates and suitable decoration with hiding spots.