Banks and credit-card companies are discussing ways to identify purchases of guns in their payment systems, a move that could be a prelude to restricting such transactions, according to people familiar with the talks.

The discussions are preliminary but could be deeply controversial. Gun-rights groups have long resisted any effort to monitor which Americans own guns; there are federal laws limiting the government’s use of electronic databases of gun sales.

The financial companies have explored creating a new credit-card code for firearms dealers, similar to how they code restaurants or department stores, according to people familiar with the matter. Another idea would require merchants to share information about specific firearm products consumers are buying, some of the people said.

Such data could allow banks to restrict purchases at certain businesses or monitor them. The talks, which are informal and might not lead to any action, have occurred against the backdrop of the national debate around guns in the wake of the Parkland, Fla., high-school shooting, which left 17 dead.

Financial firms already have come under pressure from both sides in the gun debate.