line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Flotum::API::Customer; |
2
|
4
|
|
|
4
|
|
13
|
use common::sense; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
26
|
|
3
|
4
|
|
|
4
|
|
180
|
use Moo; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
20
|
|
4
|
4
|
|
|
4
|
|
843
|
use namespace::clean; |
|
4
|
|
|
|
|
18
|
|
|
4
|
|
|
|
|
23
|
|
5
|
4
|
|
|
4
|
|
762
|
use Carp; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
188
|
|
6
|
4
|
|
|
4
|
|
13
|
use JSON::MaybeXS; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
174
|
|
7
|
4
|
|
|
4
|
|
1420
|
use Net::Flotum::Object::Charge; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
138
|
|
8
|
4
|
|
|
4
|
|
25
|
use Net::Flotum::API::ExceptionHandler; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
3092
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'flotum' => ( is => 'ro', weak_ref => 1 ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub exec_new_customer { |
13
|
2
|
|
|
2
|
0
|
1580
|
my ( $self, %opts ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
48
|
my $requester = $self->flotum->requester; |
16
|
2
|
|
|
|
|
1688
|
my $logger = $self->flotum->logger; |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
3601
|
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
|
|
|
|
|
56
|
return $ret{obj}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub exec_load_customer { |
39
|
6
|
|
|
6
|
0
|
782
|
my ( $self, %opts ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
6
|
|
|
|
|
131
|
my $requester = $self->flotum->requester; |
42
|
6
|
|
|
|
|
917
|
my $logger = $self->flotum->logger; |
43
|
|
|
|
|
|
|
|
44
|
6
|
|
|
|
|
1872
|
my ( @with_id, %params ); |
45
|
6
|
100
|
66
|
|
|
41
|
push @with_id, $opts{id} if exists $opts{id} and defined $opts{id}; |
46
|
|
|
|
|
|
|
$params{remote_id} = $opts{remote_id} |
47
|
6
|
100
|
66
|
|
|
28
|
if exists $opts{remote_id} and defined $opts{remote_id}; |
48
|
|
|
|
|
|
|
|
49
|
6
|
|
|
|
|
85
|
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
|
|
|
|
|
27
|
my $obj = $ret{obj}; |
66
|
5
|
100
|
|
|
|
21
|
$obj = $obj->{customers}[0] if exists $obj->{customers}; |
67
|
5
|
100
|
|
|
|
41
|
die "Resource does not exists\n" unless $obj->{id}; |
68
|
4
|
|
|
|
|
68
|
return $obj; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub exec_get_customer_session { |
72
|
1
|
|
|
1
|
0
|
12
|
my ( $self, %opts ) = @_; |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
19
|
my $requester = $self->flotum->requester; |
75
|
1
|
|
|
|
|
20
|
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
|
|
|
|
|
37
|
provisional => 1, # JSON->true has the same effect |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
] |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
20
|
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
|
13
|
my ( $self, %opts ) = @_; |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
20
|
my $requester = $self->flotum->requester; |
105
|
1
|
|
|
|
|
20
|
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
|
|
|
|
|
19
|
[ '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
|
|
|
|
|
15
|
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
|
11
|
my ( $self, %opts ) = @_; |
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
20
|
my $requester = $self->flotum->requester; |
130
|
1
|
|
|
|
|
35
|
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
|
|
|
|
|
23
|
[ '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
|
|
|
|
|
19
|
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
|
15
|
my ( $self, %args ) = @_; |
160
|
|
|
|
|
|
|
|
161
|
1
|
|
|
|
|
3
|
my $customer = delete $args{customer}; |
162
|
1
|
50
|
|
|
|
6
|
croak "missing 'customer'" unless defined $customer; |
163
|
|
|
|
|
|
|
|
164
|
1
|
|
|
|
|
4
|
my $customer_id = $customer->id; |
165
|
|
|
|
|
|
|
|
166
|
1
|
|
|
|
|
20
|
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
|
|
|
|
15
|
if (%ret) { |
183
|
1
|
|
|
|
|
22
|
return $ret{obj}; |
184
|
|
|
|
|
|
|
} |
185
|
0
|
|
|
|
|
|
return; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
1; |