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