Dwolla

Code / PHP

Download, tweak, customize, and learn

To get started with Dwolla and PHP, you're going to want to use our official library. Grab a copy of it, here.

Instantiate

Before you can use any of the functions described on this page, you'll have to instantiate a new Dwolla helper. Here's how you create an instance of the Dwolla helper library.

$Dwolla = new DwollaRestClient($apiKey, $apiSecret);

OAuth / Authenticate

Step 1: Redirect the user to the OAuth permissions dialog.

$url = $Dwolla->getAuthUrl();
header("Location: {$url}");

Step 2: Grab the temporary code from the querystring, and exchange it for a permanent access token.

$token = $Dwolla->requestToken($_GET['code']);

Manual Authentication

Use a previously generated access token:

$Dwolla->setToken($token);

Send Money

$pin			= '1234';
$destination	= '812-546-3855';
$amount			= 0.01;
$notes			= 'PHP Library Test';

$tid = $Dwolla->send($pin, $destinationId, $amount, $notes);
if(!$tid) { echo "Error: {$Dwolla->getError()} \n"; }
echo "Send transaction ID: {$tid} \n";

Request Money

$pin			= '1234';
$sourceId		= 'gordon@dwolla.com';
$sourceType		= 'email';
$amount			= 0.01;
$notes			= 'PHP Library Test';

$tid = $Dwolla->send($pin, $sourceId, $amount, $sourceType, $notes);
if(!$tid) { echo "Error: {$Dwolla->getError()} \n"; }
echo "Request ID: {$tid} \n";

Get Transaction Details

$transactionId = '743160';

$details = $Dwolla->transaction($transactionId);
if(!$details) { echo "Error: {$Dwolla->getError()} \n"; }
print_r($details);

Get Transactions Listing

$listing = $Dwolla->listings();
if(!$listing) { echo "Error: {$Dwolla->getError()} \n"; }
print_r($listing);

Get Transaction Statistics

$stats = $Dwolla->stats();
if(!$stats) { echo "Error: {$Dwolla->getError()} \n"; }
print_r($stats);

Get Balance

$balance = $Dwolla->balance();
if(!$balance) { echo "Error: {$Dwolla->getError()} \n"; }
echo "Balance: {$balance}";

Get Own Account Info

$me = $Dwolla->me();
if(!$me) { echo "Error: {$Dwolla->getError()} \n"; }
print_r($me);

Get User Account Info

$accountId = '812-546-3855';

$user = $Dwolla->getUser($accountId);
if(!$user) { echo "Error: {$Dwolla->getError()} \n"; }
print_r($user);

Get Own Contacts

$contacts = $Dwolla->contacts();
if(!$contacts) { echo "Error: {$Dwolla->getError()} \n"; }
print_r($contacts);

Get Nearby Contacts

$nearbyContacts = $Dwolla->nearbyContacts('Ben');
if(!$nearbyContacts) { echo "Error: {$Dwolla->getError()} \n"; }
print_r($nearbyContacts);