All you need to do is go to any metro station in Madrid and place your order at any of the ticket machines there. These machines look like ATMs but will have the branding of the Madrid metro on them. Once there you can pay either in cash or with credit card.