line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Flotum::API::Customer; |
2
|
4
|
|
|
4
|
|
26
|
use common::sense; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
27
|
|
3
|
4
|
|
|
4
|
|
197
|
use Moo; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
22
|
|
4
|
4
|
|
|
4
|
|
1220
|
use namespace::clean; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
24
|
|
5
|
4
|
|
|
4
|
|
1115
|
use Carp; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
258
|
|
6
|
4
|
|
|
4
|
|
39
|
use JSON::MaybeXS; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
209
|
|
7
|
4
|
|
|
4
|
|
1669
|
use Net::Flotum::Object::Charge; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
150
|
|
8
|
4
|
|
|
4
|
|
31
|
use Net::Flotum::API::ExceptionHandler; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
4135
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'flotum' => ( is => 'ro', weak_ref => 1 ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub exec_new_customer { |
13
|
2
|
|
|
2
|
0
|
2059
|
my ( $self, %opts ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
49
|
my $requester = $self->flotum->requester; |
16
|
2
|
|
|
|
|
2414
|
my $logger = $self->flotum->logger; |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
4355
|
my (%ret) = request_with_retries( |
19
|
|
|
|
|
|
|
logger => $logger, |
20
|
|
|
|
|
|
|
requester => $requester, |
21
|
|
|
|
|
|
|
name => 'create user', |
22
|
|
|
|
|
|
|
method => 'rest_post', |
23
|
|
|
|
|
|
|
params => [ |
24
|
|
|
|
|
|
|
'customers', |
25
|
|
|
|
|
|
|
headers => [ |
26
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
27
|
|
|
|
|
|
|
'X-api-key' => $self->flotum->merchant_api_key |
28
|
|
|
|
|
|
|
], |
29
|
|
|
|
|
|
|
code => 201, |
30
|
|
|
|
|
|
|
data => encode_json( \%opts ) |
31
|
|
|
|
|
|
|
] |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
55
|
return $ret{obj}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub exec_load_customer { |
39
|
6
|
|
|
6
|
0
|
918
|
my ( $self, %opts ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
6
|
|
|
|
|
120
|
my $requester = $self->flotum->requester; |
42
|
6
|
|
|
|
|
1111
|
my $logger = $self->flotum->logger; |
43
|
|
|
|
|
|
|
|
44
|
6
|
|
|
|
|
1948
|
my ( @with_id, %params ); |
45
|
6
|
100
|
66
|
|
|
46
|
push @with_id, $opts{id} if exists $opts{id} and defined $opts{id}; |
46
|
|
|
|
|
|
|
$params{remote_id} = $opts{remote_id} |
47
|
6
|
100
|
66
|
|
|
35
|
if exists $opts{remote_id} and defined $opts{remote_id}; |
48
|
|
|
|
|
|
|
|
49
|
6
|
|
|
|
|
70
|
my (%ret) = request_with_retries( |
50
|
|
|
|
|
|
|
logger => $logger, |
51
|
|
|
|
|
|
|
requester => $requester, |
52
|
|
|
|
|
|
|
name => 'load user', |
53
|
|
|
|
|
|
|
method => 'rest_get', |
54
|
|
|
|
|
|
|
params => [ |
55
|
|
|
|
|
|
|
[ 'customers', @with_id ], |
56
|
|
|
|
|
|
|
params => \%params, |
57
|
|
|
|
|
|
|
headers => [ |
58
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
59
|
|
|
|
|
|
|
'X-api-key' => $self->flotum->merchant_api_key |
60
|
|
|
|
|
|
|
], |
61
|
|
|
|
|
|
|
code => 200 |
62
|
|
|
|
|
|
|
] |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
5
|
|
|
|
|
32
|
my $obj = $ret{obj}; |
66
|
5
|
100
|
|
|
|
24
|
$obj = $obj->{customers}[0] if exists $obj->{customers}; |
67
|
5
|
100
|
|
|
|
40
|
die "Resource does not exists\n" unless $obj->{id}; |
68
|
4
|
|
|
|
|
73
|
return $obj; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub exec_get_customer_session { |
72
|
1
|
|
|
1
|
0
|
17
|
my ( $self, %opts ) = @_; |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
33
|
my $requester = $self->flotum->requester; |
75
|
1
|
|
|
|
|
27
|
my $logger = $self->flotum->logger; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my (%ret) = request_with_retries( |
78
|
|
|
|
|
|
|
logger => $logger, |
79
|
|
|
|
|
|
|
requester => $requester, |
80
|
|
|
|
|
|
|
name => 'get temporary user session', |
81
|
|
|
|
|
|
|
method => 'rest_post', |
82
|
|
|
|
|
|
|
params => [ |
83
|
|
|
|
|
|
|
['merchant-customer-sessions'], |
84
|
|
|
|
|
|
|
headers => [ |
85
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
86
|
|
|
|
|
|
|
'X-api-key' => $self->flotum->merchant_api_key |
87
|
|
|
|
|
|
|
], |
88
|
|
|
|
|
|
|
code => 201, |
89
|
|
|
|
|
|
|
automatic_load_item => 0, |
90
|
|
|
|
|
|
|
data => encode_json { |
91
|
|
|
|
|
|
|
merchant_customer_id => $opts{id}, |
92
|
1
|
|
|
|
|
35
|
provisional => 1, # JSON->true has the same effect |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
] |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
24
|
return $ret{obj}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
## i'm not into creathing a API::CreditCard just for this right now. |
101
|
|
|
|
|
|
|
sub exec_list_credit_cards { |
102
|
1
|
|
|
1
|
0
|
18
|
my ( $self, %opts ) = @_; |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
138
|
my $requester = $self->flotum->requester; |
105
|
1
|
|
|
|
|
42
|
my $logger = $self->flotum->logger; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my (%ret) = request_with_retries( |
108
|
|
|
|
|
|
|
logger => $logger, |
109
|
|
|
|
|
|
|
requester => $requester, |
110
|
|
|
|
|
|
|
name => 'list user credit cards', |
111
|
|
|
|
|
|
|
method => 'rest_get', |
112
|
|
|
|
|
|
|
params => [ |
113
|
1
|
|
|
|
|
35
|
[ 'customers', $opts{id}, 'credit-cards' ], |
114
|
|
|
|
|
|
|
headers => [ |
115
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
116
|
|
|
|
|
|
|
'X-api-key' => $self->flotum->merchant_api_key |
117
|
|
|
|
|
|
|
], |
118
|
|
|
|
|
|
|
code => 200 |
119
|
|
|
|
|
|
|
] |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
|
122
|
1
|
|
|
|
|
19
|
return $ret{obj}; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
## i'm not into creathing a API::CreditCard just for this right now. (2) |
126
|
|
|
|
|
|
|
sub exec_remove_credit_card { |
127
|
1
|
|
|
1
|
0
|
16
|
my ( $self, %opts ) = @_; |
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
29
|
my $requester = $self->flotum->requester; |
130
|
1
|
|
|
|
|
27
|
my $logger = $self->flotum->logger; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my (%ret) = request_with_retries( |
133
|
|
|
|
|
|
|
logger => $logger, |
134
|
|
|
|
|
|
|
requester => $requester, |
135
|
|
|
|
|
|
|
name => 'remove credit one card', |
136
|
|
|
|
|
|
|
method => 'rest_delete', |
137
|
|
|
|
|
|
|
params => [ |
138
|
1
|
|
|
|
|
19
|
[ 'customers', $opts{merchant_customer_id}, 'credit-cards', $opts{id} ], |
139
|
|
|
|
|
|
|
headers => [ |
140
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
141
|
|
|
|
|
|
|
'X-api-key' => $self->flotum->merchant_api_key |
142
|
|
|
|
|
|
|
], |
143
|
|
|
|
|
|
|
code => 204 |
144
|
|
|
|
|
|
|
] |
145
|
|
|
|
|
|
|
); |
146
|
|
|
|
|
|
|
|
147
|
1
|
|
|
|
|
16
|
return $ret{obj}; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub exec_new_charge { |
151
|
0
|
|
|
0
|
0
|
0
|
my ( $self, %args ) = @_; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
0
|
my $ret = $self->flotum->_new_charge->exec_new_charge( customer => $self ); |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
0
|
return $ret; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub exec_update_customer { |
159
|
1
|
|
|
1
|
0
|
22
|
my ( $self, %args ) = @_; |
160
|
|
|
|
|
|
|
|
161
|
1
|
|
|
|
|
4
|
my $customer = delete $args{customer}; |
162
|
1
|
50
|
|
|
|
5
|
croak "missing 'customer'" unless defined $customer; |
163
|
|
|
|
|
|
|
|
164
|
1
|
|
|
|
|
5
|
my $customer_id = $customer->id; |
165
|
|
|
|
|
|
|
|
166
|
1
|
|
|
|
|
22
|
my %ret = request_with_retries( |
167
|
|
|
|
|
|
|
logger => $self->flotum->logger, |
168
|
|
|
|
|
|
|
requester => $self->flotum->requester, |
169
|
|
|
|
|
|
|
name => 'update customer', |
170
|
|
|
|
|
|
|
method => 'rest_put', |
171
|
|
|
|
|
|
|
params => [ |
172
|
|
|
|
|
|
|
join( "/", 'customers', $customer_id ), |
173
|
|
|
|
|
|
|
headers => [ |
174
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
175
|
|
|
|
|
|
|
'X-api-key' => $self->flotum->merchant_api_key, |
176
|
|
|
|
|
|
|
], |
177
|
|
|
|
|
|
|
code => 202, |
178
|
|
|
|
|
|
|
data => encode_json( {%args} ) |
179
|
|
|
|
|
|
|
] |
180
|
|
|
|
|
|
|
); |
181
|
|
|
|
|
|
|
|
182
|
1
|
50
|
|
|
|
12
|
if (%ret) { |
183
|
1
|
|
|
|
|
19
|
return $ret{obj}; |
184
|
|
|
|
|
|
|
} |
185
|
0
|
|
|
|
|
|
return; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
1; |