NAME

WebService::HMRC - Interact with the UK HMRC Making Tax Digital API

VERSION

Version 0.02

SYNOPSIS

use WebService::HMRC::Request;

my $r = WebService::HMRC::Request->new();
$r->auth->access_token('MY_ACCESS_TOKEN');

my $response = $r->get_endpoint({
    endpoint => '/hello/user',
    auth_type => 'user',
});
print $response->data->{message} if $response->is_success;

DESCRIPTION

This Perl module is a base for a suite of modules used for interacting with the HMRC Making Tax Digital (MTD) and Making Tax Digital for Business (MTDfB) APIs.

HMRC is the UK government tax authority. Their APIs provide a means to submit and query information relating to personal and business tax and customs affairs.

These base modules will normally not be used directly by an application. Instead, applications will generally use a higher-level module which inherits from these classes.

For more information, see: https://developer.service.hmrc.gov.uk/api-documentation/docs/api

CORE MODULES

This module is distributed with the following low-level modules comprising the essential core classes for interacting with the API:

WebService::HMRC::Request
WebService::HMRC::Response
WebService::HMRC::Authenticate

API MODULES

Rather than using the low-level modules directly, applications will generally use a module specific to the API they wish to access (which will inherit from the core modules). At the time of writing, the following API modules are available:

WebService::HMRC::HelloWorld
WebService::HMRC::CreateTestUser
WebService::HMRC::VAT

INSTALLATION

To install this module, run the following commands:

perl Makefile.PL
make
make test
make install

AUTHORISATION

Except for a small number of open endpoints, access to the HMRC APIs requires application or user credentials. These must be obtained from HMRC. Application credentials (and documentation) may be obtained from their Developer Hub

TESTING

The basic tests, as run as part of the installation instructions shown above, do not require an internet connection or authorisation with HMRC.

Developer pre-release tests may be run with the following command:

prove -l xt/

With a working internet connection and appropriate HMRC credentials, specified as environment variables, interaction with the real HMRC sandbox api, using authorisation, may be tested:

Test generation of a valid authorisation url

To run these tests:

  • An application must be registered with HMRC.

  • The application must be enabled for the 'Hello World' test api with HMRC.

  • urn:ietf:wg:oauth:2.0:oob must be set as a valid redirect_uri for the application.

  • HMRC_CLIENT_ID environment variable must be set (issued when application was registered).

  • The HMRC sandbox test api endpoints must be functioning.

HMRC_CLIENT_ID=[MY-CLIENT-ID] prove -l t/04-hmrc-authenticate.t

This test generates a url, shown in the test output, which can be pasted into a browser to authorise the application and obtain an Authorisation Code for the following test stage.

Test token generation and renewal

In addition to the requirements of the test above, the following environment variables must be set:

  • HMRC_CLIENT_SECRET (issued when application was registered).

  • HMRC_AUTH_CODE (obtained after following the authorisation url generated above).

HMRC_CLIENT_ID=[MY-CLIENT-ID] \
HMRC_CLIENT_SECRET=[MY-CLIENT_SECRET] \
HMRC_AUTH_CODE=[MY-AUTH_CODE] \
prove -l t/04-hmrc-authenticate.t

When successful, this test will output the response from refreshing access tokens, including new access and refresh tokens.

Test API Interaction

These tests query the HMRC Hello World API, testing each of the authentication types and checking for an expected response. Prerequisites must be in place as for the other tests above and the following environment variables set:

  • HMRC_SERVER_TOKEN (issued when application was registered)

  • HMRC_ACCESS_TOKEN (refreshed access_token output by previous test above)

HMRC_SERVER_TOKEN=[MY-SERVER-TOKEN] \
HMRC_ACCESS_TOKEN=[MY-ACCESS-TOKEN] \
prove -l t/05-hmrc-api.t

AUTHOR

Nick Prater, <nick@npbroadcast.com>

BUGS

Please report any bugs or feature requests to bug-webservice-hmrc@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WebService-HMRC. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT AND DOCUMENTATION

After installation, you can find documentation for this module with the perldoc command.

perldoc WebService::HMRC

The README.pod file supplied with this distribution is generated from the WebService::HMRC module's pod by running the following command from the distribution root:

perldoc -u lib/WebService/HMRC.pm > README.pod

You can also look for information at:

ACKNOWLEDGEMENTS

This module was originally developed for use as part of the LedgerSMB open source accounting software.

LICENSE AND COPYRIGHT

Copyright 2018 Nick Prater, NP Broadcast Limited.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.