Kevin James was arrested following a tip-off after he was seen with a man who was acting in a suspicious manner near shops in the town last year.
Aimee Parkes, prosecuting, told the town's crown court the defendant was caught with 1.44g of heroin and 6.06 grams of cocaine by West Midlands Police officers assisting with an operation.
"On Sunday September 20 at around 5pm police officers on duty in plain clothes went to Costcutter in Whitchurch Road following report of a male acting suspiciously," she said.
"The officers watched the male from a nearby car park. He was described at being agitated, pacing around and using his phone. At about 5.05pm the defendant arrived on a motorcycle. He had with him a 'man bag' with a strap across his chest.
"The officers saw what they perceived to be drug dealing. The defendant went inside the shop. As he came out he was detained and searched," Miss Parkes said.
The court heard that £925 in cash, 14 wraps of cocaine worth up to £850, plus 11 wraps of a heroin valued at £110 and two mobile phones were seized from him.
James, of Seacole Way, Copthorne, pleaded guilty to an offence of possession heroin with intent to supply and an offence of possessing cocaine with intent to supply at a previous hearing in Wolverhampton.
Mr Stephen Scully, defending, told the sentencing hearing that James had played a lesser role and had been drawn into dealing after self-medicating. He said the defendant had autism, severe anxiety and post traumatic stress disorder.
James was jailed for two years suspended for two years with requirements. He must attend 25 activity days and drug rehabilitation for six months. The court also ordered the forfeiture of the cash under the Misuse of Drugs Act and the forfeiture and destruction of the drugs.