Ideas:
1) Establish as much of a communications trail with the buyer (or seller) ahead of time as possible. If you can, get phone number(s), email, and anything else. The more they give you the less likely they are to be someone who will try and pull a heist and disappear. Not perfect, of course, but the less forthcoming they are about identity the less I'd be inclined to trust.
2) Obviously a well-lit, highly public place with security cameras is a must. Walmart parking lots have lots of security cameras and they're fairly visible. Don't then go hide in the farthest corner away from the crowds, though. Got to strike a balance, of course, between alarming the patrons and having no visibility. Police stations are another really, really good choice. Again, not any guarantee, but someone setting out to rob you probably won't meet you at the cop shop. Other good choices -- Sheetz/Wawa or other modern style convenience store with tons of lighting, tons of customers cycling through the parking lot, good security cams.
3) Bring a friend. But not so they can shoot your attackers if things go bad...or not primarily for that reason. Another person there changes the dynamic. Even two thugs are less likely to try and hold up you and the buddy sitting over on the car fender watching. It is much harder to distract two sets of eyes from a sneak/flank maneuver like these dudes pulled on your pal. There is another witness. There is at least some inherent suggestion of physical force capacity. Your pal may have sense enough not to blaze up the parking lot with the Glock under his coat, but they don't know that.
4) Don't JUST bring someone. If they're there, they're there for a reason and you should have some plan to make their presence maximally useful. Discuss what you want your pal to do, and not to do. You really DON'T want him unlimbering his blaster and firing at anyone -- not even if a robbery happens, in many cases. You do want him out of the car, at least a few feet away from the transaction area, watchful (though not intimidating -- 99% of these transactions are good folks, perfectly peaceable, and there's no reason to play the mob heavy, brooding in an overcoat, fingering his gun). You should be there early, if possible, and he should be positioned well and spotting and observing the approaching car and its occupants. He should be watching, and perhaps engaging in conversation, the OTHER guy(s) while you're talking to the buyer/seller. If he's peeking over your shoulder at the trade goods and not paying attention to what's going on around you then he's not helping at all. Keep spread out, even keep the car between you two, so you can't be easily flanked/surprised. Arrange the situation to make it most advantageous for you, and passively most disadvantageous for a hold-up, and most criminals will not be interested in even starting their process.
4) A shootout? Heavens, no! Not unless you are convinced you're about to DIE, and all the possible and likely negative outcomes of gunplay are better than what's going to happen in the next second. Your pal wasn't about to die, they just wanted to commit a robbery. He had a gun to his head. The odds of drawing successfully and engaging the bad guy are really, really low. (If you're trained so very well that you can pull off a disarm and engage under those circumstances, then you don't need me to tell you how bad your odds are.) Few robberies actually end in the victim being killed. NOT killing someone yourself is a very positive outcome, and having to shoot and/or kill someone is the second WORST outcome to this scenario. (Maybe third...killing someone else who happened to get in the way of your bullets while you were defending yourself is probably the second worst.) I won't tell you to be a passive victim, per se but to use your brains and social skills to determine if drawing and firing a weapon is what you MUST do or a poor choice. Those two dudes driving off with your pal's guns, leaving him unharmed and able to go about his life -- that's a very good outcome.
And your pal? If you're being held up, and he's shooting at THEM, then he's shooting at YOU, TOO. And you may have just about worked through this negative social encounter when he fired and now you're standing in a gunfight. That looks cool in the movies. It isn't very cool in real life.
There's a lot of nuance here, almost infinite ways things can go, can work out or end badly. Your infinitely better option is to set things up so that you aren't chosen as a victim -- your location, your position, your presence(s) make a criminal simply drive on by and not begin his plan.