| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Braintree::HTTP; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
515
|
use HTTP::Request; |
|
|
1
|
|
|
|
|
24143
|
|
|
|
1
|
|
|
|
|
36
|
|
|
4
|
1
|
|
|
1
|
|
2829
|
use LWP::UserAgent; |
|
|
1
|
|
|
|
|
29055
|
|
|
|
1
|
|
|
|
|
38
|
|
|
5
|
1
|
|
|
1
|
|
467
|
use Net::Braintree::Xml; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moose; |
|
7
|
|
|
|
|
|
|
use Carp qw(confess); |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'config' => (is => 'ro', default => sub { Net::Braintree->configuration }); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub post { |
|
12
|
|
|
|
|
|
|
my ($self, $path, $params) = @_; |
|
13
|
|
|
|
|
|
|
$self -> make_request($path, $params, 'POST'); |
|
14
|
|
|
|
|
|
|
} |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub put { |
|
17
|
|
|
|
|
|
|
my ($self, $path, $params) = @_; |
|
18
|
|
|
|
|
|
|
$self -> make_request($path, $params, 'PUT'); |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub get { |
|
22
|
|
|
|
|
|
|
my ($self, $path, $params) = @_; |
|
23
|
|
|
|
|
|
|
$self -> make_request($path, $params, 'GET'); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub delete { |
|
27
|
|
|
|
|
|
|
my ($self, $path, $params) = @_; |
|
28
|
|
|
|
|
|
|
$self -> make_request($path, undef, 'DELETE'); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub make_request { |
|
32
|
|
|
|
|
|
|
my ($self, $path, $params, $verb) = @_; |
|
33
|
|
|
|
|
|
|
my $request = HTTP::Request->new($verb => $self->config->base_merchant_url . $path); |
|
34
|
|
|
|
|
|
|
$request->headers->authorization_basic($self->config->public_key, $self->config->private_key); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
if ($params) { |
|
37
|
|
|
|
|
|
|
$request->content(hash_to_xml($params)); |
|
38
|
|
|
|
|
|
|
$request->content_type("text/xml; charset=utf-8"); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$request->header("X-ApiVersion" => $self->config->api_version); |
|
42
|
|
|
|
|
|
|
$request->header("environment" => $self->config->environment); |
|
43
|
|
|
|
|
|
|
$request->header("User-Agent" => "Braintree Perl Module " . Net::Braintree->VERSION); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $agent = LWP::UserAgent->new; |
|
46
|
|
|
|
|
|
|
my $response = $agent->request($request); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$self->check_response_code($response->code); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
if($response->header('Content-Length') > 1) { |
|
51
|
|
|
|
|
|
|
return xml_to_hash($response->content); |
|
52
|
|
|
|
|
|
|
} else { |
|
53
|
|
|
|
|
|
|
return {http_status => $response->code}; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub check_response_code { |
|
58
|
|
|
|
|
|
|
my ($self, $code) = @_; |
|
59
|
|
|
|
|
|
|
confess "NotFoundError" if $code eq '404'; |
|
60
|
|
|
|
|
|
|
confess "AuthenticationError" if $code eq '401'; |
|
61
|
|
|
|
|
|
|
confess "AuthorizationError" if $code eq '403'; |
|
62
|
|
|
|
|
|
|
confess "ServerError" if $code eq '500'; |
|
63
|
|
|
|
|
|
|
confess "DownForMaintenance" if $code eq '503'; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |