File Coverage

blib/lib/Business/GoCardless.pm
Criterion Covered Total %
statement 57 57 100.0
branch 4 4 100.0
condition 2 3 66.6
subroutine 22 22 100.0
pod 0 15 0.0
total 85 101 84.1


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.38
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   1986 use strict;
  19         51  
  19         598  
34 19     19   111 use warnings;
  19         40  
  19         484  
35              
36 19     19   758 use Moo;
  19         12157  
  19         141  
37 19     19   9022 use Carp qw/ confess /;
  19         79  
  19         1213  
38              
39 19     19   617 use Business::GoCardless::Client;
  19         57  
  19         584  
40 19     19   6745 use Business::GoCardless::Webhook;
  19         61  
  19         21037  
41              
42             $Business::GoCardless::VERSION = '0.38';
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 71 my ( $self,%params ) = @_;
94 4         102 return $self->client->_confirm_resource( \%params );
95             }
96              
97             sub new_bill_url {
98 1     1 0 978 my ( $self,%params ) = @_;
99 1         26 return $self->client->_new_bill_url( \%params );
100             }
101              
102             sub bill {
103 2     2 0 8240 my ( $self,$id ) = @_;
104              
105 2 100       53 if ( $self->client->api_version > 1 ) {
106 1         37 return $self->payment( $id );
107             } else {
108 1         36 return $self->_generic_find_obj( $id,'Bill' );
109             }
110             }
111              
112             sub bills {
113 4     4 0 28304 my ( $self,%filters ) = @_;
114              
115 4 100       106 if ( $self->client->api_version > 1 ) {
116 2         77 return $self->payments( %filters );
117             } else {
118 2         91 return $self->merchant( $self->client->merchant_id )
119             ->bills( \%filters );
120             }
121             }
122              
123             sub merchant {
124 7     7 0 876 my ( $self,$merchant_id ) = @_;
125              
126 7   66     54 $merchant_id //= $self->client->merchant_id;
127 7         179 return Business::GoCardless::Merchant->new(
128             client => $self->client,
129             id => $merchant_id
130             );
131             }
132              
133             sub payouts {
134 1     1 0 3083 my ( $self,%filters ) = @_;
135 1         27 return $self->merchant( $self->client->merchant_id )
136             ->payouts( \%filters );
137             }
138              
139             sub payout {
140 2     2 0 5061 my ( $self,$id ) = @_;
141 2         9 return $self->_generic_find_obj( $id,'Payout' );
142             }
143              
144             sub new_pre_authorization_url {
145 1     1 0 1980 my ( $self,%params ) = @_;
146 1         27 return $self->client->_new_pre_authorization_url( \%params );
147             }
148              
149             sub pre_authorization {
150 1     1 0 6508 my ( $self,$id ) = @_;
151 1         6 return $self->_generic_find_obj( $id,'PreAuthorization' );
152             }
153              
154             sub pre_authorizations {
155 1     1 0 2074 my ( $self,%filters ) = @_;
156 1         26 return $self->merchant( $self->client->merchant_id )
157             ->pre_authorizations( \%filters );
158             }
159              
160             sub new_subscription_url {
161 1     1 0 672 my ( $self,%params ) = @_;
162 1         27 return $self->client->_new_subscription_url( \%params );
163             }
164              
165             sub subscription {
166 1     1 0 6612 my ( $self,$id ) = @_;
167 1         6 return $self->_generic_find_obj( $id,'Subscription' );
168             }
169              
170             sub subscriptions {
171 1     1 0 3427 my ( $self,%filters ) = @_;
172 1         28 return $self->merchant( $self->client->merchant_id )
173             ->subscriptions( \%filters );
174             }
175              
176             sub users {
177 1     1 0 709 my ( $self,%filters ) = @_;
178 1         27 return $self->merchant( $self->client->merchant_id )
179             ->users( \%filters );
180             }
181              
182             sub webhook {
183 2     2 0 4880 my ( $self,$data ) = @_;
184              
185 2         52 return Business::GoCardless::Webhook->new(
186             client => $self->client,
187             json => $data,
188             );
189             }
190              
191             sub _generic_find_obj {
192 9     9   36 my ( $self,$id,$class,$sub_key ) = @_;
193 9         33 $class = "Business::GoCardless::$class";
194 9         239 my $obj = $class->new(
195             id => $id,
196             client => $self->client
197             );
198 9         130 return $obj->find_with_client( $sub_key );
199             }
200              
201             =head1 SEE ALSO
202              
203             L
204              
205             =head1 AUTHOR
206              
207             Lee Johnson - C
208              
209             =head1 CONTRIBUTORS
210              
211             grifferz - C
212              
213             =head1 LICENSE
214              
215             This library is free software; you can redistribute it and/or modify it under
216             the same terms as Perl itself. If you would like to contribute documentation,
217             features, bug fixes, or anything else then please raise an issue / pull request:
218              
219             https://github.com/Humanstate/business-gocardless
220              
221             =cut
222              
223             1;
224              
225             # vim: ts=4:sw=4:et