How can I create a system/backend that will generate a discount code then allow that code to be distributed/retrieved to/from a 3rd party system?
You need to create a web application and expose its functionality via API. Then protect the API with auth (for example OAuth), write documentation and provide it to 3rd party.
I suggest reading on RESTful APIs and using Ruby on Rails.