There is a magnet with plastic around it, which you could pin under the lining and fabric. Once you pin it where you want to, for closure, you could sew the magnet around the plastic on the bag.
There is another type of magnet that you don’t have to sew on. You just have to mark where you want to put the magnet. These magnets have little sharp points for you to stick into the fabric and close the points for it to stay.
I usually put an extra piece of small fabric around the magnet if the fabric is light weight, to give it more strength, so the magnet wouldn’t come apart. If the fabric is thick, you don’t need the extra fabric.