Question

So I'm about to implement stripe payments to one of our projects and I've read the documentation of their API which stands as:

The Stripe API is organized around REST. Our API is designed to have predictable, resource-oriented URLs and to use HTTP response codes to indicate API errors. We use built-in HTTP features, like HTTP authentication and HTTP verbs, which can be understood by off-the-shelf HTTP clients, and we support cross-origin resource sharing to allow you to interact securely with our API from a client-side web application (though you should remember that you should never expose your secret API key in any public website's client-side code). JSON will be returned in all responses from the API, including errors (though if you're using API bindings, we will convert the response to the appropriate language-specific object).

They have a good pack of ready-to-use API libraries for popular languages so you import them to your favorite language and just start using their API, including PHP, which is what we are using for this project.

Now, their API is large and they have a lot of objects. We are not actually going to use the whole set of features so my initial thought was to just wrap around their HTTP RESTFul interface around simple cURL code so I don't have to load their whole set of classes for the sake of performance.

Now, before I actually implemented my own cURL client arount their HTTP API I took a couple of minutes to look at the sources of their PHP libraries and they seem to do exactly that: wrap around cURL functions, throw errors, expose objectified responses, etc.

Then the question is: Is it worth to just use their library even when I know I'll be loading a lot of clases I won't use, or should I write my own wrapper with cURL around their REST API?

Consider that this question came to my mind sice we are using other services (TangoCard, for instance) and most of them have deprecated "native" libraries favoring the use of whatever is your favorite HTTP client library and just use the REST API.

Thanks!

Was it helpful?

Solution

Loading classes is almost a non-issue in terms of performance, especially if you are using APC. I think the time saved by using what they give you completely justifies the slight performance loss due to loading their classes.

However, if their code is well written you shouldn't load any classes you don't actually use.

Also, if they maintain their library it will be easier to receive updates as time goes on. For instance, we used to roll our own Facebook APIs that used curl and had to stop due to their high number of updates and breaking changes over time.

OTHER TIPS

I would strongly recommend using the official libraries.
Stripe's official code has certainly been developed carefully and tested deeply. Especially for important things like handling payments and dealing with customers' money, I believe you should want the most stable platform possible.

The difference in performance, even without caching systems such as APC, should be totally negligible, and unless your scale is comparable to Amazon's or other big online stores, I hardly doubt you should focus your resources in optimizing that part of the code.
Additionally, using the official library makes it easy to maintain and update the code in response to changes on Stripe's side.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top