line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Flotum::API::Charge; |
2
|
4
|
|
|
4
|
|
1448
|
use common::sense; |
|
4
|
|
|
|
|
38
|
|
|
4
|
|
|
|
|
25
|
|
3
|
4
|
|
|
4
|
|
210
|
use Moo; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
28
|
|
4
|
4
|
|
|
4
|
|
1187
|
use namespace::clean; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
29
|
|
5
|
4
|
|
|
4
|
|
2700
|
use MooX::late; |
|
4
|
|
|
|
|
87725
|
|
|
4
|
|
|
|
|
26
|
|
6
|
4
|
|
|
4
|
|
638
|
use Carp; |
|
4
|
|
|
|
|
21
|
|
|
4
|
|
|
|
|
248
|
|
7
|
4
|
|
|
4
|
|
40
|
use JSON::MaybeXS; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
212
|
|
8
|
4
|
|
|
4
|
|
1919
|
use Net::Flotum::API::ExceptionHandler; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
3390
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has flotum => ( |
11
|
|
|
|
|
|
|
is => "ro", |
12
|
|
|
|
|
|
|
weak_ref => 1, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub exec_new_charge { |
16
|
1
|
|
|
1
|
0
|
1344
|
my ( $self, %args ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
4
|
my $customer = delete $args{customer}; |
19
|
1
|
50
|
|
|
|
5
|
croak "missing 'customer'" unless defined $customer; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
5
|
my $customer_id = $customer->id; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
25
|
my %ret = request_with_retries( |
24
|
|
|
|
|
|
|
logger => $self->flotum->logger, |
25
|
|
|
|
|
|
|
requester => $self->flotum->requester, |
26
|
|
|
|
|
|
|
name => 'new charge', |
27
|
|
|
|
|
|
|
method => 'rest_post', |
28
|
|
|
|
|
|
|
params => [ |
29
|
|
|
|
|
|
|
join( "/", 'customers', $customer_id, 'charges' ), |
30
|
|
|
|
|
|
|
headers => [ |
31
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
32
|
|
|
|
|
|
|
'X-api-key' => $self->flotum->merchant_api_key, |
33
|
|
|
|
|
|
|
], |
34
|
|
|
|
|
|
|
code => 201, |
35
|
|
|
|
|
|
|
data => encode_json( {%args} ) |
36
|
|
|
|
|
|
|
] |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
1
|
50
|
|
|
|
11
|
if (%ret) { |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return Net::Flotum::Object::Charge->new( |
42
|
|
|
|
|
|
|
flotum => $self->flotum, |
43
|
|
|
|
|
|
|
customer => $customer, |
44
|
|
|
|
|
|
|
id => $ret{obj}{id} |
45
|
1
|
|
|
|
|
21
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
0
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub exec_payment_charge { |
52
|
1
|
|
|
1
|
0
|
19
|
my ( $self, %args ) = @_; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Required args. |
55
|
1
|
|
|
|
|
4
|
for (qw(charge)) { |
56
|
1
|
50
|
|
|
|
6
|
croak "missing '$_'" unless defined $args{$_}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
3
|
my $charge = delete $args{charge}; |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
22
|
my $customer_id = $charge->customer->id; |
62
|
1
|
|
|
|
|
33
|
my $charge_id = $charge->id; |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
25
|
my %ret = request_with_retries( |
65
|
|
|
|
|
|
|
logger => $self->flotum->logger, |
66
|
|
|
|
|
|
|
requester => $self->flotum->requester, |
67
|
|
|
|
|
|
|
name => 'payment charge', |
68
|
|
|
|
|
|
|
method => 'rest_post', |
69
|
|
|
|
|
|
|
params => [ |
70
|
|
|
|
|
|
|
join( "/", 'customers', $customer_id, 'charges', $charge_id, 'payment' ), |
71
|
|
|
|
|
|
|
headers => [ |
72
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
73
|
|
|
|
|
|
|
'X-api-key' => $self->flotum->merchant_api_key, |
74
|
|
|
|
|
|
|
], |
75
|
|
|
|
|
|
|
code => 202, |
76
|
|
|
|
|
|
|
data => encode_json( \%args ) |
77
|
|
|
|
|
|
|
] |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
1
|
50
|
|
|
|
10
|
if (%ret) { |
81
|
1
|
|
|
|
|
24
|
return $ret{obj}; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
0
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub exec_capture_charge { |
87
|
1
|
|
|
1
|
0
|
22
|
my ( $self, %args ) = @_; |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
5
|
my $charge = delete $args{charge}; |
90
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
20
|
my $customer_id = $charge->customer->id; |
92
|
1
|
|
|
|
|
29
|
my $charge_id = $charge->id; |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
26
|
my %ret = request_with_retries( |
95
|
|
|
|
|
|
|
logger => $self->flotum->logger, |
96
|
|
|
|
|
|
|
requester => $self->flotum->requester, |
97
|
|
|
|
|
|
|
name => 'capture charge', |
98
|
|
|
|
|
|
|
method => 'rest_post', |
99
|
|
|
|
|
|
|
params => [ |
100
|
|
|
|
|
|
|
join( "/", 'customers', $customer_id, 'charges', $charge_id, 'capture' ), |
101
|
|
|
|
|
|
|
headers => [ |
102
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
103
|
|
|
|
|
|
|
'X-api-key' => $self->flotum->merchant_api_key, |
104
|
|
|
|
|
|
|
], |
105
|
|
|
|
|
|
|
code => 202, |
106
|
|
|
|
|
|
|
data => encode_json( \%args ) |
107
|
|
|
|
|
|
|
] |
108
|
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
|
110
|
1
|
50
|
|
|
|
10
|
if (%ret) { |
111
|
1
|
|
|
|
|
15
|
return $ret{obj}; |
112
|
|
|
|
|
|
|
} |
113
|
0
|
|
|
|
|
0
|
return; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub exec_refund_charge { |
117
|
1
|
|
|
1
|
0
|
13
|
my ( $self, %args ) = @_; |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
3
|
my $charge = delete $args{charge}; |
120
|
|
|
|
|
|
|
|
121
|
1
|
|
|
|
|
19
|
my $customer_id = $charge->customer->id; |
122
|
1
|
|
|
|
|
24
|
my $charge_id = $charge->id; |
123
|
|
|
|
|
|
|
|
124
|
1
|
|
|
|
|
24
|
my %ret = request_with_retries( |
125
|
|
|
|
|
|
|
logger => $self->flotum->logger, |
126
|
|
|
|
|
|
|
requester => $self->flotum->requester, |
127
|
|
|
|
|
|
|
name => 'refund charge', |
128
|
|
|
|
|
|
|
method => 'rest_post', |
129
|
|
|
|
|
|
|
params => [ |
130
|
|
|
|
|
|
|
join( "/", 'customers', $customer_id, 'charges', $charge_id, 'refund' ), |
131
|
|
|
|
|
|
|
headers => [ |
132
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
133
|
|
|
|
|
|
|
'X-api-key' => $self->flotum->merchant_api_key, |
134
|
|
|
|
|
|
|
], |
135
|
|
|
|
|
|
|
code => 202, |
136
|
|
|
|
|
|
|
data => '{}' |
137
|
|
|
|
|
|
|
] |
138
|
|
|
|
|
|
|
); |
139
|
|
|
|
|
|
|
|
140
|
1
|
50
|
|
|
|
8
|
if (%ret) { |
141
|
1
|
|
|
|
|
20
|
return $ret{obj}; |
142
|
|
|
|
|
|
|
} |
143
|
0
|
|
|
|
|
|
return; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |