| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Stancer::Customer; |
|
2
|
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
333187
|
use 5.020; |
|
|
15
|
|
|
|
|
66
|
|
|
4
|
15
|
|
|
15
|
|
105
|
use strict; |
|
|
15
|
|
|
|
|
30
|
|
|
|
15
|
|
|
|
|
515
|
|
|
5
|
15
|
|
|
15
|
|
84
|
use warnings; |
|
|
15
|
|
|
|
|
34
|
|
|
|
15
|
|
|
|
|
1469
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Customer representation |
|
8
|
|
|
|
|
|
|
our $VERSION = '1.0.3'; # VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
15
|
|
|
15
|
|
1065
|
use Stancer::Core::Types qw(Email ExternalId Maybe Mobile); |
|
|
15
|
|
|
|
|
37
|
|
|
|
15
|
|
|
|
|
1750
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
15
|
|
|
15
|
|
1344
|
use Stancer::Exceptions::BadMethodCall; |
|
|
15
|
|
|
|
|
84
|
|
|
|
15
|
|
|
|
|
635
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
15
|
|
|
15
|
|
90
|
use Moo; |
|
|
15
|
|
|
|
|
37
|
|
|
|
15
|
|
|
|
|
137
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
extends 'Stancer::Core::Object'; |
|
17
|
|
|
|
|
|
|
with 'Stancer::Role::Name'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
15
|
|
|
15
|
|
8315
|
use namespace::clean; |
|
|
15
|
|
|
|
|
52
|
|
|
|
15
|
|
|
|
|
151
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has '+endpoint' => ( |
|
22
|
|
|
|
|
|
|
default => 'customers', |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has email => ( |
|
27
|
|
|
|
|
|
|
is => 'rw', |
|
28
|
|
|
|
|
|
|
isa => Maybe[Email], |
|
29
|
5
|
|
|
5
|
|
229
|
builder => sub { $_[0]->_attribute_builder('email') }, |
|
30
|
|
|
|
|
|
|
lazy => 1, |
|
31
|
|
|
|
|
|
|
predicate => 1, |
|
32
|
|
|
|
|
|
|
trigger => sub { $_[0]->_add_modified('email') }, |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has external_id => ( |
|
37
|
|
|
|
|
|
|
is => 'rw', |
|
38
|
|
|
|
|
|
|
isa => Maybe[ExternalId], |
|
39
|
2
|
|
|
2
|
|
188
|
builder => sub { $_[0]->_attribute_builder('external_id') }, |
|
40
|
|
|
|
|
|
|
lazy => 1, |
|
41
|
|
|
|
|
|
|
predicate => 1, |
|
42
|
|
|
|
|
|
|
trigger => sub { $_[0]->_add_modified('external_id') }, |
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has mobile => ( |
|
47
|
|
|
|
|
|
|
is => 'rw', |
|
48
|
|
|
|
|
|
|
isa => Maybe[Mobile], |
|
49
|
4
|
|
|
4
|
|
4377
|
builder => sub { $_[0]->_attribute_builder('mobile') }, |
|
50
|
|
|
|
|
|
|
lazy => 1, |
|
51
|
|
|
|
|
|
|
predicate => 1, |
|
52
|
|
|
|
|
|
|
trigger => sub { $_[0]->_add_modified('mobile') }, |
|
53
|
|
|
|
|
|
|
); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
around send => sub { |
|
57
|
|
|
|
|
|
|
my ($orig, $this, $values) = @_; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
if (!$this->has_id && !$this->has_email && !$this->has_mobile) { |
|
60
|
|
|
|
|
|
|
my $message = 'You must provide an email or a phone number to create a customer.'; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Stancer::Exceptions::BadMethodCall->throw(message => $message); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return $this->$orig($values); |
|
66
|
|
|
|
|
|
|
}; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=pod |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=encoding UTF-8 |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 NAME |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Stancer::Customer - Customer representation |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 VERSION |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
version 1.0.3 |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 C<email> |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Read/Write 5 to 64 characters. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Customer email |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 C<external_id> |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Read/Write 36 characters maximum string. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
External for the API, you can store your customer's identifier here. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 C<mobile> |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Read/Write 8 to 16 characters. |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Customer mobile phone number |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 C<name> |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Read/Write 4 to 64 characters. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Customer name |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 METHODS |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 C<< Stancer::Customer->new() : I<self> >> |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 C<< Stancer::Customer->new(I<$token>) : I<self> >> |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 C<< Stancer::Customer->new(I<%args>) : I<self> >> |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 C<< Stancer::Customer->new(I<\%args>) : I<self> >> |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This method accept an optional string, it will be used as an entity ID for API calls. |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Get an empty new customer |
|
123
|
|
|
|
|
|
|
my $new = Stancer::Customer->new(); |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Get an existing customer |
|
126
|
|
|
|
|
|
|
my $exist = Stancer::Customer->new($token); |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 USAGE |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 Logging |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
We use the L<Log::Any> framework for logging events. |
|
135
|
|
|
|
|
|
|
You may tell where it should log using any available L<Log::Any::Adapter> module. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
For example, to log everything to a file you just have to add a line to your script, like this: |
|
138
|
|
|
|
|
|
|
#! /usr/bin/env perl |
|
139
|
|
|
|
|
|
|
use Log::Any::Adapter (File => '/var/log/payment.log'); |
|
140
|
|
|
|
|
|
|
use Stancer::Customer; |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
You must import C<Log::Any::Adapter> before our libraries, to initialize the logger instance before use. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
You can choose your log level on import directly: |
|
145
|
|
|
|
|
|
|
use Log::Any::Adapter (File => '/var/log/payment.log', log_level => 'info'); |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Read the L<Log::Any> documentation to know what other options you have. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 SECURITY |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=over |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item * |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Never, never, NEVER register a card or a bank account number in your database. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item * |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Always uses HTTPS in card/SEPA in communication. |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item * |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Our API will never give you a complete card/SEPA number, only the last four digits. |
|
166
|
|
|
|
|
|
|
If you need to keep track, use these last four digit. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=back |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 BUGS |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website |
|
175
|
|
|
|
|
|
|
L<https://gitlab.com/wearestancer/library/lib-perl/-/issues> or by email to |
|
176
|
|
|
|
|
|
|
L<bug-stancer@rt.cpan.org|mailto:bug-stancer@rt.cpan.org>. |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
|
179
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
|
180
|
|
|
|
|
|
|
feature. |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 AUTHOR |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Joel Da Silva <jdasilva@cpan.org> |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This software is Copyright (c) 2018-2024 by Stancer / Iliad78. |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
This is free software, licensed under: |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |