Need Minecraft command block

I'm making a custom skyblock world and I want to involve a purchasing system using command blocks. This purchasing system will allow you to purchase most vanilla blocks and items which would otherwise be unavailable in skyblock using emeralds.

The basic requirements I want for the command blocks are as such:

If a player types "*purchase [item]*," they will receive the specified item in their inventory and the cost in emeralds will be deducted from their inventory.

If there are not enough emeralds in the player's inventory, they will not receive any items.

I don't know if this is possible, but it would really help out if somebody could sort this out for me.

Also, it can use however many command blocks you want. I understand completely that it will most likely be one block per item.

Nobody cares