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