NAME
LWP::Authen::OAuth2::ServiceProvider::Dwolla - Access Dwolla API v2
VERSION
version 0.20
SYNOPSIS
my $oauth_dwolla = LWP::Authen::OAuth2->new(
# client_id/client_secret come from your Dwolla account, under API Keys in
# Registered Applications
client_id => DWOLLA_APP_KEY,
client_secret => DWOLLA_APP_SECRET,
service_provider => 'Dwolla',
# $use_test = 1 to use uat.dwolla.com in your dev sandbox, for test transactions
use_test_urls => $use_test ? 1 : 0,
redirect_uri => 'http://my.host/dwolla_redirect_handler',
# scope for reading funding sources and sending money; see Dwolla docs for other scopes
scope => 'Send|Funding',
);
# read user's list of funding sources
my $account = $oauth_dwolla->access_token()->{'_links'}->{'account'}->{'href'};
my $funding_sources = eval { $oauth_dwolla->make_api_call($account.'/funding-sources') };
# get all verified bank accounts
my @verified_sources = grep {
$_->{'status'} eq 'verified' && $_->{'type'} ne 'balance'
} @{ $funding_sources->{'_embedded'}->{'funding-sources'} };
# get user's Dwolla balance, if it has a positive balance
my ($balance_source) = grep {
$_->{'type'} eq 'balance'
} @{ $funding_sources->{'_embedded'}->{'funding-sources'} };
my $dwolla_balance = eval {
$oauth_dwolla->make_api_call($balance_source->{'_links'}->{'with-available-balance'}->{'href'})
};
print 'Dwolla balance = '.$dwolla_balance->{'balance'}->{'value'}."\n";
# send 100USD from first verified bank account to $recipient_account_id
my $success = eval { $oauth2->make_api_call('/transfers', {
_links => {
destination => { href => $oauth2->api_url_base().'/accounts/'.$recipient_account_id },
source => { href => $verified_sources[0]->{'_links'}->{'account'}->{'href'} },
},
amount => { currency => 'USD', value => '100.00' },
}) };
# (to send via Dwolla balance, use $balance_source->{'_links'}->{'account'}->{'href'}
# as source href instead)
REGISTERING
First get a Dwolla account, by signing up at dwolla.com. Then create a new application via API Keys -> Create an application. Set up the OAuth Redirect to match the redirect_uri
in your LWP::Authen::OAuth2 object, and use the application's Key and Secret values in client_id and client_secret.
Full Dwolla API v2 docs can be found here:
https://docsv2.dwolla.com/, https://developers.dwolla.com/
AUTHOR
Adi Fairbank, <https://github.com/adifairbank>
AUTHORS
Ben Tilly, <btilly at gmail.com>
Thomas Klausner <domm@plix.at>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 - 2022 by Ben Tilly, Rent.com, Thomas Klausner.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.