File Coverage

blib/lib/PayProp/API/Public/Client/Request/Export/Beneficiaries.pm
Criterion Covered Total %
statement 43 43 100.0
branch 3 4 75.0
condition 5 8 62.5
subroutine 11 11 100.0
pod 1 1 100.0
total 63 67 94.0


line stmt bran cond sub pod time code
1             package PayProp::API::Public::Client::Request::Export::Beneficiaries;
2              
3 3     3   607083 use strict;
  3         8  
  3         124  
4 3     3   19 use warnings;
  3         5  
  3         248  
5              
6 3     3   23 use Mouse;
  3         10  
  3         27  
7             with qw/ PayProp::API::Public::Client::Role::APIRequest /;
8              
9 3     3   3552 use PayProp::API::Public::Client::Response::Export::Beneficiary;
  3         358  
  3         170  
10 3     3   1918 use PayProp::API::Public::Client::Response::Export::Beneficiary::Address;
  3         309  
  3         129  
11 3     3   1910 use PayProp::API::Public::Client::Response::Export::Beneficiary::Property;
  3         329  
  3         2719  
12              
13              
14             has '+url' => (
15             default => sub {
16             my ( $self ) = @_;
17             return $self->abs_domain . '/api/agency/' . $self->api_version . '/export/beneficiaries';
18             },
19             );
20              
21              
22             sub list_p {
23 1     1 1 21 my ( $self, $args ) = @_;
24              
25 1   50     18 $args //= {};
26 1         2 my $params = $args->{params};
27              
28             return $self
29             ->api_request_p({
30             params => $params,
31 1     1   5 handle_response_cb => sub { $self->_get_beneficiaries( @_ ) },
32             })
33 1         34 ;
34             }
35              
36             sub _get_beneficiaries {
37 1     1   2 my ( $self, $response_json ) = @_;
38              
39 1         2 my @beneficiaries;
40 1   50     1 for my $beneficiary ( @{ $response_json->{items} // [] } ) {
  1         4  
41             my $Beneficiary = PayProp::API::Public::Client::Response::Export::Beneficiary->new(
42             id => $beneficiary->{id},
43             comment => $beneficiary->{comment},
44             is_owner => $beneficiary->{is_owner},
45             owner_app => $beneficiary->{owner_app},
46             last_name => $beneficiary->{last_name},
47             first_name => $beneficiary->{first_name},
48             notify_sms => $beneficiary->{notify_sms},
49             id_type_id => $beneficiary->{id_type_id},
50             vat_number => $beneficiary->{vat_number},
51             customer_id => $beneficiary->{customer_id},
52             notify_email => $beneficiary->{notify_email},
53             international => $beneficiary->{international},
54             email_address => $beneficiary->{email_address},
55             mobile_number => $beneficiary->{mobile_number},
56             id_reg_number => $beneficiary->{id_reg_number},
57             business_name => $beneficiary->{business_name},
58             is_active_owner => $beneficiary->{is_active_owner},
59             email_cc_address => $beneficiary->{email_cc_address},
60             customer_reference => $beneficiary->{customer_reference},
61              
62             properties => $self->_build_properties( $beneficiary->{properties} ),
63 2         38 billing_address => $self->_build_address( $beneficiary->{billing_address} ),
64             );
65              
66 2         234 push( @beneficiaries, $Beneficiary );
67             }
68              
69 1         10 return \@beneficiaries;
70             }
71              
72             sub _build_properties {
73 2     2   4 my ( $self, $properties_ref ) = @_;
74              
75 2 50 50     5 return [] unless @{ $properties_ref // [] };
  2         8  
76              
77 2         3 my @properties;
78              
79 2         6 foreach my $property ( $properties_ref->@* ) {
80             my $Property = PayProp::API::Public::Client::Response::Export::Beneficiary::Property->new(
81             id => $property->{id},
82             balance => $property->{balance},
83             comment => $property->{comment},
84             listed_from => $property->{listed_from},
85             listed_until => $property->{listed_until},
86             property_name => $property->{property_name},
87             allow_payments => $property->{allow_payments},
88             account_balance => $property->{account_balance},
89             approval_required => $property->{approval_required},
90             responsible_agent => $property->{responsible_agent},
91             customer_reference => $property->{customer_reference},
92             hold_all_owner_funds => $property->{hold_all_owner_funds},
93             last_processing_info => $property->{last_processing_info},
94             property_account_minimum_balance => $property->{property_account_minimum_balance},
95              
96 3         17 address => $self->_build_address( $property->{address} ),
97             );
98              
99 3         325 push( @properties, $Property );
100             }
101              
102 2         8 return \@properties;
103             }
104              
105             sub _build_address {
106 5     5   11 my ( $self, $addres_ref ) = @_;
107              
108 5 100 100     7 return undef unless %{ $addres_ref // {} };
  5         96  
109              
110             my $Address = PayProp::API::Public::Client::Response::Export::Beneficiary::Address->new(
111             id => $addres_ref->{id},
112             fax => $addres_ref->{fax},
113             city => $addres_ref->{city},
114             email => $addres_ref->{email},
115             phone => $addres_ref->{phone},
116             state => $addres_ref->{state},
117             created => $addres_ref->{created},
118             zip_code => $addres_ref->{zip_code},
119             modified => $addres_ref->{modified},
120             latitude => $addres_ref->{latitude},
121             longitude => $addres_ref->{longitude},
122             third_line => $addres_ref->{third_line},
123             first_line => $addres_ref->{first_line},
124             second_line => $addres_ref->{second_line},
125             country_code => $addres_ref->{country_code},
126 2         33 );
127              
128 2         168 return $Address;
129             }
130              
131             __PACKAGE__->meta->make_immutable;
132              
133             __END__