Expanding Objects in Stripe API

Expanding Objects in Stripe API

Aug 01, 2017 | By Matt |

Ruby on Rails, Development

Learn this quick tip to reduce the number of API requests and speed up your payments integration.

Reducing API Requests

Reducing the number of network calls in any web application is a great way to improve not only speed, but reliability of code. Just imagine we have a worker unit that asks Stripe for a Customer, Card, and Invoice via three separate API requests. Not only is this slower than making a single network call, it also triples our chance for errors or failures.

First Attempt

In this first attempt, we simply fetch the refund from stripe and ask for the balance transaction in a separate request.

Single Request

We can definitely improve this by using the expand parameter to fetch the balance transaction at the same time as the refund.

Notice that we pass a Hash to retrieve instead of just an identifier. We spent awhile debugging and digging through the Stripe Ruby gem source before noticing why the expand parameter was being ignored.

We were also sad to see that it is not possible to expand properties for a Stripe::Event.

Stripe API Docs

You can read more about expanding multiple objects on the official Stripe Docs.

Written by Matt

Dad, husband, and Founder of Lotus Apps providing Rails and RubyMotion development out of Knoxville TN. Creator of http://www.gemprospector.com for #ruby devs.
Find me on:

Subscribe to Email Updates

Web vs Mobile software solutions
Why Should I Brand My Company?