line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Flotum; |
2
|
4
|
|
|
4
|
|
2106
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
105
|
|
3
|
4
|
|
|
4
|
|
100
|
use 5.008_005; |
|
4
|
|
|
|
|
9
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
14
|
use warnings; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
106
|
|
7
|
4
|
|
|
4
|
|
1394
|
use utf8; |
|
4
|
|
|
|
|
27
|
|
|
4
|
|
|
|
|
23
|
|
8
|
4
|
|
|
4
|
|
116
|
use Carp qw/croak confess/; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
253
|
|
9
|
4
|
|
|
4
|
|
1587
|
use Moo; |
|
4
|
|
|
|
|
42554
|
|
|
4
|
|
|
|
|
25
|
|
10
|
4
|
|
|
4
|
|
6479
|
use namespace::clean; |
|
4
|
|
|
|
|
35867
|
|
|
4
|
|
|
|
|
24
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
2454
|
use Net::Flotum::API::Charge; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
124
|
|
13
|
4
|
|
|
4
|
|
1526
|
use Net::Flotum::API::Customer; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
123
|
|
14
|
4
|
|
|
4
|
|
1721
|
use Net::Flotum::API::RequestHandler; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
126
|
|
15
|
4
|
|
|
4
|
|
2093
|
use Log::Any; |
|
4
|
|
|
|
|
24087
|
|
|
4
|
|
|
|
|
24
|
|
16
|
4
|
|
|
4
|
|
2078
|
use Net::Flotum::Object::Customer; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
2723
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'logger' => ( is => 'ro', builder => '_build_logger', lazy => 1 ); |
19
|
|
|
|
|
|
|
has 'requester' => ( is => 'ro', builder => '_build_requester', lazy => 1 ); |
20
|
|
|
|
|
|
|
has 'merchant_api_key' => ( is => 'rw', required => 1 ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'customer_api' => ( is => 'ro', builder => '_build_customer_api', lazy => 1 ); |
23
|
|
|
|
|
|
|
has 'charge_api' => ( is => 'ro', builder => '_build_charge_api', lazy => 1 ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _build_requester { |
26
|
3
|
|
|
3
|
|
37
|
Net::Flotum::API::RequestHandler->new; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _build_logger { |
30
|
3
|
|
|
3
|
|
42
|
Log::Any->get_logger; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _build_customer_api { |
34
|
3
|
|
|
3
|
|
17
|
my ($self) = @_; |
35
|
3
|
|
|
|
|
28
|
Net::Flotum::API::Customer->new( flotum => $self, ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _build_charge_api { |
39
|
1
|
|
|
1
|
|
12
|
my ($self) = @_; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
17
|
Net::Flotum::API::Charge->new( flotum => $self ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub load_customer { |
45
|
4
|
|
|
4
|
0
|
2714
|
my ( $self, %opts ) = @_; |
46
|
|
|
|
|
|
|
|
47
|
4
|
50
|
66
|
|
|
20
|
my $lazy = 1 if exists $opts{lazy} && $opts{lazy}; |
48
|
4
|
|
|
|
|
6
|
my $cus; |
49
|
4
|
100
|
|
|
|
18
|
if ( exists $opts{id} ) { |
|
|
50
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$cus = Net::Flotum::Object::Customer->new( |
51
|
|
|
|
|
|
|
flotum => $self, |
52
|
|
|
|
|
|
|
id => $opts{id} |
53
|
2
|
|
|
|
|
35
|
); |
54
|
2
|
100
|
|
|
|
961
|
$cus->_load_from_id unless $lazy; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif ( exists $opts{remote_id} ) { |
57
|
2
|
|
|
|
|
56
|
$cus = Net::Flotum::Object::Customer->new( |
58
|
|
|
|
|
|
|
flotum => $self, |
59
|
|
|
|
|
|
|
id => '_ID_IS_REQUIRED_' |
60
|
|
|
|
|
|
|
); |
61
|
2
|
|
|
|
|
64
|
$cus->_load_from_remote_id( $opts{remote_id} ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
0
|
|
|
|
|
0
|
croak 'missing parameter: `remote_id` or `id` is required'; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
8
|
return $cus; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub new_customer { |
71
|
2
|
|
|
2
|
0
|
3932
|
my ( $self, %opts ) = @_; |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
43
|
my $customer_id = $self->customer_api->exec_new_customer(%opts); |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
35
|
return Net::Flotum::Object::Customer->new( |
76
|
|
|
|
|
|
|
flotum => $self, |
77
|
|
|
|
|
|
|
%$customer_id |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _new_charge { |
82
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
83
|
1
|
|
|
|
|
50
|
return $self->charge_api->exec_new_charge(@_); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _update_customer { |
87
|
1
|
|
|
1
|
|
1
|
my $self = shift; |
88
|
1
|
|
|
|
|
23
|
return $self->customer_api->exec_update_customer(@_); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _payment_charge { |
92
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
36
|
return $self->charge_api->exec_payment_charge(@_); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _capture_charge { |
98
|
2
|
|
|
2
|
|
7
|
my $self = shift; |
99
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
193
|
return $self->charge_api->exec_capture_charge(@_); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _refund_charge { |
104
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
105
|
|
|
|
|
|
|
|
106
|
1
|
|
|
|
|
36
|
return $self->charge_api->exec_refund_charge(@_); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _get_customer_data { |
110
|
6
|
|
|
6
|
|
20
|
my ( $self, %opts ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
confess 'missing parameter: `remote_id` or `id` is required' |
113
|
|
|
|
|
|
|
unless ( exists $opts{remote_id} && defined $opts{remote_id} ) |
114
|
6
|
50
|
66
|
|
|
70
|
|| ( exists $opts{id} && defined $opts{id} ); |
|
|
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
6
|
|
|
|
|
144
|
return $self->customer_api->exec_load_customer(%opts); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _get_customer_session_key { |
121
|
1
|
|
|
1
|
|
2
|
my ( $self, %opts ) = @_; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
confess 'missing parameter: `id` is required' |
124
|
1
|
50
|
33
|
|
|
10
|
unless ( exists $opts{id} && defined $opts{id} ); |
125
|
|
|
|
|
|
|
|
126
|
1
|
|
|
|
|
25
|
return $self->customer_api->exec_get_customer_session(%opts)->{api_key}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub _get_list_customer_credit_cards { |
130
|
1
|
|
|
1
|
|
3
|
my ( $self, %opts ) = @_; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
confess 'missing parameter: `id` is required' |
133
|
1
|
50
|
33
|
|
|
11
|
unless ( exists $opts{id} && defined $opts{id} ); |
134
|
|
|
|
|
|
|
|
135
|
1
|
|
|
|
|
24
|
my $arr = $self->customer_api->exec_list_credit_cards(%opts)->{credit_cards}; |
136
|
1
|
50
|
|
|
|
8
|
return wantarray ? @$arr : $arr; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub _remove_customer_credit_cards { |
140
|
1
|
|
|
1
|
|
4
|
my ( $self, %opts ) = @_; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
confess 'missing parameter: `id` is required' |
143
|
1
|
50
|
33
|
|
|
9
|
unless ( exists $opts{id} && defined $opts{id} ); |
144
|
|
|
|
|
|
|
confess 'missing parameter: `merchant_customer_id` is required' |
145
|
1
|
50
|
33
|
|
|
7
|
unless ( exists $opts{merchant_customer_id} && defined $opts{merchant_customer_id} ); |
146
|
|
|
|
|
|
|
|
147
|
1
|
|
|
|
|
24
|
my $bool = $self->customer_api->exec_remove_credit_card(%opts); |
148
|
1
|
|
|
|
|
9
|
return $bool; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
__END__ |