| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Business::Mondo; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Business::Mondo - Perl library for interacting with the Mondo API |
|
6
|
|
|
|
|
|
|
(https://api.getmondo.co.uk) |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=for html |
|
9
|
|
|
|
|
|
|
<a href='https://travis-ci.org/leejo/business-mondo?branch=master'><img src='https://travis-ci.org/leejo/business-mondo.svg?branch=master' alt='Build Status' /></a> |
|
10
|
|
|
|
|
|
|
<a href='https://coveralls.io/r/leejo/business-mondo?branch=master'><img src='https://coveralls.io/repos/leejo/business-mondo/badge.png?branch=master' alt='Coverage Status' /></a> |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
0.05 |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Business::Mondo is a library for easy interface to the Mondo banking API, |
|
19
|
|
|
|
|
|
|
it implements all of the functionality currently found in the service's API |
|
20
|
|
|
|
|
|
|
documentation: L<https://getmondo.co.uk/docs> |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
B<You should refer to the official Mondo API documentation in conjunction> |
|
23
|
|
|
|
|
|
|
B<with this perldoc>, as the official API documentation explains in more depth |
|
24
|
|
|
|
|
|
|
some of the functionality including required / optional parameters for certain |
|
25
|
|
|
|
|
|
|
methods. |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Please note this library is very much a work in progress, as is the Mondo API. |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
All objects within the Business::Mondo namespace are immutable. Calls to methods |
|
30
|
|
|
|
|
|
|
will, for the most part, return new instances of objects. |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $mondo = Business::Mondo->new( |
|
35
|
|
|
|
|
|
|
token => $token, # REQUIRED |
|
36
|
|
|
|
|
|
|
api_url => $url, # optional |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# transaction related information |
|
40
|
|
|
|
|
|
|
my @transactions = $mondo->transactions( account_id => $account_id ); |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $Transaction = $mondo->transaction( id => 1 ); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$Transaction->annotate( |
|
45
|
|
|
|
|
|
|
foo => 'bar', |
|
46
|
|
|
|
|
|
|
baz => 'boz, |
|
47
|
|
|
|
|
|
|
); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $annotations = $Transaction->annotations; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# account related information |
|
52
|
|
|
|
|
|
|
my @accounts = $mondo->accounts; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
foreach my $Account ( @accounts ) { |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my @transactions = $Account->transactions; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$Account->add_feed_item( |
|
59
|
|
|
|
|
|
|
params => { |
|
60
|
|
|
|
|
|
|
title => 'My Feed Item', |
|
61
|
|
|
|
|
|
|
image_url => 'http://...', |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# balance information |
|
66
|
|
|
|
|
|
|
my $Balance = $Account->balance; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# webhooks |
|
69
|
|
|
|
|
|
|
my @webhooks = $Account->webhooks; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $Webhook = $Account->register_webhook( |
|
72
|
|
|
|
|
|
|
callback_url => 'http://www.foo.com', |
|
73
|
|
|
|
|
|
|
); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$Webhook->delete |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# attachments |
|
79
|
|
|
|
|
|
|
my $Attachment = $mondo->upload_attachment( |
|
80
|
|
|
|
|
|
|
file_name => 'foo.png', |
|
81
|
|
|
|
|
|
|
file_type => 'image/png', |
|
82
|
|
|
|
|
|
|
); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$Attachment->register( |
|
85
|
|
|
|
|
|
|
external_id => 'my_id' |
|
86
|
|
|
|
|
|
|
); |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$Attachment->deregister; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 ERROR HANDLING |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Any problems or errors will result in a Business::Mondo::Exception |
|
93
|
|
|
|
|
|
|
object being thrown, so you should wrap any calls to the library in the |
|
94
|
|
|
|
|
|
|
appropriate error catching code (ideally a module from CPAN): |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
try { |
|
97
|
|
|
|
|
|
|
... |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
catch ( Business::Mondo::Exception $e ) { |
|
100
|
|
|
|
|
|
|
# error specific to Business::Mondo |
|
101
|
|
|
|
|
|
|
... |
|
102
|
|
|
|
|
|
|
say $e->message; # error message |
|
103
|
|
|
|
|
|
|
say $e->code; # HTTP status code |
|
104
|
|
|
|
|
|
|
say $e->response; # HTTP status message |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# ->request may not always be present |
|
107
|
|
|
|
|
|
|
say $e->request->{path} if $e->request |
|
108
|
|
|
|
|
|
|
say $e->request->{params} if $e->request |
|
109
|
|
|
|
|
|
|
say $e->request->{headers} if $e->request |
|
110
|
|
|
|
|
|
|
say $e->request->{content} if $e->request |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
catch ( $e ) { |
|
113
|
|
|
|
|
|
|
# some other failure? |
|
114
|
|
|
|
|
|
|
... |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
You can view some useful debugging information by setting the MONDO_DEBUG |
|
118
|
|
|
|
|
|
|
env varible, this will show the calls to the Mondo endpoints as well as a |
|
119
|
|
|
|
|
|
|
stack trace in the event of exceptions: |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
$ENV{MONDO_DEBUG} = 1; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
|
124
|
|
|
|
|
|
|
|
|
125
|
3
|
|
|
3
|
|
102172
|
use strict; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
64
|
|
|
126
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
51
|
|
|
127
|
|
|
|
|
|
|
|
|
128
|
3
|
|
|
3
|
|
1299
|
use Moo; |
|
|
3
|
|
|
|
|
26810
|
|
|
|
3
|
|
|
|
|
11
|
|
|
129
|
|
|
|
|
|
|
with 'Business::Mondo::Version'; |
|
130
|
|
|
|
|
|
|
|
|
131
|
3
|
|
|
3
|
|
3106
|
use Carp qw/ confess /; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
109
|
|
|
132
|
|
|
|
|
|
|
|
|
133
|
3
|
|
|
3
|
|
989
|
use Business::Mondo::Client; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
91
|
|
|
134
|
3
|
|
|
3
|
|
15
|
use Business::Mondo::Account; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
52
|
|
|
135
|
3
|
|
|
3
|
|
9
|
use Business::Mondo::Attachment; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
1074
|
|
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 token |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Your Mondo access token, this is required |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 api_url |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
The Mondo url, which will default to https://api.getmondo.co.uk |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 client |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
A Business::Mondo::Client object, this will be constructed for you so |
|
150
|
|
|
|
|
|
|
you shouldn't need to pass this |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
has [ qw/ token / ] => ( |
|
155
|
|
|
|
|
|
|
is => 'ro', |
|
156
|
|
|
|
|
|
|
required => 1, |
|
157
|
|
|
|
|
|
|
); |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
has api_url => ( |
|
160
|
|
|
|
|
|
|
is => 'ro', |
|
161
|
|
|
|
|
|
|
required => 0, |
|
162
|
|
|
|
|
|
|
default => sub { $Business::Mondo::API_URL }, |
|
163
|
|
|
|
|
|
|
); |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
has client => ( |
|
166
|
|
|
|
|
|
|
is => 'ro', |
|
167
|
|
|
|
|
|
|
isa => sub { |
|
168
|
|
|
|
|
|
|
confess( "$_[0] is not a Business::Mondo::Client" ) |
|
169
|
|
|
|
|
|
|
if ref $_[0] ne 'Business::Mondo::Client'; |
|
170
|
|
|
|
|
|
|
}, |
|
171
|
|
|
|
|
|
|
required => 0, |
|
172
|
|
|
|
|
|
|
lazy => 1, |
|
173
|
|
|
|
|
|
|
default => sub { |
|
174
|
|
|
|
|
|
|
my ( $self ) = @_; |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# fix any load order issues with Resources requiring a Client |
|
177
|
|
|
|
|
|
|
$Business::Mondo::Resource::client = Business::Mondo::Client->new( |
|
178
|
|
|
|
|
|
|
token => $self->token, |
|
179
|
|
|
|
|
|
|
api_url => $self->api_url, |
|
180
|
|
|
|
|
|
|
); |
|
181
|
|
|
|
|
|
|
}, |
|
182
|
|
|
|
|
|
|
); |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 METHODS |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
In the following %query_params refers to the possible query params as shown in |
|
187
|
|
|
|
|
|
|
the Mondo API documentation. For example: limit=100. |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# transactions in the previous month |
|
190
|
|
|
|
|
|
|
my @transactions = $mondo->transactions( |
|
191
|
|
|
|
|
|
|
since => DateTime->now->subtract( months => 1 ), |
|
192
|
|
|
|
|
|
|
); |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 transactions |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
$mondo->transactions( %query_params ); |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Get a list of transactions. Will return a list of L<Business::Mondo::Transaction> |
|
201
|
|
|
|
|
|
|
objects. Note you must supply an account_id in the params hash; |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub transactions { |
|
206
|
1
|
|
|
1
|
1
|
3
|
my ( $self,%params ) = @_; |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
# transactions requires account_id, whereas transaction doesn't |
|
209
|
|
|
|
|
|
|
# the Mondo API is a little inconsistent at this point... |
|
210
|
1
|
50
|
|
|
|
3
|
$params{account_id} || Business::Mondo::Exception->throw({ |
|
211
|
|
|
|
|
|
|
message => "transactions requires params: account_id", |
|
212
|
|
|
|
|
|
|
}); |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
return Business::Mondo::Account->new( |
|
215
|
|
|
|
|
|
|
client => $self->client, |
|
216
|
|
|
|
|
|
|
id => $params{account_id}, |
|
217
|
1
|
|
|
|
|
21
|
)->transactions; |
|
218
|
|
|
|
|
|
|
} |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 balance |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
my $Balance = $mondo->balance( account_id => $account_id ); |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Get an account balance Returns a L<Business::Mondo::Balance> object. |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=cut |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub balance { |
|
229
|
1
|
|
|
1
|
1
|
245
|
my ( $self,%params ) = @_; |
|
230
|
|
|
|
|
|
|
|
|
231
|
1
|
50
|
|
|
|
4
|
$params{account_id} || Business::Mondo::Exception->throw({ |
|
232
|
|
|
|
|
|
|
message => "balance requires params: account_id", |
|
233
|
|
|
|
|
|
|
}); |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
return Business::Mondo::Account->new( |
|
236
|
|
|
|
|
|
|
client => $self->client, |
|
237
|
|
|
|
|
|
|
id => $params{account_id}, |
|
238
|
1
|
|
|
|
|
20
|
)->balance( %params ); |
|
239
|
|
|
|
|
|
|
} |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head2 transaction |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
my $Transaction = $mondo->transaction( |
|
244
|
|
|
|
|
|
|
id => $id, |
|
245
|
|
|
|
|
|
|
expand => 'merchant' |
|
246
|
|
|
|
|
|
|
); |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Get a transaction. Will return a L<Business::Mondo::Transaction> object |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=cut |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
sub transaction { |
|
253
|
1
|
|
|
1
|
1
|
392
|
my ( $self,%params ) = @_; |
|
254
|
|
|
|
|
|
|
|
|
255
|
1
|
50
|
|
|
|
4
|
if ( my $expand = delete( $params{expand} ) ) { |
|
256
|
0
|
|
|
|
|
0
|
$params{'expand[]'} = $expand; |
|
257
|
|
|
|
|
|
|
} |
|
258
|
|
|
|
|
|
|
|
|
259
|
1
|
|
|
|
|
20
|
return $self->client->_get_transaction( \%params ); |
|
260
|
|
|
|
|
|
|
} |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head2 accounts |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
$mondo->accounts; |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Get a list of accounts. Will return a list of L<Business::Mondo::Account> |
|
267
|
|
|
|
|
|
|
objects |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=cut |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
sub accounts { |
|
272
|
1
|
|
|
1
|
1
|
321
|
my ( $self ) = @_; |
|
273
|
1
|
|
|
|
|
19
|
return $self->client->_get_accounts; |
|
274
|
|
|
|
|
|
|
} |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
sub upload_attachment { |
|
277
|
1
|
|
|
1
|
0
|
258
|
my ( $self,%params ) = @_; |
|
278
|
|
|
|
|
|
|
|
|
279
|
1
|
|
|
|
|
21
|
return Business::Mondo::Attachment->new( |
|
280
|
|
|
|
|
|
|
client => $self->client, |
|
281
|
|
|
|
|
|
|
)->upload( %params ); |
|
282
|
|
|
|
|
|
|
} |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head1 EXAMPLES |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
See the t/002_end_to_end.t test included with this distribution. you can run |
|
287
|
|
|
|
|
|
|
this test against the Mondo emulator by running end_to_end_emulated.sh (this |
|
288
|
|
|
|
|
|
|
is advised, don't run it against a live endpoint). |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
L<Business::Mondo::Account> |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
L<Business::Mondo::Attachment> |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
L<Business::Mondo::Balance> |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
L<Business::Mondo::Transaction> |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
L<Business::Mondo::Webhook> |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=head1 AUTHOR |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
Lee Johnson - C<leejo@cpan.org> |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=head1 LICENSE |
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
|
309
|
|
|
|
|
|
|
the same terms as Perl itself. If you would like to contribute documentation, |
|
310
|
|
|
|
|
|
|
features, bug fixes, or anything else then please raise an issue / pull request: |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
https://github.com/leejo/business-mondo |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=cut |
|
315
|
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
1; |
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
# vim: ts=4:sw=4:et |