line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::MinFraud::Validator; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
140784
|
use Moo; |
|
2
|
|
|
|
|
8837
|
|
|
2
|
|
|
|
|
10
|
|
4
|
2
|
|
|
2
|
|
1847
|
use namespace::autoclean; |
|
2
|
|
|
|
|
9222
|
|
|
2
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.009001'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
935
|
use Data::Delete 0.05; |
|
2
|
|
|
|
|
37049
|
|
|
2
|
|
|
|
|
64
|
|
9
|
2
|
|
|
2
|
|
15
|
use Try::Tiny; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
125
|
|
10
|
2
|
|
|
2
|
|
554
|
use Types::Standard qw( InstanceOf Object HashRef ); |
|
2
|
|
|
|
|
65202
|
|
|
2
|
|
|
|
|
19
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
2542
|
use WebService::MinFraud::Validator::Chargeback; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
70
|
|
13
|
2
|
|
|
2
|
|
845
|
use WebService::MinFraud::Validator::Score; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
96
|
|
14
|
2
|
|
|
2
|
|
766
|
use WebService::MinFraud::Validator::Insights; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
58
|
|
15
|
2
|
|
|
2
|
|
775
|
use WebService::MinFraud::Validator::Factors; |
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
58
|
|
16
|
2
|
|
|
2
|
|
13
|
use WebService::MinFraud::Validator::FraudService; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1056
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has _deleter => ( |
19
|
|
|
|
|
|
|
is => 'lazy', |
20
|
|
|
|
|
|
|
isa => InstanceOf ['Data::Delete'], |
21
|
54
|
|
|
54
|
|
12215
|
builder => sub { Data::Delete->new }, |
22
|
|
|
|
|
|
|
handles => { _delete => 'delete' }, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has _validator_chargeback => ( |
26
|
|
|
|
|
|
|
is => 'lazy', |
27
|
|
|
|
|
|
|
isa => InstanceOf ['WebService::MinFraud::Validator::Chargeback'], |
28
|
15
|
|
|
15
|
|
451
|
builder => sub { WebService::MinFraud::Validator::Chargeback->new }, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has _validator_score => ( |
32
|
|
|
|
|
|
|
is => 'lazy', |
33
|
|
|
|
|
|
|
isa => InstanceOf ['WebService::MinFraud::Validator::Score'], |
34
|
13
|
|
|
13
|
|
407
|
builder => sub { WebService::MinFraud::Validator::Score->new }, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has _validator_insights => ( |
38
|
|
|
|
|
|
|
is => 'lazy', |
39
|
|
|
|
|
|
|
isa => InstanceOf ['WebService::MinFraud::Validator::Insights'], |
40
|
13
|
|
|
13
|
|
402
|
builder => sub { WebService::MinFraud::Validator::Insights->new }, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has _validator_factors => ( |
44
|
|
|
|
|
|
|
is => 'lazy', |
45
|
|
|
|
|
|
|
isa => InstanceOf ['WebService::MinFraud::Validator::Factors'], |
46
|
13
|
|
|
13
|
|
409
|
builder => sub { WebService::MinFraud::Validator::Factors->new }, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has _validator_fraud_service => ( |
50
|
|
|
|
|
|
|
is => 'lazy', |
51
|
|
|
|
|
|
|
isa => InstanceOf ['WebService::MinFraud::Validator::FraudService'], |
52
|
1
|
|
|
1
|
|
33
|
builder => sub { WebService::MinFraud::Validator::FraudService->new }, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
has _dispatch_validator => ( |
56
|
|
|
|
|
|
|
is => 'lazy', |
57
|
|
|
|
|
|
|
isa => HashRef, |
58
|
|
|
|
|
|
|
builder => sub { |
59
|
54
|
|
|
54
|
|
628
|
my $self = shift; |
60
|
|
|
|
|
|
|
return { |
61
|
50
|
|
|
50
|
|
1090
|
fraud_service => sub { $self->_validator_fraud_service }, |
62
|
13
|
|
|
13
|
|
557
|
score => sub { $self->_validator_score }, |
63
|
20
|
|
|
20
|
|
746
|
chargeback => sub { $self->_validator_chargeback }, |
64
|
13
|
|
|
13
|
|
581
|
factors => sub { $self->_validator_factors }, |
65
|
13
|
|
|
13
|
|
528
|
insights => sub { $self->_validator_insights }, |
66
|
54
|
|
|
|
|
1503
|
}; |
67
|
|
|
|
|
|
|
}, |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub validate_request { |
71
|
109
|
|
|
109
|
1
|
138545
|
my ( $self, $request, $path ) = @_; |
72
|
|
|
|
|
|
|
|
73
|
109
|
100
|
|
|
|
378
|
if ( !defined $path ) { |
74
|
50
|
|
|
|
|
82
|
$path = 'fraud_service'; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
try { |
78
|
109
|
|
|
109
|
|
6885
|
$self->_dispatch_validator->{$path}()->assert_valid($request); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
catch { |
81
|
|
|
|
|
|
|
my @error_strings = map { |
82
|
31
|
100
|
|
|
|
139
|
'VALUE: ' |
83
|
|
|
|
|
|
|
. ( defined $_->value ? $_->value : 'undef' ) |
84
|
|
|
|
|
|
|
. ' caused ERROR: ' |
85
|
|
|
|
|
|
|
. $_->stringify |
86
|
31
|
|
|
31
|
|
21112
|
} @{ $_->failures }; |
|
31
|
|
|
|
|
84
|
|
87
|
31
|
|
|
|
|
9420
|
my $all_error_strings = join "\n", @error_strings; |
88
|
31
|
|
|
|
|
557
|
die $all_error_strings; |
89
|
109
|
|
|
|
|
839
|
}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# ABSTRACT: Validation for the minFraud requests |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=pod |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=encoding UTF-8 |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 NAME |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
WebService::MinFraud::Validator - Validation for the minFraud requests |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 VERSION |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
version 1.009001 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SYNOPSIS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
use 5.010; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
use WebService::MinFraud::Validator; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $validator = WebService::MinFraud::Validator->new; |
117
|
|
|
|
|
|
|
my $request = { device => { ip_address => '24.24.24.24' } }; |
118
|
|
|
|
|
|
|
$validator->validate_request($request, 'score'); # takes an optional 'path' |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 DESCRIPTION |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This module defines the request schema for the minFraud API. In addition, it |
123
|
|
|
|
|
|
|
provides a C<validate_request> method that is used to validate any request |
124
|
|
|
|
|
|
|
passed to the C<score>, C<insights>, C<factors>, or C<chargeback> methods. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 METHODS |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 validate_request |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $validator = WebService::MinFraud::Validator->new; |
131
|
|
|
|
|
|
|
my $request = { ip => '24.24.24.24' }; |
132
|
|
|
|
|
|
|
$validator->validate_request($request, 'chargeback'); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
$request = { device => { ip_address => '24.24.24.24' } }; |
135
|
|
|
|
|
|
|
$validator->validate_request($request); # by default will use WebService::MinFraud::Validator::FraudService |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This method takes a minFraud request as a HashRef and validates it against the |
138
|
|
|
|
|
|
|
minFraud request schema for the specified API endpoint. A second optional argument can be used |
139
|
|
|
|
|
|
|
to specify the schema to use, C<socre>, C<insights>, C<factors>, C<chargeback>, |
140
|
|
|
|
|
|
|
or C<fraud_service>. If the request HashRef fails validation, an exception |
141
|
|
|
|
|
|
|
is thrown, which is a string containing all of the validation errors. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 SUPPORT |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Bugs may be submitted through L<https://github.com/maxmind/minfraud-api-perl/issues>. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 AUTHOR |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Mateu Hunter <mhunter@maxmind.com> |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This software is copyright (c) 2015 - 2019 by MaxMind, Inc. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
156
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |