File Coverage

blib/lib/Business/GoCardless.pm
Criterion Covered Total %
statement 58 59 98.3
branch 5 6 83.3
condition 2 3 66.6
subroutine 22 22 100.0
pod 0 15 0.0
total 87 105 82.8


line stmt bran cond sub pod time code
1             package Business::GoCardless;
2              
3             =head1 NAME
4              
5             Business::GoCardless - Top level namespace for the Business::GoCardless
6             set of modules
7              
8             =for html
9             Build Status
10             Coverage Status
11              
12             =head1 VERSION
13              
14             0.44
15              
16             =head1 DESCRIPTION
17              
18             Business::GoCardless is a set of libraries for easy interface to the gocardless
19             payment service, they implement most of the functionality currently found
20             in the service's API documentation: https://developer.gocardless.com
21              
22             Current missing functionality is partner account handling, but all resource
23             manipulation (Bill, Merchant, Payout etc) is handled along with webhooks and
24             the checking/generation of signature, nonce, param normalisation, and other
25             such lower level interface with the API.
26              
27             =head1 Do Not Use This Module Directly
28              
29             You should go straight to L and start there.
30              
31             =cut
32              
33 19     19   498235 use strict;
  19         45  
  19         753  
34 19     19   92 use warnings;
  19         53  
  19         1057  
35              
36 19     19   800 use Moo;
  19         12040  
  19         123  
37 19     19   11495 use Carp qw/ confess /;
  19         63  
  19         1596  
38              
39 19     19   828 use Business::GoCardless::Client;
  19         42  
  19         652  
40 19     19   7630 use Business::GoCardless::Webhook;
  19         103  
  19         19922  
41              
42             $Business::GoCardless::VERSION = '0.44';
43              
44             has api_version => (
45             is => 'ro',
46             required => 0,
47             lazy => 1,
48             default => sub { $ENV{GOCARDLESS_API_VERSION} // 1 },
49             );
50              
51             has token => (
52             is => 'ro',
53             required => 1,
54             );
55              
56             has client_details => (
57             is => 'ro',
58             isa => sub {
59             confess( "$_[0] is not a hashref" )
60             if ref( $_[0] ) ne 'HASH';
61             },
62             required => 0,
63             lazy => 1,
64             default => sub {
65             my ( $self ) = @_;
66             return {
67             api_version => $self->api_version,
68             };
69             },
70             );
71              
72             has client => (
73             is => 'ro',
74             isa => sub {
75             confess( "$_[0] is not a Business::GoCardless::Client" )
76             if ref $_[0] ne 'Business::GoCardless::Client'
77             },
78             required => 0,
79             lazy => 1,
80             default => sub {
81             my ( $self ) = @_;
82              
83             return Business::GoCardless::Client->new(
84             %{ $self->client_details },
85             token => $self->token,
86             api_version => $self->api_version,
87             );
88             },
89             );
90              
91              
92             sub confirm_resource {
93 4     4 0 76 my ( $self,%params ) = @_;
94 4         179 return $self->client->_confirm_resource( \%params );
95             }
96              
97             sub new_bill_url {
98 1     1 0 1796 my ( $self,%params ) = @_;
99 1         39 return $self->client->_new_bill_url( \%params );
100             }
101              
102             sub bill {
103 2     2 0 8050 my ( $self,$id ) = @_;
104              
105 2 100       72 if ( $self->client->api_version > 1 ) {
106 1         31 return $self->payment( $id );
107             } else {
108 1         48 return $self->_generic_find_obj( $id,'Bill' );
109             }
110             }
111              
112             sub bills {
113 4     4 0 30572 my ( $self,%filters ) = @_;
114              
115 4 100       151 if ( $self->client->api_version > 1 ) {
116 2         68 return $self->payments( %filters );
117             } else {
118 2         141 return $self->merchant( $self->client->merchant_id )
119             ->bills( \%filters );
120             }
121             }
122              
123             sub merchant {
124 7     7 0 1605 my ( $self,$merchant_id ) = @_;
125              
126 7   66     78 $merchant_id //= $self->client->merchant_id;
127 7         227 return Business::GoCardless::Merchant->new(
128             client => $self->client,
129             id => $merchant_id
130             );
131             }
132              
133             sub payouts {
134 1     1 0 4263 my ( $self,%filters ) = @_;
135              
136 1 50       60 if ( $self->client->api_version > 1 ) {
137 0         0 return $self->_list( 'payouts',%filters );
138             } else {
139 1         95 return $self->merchant( $self->client->merchant_id )
140             ->payouts( \%filters );
141             }
142             }
143              
144             sub payout {
145 2     2 0 6681 my ( $self,$id ) = @_;
146 2         11 return $self->_generic_find_obj( $id,'Payout','payouts' );
147             }
148              
149             sub new_pre_authorization_url {
150 1     1 0 3058 my ( $self,%params ) = @_;
151 1         42 return $self->client->_new_pre_authorization_url( \%params );
152             }
153              
154             sub pre_authorization {
155 1     1 0 9801 my ( $self,$id ) = @_;
156 1         9 return $self->_generic_find_obj( $id,'PreAuthorization' );
157             }
158              
159             sub pre_authorizations {
160 1     1 0 2832 my ( $self,%filters ) = @_;
161 1         41 return $self->merchant( $self->client->merchant_id )
162             ->pre_authorizations( \%filters );
163             }
164              
165             sub new_subscription_url {
166 1     1 0 1309 my ( $self,%params ) = @_;
167 1         57 return $self->client->_new_subscription_url( \%params );
168             }
169              
170             sub subscription {
171 1     1 0 9124 my ( $self,$id ) = @_;
172 1         8 return $self->_generic_find_obj( $id,'Subscription' );
173             }
174              
175             sub subscriptions {
176 1     1 0 4532 my ( $self,%filters ) = @_;
177 1         54 return $self->merchant( $self->client->merchant_id )
178             ->subscriptions( \%filters );
179             }
180              
181             sub users {
182 1     1 0 1356 my ( $self,%filters ) = @_;
183 1         56 return $self->merchant( $self->client->merchant_id )
184             ->users( \%filters );
185             }
186              
187             sub webhook {
188 2     2 0 7687 my ( $self,$data ) = @_;
189              
190 2         104 return Business::GoCardless::Webhook->new(
191             client => $self->client,
192             json => $data,
193             );
194             }
195              
196             sub _generic_find_obj {
197 9     9   42 my ( $self,$id,$class,$sub_key ) = @_;
198 9         27 $class = "Business::GoCardless::$class";
199 9         403 my $obj = $class->new(
200             id => $id,
201             client => $self->client
202             );
203 9         175 return $obj->find_with_client( $sub_key );
204             }
205              
206             =head1 SEE ALSO
207              
208             L
209              
210             =head1 AUTHOR
211              
212             Lee Johnson - C
213              
214             =head1 CONTRIBUTORS
215              
216             grifferz - C
217              
218             =head1 LICENSE
219              
220             This library is free software; you can redistribute it and/or modify it under
221             the same terms as Perl itself. If you would like to contribute documentation,
222             features, bug fixes, or anything else then please raise an issue / pull request:
223              
224             https://github.com/Humanstate/business-gocardless
225              
226             =cut
227              
228             1;
229              
230             # vim: ts=4:sw=4:et