I ‘think’ it should be fine. Flowers have their own filtering system so as long as your soap is biodegradable (which I think most are) and the dilution rate is fairly high then there shouldn’t be any problems. Only drawback might be the soap marking / leaving a residue on the flowers, so you may want to water around the roots. On the flip side soap is great for getting rid of aphids so watering over the leaves will keep the bugs away. Spraying plants with a water / washing up liquid mix has been used as a way to get rid of greenfly for years, and I have never heard of it being a problem to the plants. Even on vegetables.
The only thing I’m not sure about is the shaving foam (not sure what it contains) but the dilution should be good enough to sort it out. The rain that falls will contain as many ‘bad’ petrochemicals as any soap / shaving cream solution would.*
*probably 😉