File Coverage

blib/lib/Business/BalancedPayments/Base.pm
Criterion Covered Total %
statement 14 43 32.5
branch 1 22 4.5
condition 0 5 0.0
subroutine 5 14 35.7
pod 0 9 0.0
total 20 93 21.5


line stmt bran cond sub pod time code
1             package Business::BalancedPayments::Base;
2 11     11   75845 use Moo::Role;
  11         16  
  11         51  
3             with 'WebService::Client';
4              
5             our $VERSION = '1.0500'; # VERSION
6              
7 11     11   3104 use Carp qw(croak);
  11         15  
  11         526  
8 11     11   6816 use HTTP::Request::Common qw(GET POST);
  11         199874  
  11         767  
9 11     11   6007 use JSON qw(encode_json);
  11         90638  
  11         53  
10              
11             requires qw(_build_marketplace _build_uris);
12              
13             has '+base_url' => (is => 'ro', default => 'https://api.balancedpayments.com');
14              
15             has secret => (is => 'ro', required => 1);
16              
17             has uris => (is => 'ro', lazy => 1, builder => '_build_uris' );
18              
19             has marketplace => (is => 'ro', lazy => 1, builder => '_build_marketplace');
20              
21             around req => sub {
22             my ($orig, $self, $req, @rest) = @_;
23             $req->authorization_basic($self->secret);
24             return $self->$orig($req, @rest);
25             };
26              
27             sub get_card {
28 0     0 0 0 my ($self, $id) = @_;
29 0 0       0 croak 'The id param is missing' unless defined $id;
30 0         0 return $self->get($self->_uri('cards', $id));
31             }
32              
33             sub create_card {
34 0     0 0 0 my ($self, $card) = @_;
35 0 0       0 croak 'The card param must be a hashref' unless ref $card eq 'HASH';
36 0         0 return $self->post($self->_uri('cards'), $card);
37             }
38              
39             sub get_customer {
40 0     0 0 0 my ($self, $id) = @_;
41 0 0       0 croak 'The id param is missing' unless defined $id;
42 0         0 return $self->get($self->_uri('customers', $id));
43             }
44              
45             sub create_customer {
46 0     0 0 0 my ($self, $customer) = @_;
47 0   0     0 $customer ||= {};
48 0 0       0 croak 'The customer param must be a hashref' unless ref $customer eq 'HASH';
49 0         0 return $self->post($self->_uri('customers'), $customer);
50             }
51              
52             sub get_debit {
53 0     0 0 0 my ($self, $id) = @_;
54 0 0       0 croak 'The id param is missing' unless defined $id;
55 0         0 return $self->get($self->_uri('debits', $id));
56             }
57              
58             sub get_bank_account {
59 0     0 0 0 my ($self, $id) = @_;
60 0 0       0 croak 'The id param is missing' unless defined $id;
61 0         0 return $self->get($self->_uri('bank_accounts', $id));
62             }
63              
64             sub create_bank_account {
65 0     0 0 0 my ($self, $bank) = @_;
66 0 0       0 croak 'The bank account must be a hashref' unless ref $bank eq 'HASH';
67 0         0 return $self->post($self->_uri('bank_accounts'), $bank);
68             }
69              
70             sub get_credit {
71 0     0 0 0 my ($self, $id) = @_;
72 0 0       0 croak 'The id param is missing' unless defined $id;
73 0         0 return $self->get($self->_uri('credits', $id));
74             }
75              
76             sub log {
77 9     9 0 3006330 my ($self, $msg) = @_;
78 9 50       63 return unless $self->logger;
79 0           $self->logger->DEBUG("BP: $msg");
80             }
81              
82             sub _uri {
83 0     0     my ($self, $key, $id) = @_;
84 0 0 0       return $id if $id and $id =~ /\//; # in case a uri was passed in
85 0 0         return $self->uris->{$key} . ( defined $id ? "/$id" : '' );
86             }
87              
88             1;
89              
90             __END__
91              
92             =pod
93              
94             =encoding UTF-8
95              
96             =head1 NAME
97              
98             Business::BalancedPayments::Base
99              
100             =head1 VERSION
101              
102             version 1.0500
103              
104             =head1 AUTHORS
105              
106             =over 4
107              
108             =item *
109              
110             Ali Anari <ali@tilt.com>
111              
112             =item *
113              
114             Khaled Hussein <khaled@tilt.com>
115              
116             =item *
117              
118             Naveed Massjouni <naveed@tilt.com>
119              
120             =item *
121              
122             Al Newkirk <al@tilt.com>
123              
124             =item *
125              
126             Will Wolf <will@tilt.com>
127              
128             =back
129              
130             =head1 COPYRIGHT AND LICENSE
131              
132             This software is copyright (c) 2012 by Crowdtilt, Inc..
133              
134             This is free software; you can redistribute it and/or modify it under
135             the same terms as the Perl 5 programming language system itself.
136              
137             =cut