File Coverage

blib/lib/Business/BalancedPayments/V11.pm
Criterion Covered Total %
statement 36 261 13.7
branch 0 234 0.0
condition 0 93 0.0
subroutine 27 51 52.9
pod 0 1 0.0
total 63 640 9.8


line stmt bran cond sub pod time code
1             package Business::BalancedPayments::V11;
2 11     11   69 use Moo;
  11         19  
  11         79  
3             with 'Business::BalancedPayments::Base';
4              
5             our $VERSION = '1.0402'; # VERSION
6              
7 11     11   4575 use Carp qw(croak);
  11         19  
  11         889  
8 11     11   8858 use Method::Signatures;
  11         778407  
  11         93  
9 11     11   5940 use Scalar::Util qw(blessed);
  11         27  
  11         2175  
10              
11             has marketplaces_uri => ( is => 'ro', default => '/marketplaces' );
12              
13             has marketplaces => ( is => 'ro', lazy => 1, builder => '_build_marketplaces' );
14              
15             sub BUILD {
16 0     0 0 0 my ($self) = @_;
17 0         0 $self->ua->default_header(
18             accept => 'application/vnd.api+json;revision=1.1');
19             }
20              
21             around get_card => _unpack_response('cards');
22              
23             around create_card => _unpack_response('cards');
24              
25 11 0 0 11   1597379 method add_card(HashRef $card, HashRef :$customer!) {
  0 0 0 0   0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
26 0 0       0 my $card_href = $card->{href} or croak 'The card href is missing';
27 0 0       0 my $cust_href = $customer->{href} or croak 'The customer href is missing';
28 0         0 return $self->put($card->{href}, { customer => $cust_href })->{cards}[0];
29             }
30              
31             around get_customer => _unpack_response('customers');
32              
33             around create_customer => _unpack_response('customers');
34              
35 11 0 0 11   41566 method update_customer(HashRef $customer) {
  0 0   0   0  
  0 0       0  
  0         0  
  0         0  
  0         0  
36 0 0       0 my $cust_href = $customer->{href} or croak 'The customer href is missing';
37 0         0 return $self->put($cust_href, $customer)->{customers}[0];
38             }
39              
40 11 0 0 11   34890 method get_hold(Str $id) {
  0 0   0   0  
  0 0       0  
  0         0  
  0         0  
  0         0  
41 0         0 my $res = $self->get($self->_uri('card_holds', $id));
42 0 0       0 return $res ? $res->{card_holds}[0] : undef;
43             }
44              
45 11 0 0 11   49726 method create_hold(HashRef $hold, HashRef :$card!) {
  0 0 0 0   0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
46 0 0       0 croak 'The hold amount is missing' unless $hold->{amount};
47 0 0       0 my $card_href = $card->{href} or croak 'The card href is missing';
48 0         0 return $self->post("$card_href/card_holds", $hold)->{card_holds}[0];
49             }
50              
51 11 0 0 11   88257 method capture_hold(HashRef $hold, HashRef :$debit={}) {
  0 0 0 0   0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
52 0 0       0 my $hold_href = $hold->{href} or croak 'The hold href is missing';
53 0         0 return $self->post("$hold_href/debits", $debit)->{debits}[0];
54             }
55              
56 11 0 0 11   38079 method void_hold(HashRef $hold) {
  0 0   0   0  
  0 0       0  
  0         0  
  0         0  
  0         0  
57 0 0       0 my $hold_href = $hold->{href} or croak 'The hold href is missing';
58 0         0 return $self->put($hold_href, { is_void => 'true' })->{card_holds}[0];
59             }
60              
61 11 0 0 11   54776 method create_debit(HashRef $debit, HashRef :$card!) {
  0 0 0 0   0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
62 0 0       0 croak 'The debit amount is missing' unless $debit->{amount};
63 0 0       0 my $card_href = $card->{href} or croak 'The card href is missing';
64 0         0 return $self->post("$card_href/debits", $debit)->{debits}[0];
65             }
66              
67             around get_debit => _unpack_response('debits');
68              
69 11 0 0 11   39527 method refund_debit(HashRef $debit) {
  0 0   0   0  
  0 0       0  
  0         0  
  0         0  
  0         0  
70 0 0       0 my $debit_href = $debit->{href} or croak 'The debit href is missing';
71 0         0 return $self->post("$debit_href/refunds", $debit)->{refunds}[0];
72             }
73              
74             around get_bank_account => _unpack_response('bank_accounts');
75              
76             around create_bank_account => _unpack_response('bank_accounts');
77              
78 11 0 0 11   57827 method add_bank_account(HashRef $bank, HashRef :$customer!) {
  0 0 0 0   0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
79 0 0       0 my $bank_href = $bank->{href} or croak 'The bank href is missing';
80 0 0       0 my $cust_href = $customer->{href} or croak 'The customer href is missing';
81 0         0 my $res = $self->put($bank->{href}, { customer => $cust_href });
82 0         0 return $res->{bank_accounts}[0];
83             }
84              
85 11 0 0 11   60959 method create_credit(HashRef $credit, HashRef :$bank_account, HashRef :$card) {
  0 0 0 0   0  
  0 0 0     0  
  0 0 0     0  
  0 0 0     0  
  0 0       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
86 0 0       0 croak 'The credit amount is missing' unless $credit->{amount};
87 0 0       0 if ($bank_account) {
    0          
88 0 0       0 my $bank_href = $bank_account->{href}
89             or croak 'The bank_account href is missing';
90 0         0 return $self->post("$bank_href/credits", $credit)->{credits}[0];
91             } elsif ($card) {
92 0 0       0 my $card_href = $card->{href} or croak 'The card href is missing';
93 0         0 return $self->post("$card_href/credits", $credit)->{credits}[0];
94             } else {
95 0         0 croak 'A bank or card param is required';
96             }
97             }
98              
99             around get_credit => _unpack_response('credits');
100              
101 11 0 0 11   39609 method update_bank_account(HashRef $bank) {
  0 0   0   0  
  0 0       0  
  0         0  
  0         0  
  0         0  
102 0 0       0 my $bank_href = $bank->{href} or croak 'The bank_account href is missing';
103 0         0 return $self->put($bank_href, $bank)->{bank_accounts}[0];
104             }
105              
106 11 0 0 11   47833 method create_bank_verification(HashRef :$bank_account!) {
  0 0   0   0  
  0 0       0  
  0 0       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
107 0 0       0 my $bank_href = $bank_account->{href}
108             or croak 'The bank_account href is missing';
109 0         0 return $self->post("$bank_href/verifications", {})
110             ->{bank_account_verifications}[0];
111             }
112              
113 11 0 0 11   34524 method get_bank_verification(Str $id) {
  0 0   0   0  
  0 0       0  
  0         0  
  0         0  
  0         0  
114 0         0 my $res = $self->get("/verifications/$id");
115 0 0       0 return $res ? $res->{bank_account_verifications}[0] : undef;
116             }
117              
118 11 0 0 11   67341 method confirm_bank_verification(HashRef $verification, Int :$amount_1!, Int :$amount_2!) {
  0 0 0 0   0  
  0 0 0     0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
119 0 0       0 my $ver_href = $verification->{href}
120             or croak 'The verification href is missing';
121 0         0 return $self->put($ver_href, {amount_1 => $amount_1, amount_2 => $amount_2})
122             ->{bank_account_verifications}[0];
123             }
124              
125 11 0 0 11   36567 method create_check_recipient(HashRef $rec) {
  0 0   0   0  
  0 0       0  
  0         0  
  0         0  
  0         0  
126 0 0       0 croak 'The recipient name is missing' unless defined $rec->{name};
127 0 0       0 croak 'The recipient address line1 is missing'
128             unless $rec->{address}{line1};
129 0 0       0 croak 'The recipient address postal_code is missing'
130             unless $rec->{address}{postal_code};
131 0         0 my $res = $self->post('/check_recipients', $rec);
132 0         0 return $res->{check_recipients}[0];
133             }
134              
135 11 0 0 11   34094 method get_dispute(Str $id) {
  0 0   0   0  
  0 0       0  
  0         0  
  0         0  
  0         0  
136 0         0 my $res = $self->get($self->_uri('disputes', $id));
137 0 0       0 return $res ? $res->{disputes}[0] : undef;
138             }
139              
140 11 0 0 11   56277 method get_disputes(HashRef $query = {}) {
  0 0   0   0  
  0 0       0  
  0         0  
  0         0  
141 0         0 return $self->get($self->_uri('disputes'), $query);
142             }
143              
144 11 0 0 11   49032 method create_check_recipient_credit(HashRef $credit, HashRef :$check_recipient!) {
  0 0 0 0   0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
145 0 0       0 my $rec_id = $check_recipient->{id}
146             or croak 'The check_recipient hashref needs an id';
147 0 0       0 croak 'The credit must contain an amount' unless $credit->{amount};
148 0         0 my $res = $self->post("/check_recipients/$rec_id/credits", $credit);
149 0         0 return $res->{credits}[0];
150             }
151              
152 11 0 0 11   36153 method get_all(HashRef $data) {
  0 0   0   0  
  0 0       0  
  0         0  
  0         0  
  0         0  
153 0         0 my ($key) = grep !/^(links|meta)$/, keys %$data;
154 0 0       0 croak "Could not find the top level resource" unless $key;
155 0         0 my $result = $data->{$key};
156 0         0 while ( my $next = $data->{meta}{next} ) {
157 0         0 $data = $self->get($next);
158 0         0 push @$result, @{ $data->{$key} };
  0         0  
159             }
160 0         0 return $result;
161             }
162              
163 11 0   11   10846 method _build_marketplaces { $self->get($self->marketplaces_uri) }
  0     0   0  
  0         0  
  0         0  
