API design

One gift card API over every brand's own system

How Hubble puts one gift card order API over brand systems that differ in amounts, speed, errors and terms, and why a slow answer is not a failure.

A partner calls one endpoint to buy a gift card from any of the 500+ brands on Hubble, and gets back the same order shape every time. Behind it, no two brands’ card systems agree. This is how we put one interface over them, and what it costs us.

Why one interface is hard

The card systems behind our brands differ on almost everything an order touches. One sells fixed amounts and another sells any amount in a range, and the list can change without notice. One returns a card in its reply, another only later. Each has its own error codes, and some say “out of stock” only in free text. The same brand’s card can even carry different terms depending on who issues it.

A partner should see none of this. Their order should succeed, fail or say it is still working, in one shape, with one set of error codes.

Two facts raise the stakes. The buyer’s money moves before the card exists, and a card, once issued, cannot be taken back. A wrong answer either keeps money for a card that never came or gives away a card nobody paid for.

The public contract

The contract a partner builds against is small on purpose.

  • One order shape for every brand. The same request and the same response, whatever system sits behind the brand.
  • In progress is a normal answer. An order can be complete, failed or still in progress, and none of these is an error.
  • Results by webhook or polling. A partner hears the outcome either way, as the orders docs describe.
  • One list of errors. Every error comes from one closed list in the error docs. A partner never sees a brand system’s own words.
  • Safe to repeat. A repeated request cannot produce a second card.

Adding a new card system must not change any line of this list. That rule shaped most of what follows.

How we built it

An adapter per card system. Each system behind our brands has its own adapter, and the contract between an adapter and the rest of our code is narrow. It places an order with a reference we give, asks about an order by that reference, and answers in one shape: a status and a list of cards. Everything a system is odd about, from how it signs in to its date formats, stays inside its adapter.

Our reference, not theirs. The reference an adapter sends is made from our own order. Asking about an order again is the same question, never a new order. That is what lets us ask as often as we need without risking a second card.

Errors translated at the edge. Each adapter maps its system’s codes and messages onto our closed list. Anything it does not recognise becomes a general error rather than leaking through. A new system never adds an error a partner has to learn.

Slow cards are a normal state. An adapter never treats a timeout as a failure. If a system did not answer in time, we cannot know whether a card was made, so the order stays in progress and the partner hears the result when it is known. A clear refusal, such as an amount the brand does not sell, ends the order, and the partner’s money goes back.

How an order reaches a brand’s system, and what we do when that system is failing, we leave out on purpose. From the partner’s side, the order shape does not change.

Trade-offs we accepted

A switch, not a plugin system. Our order code picks an adapter with one switch over a closed list. A new card system touches several places, but the compiler points to most of them, and each adapter keeps its own inputs instead of being forced into a generic interface. Where several integrations do share one shape, they share a real interface.

Waiting costs time. A partner can wait longer for an answer than a quick failure would take. We chose that over refunding orders whose cards might exist.

The common card shape is the smallest shared one. A field only one system returns is dropped unless we add it for everyone. Partners get less, but what they get is always there.

What we would tell another team

  • Decide what “I don’t know” means before you write the first adapter. Most of this design follows from treating it as its own state.
  • Own the reference. Make every outside system’s reference from your own order, so asking again is always safe.
  • Translate errors at the edge into a closed list, and give anything unknown a default.
  • Keep each outside system’s quirks inside its adapter, so adding one changes nothing a partner sees.
  • Keep the shared shape small. Adding a field for everyone later is easier than taking one away.

Our partner API is documented at docs.myhubble.money and described on the API page. For how an order stays safe when a brand is slow, see never keep money without a code. If you would like to work on problems like this, see careers at Hubble.

Questions people ask

Why not fail an order when a brand's system times out?

Because a timeout does not tell you whether a card was made. Failing the order would refund the buyer while a card might exist. We keep the order in progress and ask again with the same reference, which can never create a second card.

How does a partner get the result of an order that is still in progress?

By webhook or by polling, as the orders documentation at docs.myhubble.money describes. In progress is a normal answer in the API, not an error.

Will a partner ever see a brand system's own error messages?

No. Each adapter translates its system's codes and messages into one closed list of Hubble error codes, which is published in the API documentation. Anything it does not recognise becomes a general error.

Why a switch over a closed list instead of a plugin interface?

The systems behind brands differ too much in what they need to place an order. A switch over a closed list lets each adapter keep its own inputs, and the compiler points to most places a new system must be handled.

Build with us, or on us

Read the docs, or see the roles we are hiring for.