It depends on how compact this has to be and how automated it should be. To stop a cart you just need one or two booster rails which are powered off. When it comes onti it, it stops. This would be one way
But it can be more complex and more automated. With pistons etc. Can't find a video but I alway use it with pistons.