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