Creating an API wrapper - How would you do it?

Published 1 year ago by nate.a.johnson

Hi all,

I need to build a wrapper on Bill.com's old rest API to do things like customer creation, credit card and ACH collection, invoicing, etc. We can't use Stripe and from what I can tell there isn't a library out there for this service other than a github repo from a few years back that has only a handful of commits.

I see options like using curl or guzzle in a nice Laravel wrapper, but I'd love to hear what others have done for something similar. I've done a bit of digging into the Stripe PHP library and a similar approach to what they have done is an option as well.

Thanks all!

Nate

tekmi
tekmi
1 year ago (110,630 XP)

From what you are describing, I would probably pick up the juices out of this old github repo and use it in my own implementation.

However if you think the code in there is pretty good and should work with the newest PHP versions, maybe the fastest way would be to decorate their classes - so their class would be the constructor dependency in yours.

I would use Guzzle, since it is easily testable, follows the PSR standards and can harvest not only curl, but also php streams under the hood. And maybe I would even create the composer package, trying to share the hard work with the whole php community.

If I work with Laravel framework, I would probably wind up creating additional service provider class to encapsulate my API classes into the Laravels' DI container.

nate.a.johnson

@tekmi thanks for the great advice! It looks like the Bill.com API has changed a good bit since the old package was released, so I don't think there is much to harvest there. I like the rest of your ideas though.

tekmi
tekmi
1 year ago (110,630 XP)

@nate.a.johnson Cool. Good luck!

Please sign in or create an account to participate in this conversation.