File Coverage

blib/lib/PayProp/API/Public/Client/Request/Entity/Invoice.pm
Criterion Covered Total %
statement 35 35 100.0
branch n/a
condition 3 6 50.0
subroutine 11 11 100.0
pod 3 3 100.0
total 52 55 94.5


line stmt bran cond sub pod time code
1             package PayProp::API::Public::Client::Request::Entity::Invoice;
2              
3 5     5   841258 use strict;
  5         12  
  5         173  
4 5     5   21 use warnings;
  5         7  
  5         295  
5              
6 5     5   20 use Mouse;
  5         11  
  5         48  
7             with qw/ PayProp::API::Public::Client::Role::APIRequest /;
8              
9 5     5   5273 use PayProp::API::Public::Client::Response::Entity::Invoice;
  5         444  
  5         2890  
10              
11              
12             has '+url' => (
13             default => sub {
14             my ( $self ) = @_;
15             return $self->abs_domain . '/api/agency/' . $self->api_version . '/entity/invoice';
16             },
17             );
18              
19             sub list_p {
20 3     3 1 144 my ( $self, $args ) = @_;
21              
22 3   50     39 $args //= {};
23 3         60 my $params = $args->{params};
24 3         15 my $path_params = $args->{path_params};
25              
26 3         84 $self->ordered_path_params([qw/ external_id /]);
27              
28             return $self
29             ->api_request_p({
30             params => $params,
31             path_params => $path_params,
32 3     3   24 handle_response_cb => sub { $self->_get_invoice( @_ ) },
33             })
34 3         264 ;
35             }
36              
37             sub create_p {
38 2     2 1 168 my ( $self, $args ) = @_;
39              
40 2   50     42 $args //= {};
41 2         22 my $content = $args->{content};
42              
43             return $self
44             ->api_request_p({
45             method => 'POST',
46             content => { json => $content },
47 2     2   22 handle_response_cb => sub { $self->_get_invoice( @_ ) },
48             })
49 2         132 ;
50             }
51              
52              
53             sub update_p {
54 1     1 1 80 my ( $self, $args ) = @_;
55              
56 1   50     17 $args //= {};
57 1         7 my $params = $args->{params};
58 1         10 my $content = $args->{content};
59 1         7 my $path_params = $args->{path_params};
60              
61 1         31 $self->ordered_path_params([qw/ external_id /]);
62              
63             return $self
64             ->api_request_p({
65             method => 'PUT',
66             params => $params,
67             path_params => $path_params,
68             content => { json => $content },
69 1     1   15 handle_response_cb => sub { $self->_get_invoice( @_ ) },
70             })
71 1         132 ;
72             }
73              
74             sub _get_invoice {
75 6     6   18 my ( $self, $response_json ) = @_;
76              
77             my $Invoice = PayProp::API::Public::Client::Response::Entity::Invoice->new(
78             id => $response_json->{id},
79             tax => $response_json->{tax},
80             amount => $response_json->{amount},
81             has_tax => $response_json->{has_tax},
82             end_date => $response_json->{end_date},
83             frequency => $response_json->{frequency},
84             tenant_id => $response_json->{tenant_id},
85             tax_amount => $response_json->{tax_amount},
86             start_date => $response_json->{start_date},
87             deposit_id => $response_json->{deposit_id},
88             category_id => $response_json->{category_id},
89             property_id => $response_json->{property_id},
90             payment_day => $response_json->{payment_day},
91             customer_id => $response_json->{customer_id},
92             description => $response_json->{description},
93             is_direct_debit => $response_json->{is_direct_debit},
94             has_invoice_period => $response_json->{has_invoice_period},
95 6         534 );
96              
97 6         1646 return $Invoice;
98             }
99              
100             __PACKAGE__->meta->make_immutable;
101              
102             __END__