| 1 | package WWW::ModulrFinance; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use 5.008_005; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use HTTP::Date qw/time2str/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Digest::HMAC_SHA1 qw(hmac_sha1); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use MIME::Base64; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use URI::Escape qw/uri_escape/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use Carp qw/croak/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 1 | ▶ | use JSON; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | sub new { | ||||||||||||||||||||
| 16 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||
| 17 | 0 | ▶ | my %params = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 0 | ▶ | $params{api_key} or croak "api_key is required"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | 0 | ▶ | $params{hmac_secret} or croak "hmac_secret is required"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 0 | ▶ | $params{base_url} ||= 'https://api-sandbox.modulrfinance.com/api-sandbox/'; | ||||||||||||||||||
|
Condition0%0/2
$params{"base_url"} ||= "https://api-sandbox.modulrfinance.com/api-sandbox/"
MC/DC0%0/1
$params{"base_url"} ||= "https://api-sandbox.modulrfinance.com/api-sandbox/"
$params{"base_url"}
Truth table0%0/2
A
A= $params{"base_url"}
| |||||||||||||||||||||
| 23 | 0 | ▶ | $params{ua} ||= LWP::UserAgent->new(agent => "WWW-ModulrFinance-$VERSION"); | ||||||||||||||||||
|
Condition0%0/3
$params{"ua"} ||= "LWP::UserAgent"->new("agent", "WWW-ModulrFinance-$WWW::ModulrFinance::VERSION")
MC/DC0%0/2
$params{"ua"} ||= "LWP::UserAgent"->new("agent", "WWW-ModulrFinance-$WWW::ModulrFinance::VERSION")
$params{"ua"}
"LWP::UserAgent"->new("agent", "WWW-ModulrFinance-$WWW::ModulrFinance::VERSION")
Truth table0%0/3
A ||= B
A= $params{"ua"}B= "LWP::UserAgent"->new("agent", "WWW-ModulrFinance-$WWW::ModulrFinance::VERSION")
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 0 | return bless \%params, $class; | |||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | sub get_accounts { | ||||||||||||||||||||
| 29 | 0 | ▶ | (shift)->request('GET', 'accounts'); | ||||||||||||||||||
|
Subroutine
get_accounts: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | sub get_account { | ||||||||||||||||||||
| 33 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||
|
Subroutine
get_account: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 34 | 0 | return $self->request('GET', 'accounts/' . int($id)); | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | sub update_account { | ||||||||||||||||||||
| 38 | 0 | ▶ | my ($self, $id, $data) = @_; | ||||||||||||||||||
|
Subroutine
update_account: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 39 | 0 | return $self->request('PUT', 'accounts/' . int($id), $data); | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | sub get_customer_accounts { | ||||||||||||||||||||
| 43 | 0 | ▶ | my ($self, $cid) = @_; | ||||||||||||||||||
|
Subroutine
get_customer_accounts: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 44 | 0 | return $self->request('GET', 'customers/' . int($cid) . '/accounts'); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | sub create_customer_account { | ||||||||||||||||||||
| 48 | 0 | ▶ | my ($self, $cid, $data) = @_; | ||||||||||||||||||
|
Subroutine
create_customer_account: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 49 | 0 | return $self->request('POST', 'customers/' . int($cid) . '/accounts', $data); | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | sub get_transactions { | ||||||||||||||||||||
| 53 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||
|
Subroutine
get_transactions: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 54 | 0 | return $self->request('GET', 'accounts/' . int($id) . '/transactions'); | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | sub get_payments { | ||||||||||||||||||||
| 58 | 0 | ▶ | (shift)->request('GET', 'payments'); | ||||||||||||||||||
|
Subroutine
get_payments: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | sub post_payments { | ||||||||||||||||||||
| 62 | 0 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||
|
Subroutine
post_payments: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 63 | 0 | return $self->request('POST', 'payments', $data); | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | sub post_batchpayments { | ||||||||||||||||||||
| 67 | 0 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||
|
Subroutine
post_batchpayments: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 68 | 0 | return $self->request('POST', 'batchpayments', $data); | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | sub get_batchpayment { | ||||||||||||||||||||
| 72 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||
|
Subroutine
get_batchpayment: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 73 | 0 | return $self->request('GET', 'batchpayments/' . int($id)); | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | sub request { | ||||||||||||||||||||
| 77 | 0 | ▶ | my ($self, $method, $uri, $data) = @_; | ||||||||||||||||||
|
Subroutine
request: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | my $req = HTTP::Request->new($method => $self->{base_url} . $uri => $self->__signature()); | |||||||||||||||||||
| 80 | 0 | ▶ | $req->content(encode_json($data)) if $data; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | # print Dumper(\$req); use Data::Dumper; | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 0 | my $res = $self->{ua}->request($req); | |||||||||||||||||||
| 85 | 0 | ▶ | if ($res->header('Content-Type') =~ 'json') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 86 | 0 | return decode_json($res->content); | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | ▶ | croak $res->status_line unless $res->is_success; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | 0 | return $res->content; | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | sub __signature { | ||||||||||||||||||||
| 94 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
__signature: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 0 | my $date = time2str(time()); | |||||||||||||||||||
| 97 | 0 | my $nonce = time() . '-' . $$ . '-' . rand(100000); | |||||||||||||||||||
| 98 | 0 | my $str = "date: $date\nx-mod-nonce: $nonce"; | |||||||||||||||||||
| 99 | 0 | my $sig = uri_escape(encode_base64(hmac_sha1($str, $self->{hmac_secret}), '')); | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | # Authorization: Signature keyId="57502612d1bb2c0001000025fd53850cd9a94861507a5f7cca236882",algorithm="hmac-sha1",headers="date x-mod-nonce",signature="WBMr%2FYdhysbmiIEkdTrf2hP7SfA%3D" | ||||||||||||||||||||
| 102 | return [ | ||||||||||||||||||||
| 103 | 'Date' => $date, | ||||||||||||||||||||
| 104 | 'x-mod-nonce' => $nonce, | ||||||||||||||||||||
| 105 | 0 | 'Authorization' => qq~Signature keyId="~ . $self->{api_key} . qq~",algorithm="hmac-sha1",headers="date x-mod-nonce",signature="$sig"~ | |||||||||||||||||||
| 106 | ]; | ||||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 1 | 1; | |||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||