File Coverage

blib/lib/PayProp/API/Public/Client/Request/Entity/Payment.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::Payment;
2              
3 5     5   1342960 use strict;
  5         10  
  5         202  
4 5     5   20 use warnings;
  5         10  
  5         255  
5              
6 5     5   23 use Mouse;
  5         10  
  5         83  
7             with qw/ PayProp::API::Public::Client::Role::APIRequest /;
8              
9 5     5   5004 use PayProp::API::Public::Client::Response::Entity::Payment;
  5         613  
  5         2594  
10              
11              
12             has '+url' => (
13             default => sub {
14             my ( $self ) = @_;
15             return $self->abs_domain . '/api/agency/' . $self->api_version . '/entity/payment';
16             },
17             );
18              
19             sub list_p {
20 3     3 1 129 my ( $self, $args ) = @_;
21              
22 3   50     42 $args //= {};
23 3         138 my $params = $args->{params};
24 3         30 my $path_params = $args->{path_params};
25              
26 3         87 $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   27 handle_response_cb => sub { $self->_get_payment( @_ ) },
33             })
34 3         168 ;
35             }
36              
37             sub create_p {
38 2     2 1 216 my ( $self, $args ) = @_;
39              
40 2   50     48 $args //= {};
41 2         26 my $content = $args->{content};
42              
43             return $self
44             ->api_request_p({
45             method => 'POST',
46             content => { json => $content },
47 2     2   34 handle_response_cb => sub { $self->_get_payment( @_ ) },
48             })
49 2         146 ;
50             }
51              
52             sub update_p {
53 1     1 1 1107 my ( $self, $args ) = @_;
54              
55 1   50     14 $args //= {};
56 1         9 my $params = $args->{params};
57 1         3 my $content = $args->{content};
58 1         14 my $path_params = $args->{path_params};
59              
60 1         49 $self->ordered_path_params([qw/ external_id /]);
61              
62             return $self
63             ->api_request_p({
64             method => 'PUT',
65             params => $params,
66             path_params => $path_params,
67             content => { json => $content },
68 1     1   13 handle_response_cb => sub { $self->_get_payment( @_ ) },
69             })
70 1         71 ;
71             }
72              
73             sub _get_payment {
74 6     6   20 my ( $self, $response_json ) = @_;
75              
76             my $Payment = PayProp::API::Public::Client::Response::Entity::Payment->new(
77             id => $response_json->{id},
78             tax => $response_json->{tax},
79             amount => $response_json->{amount},
80             enabled => $response_json->{enabled},
81             has_tax => $response_json->{has_tax},
82             end_date => $response_json->{end_date},
83             frequency => $response_json->{frequency},
84             reference => $response_json->{reference},
85             tenant_id => $response_json->{tenant_id},
86             tax_amount => $response_json->{tax_amount},
87             start_date => $response_json->{start_date},
88             percentage => $response_json->{percentage},
89             payment_day => $response_json->{payment_day},
90             customer_id => $response_json->{customer_id},
91             description => $response_json->{description},
92             property_id => $response_json->{property_id},
93             category_id => $response_json->{category_id},
94             use_money_from => $response_json->{use_money_from},
95             beneficiary_id => $response_json->{beneficiary_id},
96             beneficiary_type => $response_json->{beneficiary_type},
97             global_beneficiary => $response_json->{global_beneficiary},
98             no_commission_amount => $response_json->{no_commission_amount},
99             maintenance_ticket_id => $response_json->{maintenance_ticket_id},
100 6         585 );
101              
102 6         1584 return $Payment;
103             }
104              
105             __PACKAGE__->meta->make_immutable;
106              
107             __END__