Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Stripe's API

Amber Feng
February 21, 2013

Building Stripe's API

How we built the Stripe API: lessons learned, and things we did to make the API as easy to use as possible.

Amber Feng

February 21, 2013
Tweet

More Decks by Amber Feng

Other Decks in Programming

Transcript

  1. BUILDING
    STRIPE'S API
    AMBER FENG @amfeng

    View full-size slide

  2. STRIPE:
    PAYMENTS FOR DEVELOPERS

    View full-size slide

  3. WE CARE ABOUT
    API DESIGN

    View full-size slide

  4. PAYMENTS API
    CREDIT CARD PAYMENTS
    TOKENIZED & STORED CARDS
    RECURRING BILLING
    > curl https://api.stripe.com/v1/charges \
    -u sk_test_mkGsLqEW6SLnZa487HYfJVLf: \
    -d amount=400 \
    -d currency=usd \
    -d "card[number]=4242424242424242" \
    -d "card[exp_month]=12" \
    -d "card[exp_year]=2014" \
    -d "card[cvc]=123"

    View full-size slide

  5. DESIGNING
    THE API

    View full-size slide

  6. RPC ORIENTED
    ○ method=list_charges
    ○ All calls are POST, and return 200
    POST /v0?method=list_charges
    &key=KEY
    v0 API (2010, beta)

    View full-size slide

  7. DESIGN GOALS:
    CONSISTENCY,
    SIMPLICITY,
    POWER

    View full-size slide

  8. HTTP ORIENTED
    ○ GET, POST, DELETE
    ○ HTTP status code to indicate result
    GET /v1/charges?count=60
    -u KEY:
    v1 API

    View full-size slide

  9. GET /v1/charges
    GET /v1/charges/CHARGE_ID
    POST /v1/charges
    POST /v1/charges/CHARGE_ID
    DELETE /v1/charges/CHARGE_ID
    v1 API

    View full-size slide

  10. SUPPORTING
    THE API

    View full-size slide

  11. MAKE IT EASY TO
    GET STARTED

    View full-size slide

  12. LANGUAGE-SPECIFIC
    LIBRARIES & DOCS

    View full-size slide

  13. FOCUSED API THAT
    ALLOWS FLEXIBILITY

    View full-size slide

  14. LET USERS BUILD EXTENSIONS
    WEBHOOKS
    ○ Posted events to a webhook URL
    ○ charge.succeeded, charge.refunded, etc.
    CONNECT
    ○ OAuth2 API
    ○ Users can authorize access to their Stripe accounts
    ○ Full access to Stripe API

    View full-size slide

  15. PROVIDE A TESTING
    ENVIRONMENT

    View full-size slide

  16. HELP YOUR USERS
    DEBUG

    View full-size slide

  17. {
    "error": {
    "message": "You must provide an integer
    value for 'exp_year'.",
    "type": "card_error",
    "param": "exp_year"
    }
    }

    View full-size slide

  18. >> Stripe::Customer.create
    Stripe::AuthenticationError: No API key
    provided. (HINT: set your API key using
    "Stripe.api_key = ". You can
    generate API keys from the Stripe web
    interface. See https://stripe.com/api for
    details, or email [email protected] if you
    have any questions.)

    View full-size slide

  19. >> Stripe.api_key = TEST_KEY
    => ...
    >> Stripe::Charge.retrieve(LIVE_CHARGE_ID)
    Stripe::InvalidRequestError: (Status 404) No
    such charge: ch_17SOe5QQ2exd2S; a similar
    object exists in live mode, but a test mode
    key was used to make this request.

    View full-size slide

  20. DEALING WITH
    CHANGE

    View full-size slide

  21. BACKWARDS INCOMPATIBLE CHANGES
    ○ Per-user version, set on first API call
    ○ Allow upgrading versions and detailed changelog
    ○ Pass version override in headers
    FEATURE GATING
    ○ Experimental or one-off
    ○ shows_applications
    VERSIONING

    View full-size slide

  22. MANY DEFINITIONS
    OF A "GOOD API"

    View full-size slide

  23. THANKS! (:
    AMBER FENG @amfeng

    View full-size slide