line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::HMRC::VAT; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
347887
|
use 5.006; |
|
5
|
|
|
|
|
61
|
|
4
|
5
|
|
|
5
|
|
30
|
use Carp; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
277
|
|
5
|
5
|
|
|
5
|
|
1882
|
use JSON::MaybeXS; |
|
5
|
|
|
|
|
30592
|
|
|
5
|
|
|
|
|
295
|
|
6
|
5
|
|
|
5
|
|
2665
|
use Moose; |
|
5
|
|
|
|
|
2411273
|
|
|
5
|
|
|
|
|
38
|
|
7
|
5
|
|
|
5
|
|
41283
|
use namespace::autoclean; |
|
5
|
|
|
|
|
40221
|
|
|
5
|
|
|
|
|
22
|
|
8
|
5
|
|
|
5
|
|
2684
|
use URI::Escape; |
|
5
|
|
|
|
|
7769
|
|
|
5
|
|
|
|
|
5201
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
extends 'WebService::HMRC::Request'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
WebService::HMRC::VAT - Interact with the UK HMRC VAT API |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Version 0.04 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use WebService::HMRC::VAT; |
27
|
|
|
|
|
|
|
my $vat = WebService::HMRC::VAT->new({ |
28
|
|
|
|
|
|
|
vrn => '123456789' |
29
|
|
|
|
|
|
|
}); |
30
|
|
|
|
|
|
|
$vat->auth->access_token('MY-ACCESS-TOKEN'); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Display outstanding VAT returns |
33
|
|
|
|
|
|
|
my $result = $vat->obligations({ |
34
|
|
|
|
|
|
|
from => '2018-01-01', |
35
|
|
|
|
|
|
|
to => '2018-12-31', |
36
|
|
|
|
|
|
|
state => 'O', |
37
|
|
|
|
|
|
|
}); |
38
|
|
|
|
|
|
|
if($result->is_success) { |
39
|
|
|
|
|
|
|
foreach my $o (@{$result->data->{obligations}) { |
40
|
|
|
|
|
|
|
print "VAT return " . $o->{periodKey}; |
41
|
|
|
|
|
|
|
print " due " . $o->{due} . "\n"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Submit a VAT return |
46
|
|
|
|
|
|
|
$result = $vat->submit_return({ |
47
|
|
|
|
|
|
|
periodKey => "#001", # from ->obligations() |
48
|
|
|
|
|
|
|
vatDueSales => 100.00, # Box 1 on paper form |
49
|
|
|
|
|
|
|
vatDueAcquisitions => 100.00, # Box 2 on paper form |
50
|
|
|
|
|
|
|
totalVatDue => 200.00, # Box 3 on paper form |
51
|
|
|
|
|
|
|
vatReclaimedCurrPeriod => 100.00, # Box 4 on paper form |
52
|
|
|
|
|
|
|
netVatDue => 100.00, # Box 5 on paper form |
53
|
|
|
|
|
|
|
totalValueSalesExVAT => 500, # Box 6 on paper form |
54
|
|
|
|
|
|
|
totalValuePurchasesExVAT => 500, # Box 7 on paper form |
55
|
|
|
|
|
|
|
totalValueGoodsSuppliedExVAT => 500, # Box 8 on paper form |
56
|
|
|
|
|
|
|
totalAcquisitionsExVAT => 500, # Box 9 on paper form |
57
|
|
|
|
|
|
|
finalised => 1, # Boolean user declaration |
58
|
|
|
|
|
|
|
}); |
59
|
|
|
|
|
|
|
if($result->is_success) { |
60
|
|
|
|
|
|
|
print "VAT Return submitted:\n" |
61
|
|
|
|
|
|
|
printf "Receipt ID: %s\n", $result->header('Receipt-ID'); |
62
|
|
|
|
|
|
|
printf "Form Bundle: %s\n", $result->data->{formBundleNumber}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Perl module to interact with the UK's HMRC Making Tax Digital |
68
|
|
|
|
|
|
|
`VAT` API. This allows VAT returns to be submitted or viewed, |
69
|
|
|
|
|
|
|
and obligations, payments and liabilities to be viewed. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
For more information, see: |
72
|
|
|
|
|
|
|
L<https://developer.service.hmrc.gov.uk/api-documentation/docs/api/service/vat-api/1.0> |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 REQUIRES |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=over |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item * L<JSON::MaybeXS> |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item * L<Moose> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item * L<namespace::autoclean> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item * L<URI::Escape> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=back |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 EXPORTS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Nothing |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 PROPERTIES |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Inherits from L<WebService::HMRC::Request>. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 vrn |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
VAT registration number for which records are being queries or submitted. |
99
|
|
|
|
|
|
|
Required parameter for initialisation. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The VAT registration number must be purely numeric, without any spaces or |
102
|
|
|
|
|
|
|
GB prefix. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
has vrn => ( |
107
|
|
|
|
|
|
|
is => 'rw', |
108
|
|
|
|
|
|
|
isa => 'Int', |
109
|
|
|
|
|
|
|
required => 1, |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 METHODS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Inherits from L<WebService::HMRC::Request>. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 obligations({ from => 'YYYY-MM-DD', to => 'YYYY-MM-DD', [status => $status, ] [test_mode => $test_mode] }) |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Retrieve a set of VAT filing obligations for the specified date range. Returns |
119
|
|
|
|
|
|
|
a WebService::HMRC::Response object reference. Requires permission for the |
120
|
|
|
|
|
|
|
C<read:vat> service scope. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head3 Parameters |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=over |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item from |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Return obligations from this date, specified as YYYY-MM-DD. |
129
|
|
|
|
|
|
|
Required parameter. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item to |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Return obligations up to this date, specified as YYYY-MM-DD. |
134
|
|
|
|
|
|
|
Required parameter. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item status |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Optional parameter to filter the obligations returned. May be set to 'O' to |
139
|
|
|
|
|
|
|
return only 'open' obligations, or 'F' to return only 'fulfilled' obligations. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Default is to return all obligations, both fulfilled and open. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item test_mode |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Optional parameter used only for testing against the HMRC sandbox api. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This parameter should not be used in production systems - it causes dummy |
148
|
|
|
|
|
|
|
test data to be returned. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
By default, when testing against the sandbox with no C<test_mode> specified, |
151
|
|
|
|
|
|
|
the test api simulates the scenario where the client has quarterly |
152
|
|
|
|
|
|
|
obligations and one is fulfilled |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Other test scenarios are available by setting the C<test_mode> parameter |
155
|
|
|
|
|
|
|
as detailed below: |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
C<QUARTERLY_NONE_MET> simulates the scenario where the client has quarterly |
158
|
|
|
|
|
|
|
obligations and none are fulfilled. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
C<QUARTERLY_ONE_MET> simulates the scenario where the client has quarterly |
161
|
|
|
|
|
|
|
obligations and one is fulfilled. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
C<QUARTERLY_TWO_MET> simulates the scenario where the client has quarterly |
164
|
|
|
|
|
|
|
obligations and two are fulfilled. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
C<QUARTERLY_THREE_MET> simulates the scenario where the client has quarterly |
167
|
|
|
|
|
|
|
obligations and three are fulfilled. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
C<QUARTERLY_FOUR_MET> simulates the scenario where the client has quarterly |
170
|
|
|
|
|
|
|
obligations and four are fulfilled. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
C<MONTHLY_NONE_MET> simulates the scenario where the client has monthly |
173
|
|
|
|
|
|
|
obligations and none are fulfilled. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
C<MONTHLY_ONE_MET> simulates the scenario where the client has monthly |
176
|
|
|
|
|
|
|
obligations and one month is fulfilled. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
C<MONTHLY_TWO_MET> simulates the scenario where the client has monthly |
179
|
|
|
|
|
|
|
obligations and two months are fulfilled. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
C<MONTHLY_THREE_MET> simulates the scenario where the client has monthly |
182
|
|
|
|
|
|
|
obligations and three months are fulfilled. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
C<NOT_FOUND> simulates the scenario where no data is found. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=back |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head3 Response Data |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
For full details of the response data, see the HMRC API specification. In summary, |
191
|
|
|
|
|
|
|
the data contains a single element `obligations` pointing to an array of |
192
|
|
|
|
|
|
|
VAT return obligations: |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
{ |
195
|
|
|
|
|
|
|
obligations => [ |
196
|
|
|
|
|
|
|
{ |
197
|
|
|
|
|
|
|
periodKey => "#001" |
198
|
|
|
|
|
|
|
start => "2017-04-06", |
199
|
|
|
|
|
|
|
end => "2017-07-05", |
200
|
|
|
|
|
|
|
due => "2017-08-12", |
201
|
|
|
|
|
|
|
status => "F", |
202
|
|
|
|
|
|
|
received => "2017-08-05", # only present if 'Fulfilled' |
203
|
|
|
|
|
|
|
}, |
204
|
|
|
|
|
|
|
{ |
205
|
|
|
|
|
|
|
periodKey => "#004" |
206
|
|
|
|
|
|
|
start => "2018-01-06", |
207
|
|
|
|
|
|
|
end => "2018-04-05", |
208
|
|
|
|
|
|
|
due => "2018-05-12", |
209
|
|
|
|
|
|
|
status => "O", |
210
|
|
|
|
|
|
|
}, |
211
|
|
|
|
|
|
|
] |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head3 Example usage |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
my $result = $vat->obligations({ |
217
|
|
|
|
|
|
|
from => '2018-01-01', |
218
|
|
|
|
|
|
|
to => '2018-12-31', |
219
|
|
|
|
|
|
|
}); |
220
|
|
|
|
|
|
|
foreach my $obligation( @{$result->data->{obligations}} ) { |
221
|
|
|
|
|
|
|
print "-- VAT Return Obligation --\n" |
222
|
|
|
|
|
|
|
print " ID: $obligation->{periodKey}\n"; |
223
|
|
|
|
|
|
|
print " Period Start: $obligation->{start}\n"; |
224
|
|
|
|
|
|
|
print " Period End: $obligation->{end}\n"; |
225
|
|
|
|
|
|
|
print " Due Date: $obligation->{due}\n"; |
226
|
|
|
|
|
|
|
print "Received Date: "; |
227
|
|
|
|
|
|
|
if ($obligation->{status} eq 'F') { |
228
|
|
|
|
|
|
|
print "$obligation->{received}\n"; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
else { |
231
|
|
|
|
|
|
|
print "Still Outstanding\n"; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=cut |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
sub obligations { |
238
|
|
|
|
|
|
|
|
239
|
8
|
|
|
8
|
1
|
181511
|
my ($self, $args) = @_; |
240
|
8
|
|
|
|
|
18
|
my @headers; |
241
|
|
|
|
|
|
|
|
242
|
8
|
|
|
|
|
36
|
$self->_require_date_range($args); |
243
|
|
|
|
|
|
|
|
244
|
4
|
|
|
|
|
151
|
my $endpoint = sprintf( |
245
|
|
|
|
|
|
|
'/organisations/vat/%s/obligations', |
246
|
|
|
|
|
|
|
$self->vrn, |
247
|
|
|
|
|
|
|
); |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
my $params = { |
250
|
|
|
|
|
|
|
from => $args->{from}, |
251
|
|
|
|
|
|
|
to => $args->{to}, |
252
|
4
|
|
|
|
|
21
|
}; |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
# status is an optional parameter |
255
|
4
|
100
|
|
|
|
18
|
if($args->{status}) { |
256
|
2
|
100
|
|
|
|
24
|
$args->{status} =~ m/^[OF]$/ or croak 'status parameter is invalid'; |
257
|
1
|
|
|
|
|
4
|
$params->{status} = $args->{status}; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
3
|
50
|
|
|
|
10
|
if($args->{test_mode}) { |
261
|
0
|
|
|
|
|
0
|
push @headers, ('Gov-Test-Scenario' => $args->{test_mode}); |
262
|
0
|
|
|
|
|
0
|
carp 'TEST MODE enabled - returning dummy test data!'; |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
3
|
|
|
|
|
43
|
return $self->get_endpoint({ |
266
|
|
|
|
|
|
|
endpoint => $endpoint, |
267
|
|
|
|
|
|
|
auth_type => 'user', |
268
|
|
|
|
|
|
|
parameters => $params, |
269
|
|
|
|
|
|
|
headers => [@headers], |
270
|
|
|
|
|
|
|
}); |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head2 liabilities({ from => 'YYYY-MM-DD', to => 'YYYY-MM-DD', [test_mode => $test_mode] }) |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Retrieve a set of VAT payment liabilities. Returns a WebService::HMRC::Response |
277
|
|
|
|
|
|
|
object reference. Requires permission for the C<read:vat> service scope. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head3 Parameters |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=over |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=item from |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
Return liabilities from this date, specified as YYYY-MM-DD. |
286
|
|
|
|
|
|
|
Required parameter. The date must be before today's date, otherwise the api |
287
|
|
|
|
|
|
|
will return an error. |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item to |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
Return liabilities up to this date, specified as YYYY-MM-DD. |
292
|
|
|
|
|
|
|
Required parameter. |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=item test_mode |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
Optional parameter used only for testing against the HMRC sandbox api. |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
If set to C<SINGLE_LIABILITY>, returns a single valid liability when used |
299
|
|
|
|
|
|
|
with dates from 2017-01-02 and to 2017-02-02. |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
If set to C<MULTIPLE_LIABILITIES>, returns multiple valid liabilities when |
302
|
|
|
|
|
|
|
used with dates from 2017-04-05 and to 2017-12-21. |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
This parameter should not be used in production systems - it causes dummy |
305
|
|
|
|
|
|
|
test data to be returned. |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=back |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=head3 Response Data |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
For full details of the response data, see the HMRC API specification. In summary, |
312
|
|
|
|
|
|
|
the data contains a single element `liabilities` pointing to an array of |
313
|
|
|
|
|
|
|
VAT payment liabilities: |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
{ |
316
|
|
|
|
|
|
|
liabilities => [ |
317
|
|
|
|
|
|
|
{ |
318
|
|
|
|
|
|
|
taxPeriod => { |
319
|
|
|
|
|
|
|
from => "2017-04-06", |
320
|
|
|
|
|
|
|
to => "2017-07-06" |
321
|
|
|
|
|
|
|
}, |
322
|
|
|
|
|
|
|
type => "VAT ...", |
323
|
|
|
|
|
|
|
originalAmount => 6000.00, |
324
|
|
|
|
|
|
|
outstandingAmount => 100.00, |
325
|
|
|
|
|
|
|
due => "2017-07-06" |
326
|
|
|
|
|
|
|
}, |
327
|
|
|
|
|
|
|
] |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
=head3 Example usage |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
my $result = $vat->liabilities({ |
333
|
|
|
|
|
|
|
from => '2018-01-01', |
334
|
|
|
|
|
|
|
to => '2018-03-31', |
335
|
|
|
|
|
|
|
}); |
336
|
|
|
|
|
|
|
foreach my $liability( @{$result->data->{liabilities}} ) { |
337
|
|
|
|
|
|
|
print "-- VAT Payment Liability --\n" |
338
|
|
|
|
|
|
|
print " Type: $liability->{type}\n"; |
339
|
|
|
|
|
|
|
print " Period Start: $liability->{taxPeriod}->{from}\n"; |
340
|
|
|
|
|
|
|
print " Period End: $liability->{taxPeriod}->{to}\n"; |
341
|
|
|
|
|
|
|
print "Original Amount: $liability->{originalAmount}\n"; |
342
|
|
|
|
|
|
|
print " Due Amount: $liability->{outstandingAmount}\n"; |
343
|
|
|
|
|
|
|
print " Due Date: $liability->{due}\n"; |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
=cut |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
sub liabilities { |
349
|
|
|
|
|
|
|
|
350
|
5
|
|
|
5
|
1
|
132830
|
my ($self, $args) = @_; |
351
|
5
|
|
|
|
|
10
|
my @headers; |
352
|
|
|
|
|
|
|
|
353
|
5
|
|
|
|
|
21
|
$self->_require_date_range($args); |
354
|
|
|
|
|
|
|
|
355
|
2
|
|
|
|
|
71
|
my $endpoint = sprintf( |
356
|
|
|
|
|
|
|
'/organisations/vat/%s/liabilities', |
357
|
|
|
|
|
|
|
$self->vrn, |
358
|
|
|
|
|
|
|
); |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
my $params = { |
361
|
|
|
|
|
|
|
from => $args->{from}, |
362
|
|
|
|
|
|
|
to => $args->{to}, |
363
|
2
|
|
|
|
|
9
|
}; |
364
|
|
|
|
|
|
|
|
365
|
2
|
50
|
|
|
|
7
|
if($args->{test_mode}) { |
366
|
0
|
|
|
|
|
0
|
push @headers, ('Gov-Test-Scenario' => $args->{test_mode}); |
367
|
0
|
|
|
|
|
0
|
carp 'TEST MODE enabled - returning dummy test data!'; |
368
|
|
|
|
|
|
|
} |
369
|
|
|
|
|
|
|
|
370
|
2
|
|
|
|
|
17
|
return $self->get_endpoint({ |
371
|
|
|
|
|
|
|
endpoint => $endpoint, |
372
|
|
|
|
|
|
|
auth_type => 'user', |
373
|
|
|
|
|
|
|
parameters => $params, |
374
|
|
|
|
|
|
|
headers => [@headers], |
375
|
|
|
|
|
|
|
}); |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
=head2 payments({ from => 'YYYY-MM-DD', to => 'YYYY-MM-DD', [test_mode => $test_mode] }) |
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
Retrieve a set of payments received by HMRC in respect of VAT over the |
382
|
|
|
|
|
|
|
specified date range. Returns a WebService::HMRC::Response object reference. |
383
|
|
|
|
|
|
|
Requires permission for the C<read:vat> service scope. |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
=head3 Parameters |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
=over |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
=item from |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
Return payments from this date, specified as YYYY-MM-DD. |
392
|
|
|
|
|
|
|
Required parameter. |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
=item to |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
Return payments up to this date, specified as YYYY-MM-DD. |
397
|
|
|
|
|
|
|
Required parameter. |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
=item test_mode |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
Optional parameter used only for testing against the HMRC sandbox api. |
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
If set to C<SINGLE_PAYMENT>, returns a single valid payment when used with |
404
|
|
|
|
|
|
|
dates from 2017-01-02 and to 2017-02-02. |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
If set to C<MULTIPLE_PAYMENTS>, returns multiple valid payments when used |
407
|
|
|
|
|
|
|
with dates from 2017-02-27 and to 2017-12-21. |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
This parameter should not be used in production systems - it causes dummy |
410
|
|
|
|
|
|
|
test data to be returned. |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
=back |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
=head3 Response Data |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
For full details of the response data, see the HMRC API specification. In |
417
|
|
|
|
|
|
|
summary, the data contains a single element `payments` pointing to an array |
418
|
|
|
|
|
|
|
of payments received by HMRC: |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
{ |
421
|
|
|
|
|
|
|
payments => [ |
422
|
|
|
|
|
|
|
{ |
423
|
|
|
|
|
|
|
amount => 100.00, |
424
|
|
|
|
|
|
|
received => "2017-04-06" |
425
|
|
|
|
|
|
|
}, |
426
|
|
|
|
|
|
|
] |
427
|
|
|
|
|
|
|
} |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
=head3 Example usage |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
my $result = $vat->payments( |
432
|
|
|
|
|
|
|
from => '2018-01-01', |
433
|
|
|
|
|
|
|
to => '2018-03-31', |
434
|
|
|
|
|
|
|
); |
435
|
|
|
|
|
|
|
foreach my $payment( @{$result->data->{payments}} ) { |
436
|
|
|
|
|
|
|
print "-- VAT Payments Received by HMRC --\n" |
437
|
|
|
|
|
|
|
print "Date Received: $payment->{received}\n"; |
438
|
|
|
|
|
|
|
print " Amount: $payment->{amount}\n"; |
439
|
|
|
|
|
|
|
} |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
=cut |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
sub payments { |
444
|
|
|
|
|
|
|
|
445
|
6
|
|
|
6
|
1
|
134680
|
my ($self, $args) = @_; |
446
|
6
|
|
|
|
|
15
|
my @headers; |
447
|
|
|
|
|
|
|
|
448
|
6
|
|
|
|
|
24
|
$self->_require_date_range($args); |
449
|
|
|
|
|
|
|
|
450
|
2
|
|
|
|
|
73
|
my $endpoint = sprintf( |
451
|
|
|
|
|
|
|
'/organisations/vat/%s/payments', |
452
|
|
|
|
|
|
|
$self->vrn, |
453
|
|
|
|
|
|
|
); |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
my $params = { |
456
|
|
|
|
|
|
|
from => $args->{from}, |
457
|
|
|
|
|
|
|
to => $args->{to}, |
458
|
2
|
|
|
|
|
8
|
}; |
459
|
|
|
|
|
|
|
|
460
|
2
|
50
|
|
|
|
8
|
if($args->{test_mode}) { |
461
|
0
|
|
|
|
|
0
|
push @headers, ('Gov-Test-Scenario' => $args->{test_mode}); |
462
|
0
|
|
|
|
|
0
|
carp 'TEST MODE enabled - returning dummy test data!'; |
463
|
|
|
|
|
|
|
} |
464
|
|
|
|
|
|
|
|
465
|
2
|
|
|
|
|
19
|
return $self->get_endpoint({ |
466
|
|
|
|
|
|
|
endpoint => $endpoint, |
467
|
|
|
|
|
|
|
auth_type => 'user', |
468
|
|
|
|
|
|
|
parameters => $params, |
469
|
|
|
|
|
|
|
headers => [@headers], |
470
|
|
|
|
|
|
|
}); |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
=head2 get_return({ period_key => $period_key }) |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
Retrieve a previously submitted VAT return corresponding to the supplied |
477
|
|
|
|
|
|
|
period_key. Returns a WebService::HMRC::Response object reference. |
478
|
|
|
|
|
|
|
Requires permission for the C<read:vat> service scope. |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
=head3 Parameters |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
=over |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
=item period_key |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
The ID code for the period that uniquely identifies a submitted |
487
|
|
|
|
|
|
|
VAT return, as contained within the response from an obligations() |
488
|
|
|
|
|
|
|
method call. |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
=back |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
=head3 Response Data |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
For full details of the response data, see the HMRC API specification. In |
495
|
|
|
|
|
|
|
summary, the data is a hashref comprising the following elements which |
496
|
|
|
|
|
|
|
correspond to fields on the traditional paper VAT100 form: |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
{ |
499
|
|
|
|
|
|
|
periodKey => "#001", |
500
|
|
|
|
|
|
|
vatDueSales => 100.00, |
501
|
|
|
|
|
|
|
vatDueAcquisitions => 100.00, |
502
|
|
|
|
|
|
|
totalVatDue => 200, |
503
|
|
|
|
|
|
|
vatReclaimedCurrPeriod => 100.00, |
504
|
|
|
|
|
|
|
netVatDue => 100, |
505
|
|
|
|
|
|
|
totalValueSalesExVAT => 500, |
506
|
|
|
|
|
|
|
totalValuePurchasesExVAT => 500, |
507
|
|
|
|
|
|
|
totalValueGoodsSuppliedExVAT => 500, |
508
|
|
|
|
|
|
|
totalAcquisitionsExVAT => 500 |
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
Note that some fields are returned as integers where only whole pounds |
512
|
|
|
|
|
|
|
are required to be submitted by HMRC. |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
=cut |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
sub get_return { |
517
|
|
|
|
|
|
|
|
518
|
1
|
|
|
1
|
1
|
24034
|
my ($self, $args) = @_; |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
defined $args->{period_key} |
521
|
1
|
50
|
|
|
|
7
|
or croak 'period_key parameter missing or undefined'; |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
my $endpoint = sprintf( |
524
|
|
|
|
|
|
|
'/organisations/vat/%s/returns/%s', |
525
|
|
|
|
|
|
|
$self->vrn, |
526
|
1
|
|
|
|
|
39
|
uri_escape($args->{period_key}), |
527
|
|
|
|
|
|
|
); |
528
|
|
|
|
|
|
|
|
529
|
1
|
|
|
|
|
57
|
return $self->get_endpoint({ |
530
|
|
|
|
|
|
|
endpoint => $endpoint, |
531
|
|
|
|
|
|
|
auth_type => 'user', |
532
|
|
|
|
|
|
|
}); |
533
|
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
=head2 submit_return($hashref) |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
Retrieve a previously submitted VAT return corresponding to the supplied |
539
|
|
|
|
|
|
|
period_key. Returns a WebService::HMRC::Response object reference. |
540
|
|
|
|
|
|
|
Requires permission for the C<write:vat> service scope. |
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
=head3 Parameters |
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
For full details of the required parameters and the rules for calculating |
545
|
|
|
|
|
|
|
each value, see the HMRC API specification and VAT documentation. The |
546
|
|
|
|
|
|
|
brief descriptions here are intended as a simplified overview to help |
547
|
|
|
|
|
|
|
understand the code and are not a comprehensive or necessarily accurate |
548
|
|
|
|
|
|
|
representation of VAT law. |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
In summary, the data is a hashref comprising the following elements which |
551
|
|
|
|
|
|
|
correspond to fields on the traditional paper VAT100 form. All parameters |
552
|
|
|
|
|
|
|
are required. |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
=over |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
=item period_key |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
The ID code for the period that uniquely identifies a submitted |
559
|
|
|
|
|
|
|
VAT return, as contained within the response from an obligations() |
560
|
|
|
|
|
|
|
method call. |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
=item vatDueSales |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
VAT due on sales and other outputs. Corresponds to box 1 on the traditional |
565
|
|
|
|
|
|
|
VAT100 paper form. |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
=item vatDueAcquisitions |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
VAT due on acquisitions from other EC member states as part of the reverse- |
570
|
|
|
|
|
|
|
charge scheme. Corresponds to box 2 on the traditional VAT100 paper form. |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
=item totalVatDue |
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
The sum of vatDueSales and vatDueAcquisitions. Corresponds to box 3 on the |
575
|
|
|
|
|
|
|
traditional VAT100 paper form. |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
=item vatReclaimedCurrPeriod |
578
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
VAT reclaimed on purchases and other inputs, including acquisitions from other |
580
|
|
|
|
|
|
|
EC member states. This corresponds to box 4 on the traditional VAT100 paper |
581
|
|
|
|
|
|
|
form. |
582
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
=item netVatDue |
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
The absolute (unsigned, always positive) difference between totalVatDue and |
586
|
|
|
|
|
|
|
vatReclaimedCurrPeriod. This corresponds to box 5 on the traditional VAT100 |
587
|
|
|
|
|
|
|
paper form. |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
=item totalValueSalesExVAT |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
Total value of sales and all other outputs, excluding any VAT, rounded to |
592
|
|
|
|
|
|
|
an integer value. This corresponds to box 6 on the traditional VAT100 paper |
593
|
|
|
|
|
|
|
form. |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
=item totalValuePurchasesExVAT |
596
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
Total value of purchases and all other inputs, excluding any VAT and including |
598
|
|
|
|
|
|
|
any exempt purchases. This corresponds to box 7 on the traditional VAT100 |
599
|
|
|
|
|
|
|
paper form. |
600
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
=item totalValueGoodsSuppliedExVAT |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
Total value of all supplies of goods (but not services) to other EC member |
604
|
|
|
|
|
|
|
states and costs directly related to that supply (such as freight or |
605
|
|
|
|
|
|
|
insurance), excluding any VAT. This corresponds to box 8 on the traditional |
606
|
|
|
|
|
|
|
VAT100 paper form. |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
=item totalAcquisitionsExVAT |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
Total value of acquisitions of goods from other EC member states and |
611
|
|
|
|
|
|
|
directly related costs (such as freight or insurance), excluding any VAT. |
612
|
|
|
|
|
|
|
This corresponds to box 9 on the traditional VAT100 paper form. |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
=item finalised |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
Boolean declaration that the data being submitted has been finalised and |
617
|
|
|
|
|
|
|
approved by the user. Must be true for successful submission. |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
This parameter is converted to a JSON()->true or JSON()->false |
620
|
|
|
|
|
|
|
boolean value before encoding to json for submission. |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
Defaults to false. |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
=back |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
=head3 Response Headers |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
For full details of the response headers, see the HMRC API specification. In |
629
|
|
|
|
|
|
|
summary the headers confirm receipt of the submission, comprising: |
630
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
=over |
632
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
=item Receipt ID |
634
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
Unique reference number returned for a submission. |
636
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
=item Receipt-Timestamp |
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
ISO8601 format timestamp of the form '2018-02-14T09:32:15Z'. |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
=item X-CorrelationId |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
Unique ID for this operation. |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
=back |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
=head3 Response Data |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
For full details of the response data, see the HMRC API specification. In |
650
|
|
|
|
|
|
|
summary, the response data is a hashref with keys: |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
=over |
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
=item processingDate |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
ISO8601 timestamp indicating the time that the submission was processed. |
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
=item formBundleNumber |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
Unique number representing the "Form Bundle" in which the submitted data |
661
|
|
|
|
|
|
|
has been stored by HMRC. |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
=item paymentIndicator |
664
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
Set to 'DD' if payment is due to HMRC and they hold a Direct Debit |
666
|
|
|
|
|
|
|
instruction for the client, 'BANK' if a repayment is due from HMRC and |
667
|
|
|
|
|
|
|
they hold bank details to make the repayment, otherwise this element is |
668
|
|
|
|
|
|
|
not present in the returned data. |
669
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
=item chargeRefNumber |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
Present only is payment is due to HMRC. |
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
=back |
675
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
=head3 Example |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
my $result = $vat->submit_return({ |
679
|
|
|
|
|
|
|
periodKey => "#001", |
680
|
|
|
|
|
|
|
vatDueSales => 100.00, |
681
|
|
|
|
|
|
|
vatDueAcquisitions => 0.00, |
682
|
|
|
|
|
|
|
totalVatDue => 100.00, |
683
|
|
|
|
|
|
|
vatReclaimedCurrPeriod => 50.00, |
684
|
|
|
|
|
|
|
netVatDue => 50.00, |
685
|
|
|
|
|
|
|
totalValueSalesExVAT => 500, |
686
|
|
|
|
|
|
|
totalValuePurchasesExVAT => 250, |
687
|
|
|
|
|
|
|
totalValueGoodsSuppliedExVAT => 0, |
688
|
|
|
|
|
|
|
totalAcquisitionsExVAT => 0, |
689
|
|
|
|
|
|
|
finalised => 1, |
690
|
|
|
|
|
|
|
}) |
691
|
|
|
|
|
|
|
if($result->is_success) { |
692
|
|
|
|
|
|
|
print "==== VAT Return Submitted ====\n"; |
693
|
|
|
|
|
|
|
printf " Receipt ID: %s\n", $result->header('Receipt-ID'); |
694
|
|
|
|
|
|
|
printf " Receipt Timestamp: %s\n", $result->header('Receipt-Timestamp'); |
695
|
|
|
|
|
|
|
printf " Tracking ID: %s\n", $result->header('X-CorrelationId'); |
696
|
|
|
|
|
|
|
printf " Processing Date: %s\n", $result->data->{processingDate}; |
697
|
|
|
|
|
|
|
printf " Form Bundle: %s\n", $result->data->{formBundleNumber}; |
698
|
|
|
|
|
|
|
if($result->data->{paymentIndicator}) { |
699
|
|
|
|
|
|
|
printf " Payment Indicator: %s\n", $result->data->{paymentIndicator}; |
700
|
|
|
|
|
|
|
} |
701
|
|
|
|
|
|
|
if($result->data->{paymentIndicator}) { |
702
|
|
|
|
|
|
|
printf " Charge Reference: %s\n", $result->data->{chargeRefNumber}; |
703
|
|
|
|
|
|
|
} |
704
|
|
|
|
|
|
|
} |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
=cut |
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
sub submit_return { |
709
|
|
|
|
|
|
|
|
710
|
3
|
|
|
3
|
1
|
278752
|
my ($self, $data) = @_; |
711
|
|
|
|
|
|
|
|
712
|
3
|
50
|
66
|
|
|
55
|
$data && ref $data && ref $data eq 'HASH' |
|
|
|
66
|
|
|
|
|
713
|
|
|
|
|
|
|
or croak 'data parameter is missing or not a hashref'; |
714
|
|
|
|
|
|
|
|
715
|
2
|
50
|
|
|
|
16
|
defined $data->{periodKey} or croak 'periodKey data field is undefined'; |
716
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
# Convert finalised element to JSON true/false boolean |
718
|
2
|
100
|
|
|
|
18
|
$data->{finalised} = $data->{finalised} ? JSON()->true |
719
|
|
|
|
|
|
|
: JSON()->false; |
720
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
# Validate numeric data fields, coerce into number before JSON encoding |
722
|
2
|
|
|
|
|
39
|
foreach my $field(qw( |
723
|
|
|
|
|
|
|
vatDueSales |
724
|
|
|
|
|
|
|
vatDueAcquisitions |
725
|
|
|
|
|
|
|
totalVatDue |
726
|
|
|
|
|
|
|
vatReclaimedCurrPeriod |
727
|
|
|
|
|
|
|
netVatDue |
728
|
|
|
|
|
|
|
totalValueSalesExVAT |
729
|
|
|
|
|
|
|
totalValuePurchasesExVAT |
730
|
|
|
|
|
|
|
totalValueGoodsSuppliedExVAT |
731
|
|
|
|
|
|
|
totalAcquisitionsExVAT |
732
|
|
|
|
|
|
|
)) { |
733
|
18
|
50
|
|
|
|
43
|
defined $data->{$field} or croak "$field data field is undefined"; |
734
|
18
|
|
|
|
|
42
|
$data->{$field} += 0; # coerce to number |
735
|
|
|
|
|
|
|
} |
736
|
|
|
|
|
|
|
|
737
|
2
|
|
|
|
|
88
|
my $endpoint = sprintf( |
738
|
|
|
|
|
|
|
'/organisations/vat/%s/returns', |
739
|
|
|
|
|
|
|
$self->vrn, |
740
|
|
|
|
|
|
|
); |
741
|
|
|
|
|
|
|
|
742
|
2
|
|
|
|
|
23
|
return $self->post_endpoint_json({ |
743
|
|
|
|
|
|
|
endpoint => $endpoint, |
744
|
|
|
|
|
|
|
data => $data, |
745
|
|
|
|
|
|
|
auth_type => 'user', |
746
|
|
|
|
|
|
|
}); |
747
|
|
|
|
|
|
|
} |
748
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
# PRIVATE METHODS |
752
|
|
|
|
|
|
|
|
753
|
|
|
|
|
|
|
# _require_date_range(%args) |
754
|
|
|
|
|
|
|
# |
755
|
|
|
|
|
|
|
# Checks that supplied args has has keys `from` and `to` and |
756
|
|
|
|
|
|
|
# that they match the pattern "YYYY-MM-DD". Returns true if so, |
757
|
|
|
|
|
|
|
# otherwise croaks. |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
sub _require_date_range { |
760
|
|
|
|
|
|
|
|
761
|
19
|
|
|
19
|
|
48
|
my ($self, $args) = @_; |
762
|
|
|
|
|
|
|
|
763
|
19
|
100
|
100
|
|
|
251
|
$args->{from} && $args->{from} =~ m/^\d\d\d\d-\d\d-\d\d$/ |
764
|
|
|
|
|
|
|
or croak 'from parameter is missing or invalid'; |
765
|
|
|
|
|
|
|
|
766
|
13
|
100
|
100
|
|
|
143
|
$args->{to} && $args->{to} =~ m/^\d\d\d\d-\d\d-\d\d$/ |
767
|
|
|
|
|
|
|
or croak 'to parameter is missing or invalid'; |
768
|
|
|
|
|
|
|
|
769
|
8
|
|
|
|
|
22
|
return 1; |
770
|
|
|
|
|
|
|
} |
771
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
=head1 AUTHORISATION |
773
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
Access to the HMRC Making Tax Digital VAT APIs requires that an application |
775
|
|
|
|
|
|
|
be registered with HMRC and enabled for this service. Additionally permission |
776
|
|
|
|
|
|
|
must be granted by a registered user for the application to access the |
777
|
|
|
|
|
|
|
C<read:vat> or C<write:vat> service scope, as noted for each method. |
778
|
|
|
|
|
|
|
|
779
|
|
|
|
|
|
|
Authorisation is provided by means of an C<access token>. |
780
|
|
|
|
|
|
|
|
781
|
|
|
|
|
|
|
For more details on obtaining and using access tokens, See |
782
|
|
|
|
|
|
|
L<WebService::HMRC::Authenticate>. |
783
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
Further information, application credentials and documentation may be obtained |
785
|
|
|
|
|
|
|
from the |
786
|
|
|
|
|
|
|
L<HMRC Developer Hub|https://developer.service.hmrc.gov.uk/api-documentation>. |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
=head1 TESTING |
789
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
The basic tests are run as part of the installation instructions shown above |
791
|
|
|
|
|
|
|
use an invalid uri as an endpoint. This tests basic interaction with the |
792
|
|
|
|
|
|
|
module's method and does not require an internet connection. |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
Developer pre-release tests may be run with the following command: |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
prove -l xt/ |
797
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
With a working internet connection, HMRC application credentials and an access |
799
|
|
|
|
|
|
|
token granted by a test user enrolled for the Making Tax Digital for Business |
800
|
|
|
|
|
|
|
VAT service, interaction with the real HMRC sandbox api can be tested. The |
801
|
|
|
|
|
|
|
test user's VAT registration number must also be provided. |
802
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
The credentials are specified as environment variables when running the tests: |
804
|
|
|
|
|
|
|
|
805
|
|
|
|
|
|
|
HMRC_ACCESS_TOKEN=[MY-ACCESS-TOKEN] \ |
806
|
|
|
|
|
|
|
HMRC_VRN=[USER-VAT-REGISTRATION-NUMBER] \ |
807
|
|
|
|
|
|
|
make test TEST_VERBOSE=1 |
808
|
|
|
|
|
|
|
|
809
|
|
|
|
|
|
|
=head1 AUTHOR |
810
|
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
Nick Prater, <nick@npbroadcast.com> |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
=head1 BUGS |
814
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-webservice-hmrc-vat at rt.cpan.org>, or through |
816
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WebService-HMRC-VAT>. I will be notified, and then you'll |
817
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
818
|
|
|
|
|
|
|
|
819
|
|
|
|
|
|
|
=head1 SUPPORT AND DOCUMENTATION |
820
|
|
|
|
|
|
|
|
821
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
822
|
|
|
|
|
|
|
|
823
|
|
|
|
|
|
|
perldoc WebService::HMRC::VAT |
824
|
|
|
|
|
|
|
|
825
|
|
|
|
|
|
|
The C<README.pod> file supplied with this distribution is generated from the |
826
|
|
|
|
|
|
|
L<WebService::HMRC::VAT> module's pod by running the following |
827
|
|
|
|
|
|
|
command from the distribution root: |
828
|
|
|
|
|
|
|
|
829
|
|
|
|
|
|
|
perldoc -u lib/WebService/HMRC/VAT.pm > README.pod |
830
|
|
|
|
|
|
|
|
831
|
|
|
|
|
|
|
You can also look for information at: |
832
|
|
|
|
|
|
|
|
833
|
|
|
|
|
|
|
=over 4 |
834
|
|
|
|
|
|
|
|
835
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
836
|
|
|
|
|
|
|
|
837
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WebService-HMRC-VAT> |
838
|
|
|
|
|
|
|
|
839
|
|
|
|
|
|
|
=item * CPAN Ratings |
840
|
|
|
|
|
|
|
|
841
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/WebService-HMRC-VAT> |
842
|
|
|
|
|
|
|
|
843
|
|
|
|
|
|
|
=item * Search CPAN |
844
|
|
|
|
|
|
|
|
845
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/WebService-HMRC-VAT/> |
846
|
|
|
|
|
|
|
|
847
|
|
|
|
|
|
|
=item * Github |
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
L<https://github.com/nick-prater/WebService-HMRC-VAT> |
850
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
=back |
852
|
|
|
|
|
|
|
|
853
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
854
|
|
|
|
|
|
|
|
855
|
|
|
|
|
|
|
This module was originally developed for use as part of the |
856
|
|
|
|
|
|
|
L<LedgerSMB|https://ledgersmb.org/> open source accounting software. |
857
|
|
|
|
|
|
|
|
858
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
859
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
Copyright 2018-2019 Nick Prater, NP Broadcast Limited. |
861
|
|
|
|
|
|
|
|
862
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
863
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
864
|
|
|
|
|
|
|
copy of the full license at: |
865
|
|
|
|
|
|
|
|
866
|
|
|
|
|
|
|
L<http://www.perlfoundation.org/artistic_license_2_0> |
867
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
869
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
870
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
871
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
872
|
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
874
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
875
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
878
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
879
|
|
|
|
|
|
|
|
880
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
881
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
882
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
883
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
884
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
885
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
886
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
887
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
888
|
|
|
|
|
|
|
|
889
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
890
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
891
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
892
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
893
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
894
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
895
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
896
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
897
|
|
|
|
|
|
|
|
898
|
|
|
|
|
|
|
=cut |
899
|
|
|
|
|
|
|
|
900
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
901
|
|
|
|
|
|
|
1; # End of WebService::HMRC::VAT |