File Coverage

blib/lib/Business/BalancedPayments/V10.pm
Criterion Covered Total %
statement 15 141 10.6
branch 4 122 3.2
condition 1 44 2.2
subroutine 4 24 16.6
pod 19 20 95.0
total 43 351 12.2


line stmt bran cond sub pod time code
1             package Business::BalancedPayments::V10;
2 11     11   5094 use Moo;
  11         95806  
  11         51  
3             with 'Business::BalancedPayments::Base';
4              
5             our $VERSION = '1.0500'; # VERSION
6              
7 11     11   13336 use Carp qw(croak);
  11         15  
  11         17005  
8              
9             has marketplaces_uri => ( is => 'ro', default => '/v1/marketplaces' );
10              
11             sub get_account {
12 0     0 1 0 my ($self, $id) = @_;
13 0 0       0 croak 'The id param is missing' unless defined $id;
14 0         0 return $self->get($self->_uri('accounts', $id));
15             }
16              
17             sub get_account_by_email {
18 0     0 1 0 my ($self, $email) = @_;
19 0 0       0 croak 'The email param is missing' unless $email;
20 0         0 return $self->get($self->_uri->('accounts') . "?email_address=$email");
21             }
22              
23             sub create_account {
24 0     0 1 0 my ($self, $account, %args) = @_;
25 0         0 my $card = $args{card};
26 0   0     0 $account ||= {};
27 0 0       0 croak 'The account param must be a hashref' unless ref $account eq 'HASH';
28              
29 0 0       0 if ($card) {
30 0 0       0 croak 'The card param must be a hashref' unless ref $card eq 'HASH';
31 0 0       0 croak 'The card is missing a uri' unless $card->{uri};
32 0         0 $account->{card_uri} = $card->{uri};
33             }
34 0         0 return $self->post($self->_uri('accounts'), $account);
35             }
36              
37             sub update_account {
38 0     0 1 0 my ($self, $account) = @_;
39 0 0       0 croak 'The account param must be a hashref' unless ref $account eq 'HASH';
40 0 0 0     0 croak 'The account must have an id or uri field'
41             unless $account->{uri} || $account->{id};
42 0   0     0 my $acc_uri = $account->{uri} || $self->_uri('accounts', $account->{id});
43 0         0 return $self->put($acc_uri, $account);
44             }
45              
46             sub add_card {
47 0     0 1 0 my ($self, $card, %args) = @_;
48 0         0 my $account = $args{account};
49 0 0       0 croak 'The card param must be a hashref' unless ref $card eq 'HASH';
50 0 0       0 croak 'The account param must be a hashref' unless ref $account eq 'HASH';
51 0 0       0 croak 'The account requires a cards_uri field' unless $account->{cards_uri};
52 0         0 return $self->post($account->{cards_uri}, $card);
53             }
54              
55             sub add_bank_account {
56 0     0 1 0 my ($self, $bank_account, %args) = @_;
57 0         0 my $account = $args{account};
58 0 0       0 croak 'The bank_account param must be a hashref'
59             unless ref $bank_account eq 'HASH';
60 0 0       0 croak 'The account param must be a hashref' unless ref $account eq 'HASH';
61 0 0       0 croak 'The bank_accounts_uri field is missing from the account object'
62             unless $account->{bank_accounts_uri};
63 0         0 return $self->post($account->{bank_accounts_uri}, $bank_account);
64             }
65              
66             sub create_hold {
67 2     2 1 2004 my ($self, $hold, %args) = @_;
68 2 50       6 croak 'The hold param must be a hashref' unless ref $hold eq 'HASH';
69 2 100       166 croak 'The hold is missing an amount field' unless $hold->{amount};
70 1         2 my $card = $args{card};
71 1         2 my $account = $args{account};
72 1 50 33     89 croak 'An account or card must be provided' unless $account or $card;
73 0         0 my $holds_uri;
74 0 0       0 if ($card) {
    0          
75 0 0       0 croak 'The card param must be a hashref' unless ref $card eq 'HASH';
76 0         0 $holds_uri = $card->{account}{holds_uri};
77             } elsif ($account) {
78 0 0       0 croak 'The account must be a hashref' unless ref $account eq 'HASH';
79 0         0 $holds_uri = $account->{holds_uri};
80             }
81 0 0       0 die 'Could not find a holds_uri' unless $holds_uri;
82 0 0 0     0 $hold->{source_uri} ||= $card->{uri} if $card and $card->{uri};
      0        
83 0         0 return $self->post($holds_uri, $hold);
84             }
85              
86             sub capture_hold {
87 0     0 1 0 my ($self, $hold, $params) = @_;
88 0 0       0 croak 'The hold param is missing' unless $hold;
89 0 0 0     0 croak 'The optional extra params must be a hashref'
90             if $params and ref $params ne 'HASH';
91 0 0       0 my $hold_uri = ref $hold eq 'HASH' ? $hold->{uri} : $hold;
92 0         0 my $data = { hold_uri => $hold_uri, %$params };
93 0         0 return $self->post($self->_uri('debits'), $data);
94             }
95              
96             sub create_debit {
97 0     0 1 0 my ($self, $debit, %args) = @_;
98 0 0       0 croak 'The debit param must be a hashref' unless ref $debit eq 'HASH';
99 0 0       0 croak 'No amount found' unless $debit->{amount};
100 0         0 my $card = $args{card};
101 0         0 my $account = $args{account};
102 0 0 0     0 croak 'An account or card must be provided' unless $account or $card;
103 0         0 my $debits_uri;
104 0 0       0 if ($card) {
    0          
105 0 0       0 croak 'The card param must be a hashref' unless ref $card eq 'HASH';
106 0         0 $debits_uri = $card->{account}{debits_uri};
107             } elsif ($account) {
108 0 0       0 croak 'The account must be a hashref' unless ref $account eq 'HASH';
109 0         0 $debits_uri = $account->{debits_uri};
110             }
111 0 0       0 die 'Could not find a debits_uri' unless $debits_uri;
112 0 0 0     0 $debit->{source_uri} ||= $card->{uri} if $card and $card->{uri};
      0        
113 0         0 return $self->post($debits_uri, $debit);
114             }
115              
116             sub get_hold {
117 0     0 1 0 my ($self, $id) = @_;
118 0 0       0 croak 'The id param is missing' unless defined $id;
119 0         0 return $self->get($self->_uri('holds', $id));
120             }
121              
122             sub get_refund {
123 0     0 0 0 my ($self, $id) = @_;
124 0 0       0 croak 'The id param is missing' unless defined $id;
125 0         0 return $self->get($self->_uri('refunds', $id));
126             }
127              
128             sub get_refunds {
129 0     0 1 0 my ($self, $debit) = @_;
130 0 0       0 croak 'The debit param is missing' unless defined $debit;
131 0         0 return $self->get($debit->{refunds_uri});
132             }
133              
134             sub void_hold {
135 0     0 1 0 my ($self, $hold) = @_;
136 0 0       0 croak 'The hold param must be a hashref' unless ref $hold eq 'HASH';
137 0 0       0 croak 'No hold uri found' unless $hold->{uri};
138 0         0 return $self->put($hold->{uri}, { is_void => 'True' });
139             }
140              
141             sub refund_debit {
142 0     0 1 0 my ($self, $debit) = @_;
143 0 0       0 croak 'The debit param must be a hashref' unless ref $debit eq 'HASH';
144 0 0       0 croak 'No amount found' unless $debit->{amount};
145 0 0 0     0 croak 'No debit uri found' unless $debit->{uri} || $debit->{debit_uri};
146 0   0     0 $debit->{debit_uri} ||= $debit->{uri};
147 0         0 return $self->post($self->_uri('refunds'), $debit);
148             }
149              
150             sub confirm_bank_verification {
151 0     0 1 0 my ($self, $id, %args) = @_;
152 0         0 my $verification_id = $args{verification_id};
153 0 0       0 croak 'The id param is missing' unless defined $id;
154 0 0       0 croak 'The verification_id param is missing' unless defined $verification_id;
155 0         0 my $uri = join '/',
156             $self->_uri('bank_accounts', $id), 'verifications', $verification_id;
157 0 0       0 my $amount_1 = $args{amount_1} or croak 'The amount_1 param is missing';
158 0 0       0 my $amount_2 = $args{amount_2} or croak 'The amount_2 param is missing';
159 0         0 return $self->put($uri => {amount_1 => $amount_1, amount_2 => $amount_2});
160             }
161              
162             sub create_bank_verification {
163 0     0 1 0 my ($self, $id) = @_;
164 0 0       0 croak 'The id param is missing' unless defined $id;
165 0         0 my $uri = $self->_uri('bank_accounts', $id) . '/verifications';
166 0         0 return $self->post($uri => {});
167             }
168              
169             sub update_bank_account {
170 0     0 1 0 my ($self, $bank) = @_;
171 0 0       0 croak 'The bank account must be a hashref' unless ref $bank eq 'HASH';
172 0 0 0     0 croak 'The bank account must have an id or uri field'
173             unless $bank->{uri} || $bank->{id};
174 0   0     0 my $bank_uri = $bank->{uri} || $self->_uri('bank_accounts', $bank->{id});
175 0         0 return $self->put($bank_uri, $bank);
176             }
177              
178             sub invalidate_bank_account {
179 0     0 1 0 my ($self, $bank_id) = @_;
180 0 0       0 croak 'A bank id is required' unless defined $bank_id;
181 0         0 return $self->update_bank_account({ id => $bank_id, is_valid => 0 });
182             }
183              
184             sub create_credit {
185 0     0 1 0 my ($self, $credit, %args) = @_;
186 0         0 my $account = $args{account};
187 0         0 my $bank_account = $args{bank_account};
188 0 0       0 croak 'The credit param must be a hashref' unless ref $credit eq 'HASH';
189 0 0       0 croak 'The credit must contain an amount' unless exists $credit->{amount};
190 0 0 0     0 croak 'An account or bank_account param is required'
191             unless $account or $bank_account;
192 0         0 my $credits_uri;
193 0 0       0 if ($account) {
194 0 0       0 croak 'The account param must be a hashref'
195             unless ref $account eq 'HASH';
196 0         0 $credits_uri = $account->{credits_uri};
197             }
198 0 0       0 if ($bank_account) {
199 0 0       0 croak 'The bank_account param must be a hashref'
200             unless ref $bank_account eq 'HASH';
201 0 0       0 croak 'The bank_account is a uri' unless $bank_account->{uri};
202 0 0       0 croak 'The bank_account is missing an credits_uri'
203             unless $bank_account->{account}{credits_uri};
204 0         0 $credits_uri = $bank_account->{account}{credits_uri};
205 0         0 $credit->{bank_account_uri} = $bank_account->{uri};
206             }
207 0 0       0 croak 'No credits_uri found' unless $credits_uri;
208 0         0 return $self->post($credits_uri, $credit);
209             }
210              
211             sub get_transactions {
212 0     0 1 0 my ($self) = @_;
213 0         0 return $self->get($self->_uri('transactions'));
214             }
215              
216             sub _build_marketplace {
217 3     3   2099 my ($self) = @_;
218 3         72 my $data = $self->get($self->marketplaces_uri);
219 1         77 return $data->{items}[0];
220             }
221              
222             sub _build_uris {
223 0     0     my ($self) = @_;
224             return {
225 0           map { (split /_uri$/)[0] => $self->marketplace->{$_} }
  0            
226 0           grep { /_uri$/ } keys %{ $self->marketplace }
  0            
227             };
228             }
229              
230              
231             1;
232              
233             __END__
234              
235             =pod
236              
237             =encoding UTF-8
238              
239             =head1 NAME
240              
241             Business::BalancedPayments::V10
242              
243             =head1 VERSION
244              
245             version 1.0500
246              
247             =head1 METHODS
248              
249             These methods for version 1.0 of the Balanced API
250             L<https://docs.balancedpayments.com/1.0/api>.
251             Note that version 1.0 was officially deprecated March 2014.
252              
253             For the C<get_*> methods, the C<$id> param can be the id of the resource or
254             a uri. For example, the following two lines are equivalent:
255              
256             $bp->get_card('CC92QRQcwUCp5zpzKS');
257             $bp->get_card('/v1/marketplaces/MK98f1/cards/CC92QRQcwUCp5zpzKS');
258              
259             =head2 get_transactions
260              
261             get_transactions()
262              
263             Returns the transactions for this marketplace.
264              
265             =head2 get_card
266              
267             get_card($id)
268              
269             Returns the credit card for the given id.
270              
271             Example response:
272              
273             {
274             account => { ... },
275             brand => "MasterCard",
276             card_type => "mastercard",
277             created_at => "2012-06-07T11:00:40.003671Z",
278             expiration_month => 12,
279             expiration_year => 2020,
280             id => "CC92QRQcwUCp5zpzEz7lXKS",
281             is_valid => 1,
282             last_four => 5100,
283             name => undef,
284             uri => "/v1/marketplaces/MK98f1/cards/CC92QRQcwUCp5zpzKS",
285             }
286              
287             =head2 create_card
288              
289             create_card({
290             card_number => '5105105105105100',
291             expiration_month => 12,
292             expiration_year => 2020,
293             security_code => 123,
294             })
295              
296             Creates a credit card. Returns the card object.
297              
298             =head2 get_customer
299              
300             get_customer($id)
301              
302             Returns the customer for the given id.
303              
304             Example response:
305              
306             {
307             address => {},
308             bank_accounts_uri => "/v1/customers/CU4I/bank_accounts",
309             business_name => undef,
310             cards_uri => "/v1/customers/CU4I/cards",
311             created_at => "2014-09-21T06:14:54.996408Z",
312             credits_uri => "/v1/customers/CU4I/credits",
313             debits_uri => "/v1/customers/CU4I/debits",
314             destination => undef,
315             dob => undef,
316             ein => undef,
317             email => 'bob@foo.com',
318             facebook => undef,
319             holds_uri => "/v1/customers/CU4I/holds",
320             id => "CU4I",
321             is_identity_verified => 0,
322             meta => {},
323             name => "Bob",
324             phone => undef,
325             refunds_uri => "/v1/customers/CU4I/refunds",
326             reversals_uri => "/v1/customers/CU4I/reversals",
327             source => undef,
328             ssn_last4 => undef,
329             transactions_uri => "/v1/customers/CU4I/transactions",
330             twitter => undef,
331             uri => "/v1/customers/CU4I",
332             }
333              
334             =head2 create_customer
335              
336             create_customer()
337             create_customer({ name => 'Bob', email => 'bob@foo.com' })
338              
339             Creates a customer.
340             A customer hashref is optional.
341             Returns the customer object.
342              
343             =head2 get_account
344              
345             get_account($id)
346              
347             Returns the account for the given id.
348              
349             Example response:
350              
351             {
352             id => "AC7A",
353             uri => "/v1/marketplaces/MK98/accounts/AC7A",
354             email_address => "naveed\@crowdtilt.com",
355             meta => {},
356             name => undef,
357             roles => [],
358             created_at => "2012-06-07T21:01:38.801460Z",
359             bank_accounts_uri => "/v1/marketplaces/MK98/accounts/AC7A/bank_accounts",
360             cards_uri => "/v1/marketplaces/MK98/accounts/AC7A/cards",
361             credits_uri => "/v1/marketplaces/MK98/accounts/AC7A/credits",
362             debits_uri => "/v1/marketplaces/MK98/accounts/AC7A/debits",
363             holds_uri => "/v1/marketplaces/MK98/accounts/AC7A/holds",
364             refunds_uri => "/v1/marketplaces/MK98/accounts/AC7A/refunds",
365             transactions_uri => "/v1/marketplaces/MK98/accounts/AC7A/transactions",
366             }
367              
368             =head2 get_account_by_email
369              
370             get_account_by_email($email)
371              
372             Returns the account for the given email address.
373             See L</get_account> for an example response.
374              
375             =head2 create_account
376              
377             create_account()
378             create_account($account)
379             create_account($account, card => $card)
380              
381             Creates an account.
382             An account hashref is optional.
383             The account hashref, if passed in, must have an email_address field:
384              
385             $bp->create_account({ email_address => 'bob@crowdtilt.com' });
386              
387             It is possible to create an account and associate it with a credit card at the
388             same time.
389             You can do this in 2 ways.
390             You can provide a card such as one returned by calling L</get_card>:
391              
392             my $card = $bp->get_card($card_id);
393             $bp->create_account({ email_address => 'bob@crowdtilt.com' }, card => $card)
394              
395             Alternatively, you can provide a card_uri inside the account hashref:
396              
397             my $card = $bp->get_card($card_id);
398             $bp->create_account({
399             email_address => 'bob@crowdtilt.com',
400             card_uri => $card->{uri},
401             });
402              
403             Returns an account hashref.
404             See L</get_account> for an example response.
405              
406             =head2 update_account
407              
408             update_account($account)
409              
410             Updates an account.
411             It expects an account hashref, such as one returned by L</get_account>.
412             The account hashref must contain a uri or id field.
413              
414             =head2 add_card
415              
416             add_card($card, account => $account)
417              
418             Adds a card to an account.
419             It expects a card hashref, such as one returned by L</get_card>,
420             and an account hashref, such as one returned by L</get_account>.
421              
422             Returns an account hashref.
423             See L</get_account> for an example response.
424              
425             =head2 get_debit
426              
427             get_debit($debit_id)
428              
429             Returns the debit with the given id.
430             Example response:
431              
432             {
433             id => "WD1xtdUeixQIfJEsg4RwwHjQ",
434             transaction_number => "W553-201-5667",
435             amount => 50,
436             fee => 1,
437             description => undef,
438             appears_on_statement_as => "example.com",
439             available_at => "2012-10-25T04:48:19.337522Z",
440             created_at => "2012-10-25T04:48:19.443904Z",
441             uri => "/v1/marketplaces/MK98/debits/WD2L",
442             refunds_uri => "/v1/marketplaces/MK98/debits/WD2L/refunds",
443             account => { ... },
444             hold => { ... },
445             meta => { ... },
446             source => {
447             brand => "MasterCard",
448             card_type => "mastercard",
449             created_at => "2012-06-07T11:00:40.003671Z",
450             expiration_month => 12,
451             expiration_year => 2020,
452             id => "CC92QRQcwUCp5zpzEz7lXKS",
453             is_valid => 1,
454             last_four => 5100,
455             name => undef,
456             uri => "/v1/marketplaces/MK98/accounts/AC7A/cards/CC92QRQcwUCp5zpzEz7lXKS",
457             },
458             }
459              
460             =head2 create_debit
461              
462             create_debit($debit, account => $account)
463             create_debit($debit, card => $card)
464              
465             Creates a debit.
466             It expects a debit hashref which at least contains an amount field.
467             An account or card must be provided.
468              
469             my $account = $bp->get_account($account_id);
470             $bp->create_debit ({ account => 250 }, account => $account);
471              
472             my $card = bp->get_card($card_id);
473             $bp->create_debit({ amount => 250 }, card => $card);
474              
475             Successful creation of a debit will return an associated hold as part of the
476             response.
477             This hold was created and captured behind the scenes automatically.
478             See L</get_debit> for an example response.
479              
480             =head2 get_hold
481              
482             get_hold($hold_id)
483              
484             Returns the hold with the given id.
485             Example response:
486              
487             {
488             id => "HL5byxIzSvf0entZuO9eEsWJ",
489             uri => "/v1/marketplaces/MK98/holds/HL5byxIzSvf0entZuO9eEsWJ",
490             amount => 200,
491             description => undef,
492             created_at => "2012-06-08T09:23:53.745746Z",
493             expires_at => "2012-06-15T09:23:53.705009Z",
494             fee => 35,
495             is_void => 0,
496             account => { ... },
497             debit => { ... },
498             meta => { ... },
499             source => { ... },
500             }
501              
502             =head2 create_hold
503              
504             create_hold($hold, account => $account)
505             create_hold($hold, card => $card)
506              
507             Creates a hold for the given account.
508             It expects a hold hashref which at least contains an amount field.
509              
510             An account or card must be provided.
511             If an account is provided, Balanced defaults to charging the most recently
512             added card for the account.
513              
514             my $account = $bp->get_account($account_id);
515             $bp->create_hold ({ account => 250 }, account => $account);
516              
517             You can pass in a card if you want to charge a specific card:
518              
519             my $card = bp->get_card($card_id);
520             $bp->create_hold({ amount => 250 }, card => $card);
521              
522             See L</get_hold> for an example response.
523              
524             =head2 capture_hold
525              
526             capture_hold($hold)
527             capture_hold($hold, {
528             amount => ...,
529             appears_on_statement_as => ...,
530             meta => ...,
531             description => ...,
532             on_behalf_of_uri => ...,
533             source_uri => ...,
534             bank_account_uri => ...,
535             })
536              
537             Capturing a hold will create a debit representing the flow of funds from the
538             buyer's account to your marketplace.
539             The C<hold> param is required and may be a hold object or a hold uri.
540             A an optional hashref of extra parameters may be provided.
541             They will be passed on to Balanced.
542              
543             my $hold = $bp->get_hold($hold_id);
544             my $merchant_account = $bp->get_account($merchant_id);
545             $bp->capture_hold($hold, { on_behalf_of_uri => $merchant_account->{uri} });
546              
547             Returns a debit hashref.
548             Example response:
549              
550             {
551             id => "WD2Lpzyz8Okbhx2Nbw7YuTP3",
552             transaction_number => "W476-365-3767",
553             uri => "/v1/marketplaces/MK98/debits/WD2L",
554             amount => 50,
555             appears_on_statement_as => "example.com",
556             available_at => "2012-06-08T09:57:27.686977Z",
557             created_at => "2012-06-08T09:57:27.750828Z",
558             description => undef,
559             fee => 1,
560             meta => { ... },
561             hold => { ... },
562             account => { ... },
563             source => { ... },
564             refunds_uri => "/v1/marketplaces/MK98/debits/WD2L/refunds",
565             }
566              
567             =head2 get_refund
568              
569             get_refund($id)
570              
571             Gets a refund by id.
572              
573             $bp->get_refund($id);
574              
575             Returns a refund hashref.
576             Example response.
577             {
578             id => 'RF74',
579             transaction_number => 'RF966-744-5492',
580             amount => 323,
581             fee => -10,
582             description => '',
583             appears_on_statement_as => 'example.com',
584             created_at => '2012-08-27T16:54:46.595330Z',
585             debit => { ... },
586             meta => { ... },
587             account => { ... },
588             uri => '/v1/marketplaces/MP35/refunds/RF74',
589             }
590              
591             =head2 get_refunds
592              
593             get_refunds($debit)
594              
595             Gets the refunds associated with a specific debit.
596              
597             my $debit = $bp->get_debit($debit_id);
598             $bp->get_refunds($debit);
599              
600             Returns a refunds hashref.
601             Example response.
602             {
603             items => [
604             {
605             id => 'RF74',
606             transaction_number => 'RF966-744-5492',
607             amount => 323,
608             fee => -10,
609             description => '',
610             appears_on_statement_as => 'example.com',
611             created_at => '2012-08-27T16:54:46.595330Z',
612             debit => { ... },
613             meta => { ... },
614             account => { ... },
615             uri => '/v1/marketplaces/MP35/refunds/RF74',
616             }
617             ],
618             offset => 0,
619             limit => 10,
620             next_uri => undef,
621             total => 1,
622             uri => '/v1/marketplaces/MP35/debits/WD2L/refunds?limit=10&offset=0',
623             first_uri => '/v1/marketplaces/MP35/debits/WD2L/refunds?limit=10&offset=0',
624             last_uri => '/v1/marketplaces/MP35/debits/WD2L/refunds?limit=10&offset=0',
625             previous_uri => undef,
626             }
627              
628             =head2 void_hold
629              
630             void_hold($hold)
631              
632             Voids a hold.
633              
634             my $hold = $bp->get_hold($hold_id);
635             $bp->void_hold($hold);
636              
637             Returns a hold hashref.
638             See L</get_hold> for an example response.
639              
640             =head2 refund_debit
641              
642             refund_debit($debit)
643              
644             Refunds a debit.
645             If no amount is found in the debit hashref,
646             then Balanced refunds the entire amount.
647              
648             my $account = $bp->get_account($account_id);
649             my $debit = $bp->capture_hold(
650             $bp->create_hold({ amount => 305 }, account => $account)
651             );
652             $bp->refund_debit($debit);
653              
654             Example response:
655              
656             {
657             id => "RFrFB30adjtze8HSIoghLPr",
658             uri => "/v1/marketplaces/MK98/refunds/RFrFB30adLPr",
659             amount => 305,
660             created_at => "2012-06-11T11:31:59.414827Z",
661             description => undef,
662             fee => -10,
663             meta => {},
664             transaction_number => "RF536-609-0270",
665             appears_on_statement_as => "example.com",
666             account => { ... },
667             debit => { ... },
668             }
669              
670             =head2 get_bank_account
671              
672             get_bank_account($id)
673              
674             Returns the bank account for the given id.
675              
676             Example response:
677              
678             {
679             id => "BA3gES",
680             uri => "/v1/marketplaces/MK98/bank_accounts/BA3gES",
681             name => "WHC III Checking",
682             bank_name => "SAN MATEO CREDIT UNION",
683             bank_code => 321174851,
684             last_four => 1234,
685             created_at => "2012-06-12T15:00:59.248638Z",
686             is_valid => 1,
687             account => { ... },
688             }
689              
690             =head2 confirm_bank_verification
691              
692             confirm_bank_verification($bank_id, verification_id => $verification_id,
693             amount_1 => $x, amount_2 => $y)
694              
695             Returns the bank account verification status for the given ids.
696              
697             Example response:
698              
699             {
700             _type => "bank_account_authentication",
701             _uris => {},
702             attempts => 0,
703             created_at => "2014-01-09T03:11:11.080804Z",
704             id => "BZ5nDyPcUn2QNkgQn4o62gjM",
705             remaining_attempts => 3,
706             state => "deposit_succeeded",
707             updated_at => "2014-01-09T03:11:11.490600Z",
708             uri => "/v1/bank_accounts/BA5lj/verifications/BZ5nD"
709             }
710              
711             =head2 create_bank_account
712              
713             create_bank_account($bank_account)
714              
715             Creates a bank account.
716             A bank account hashref is required:
717              
718             $bp->create_bank_account({
719             name => "WHC III Checking",
720             account_number => "12341234",
721             bank_code => "321174851",
722             });
723              
724             Returns a bank account hashref.
725             See L</get_bank_account> for an example response.
726              
727             =head2 create_bank_verification
728              
729             create_bank_verification($bank_id)
730              
731             Returns the bank account verification receipt for the request.
732              
733             Example response:
734              
735             {
736             _type => "bank_account_authentication",
737             _uris => {},
738             attempts => 1,
739             created_at => "2014-01-09T03:11:20.160110Z",
740             id => "BZ5xQsMUtax4itwPTPM2Ducu",
741             remaining_attempts => 2,
742             state => "verified",
743             updated_at => "2014-01-09T03:11:21.482255Z",
744             uri => "/v1/bank_accounts/BA5vJy/verifications/BZ5xQs"
745             }
746              
747             =head2 add_bank_account
748              
749             add_bank_account($bank_account, account => $account)
750              
751             Adds a bank account to an account.
752             It expects a bank account hashref and an account hashref:
753              
754             my $account = $bp->get_account($account_id);
755             $bp->add_bank_account(
756             {
757             name => "WHC III Checking",
758             account_number => "12341234",
759             bank_code => "321174851",
760             },
761             account => $account
762             );
763              
764             This operation implicitly adds the "merchant" role to the account.
765              
766             Returns a bank account hashref.
767             See L</get_bank_account> for an example response.
768              
769             =head2 update_bank_account
770              
771             update_bank_account($bank_account)
772              
773             Updates a bank account.
774             A bank account hashref must be provided which must contain an id or uri for
775             the bank account.
776             Balanced only allows you to update the is_valid and meta fields.
777             You may invalidate a bank account by passing is_valid with a false value.
778             Once a bank account has been invalidated it cannot be re-activated.
779              
780             $bp->update_bank_account({
781             id => 'BA3gES',
782             is_valid => 0,
783             meta => { foo => 'bar' },
784             });
785              
786             Returns a bank account hashref.
787             See L</get_bank_account> for an example response.
788              
789             =head2 invalidate_bank_account
790              
791             invalidate_bank_account($bank_account_id);
792              
793             Invalidates a bank account.
794             A bank account id is required.
795             This is a convenience method that does the equivalent of:
796              
797             update_bank_account({ id => $bank_id, is_valid => 0 });
798              
799             Returns a bank account hashref.
800             See L</get_bank_account> for an example response.
801              
802             =head2 get_credit
803              
804             get_credit($credit_id);
805              
806             Gets a credit.
807             This is a way to get information about a specific credit, which can be useful
808             to check its status or get fee information about it.
809              
810             =head2 create_credit
811              
812             create_credit($credit, account => $account);
813             create_credit($credit, bank_account => $bank_account);
814              
815             Creates a credit.
816             This is a way of sending money to merchant accounts.
817             The credit hashref should at least contain an amount field.
818             An account or bank account hashref is required.
819             You may pass in a bank account if you would like to specify a specific bank
820             account to send money to.
821              
822             my $bank_account = $bp->get_bank_account($bank_account_id);
823             $bp->create_credit({ amount => 50 }, bank_account => $bank_account);
824              
825             If an account is provided, Balanced will default to crediting the most recently
826             added bank account.
827             The account should have the merchant role.
828              
829             my $account = $bp->get_account($account_id);
830             $bp->create_credit({ amount => 50 }, account => $account);
831              
832             Returnds a credit hashref.
833             Example response:
834              
835             {
836             id => "CR4GkfkOzYNBjFXW5Mxtpn1I",
837             uri => "/v1/marketplaces/MK98/credits/CR4Gkf",
838             amount => 50,
839             created_at => "2012-06-12T18:51:21.097085Z",
840             description => undef,
841             meta => {},
842             transaction_number => "CR382-740-3389",
843             account => { ... },
844             destination => {
845             bank_code => 321174851,
846             bank_name => "SAN MATEO CREDIT UNION",
847             created_at => "2012-06-12T15:00:59.248638Z",
848             id => "BA3gESxjg9yO61fj3CVUhGQm",
849             is_valid => 1,
850             last_four => 1234,
851             name => "WHC III Checking",
852             uri => "/v1/marketplaces/MK98/accounts/AC78/bank_accounts/BA3g",
853             },
854             }
855              
856             =head1 AUTHORS
857              
858             =over 4
859              
860             =item *
861              
862             Ali Anari <ali@tilt.com>
863              
864             =item *
865              
866             Khaled Hussein <khaled@tilt.com>
867              
868             =item *
869              
870             Naveed Massjouni <naveed@tilt.com>
871              
872             =item *
873              
874             Al Newkirk <al@tilt.com>
875              
876             =item *
877              
878             Will Wolf <will@tilt.com>
879              
880             =back
881              
882             =head1 COPYRIGHT AND LICENSE
883              
884             This software is copyright (c) 2012 by Crowdtilt, Inc..
885              
886             This is free software; you can redistribute it and/or modify it under
887             the same terms as the Perl 5 programming language system itself.
888              
889             =cut