PHP - Dwolla Developer Portal

Documentation Index

Fetch the complete documentation index at: /llms.txt

Use this file to discover all available pages before exploring further.

dwolla-php is available on Packagist with source code available on our GitHub page.

Beta Release – This SDK is currently in beta. All API operations are fully supported, and we’re gathering feedback from early adopters before making this generally available. Breaking changes may occur as we continue refining the SDK. Please use caution when integrating into production environments. We welcome beta users to integrate, report issues, and help us identify any edge cases.

Getting Started

Installation

The SDK relies on Composer to manage its dependencies. To install the SDK and add it as a dependency to an existing composer.json file:

composer require "dwolla/dwolla-php"

Initialization

Before any API requests can be made, you must first determine which environment you will be using, as well as fetch the application key and secret. To fetch your application key and secret, please visit one of the following links:

Finally, you can create an instance of Dwolla with your application credentials:

declare(strict_types=1);

require 'vendor/autoload.php';

use Dwolla;
use Dwolla\Models\Components;

$sdk = Dwolla\Dwolla::builder()
    ->setSecurity(
        new Components\Security(
            clientID: 'YOUR_CLIENT_ID',
            clientSecret: 'YOUR_CLIENT_SECRET',
        )
    )
    ->build();

Making Requests

Once you’ve created a Dwolla client, you can make requests using the SDK methods.

High-Level SDK Methods

The PHP SDK provides strongly-typed methods for all Dwolla API operations:

// Get root API information
$response = $sdk->root->get();

// List customers
$response = $sdk->customers->list();

// Get customer details
$response = $sdk->customers->get(id: 'customer-id-here');

Authentication

The SDK supports multiple authentication schemes:

OAuth2 Client Credentials (Recommended)

use Dwolla;
use Dwolla\Models\Components;

$sdk = Dwolla\Dwolla::builder()
    ->setSecurity(
        new Components\Security(
            clientID: 'YOUR_CLIENT_ID',
            clientSecret: 'YOUR_CLIENT_SECRET',
        )
    )
    ->build();

Application Access Token Creation

When creating application access tokens, you’ll need to provide Basic Authentication at the request level:

use Dwolla;
use Dwolla\Models\Operations;

$sdk = Dwolla\Dwolla::builder()->build();

$request = new Operations\CreateApplicationAccessTokenRequest(
    grantType: Operations\GrantType::ClientCredentials,
);
$requestSecurity = new Operations\CreateApplicationAccessTokenSecurity(
    basicAuth: 'YOUR_BASIC_AUTH',
);

$response = $sdk->tokens->create(
    request: $request,
    security: $requestSecurity
);

if ($response->object !== null) {
    // handle response
}

Working with Transfers

// Initiate a transfer
$response = $sdk->transfers->create(/* transfer parameters */);

// Get transfer details
$response = $sdk->transfers->get(id: 'transfer-id-here');

// Cancel a transfer (if eligible)
$response = $sdk->transfers->cancel(id: 'transfer-id-here');

Working with Funding Sources

// List customer funding sources
$response = $sdk->customers->fundingSources->list(id: 'customer-id-here');

// Create a funding source
$customerUrl = "https://api-sandbox.dwolla.com/customers/customer-id-here";
$response = $sdk->customers->fundingSources->create(
    id: 'customer-id-here',
    requestBody: [
        "routingNumber" => "222222226",
        "accountNumber" => "123456789",
        "bankAccountType" => "checking",
        "name" => "My Checking Account"
    ]
);

// Get funding source balance
$response = $sdk->fundingSources->balance->get(id: 'funding-source-id-here');

Error Handling

The SDK provides comprehensive error handling with typed exception classes:

use Dwolla;
use Dwolla\Models\Errors;
use Dwolla\Models\Operations;

$sdk = Dwolla\Dwolla::builder()->build();

try {
    $request = new Operations\CreateApplicationAccessTokenRequest(
        grantType: Operations\GrantType::ClientCredentials,
    );
    $requestSecurity = new Operations\CreateApplicationAccessTokenSecurity(
        basicAuth: 'YOUR_BASIC_AUTH',
    );

$response = $sdk->tokens->create(
        request: $request,
        security: $requestSecurity
    );

if ($response->object !== null) {
        // handle response
    }
} catch (Errors\UnauthorizedExceptionThrowable $e) {
    // handle unauthorized error
    throw $e;
} catch (Errors\APIException $e) {
    // handle default exception
    throw $e;
}

By default, an API error will raise an Errors\APIException exception, which has the following properties:

Property Type Description
$message string The error message
$statusCode int The HTTP status code
$rawResponse ?Psr\Http\Message\ResponseInterface The raw HTTP response
$body string The response content

Server Selection

You can specify which Dwolla environment to use:

use Dwolla;

// Use sandbox environment
$sdk = Dwolla\Dwolla::builder()
    ->setServer('sandbox')
    ->build();

// Use production environment
$sdk = Dwolla\Dwolla::builder()
    ->setServer('prod')
    ->build();

// Use custom server URL
$sdk = Dwolla\Dwolla::builder()
    ->setServerURL('https://api-sandbox.dwolla.com')
    ->build();
Name Server Description
prod https://api.dwolla.com Production server
sandbox https://api-sandbox.dwolla.com Sandbox server

Available Resources and Operations

The SDK provides access to the following resources:

For detailed information on each resource and its operations, see the SDK documentation on GitHub.

Community