LWP::A...Dwolla(3pm)
π LWP::Authen::OAuth2::ServiceProvider::Dwolla β the vibe π
okay so bestie, gather round, because this is the little Perl module that lets you slide into Dwolla's API v2 and do money things. it's a service provider plugin for LWP::Authen::OAuth2, which means it's the friend that handles all the OAuth handshake drama so you don't have to. it lives in the User Contributed Perl Documentation corner of your manual, under section 3pm. π
β¨ VERSION β¨
version 0.20 β that's the one, that's the girl. π
π¦ SYNOPSIS π¦
here's the whole glow-up, start to finish. first you make the object, and yes, client_id and client_secret come straight from your Dwolla account, under API Keys in Registered Applications, no cap:
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',
);
quick translation bestie: set $use_test = 1 if you want to use uat.dwolla.com in your dev sandbox for test transactions, and that scope is the one for reading funding sources and sending money β hit the Dwolla docs if you want other scopes. π
then we read the user's list of funding sources:
# 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";
verified bank accounts? filtered. balance source? found. balance value? printed. iconic behaviour fr fr. π
and now the main character moment β sending 100USD from the first verified bank account to $recipient_account_id:
# 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)
heads up: to send via Dwolla balance instead, you use $balance_source->{'_links'}->{'account'}->{'href'} as the source href. the original literally says it in that comment, so i'm saying it too. π
πΈ REGISTERING πΈ
step one, bestie: get a Dwolla account, by signing up at dwolla.com. no account, no vibe check.
then create a new application via API Keys -> Create an application. set up the OAuth Redirect so it matches the "redirect_uri" in your LWP::Authen::OAuth2 object, and use the application's Key and Secret values in client_id and client_secret. that's the whole ritual. β¨
full Dwolla API v2 docs can be found here:
π 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.
and that's the whole page, bestie!! π this was documented with perl v5.36.0 and dated 2023-02-04, so shoutout to the past for leaving us this little gem. go forth and OAuth responsibly. πβ¨π¦
π¦ where this page comes from
- debian bookworm: liblwp-authen-oauth2-perl 0.20-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: liblwp-authen-oauth2-perl 0.20-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: liblwp-authen-oauth2-perl 0.20-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: liblwp-authen-oauth2-perl 0.20-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liblwp-authen-oauth2-perl 0.20-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms