Ever since its introduction in 1995, PHP has been a favorite of web programmers around the world; over 200 million websites are powered by PHP. With such high volume, Dwolla has newly rewritten the PHP library—dwolla-php. Now, dwolla-php is officially supported and regularly audited for security and user feature requests.
Since dwolla-php is popular among our community of developers, we wanted to walk you through some of the best practices for setup from a technical perspective.
In accordance with best practices, you should not plainly clone the Git repository or download it as a *.zip archive. Instead, it is best to use Composer, a package manager used to distribute various PHP libraries including dwolla-php. While the Composer requires you to install another application on your development box/server, it automatically manages all your packages, dependencies, and includes so that you won’t have to worry about a “class not found” error again.
Find instructions on how to install Composer here.
First, add dwolla-php as a requirement for your project. Composer stores its requirements in a file named “composer.json”; allowing you to specify version constraints for each package requirement. This helps keep your software running without the risk of updating to packages that may cause potentially breaking changes.
dwolla-php 2.x will always be compatible with all 2.x releases as we use semantic versioning. Set a version constraint against the latest 2.x release available, and download it into our working directory.
Getting your hands dirty
Now that you’ve got dwolla-php, it’s time to have some fun. Let’s walk through sending someone $5—the best part is that it only takes three lines of code.
That wasn’t so bad, was it? Let’s go over what just happened:
- The first `require` line calls in Composer’s autoloader. This is just another perk of using Composer. You can import as many libraries as are defined in your composer.json, with just one require statement!
- The second line instantiates the “Transactions” grouping of the dwolla-php library, granting you access to the send functionality of library. Read more here!
- The $Transactions->send() function above sends 5 dollars to ‘812-202-3784’, which is the dwolla-php’s author Dwolla ID. It returns the resulting transaction ID of sending money.
Keeping up with the times
You can do a lot more with dwolla-php than just send money. Dwolla-php supports all of the endpoints that the Dwolla API offers and comes with awesome support from our API Support forum and GitHub issue reports
You can always drop us a line and we’ll be right there to help you integrate.
This post comes from one of our developer interns, David Stancu. David writes libraries for the Dwolla API to make developers’ lives easier – one line at a time. His free time is typically spent building robots or catching up on much-needed sleep.