line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Flotum::API::Charge; |
2
|
4
|
|
|
4
|
|
17
|
use common::sense; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
27
|
|
3
|
4
|
|
|
4
|
|
181
|
use Moo; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
24
|
|
4
|
4
|
|
|
4
|
|
869
|
use namespace::clean; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
20
|
|
5
|
4
|
|
|
4
|
|
2218
|
use MooX::late; |
|
4
|
|
|
|
|
68562
|
|
|
4
|
|
|
|
|
22
|
|
6
|
4
|
|
|
4
|
|
442
|
use Carp; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
225
|
|
7
|
4
|
|
|
4
|
|
1599
|
use JSON::MaybeXS; |
|
4
|
|
|
|
|
2725
|
|
|
4
|
|
|
|
|
224
|
|
8
|
4
|
|
|
4
|
|
1514
|
use Net::Flotum::API::ExceptionHandler; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
2421
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has flotum => ( |
11
|
|
|
|
|
|
|
is => "ro", |
12
|
|
|
|
|
|
|
weak_ref => 1, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub exec_new_charge { |
16
|
1
|
|
|
1
|
0
|
1526
|
my ( $self, %args ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
4
|
my $customer = delete $args{customer}; |
19
|
1
|
50
|
|
|
|
9
|
croak "missing 'customer'" unless defined $customer; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
5
|
my $customer_id = $customer->id; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
35
|
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
|
|
|
|
15
|
if (%ret) { |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return Net::Flotum::Object::Charge->new( |
42
|
|
|
|
|
|
|
flotum => $self->flotum, |
43
|
|
|
|
|
|
|
customer => $customer, |
44
|
|
|
|
|
|
|
id => $ret{obj}{id} |
45
|
1
|
|
|
|
|
28
|
); |
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
|
|
|
|
|
3
|
for (qw(charge)) { |
56
|
1
|
50
|
|
|
|
8
|
croak "missing '$_'" unless defined $args{$_}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
6
|
my $charge = delete $args{charge}; |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
30
|
my $customer_id = $charge->customer->id; |
62
|
1
|
|
|
|
|
33
|
my $charge_id = $charge->id; |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
33
|
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
|
|
|
|
|
31
|
return $ret{obj}; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
0
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub exec_capture_charge { |
87
|
2
|
|
|
2
|
0
|
51
|
my ( $self, %args ) = @_; |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
|
|
|
42
|
my $charge = delete $args{charge}; |
90
|
|
|
|
|
|
|
|
91
|
2
|
|
|
|
|
63
|
my $customer_id = $charge->customer->id; |
92
|
2
|
|
|
|
|
76
|
my $charge_id = $charge->id; |
93
|
|
|
|
|
|
|
|
94
|
2
|
|
|
|
|
69
|
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
|
|
|
|
6
|
if (%ret) { |
111
|
1
|
|
|
|
|
15
|
return $ret{obj}; |
112
|
|
|
|
|
|
|
} |
113
|
0
|
|
|
|
|
0
|
return; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub exec_refund_charge { |
117
|
1
|
|
|
1
|
0
|
16
|
my ( $self, %args ) = @_; |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
4
|
my $charge = delete $args{charge}; |
120
|
|
|
|
|
|
|
|
121
|
1
|
|
|
|
|
25
|
my $customer_id = $charge->customer->id; |
122
|
1
|
|
|
|
|
22
|
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
|
|
|
|
6
|
if (%ret) { |
141
|
1
|
|
|
|
|
20
|
return $ret{obj}; |
142
|
|
|
|
|
|
|
} |
143
|
0
|
|
|
|
|
|
return; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |