File Coverage

blib/lib/Business/BalancedPayments.pm
Criterion Covered Total %
statement 13 13 100.0
branch 2 4 50.0
condition 2 5 40.0
subroutine 4 4 100.0
pod 1 1 100.0
total 22 27 81.4


line stmt bran cond sub pod time code
1             package Business::BalancedPayments;
2              
3             our $VERSION = '1.0500'; # VERSION
4              
5 11     11   616126 use Business::BalancedPayments::V10;
  11         38  
  11         347  
6 11     11   4838 use Business::BalancedPayments::V11;
  11         29  
  11         458  
7 11     11   83 use Carp qw(croak);
  11         13  
  11         1825  
8              
9             sub client {
10 4     4 1 5157 my ($class, %args) = @_;
11 4   50     16 $args{version} ||= 1.1;
12 4 50 33     20 croak "only versions 1.0 and 1.1 are supported"
13             unless $args{version} == 1 or $args{version} == 1.1;
14 4 50       93 return $args{version} == 1
15             ? Business::BalancedPayments::V10->new(%args)
16             : Business::BalancedPayments::V11->new(%args);
17             }
18              
19             # ABSTRACT: Balanced Payments API bindings
20              
21              
22             1;
23              
24             __END__
25              
26             =pod
27              
28             =encoding UTF-8
29              
30             =head1 NAME
31              
32             Business::BalancedPayments - Balanced Payments API bindings
33              
34             =head1 VERSION
35              
36             version 1.0500
37              
38             =head1 SYNOPSIS
39              
40             use Business::BalancedPayments;
41              
42             my $bp = Business::BalancedPayments->client(secret => 'abc123');
43              
44             my $customer = $bp->create_customer;
45              
46             my $card = $bp->create_card({
47             card_number => '5105105105105100',
48             expiration_month => 12,
49             expiration_year => 2020,
50             security_code => 123,
51             });
52              
53             $bp->add_card($card, customer => $customer);
54              
55             =head1 DESCRIPTION
56              
57             This module provides bindings for the
58             L<Balanced|https://www.balancedpayments.com> API.
59              
60             =head1 METHODS
61              
62             The client methods documented here are for v1.1 of the Balanced API
63             L<https://docs.balancedpayments.com/1.1/api>.
64             See L<Business::BalancedPayments::V10> for the v1.0 methods.
65              
66             For the C<get_*> methods, the C<$id> param can be the id of the resource or
67             a uri. For example, the following two lines are equivalent:
68              
69             $bp->get_card('CC6J123');
70             $bp->get_card('/cards/CC6J123');
71              
72             =head2 client
73              
74             my $bp = Business::BalancedPayments->client(
75             secret => $secret,
76             version => 1.1, # optional, defaults to 1.1
77             logger => $logger, # optional
78             retries => 3, # optional
79             );
80              
81             Returns a new Balanced client object.
82             Parameters:
83              
84             =over 4
85              
86             =item secret
87              
88             Required. The Balanced Payments secret key for your account.
89              
90             =item version
91              
92             Optional. Defaults to C<'1.1'>.
93             The only supported versions currently are C<'1.0'> and C<'1.1'>.
94             Note that version C<'1.0'> was officially deprecated March 2014.
95              
96             =back
97              
98             See L<WebService::Client> for other supported parameters such as C<logger>,
99             C<retries>, and C<timeout>.
100              
101             =head2 get_card
102              
103             get_card($id)
104              
105             Returns the card for the given id.
106              
107             Example response:
108              
109             {
110             'id' => 'CC6J',
111             'href' => '/cards/CC6J',
112             'address' => {
113             'city' => undef,
114             'country_code' => undef,
115             'line1' => undef,
116             'line2' => undef,
117             'postal_code' => undef,
118             'state' => undef
119             },
120             'avs_postal_match' => undef,
121             'avs_result' => undef,
122             'avs_street_match' => undef,
123             'bank_name' => 'BANK OF HAWAII',
124             'brand' => 'MasterCard',
125             'can_credit' => 0,
126             'can_debit' => 1,
127             'category' => 'other',
128             'created_at' => '2014-09-21T05:55:17.564617Z',
129             'cvv' => undef,
130             'cvv_match' => undef,
131             'cvv_result' => undef,
132             'expiration_month' => 12,
133             'expiration_year' => 2020,
134             'fingerprint' => 'fc4c',
135             'is_verified' => $VAR1->{'cards'}[0]{'can_debit'},
136             'links' => { 'customer' => undef },
137             'meta' => {},
138             'name' => undef,
139             'number' => 'xxxxxxxxxxxx5100',
140             'type' => 'credit',
141             'updated_at' => '2014-09-21T05:55:17.564619Z'
142             }
143              
144             =head2 create_card
145              
146             create_card($card)
147              
148             Creates a card.
149             Returns the card card that was created.
150              
151             Example:
152              
153             my $card = $bp->create_card({
154             number => '5105105105105100',
155             expiration_month => 12,
156             expiration_year => 2020,
157             });
158              
159             =head2 add_card
160              
161             add_card($card, customer => $customer);
162              
163             Associates a card with a customer.
164             It expects a card hashref, such as one returned by L</get_card>,
165             and a customer hashref, such as one returned by L</get_customer>.
166             Returns the card.
167              
168             Example:
169              
170             my $customer = $bp->create_customer;
171             my $card = $bp->get_card($card_id);
172             $bp->add_card($card, customer => $customer);
173              
174             =head2 get_customer
175              
176             get_customer($id)
177              
178             Returns the customer for the given id.
179              
180             Example response:
181              
182             {
183             'address' => {
184             'city' => undef,
185             'country_code' => undef,
186             'line1' => undef,
187             'line2' => undef,
188             'postal_code' => undef,
189             'state' => undef
190             },
191             'business_name' => undef,
192             'created_at' => '2014-10-02T07:59:26.311760Z',
193             'dob_month' => undef,
194             'dob_year' => undef,
195             'ein' => undef,
196             'email' => 'foo@bar.com',
197             'href' => '/customers/CUe3pf7nX93sMvrd9qcC29W',
198             'id' => 'CUe3pf7nX93sMvrd9qcC29W',
199             'links' => {
200             'destination' => undef,
201             'source' => undef
202             },
203             'merchant_status' => 'no-match',
204             'meta' => {},
205             'name' => undef,
206             'phone' => undef,
207             'ssn_last4' => undef,
208             'updated_at' => '2014-10-02T07:59:26.405946Z'
209             }
210              
211             =head2 create_customer
212              
213             create_customer($customer)
214              
215             Creates a customer.
216             A customer hashref is optional.
217             Returns the customer.
218              
219             Example:
220              
221             $bp->create_customer({ name => 'Bob', email => 'bob@foo.com' });
222              
223             =head2 update_customer
224              
225             update_customer($customer)
226              
227             Updates a customer.
228             Returns the updated customer.
229              
230             Example:
231              
232             my $customer = $bp->get_customer($customer_id);
233             $customer->{email} = 'sue@foo.com';
234             $bp->update_customer($customer);
235              
236             =head2 get_hold
237              
238             get_hold($id)
239              
240             Returns the card hold for the given id.
241              
242             Example response:
243              
244             {
245             'amount' => 123,
246             'created_at' => '2014-10-03T03:39:46.933465Z',
247             'currency' => 'USD',
248             'description' => undef,
249             'expires_at' => '2014-10-10T03:39:47.051257Z',
250             'failure_reason' => undef,
251             'failure_reason_code' => undef,
252             'href' => '/card_holds/HL7b0bw2Ooe6G3yad7dR1rRr',
253             'id' => 'HL7b0bw2Ooe6G3yad7dR1rRr',
254             'links' => {
255             'card' => 'CC7af3NesZk2bYR5GxqLLmfe',
256             'debit' => undef,
257             'order' => undef
258             },
259             'meta' => {},
260             'status' => 'succeeded',
261             'transaction_number' => 'HL7JT-EWF-5CQ6',
262             'updated_at' => '2014-10-03T03:39:47.094448Z',
263             'voided_at' => undef
264             }
265              
266             =head2 create_hold
267              
268             create_hold($hold_data, card => $card)
269              
270             Creates a card hold.
271             The C<$hold_data> hashref must contain an amount.
272             The card param is a hashref such as one returned from L</get_card>.
273             Returns the created hold.
274              
275             =head2 capture_hold
276              
277             capture_hold($hold, debit => $debit)
278              
279             Captures a previously created card hold.
280             This creates a debit.
281             The C<$debit> hashref is optional and can contain an amount.
282             Any amount up to the amount of the hold may be captured.
283             Returns the created debit.
284              
285             Example:
286              
287             my $hold = $bp->get_hold($hold_id);
288             my $debit = $bp->capture_hold(
289             $hold,
290             debit => {
291             amount => 1000,
292             description => 'money for stuffs',
293             appears_on_statement_as => 'ACME 123',
294             }
295             );
296              
297             =head2 void_hold
298              
299             void_hold($hold)
300              
301             Cancels the hold.
302             Once voided, the hold can no longer be captured.
303             Returns the voided hold.
304              
305             Example:
306              
307             my $hold = $bp->get_hold($hold_id);
308             my $voided_hold = $bp->void_hold($hold);
309              
310             =head2 get_debit
311              
312             get_debit($id)
313              
314             Returns the debit for the given id.
315              
316             Example response:
317              
318             {
319             'amount' => 123,
320             'appears_on_statement_as' => 'BAL*Tilt.com',
321             'created_at' => '2014-10-06T05:01:39.045336Z',
322             'currency' => 'USD',
323             'description' => undef,
324             'failure_reason' => undef,
325             'failure_reason_code' => undef,
326             'href' => '/debits/WD6F5x4VpYx4hfB02tGIqNU1',
327             'id' => 'WD6F5x4VpYx4hfB02tGIqNU1',
328             'links' => {
329             'card_hold' => 'HL6F4q5kJGxt1ftH8vgZZJkh',
330             'customer' => undef,
331             'dispute' => undef,
332             'order' => undef,
333             'source' => 'CC6DFWepK7eeL03cZ06Sb9Xf'
334             },
335             'meta' => {},
336             'status' => 'succeeded',
337             'transaction_number' => 'WAVD-B0K-R7TX',
338             'updated_at' => '2014-10-06T05:01:39.542306Z'
339             }
340              
341             =head2 create_debit
342              
343             create_debit($debit, card => $card)
344              
345             Debits a card.
346             The C<$debit> hashref must contain an amount.
347             The card param is a hashref such as one returned from L</get_card>.
348             Returns the created debit.
349              
350             Example:
351              
352             my $card = $bp->get_card($card_id);
353             my $debit = $bp->create_debit({ amount => 123 }, card => $card);
354              
355             =head2 refund_debit
356              
357             refund_debit($debit)
358              
359             Refunds a debit.
360             Returnds the refund.
361              
362             Example:
363              
364             my $debit = $bp->get_debit($debit_id);
365             my $refund = $bp->refund_debit($debit);
366              
367             Example response:
368              
369             {
370             'amount' => 123,
371             'created_at' => '2014-10-06T04:57:44.959806Z',
372             'currency' => 'USD',
373             'description' => undef,
374             'href' => '/refunds/RF2pO6Fz8breGs2TAIpfE2nr',
375             'id' => 'RF2pO6Fz8breGs2TAIpfE2nr',
376             'links' => {
377             'debit' => 'WD2hQV9COFX0aPMSIzyeAuAg',
378             'dispute' => undef,
379             'order' => undef
380             },
381             'meta' => {},
382             'status' => 'succeeded',
383             'transaction_number' => 'RFRGL-EU1-A39B',
384             'updated_at' => '2014-10-06T04:57:48.161218Z'
385             }
386              
387             =head2 get_bank_account
388              
389             get_bank_account($id)
390              
391             Returns the bank account for the given id.
392              
393             Example response:
394              
395             {
396             'account_number' => 'xxxxxxxx6789',
397             'account_type' => 'checking',
398             'address' => {
399             'city' => undef,
400             'country_code' => 'USA',
401             'line1' => '123 Abc St',
402             'line2' => undef,
403             'postal_code' => '94103',
404             'state' => undef
405             },
406             'bank_name' => '',
407             'can_credit' => bless( do{\(my $o = 1)}, 'JSON::XS::Boolean' ),
408             'can_debit' => bless( do{\(my $o = 0)}, 'JSON::XS::Boolean' ),
409             'created_at' => '2014-10-06T06:40:14.649386Z',
410             'fingerprint' => 'cc552495fc90556293db500b985bacc918d9fb4d37b42052adf64',
411             'href' => '/bank_accounts/BA4TAWvO3d3J14i6BdjJUZsp',
412             'id' => 'BA4TAWvO3d3J14i6BdjJUZsp',
413             'links' => {
414             'bank_account_verification' => undef,
415             'customer' => undef
416             },
417             'meta' => {},
418             'name' => 'Bob Smith',
419             'routing_number' => '110000000',
420             'updated_at' => '2014-10-06T06:40:14.649388Z'
421             }
422              
423             =head2 create_bank_account
424              
425             create_bank_account($bank)
426              
427             Creates a bank account.
428             Returns the bank account that was created.
429              
430             Example:
431              
432             my $bank = $bp->create_bank_account({
433             account_number => '000123456789',
434             acount_type => 'checking',
435             name => 'Bob Smith',
436             routing_number => '110000000',
437             address => {
438             line1 => '123 Abc St',
439             postal_code => '94103',
440             },
441             });
442              
443             =head2 add_bank_account
444              
445             add_bank_account($bank, customer => $customer)
446              
447             Associates a bank account to the given customer.
448             Returns the bank account.
449              
450             Example:
451              
452             my $bank = $bp->add_bank_account($bank_id);
453             my $customer = $bp->get_customer($customer_id);
454             $bank = $bp->add_bank_account($bank, customer => $customer);
455              
456             =head2 get_credit
457              
458             get_credit($id)
459              
460             Returns the credit for the given id.
461              
462             Example response:
463              
464             {
465             'amount' => 123,
466             'appears_on_statement_as' => 'Tilt.com',
467             'created_at' => '2014-10-06T06:52:00.522212Z',
468             'currency' => 'USD',
469             'description' => undef,
470             'failure_reason' => undef,
471             'failure_reason_code' => undef,
472             'href' => '/credits/CR27ns5sg1FFgHsGy5VEhowd',
473             'id' => 'CR27ns5sg1FFgHsGy5VEhowd',
474             'links' => {
475             'customer' => undef,
476             'destination' => 'BA26JfFfg1vqrCoXPzSSxtKg',
477             'order' => undef
478             },
479             'meta' => {},
480             'status' => 'succeeded',
481             'transaction_number' => 'CR4F7-4XQ-JLDG',
482             'updated_at' => '2014-10-06T06:52:03.558485Z'
483             }
484              
485             =head2 create_credit
486              
487             create_credit($credit, bank_account => $bank)
488             create_credit($credit, card => $card)
489              
490             Sends money to a bank account or a credit card.
491             The C<$credit> hashref must contain an amount.
492             A bank_account or card param is required.
493             Returns the created credit.
494              
495             Example:
496              
497             my $bank = $bp->get_bank_account($bank_account_id);
498             my $credit = $bp->create_credit({ amount => 123 }, bank_account => $bank);
499              
500             =head2 get_bank_verification
501              
502             get_bank_verification($id)
503              
504             Gets a bank account verification.
505              
506             Example response:
507              
508             {
509             'attempts' => 0,
510             'attempts_remaining' => 3,
511             'created_at' => '2014-10-06T08:01:59.972034Z',
512             'deposit_status' => 'succeeded',
513             'href' => '/verifications/BZnWun9Itq7FVtj1nludGjC',
514             'id' => 'BZnWun9Itq7FVtj1nludGjC',
515             'links' => {
516             'bank_account' => 'BAdFCPv3GkIlXEWQrdTyIW9'
517             },
518             'meta' => {},
519             'updated_at' => '2014-10-06T08:02:00.268756Z',
520             'verification_status' => 'pending'
521             }
522              
523             =head2 create_bank_verification
524              
525             create_bank_verification(bank_account => $bank)
526              
527             Create a new bank account verification.
528             This initiates the process of sending micro deposits to the bank account which
529             will be used to verify bank account ownership.
530             A bank_account param is required.
531             Returns the created bank account verification.
532              
533             Example:
534              
535             my $bank = $bp->get_bank_account($bank_account_id);
536             my $verification = $bp->create_bank_verification(bank_account => $bank);
537              
538             =head2 confirm_bank_verification
539              
540             confirm_bank_verification($verification,
541             amount_1 => $amount_1, amount_2 => $amount_2);
542              
543             Confirm the trial deposit amounts that were sent to the bank account.
544             Returns the bank account verification.
545              
546             Example:
547              
548             my $ver = $bp->get_bank_account($bank_account_id);
549             $verification =
550             $bp->confirm_bank_verification($ver, amount_1 => 1, amount_2 => 2);
551              
552             =head2 get_disputes
553              
554             get_disputes({
555             $start_date => '2014-01-01T12:00:00',
556             $end_date => DateTime->now,
557             $limit => 10,
558             $offset => 0,
559             })
560              
561             Lists all disputes (chargebacks).
562             All of the parameters are optional and must be passed inside of a HashRef.
563             The C<$start_date> and C<$end_date> parameters can either be DateTime objects, or
564             ISO8601 formatted strings.
565             The C<$limit> and C<$offset> parameters must be valid integers.
566              
567             Example response:
568              
569             {
570             disputes => [
571             {
572             amount => 6150,
573             created_at => '2013-12-06T02:05:13.656744Z',
574             currency => 'USD',
575             href => '/disputes/DT1234567890',
576             id => 'DT1234567890',
577             initiated_at => '2013-09-11T00:00:00Z',
578             links => {
579             transaction => 'WD1234567890'
580             },
581             meta => {},
582             reason => 'clerical',
583             respond_by => '2013-10-15T00:00:00Z',
584             status => 'lost',
585             updated_at => '2013-12-06T20:59:33.884181Z'
586             },
587             {
588             amount => 10250,
589             created_at => '2013-12-06T01:55:28.882064Z',
590             currency => 'USD',
591             href => '/disputes/DT0987654321',
592             id => 'DT0987654321',
593             initiated_at => '2013-08-28T00:00:00Z',
594             links => {
595             transaction => 'WD0987654321'
596             },
597             meta => {},
598             reason => 'clerical',
599             respond_by => '2013-10-02T00:00:00Z',
600             status => 'lost',
601             updated_at => '2013-12-06T21:04:11.158050Z'
602             }
603             ],
604             links => {
605             disputes.events => '/disputes/{disputes.id}/events',
606             disputes.transaction => '/resources/{disputes.transaction}',
607             },
608             meta {
609             first => '/disputes?limit=10&offset=0',
610             href => '/disputes?limit=10&offset=0',
611             last => '/disputes?limit=10&offset=300',
612             limit => 10,
613             next => '/disputes?limit=10&offset=10',
614             offset => 0,
615             previous => undef,
616             total => 100
617             }
618             }
619              
620             =head2 get_dispute
621              
622             get_dispute('DT1234567890')
623              
624             Fetches a dispute (chargeback).
625             The C<$id> of the dispute is a required parameter.
626              
627             Example response:
628              
629             {
630             amount => 6150,
631             created_at => '2013-12-06T02:05:13.656744Z',
632             currency => 'USD',
633             href => '/disputes/DT1234567890',
634             id => 'DT1234567890',
635             initiated_at => '2013-09-11T00:00:00Z',
636             links => {
637             transaction => 'WD1234567890'
638             },
639             meta => {},
640             reason => 'clerical',
641             respond_by => '2013-10-15T00:00:00Z',
642             status => 'lost',
643             updated_at => '2013-12-06T20:59:33.884181Z'
644             }
645              
646             =head1 AUTHORS
647              
648             =over 4
649              
650             =item *
651              
652             Ali Anari <ali@tilt.com>
653              
654             =item *
655              
656             Khaled Hussein <khaled@tilt.com>
657              
658             =item *
659              
660             Naveed Massjouni <naveed@tilt.com>
661              
662             =item *
663              
664             Al Newkirk <al@tilt.com>
665              
666             =item *
667              
668             Will Wolf <will@tilt.com>
669              
670             =back
671              
672             =head1 COPYRIGHT AND LICENSE
673              
674             This software is copyright (c) 2012 by Crowdtilt, Inc..
675              
676             This is free software; you can redistribute it and/or modify it under
677             the same terms as the Perl 5 programming language system itself.
678              
679             =cut