164              
165 11 0   11   7098 method _build_marketplace { $self->marketplaces->{marketplaces}[0] }
  0     0   0  
  0         0  
  0         0  
166              
167 11 0   11   6876 method _build_uris {
  0     0   0  
  0         0  
168 0         0 my $links = $self->marketplaces->{links};
169 0         0 return { map { (split /^marketplaces./)[1] => $links->{$_} } keys %$links };
  0         0  
170             }
171              
172             sub _unpack_response {
173 88     88   172 my ($name) = @_;
174             return sub {
175 0     0     my ($orig, $self, @args) = @_;
176 0           my $res = $self->$orig(@args);
177 0 0         return $res->{$name}[0] if $res;
178 0           return $res;
179             }
180 88         590 };
181              
182             1;
183              
184             __END__
185              
186             =pod
187              
188             =encoding UTF-8
189              
190             =head1 NAME
191              
192             Business::BalancedPayments::V11
193              
194             =head1 VERSION
195              
196             version 1.0402
197              
198             =head1 AUTHORS
199              
200             =over 4
201              
202             =item *
203              
204             Ali Anari <ali@tilt.com>
205              
206             =item *
207              
208             Khaled Hussein <khaled@tilt.com>
209              
210             =item *
211              
212             Naveed Massjouni <naveed@tilt.com>
213              
214             =item *
215              
216             Al Newkirk <al@tilt.com>
217              
218             =item *
219              
220             Will Wolf <will@tilt.com>
221              
222             =back
223              
224             =head1 COPYRIGHT AND LICENSE
225              
226             This software is copyright (c) 2012 by Crowdtilt, Inc..
227              
228             This is free software; you can redistribute it and/or modify it under
229             the same terms as the Perl 5 programming language system itself.
230              
231             =cut