line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Flotum::Object::Customer; |
2
|
8
|
|
|
8
|
|
29
|
use strict; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
181
|
|
3
|
8
|
|
|
8
|
|
25
|
use warnings; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
188
|
|
4
|
8
|
|
|
8
|
|
22
|
use utf8; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
27
|
|
5
|
8
|
|
|
8
|
|
147
|
use Carp qw/croak/; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
286
|
|
6
|
8
|
|
|
8
|
|
32
|
use Moo; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
45
|
|
7
|
8
|
|
|
8
|
|
1469
|
use namespace::clean; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
69
|
|
8
|
8
|
|
|
8
|
|
3590
|
use Net::Flotum::Object::CreditCard; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
213
|
|
9
|
8
|
|
|
8
|
|
40
|
use URI::Escape; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
4042
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'flotum' => ( is => 'ro', weak_ref => 1, ); |
12
|
|
|
|
|
|
|
has 'id' => ( is => 'rwp', required => 1 ); |
13
|
|
|
|
|
|
|
has 'loaded' => ( is => 'rwp', default => 0 ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
for ( |
16
|
|
|
|
|
|
|
qw/ |
17
|
|
|
|
|
|
|
name remote_id legal_document |
18
|
|
|
|
|
|
|
default_address_name default_address_zip default_address_street default_address_number |
19
|
|
|
|
|
|
|
default_address_observation default_address_neighbourhood default_address_city default_address_state |
20
|
|
|
|
|
|
|
default_address_inputed_at |
21
|
|
|
|
|
|
|
/ |
22
|
|
|
|
|
|
|
) { |
23
|
|
|
|
|
|
|
has $_ => ( is => 'rwp' ); |
24
|
|
|
|
|
|
|
before $_ => sub { |
25
|
|
|
|
|
|
|
my ($self) = @_; |
26
|
|
|
|
|
|
|
return if $self->loaded; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$self->_load_from_id; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _load_from_id { |
33
|
3
|
|
|
3
|
|
3
|
my ($self) = @_; |
34
|
3
|
|
|
|
|
28
|
my $mydata = $self->flotum->_get_customer_data( id => $self->id ); |
35
|
2
|
|
|
|
|
16
|
for my $field ( keys %$mydata ) { |
36
|
42
|
100
|
|
|
|
179
|
if ( $self->can($field) ) { |
37
|
24
|
|
|
|
|
32
|
my $method = "_set_$field"; |
38
|
24
|
|
|
|
|
83
|
$self->$method( $mydata->{$field} ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
2
|
|
|
|
|
49
|
$self->_set_loaded(1); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _load_from_remote_id { |
45
|
2
|
|
|
2
|
|
4
|
my ( $self, $remote_id ) = @_; |
46
|
2
|
|
|
|
|
13
|
my $mydata = $self->flotum->_get_customer_data( remote_id => $remote_id ); |
47
|
1
|
|
|
|
|
6
|
for my $field ( keys %$mydata ) { |
48
|
21
|
100
|
|
|
|
70
|
if ( $self->can($field) ) { |
49
|
12
|
|
|
|
|
12
|
my $method = "_set_$field"; |
50
|
12
|
|
|
|
|
39
|
$self->$method( $mydata->{$field} ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
1
|
|
|
|
|
9
|
$self->_set_loaded(1); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub add_credit_card { |
57
|
3
|
|
|
3
|
0
|
5785
|
my ( $self, %opts ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
7
|
my $callback = delete $opts{callback}; |
60
|
|
|
|
|
|
|
|
61
|
3
|
|
|
|
|
32
|
my $session = $self->flotum->_get_customer_session_key( id => $self->id ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return { |
64
|
|
|
|
|
|
|
method => 'POST', |
65
|
|
|
|
|
|
|
href => ( |
66
|
|
|
|
|
|
|
join '/', $self->flotum->requester->flotum_api, |
67
|
|
|
|
|
|
|
'customers', $self->id, 'credit-cards', |
68
|
|
|
|
|
|
|
'?api_key=' . uri_escape($session) . ( $callback ? '&callback=' . uri_escape($callback) : '' ) |
69
|
|
|
|
|
|
|
), |
70
|
|
|
|
|
|
|
valid_until => time + 900, |
71
|
|
|
|
|
|
|
fields => { |
72
|
|
|
|
|
|
|
( |
73
|
24
|
|
|
|
|
237
|
map { $_ => '?Str' } |
74
|
|
|
|
|
|
|
qw/address_name |
75
|
|
|
|
|
|
|
address_zip |
76
|
|
|
|
|
|
|
address_street |
77
|
|
|
|
|
|
|
address_number |
78
|
|
|
|
|
|
|
address_observation |
79
|
|
|
|
|
|
|
address_neighbourhood |
80
|
|
|
|
|
|
|
address_city |
81
|
|
|
|
|
|
|
address_state/ |
82
|
|
|
|
|
|
|
), |
83
|
3
|
100
|
|
|
|
150
|
( map { $_ => '*Str' } qw/name_on_card legal_document/ ), |
|
6
|
|
|
|
|
68
|
|
84
|
|
|
|
|
|
|
number => '*CreditCard', |
85
|
|
|
|
|
|
|
csc => '*CSC', |
86
|
|
|
|
|
|
|
brand => '*Brand', |
87
|
|
|
|
|
|
|
validity => '*YYYYDD', |
88
|
|
|
|
|
|
|
address_inputed_at => '?GmtDateTime', |
89
|
|
|
|
|
|
|
}, |
90
|
|
|
|
|
|
|
accept => 'application/json' |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub list_credit_cards { |
95
|
1
|
|
|
1
|
0
|
630501
|
my ($self) = @_; |
96
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
13
|
my @credit_cards = $self->flotum->_get_list_customer_credit_cards( id => $self->id ); |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
2
|
my @objs; |
100
|
1
|
|
|
|
|
2
|
foreach my $cc_data (@credit_cards) { |
101
|
1
|
|
|
|
|
22
|
push @objs, |
102
|
|
|
|
|
|
|
Net::Flotum::Object::CreditCard->new( |
103
|
|
|
|
|
|
|
flotum => $self->flotum, |
104
|
|
|
|
|
|
|
merchant_customer_id => $self->id, |
105
|
|
|
|
|
|
|
%$cc_data, |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
1
|
50
|
|
|
|
1617
|
return wantarray ? @objs : \@objs; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub new_charge { |
114
|
1
|
|
|
1
|
0
|
604136
|
my $self = shift; |
115
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
12
|
return $self->flotum->_new_charge( @_, customer => $self ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |