« lib/WebService/Braintree/Role/MakeRequest.pm
↑ Summary
lib/WebService/Braintree/_/Transaction.pm »
| 1 | # vim: sw=4 ts=4 ft=perl | ||||||||||
| 2 | |||||||||||
| 3 | package # hide from pause | ||||||||||
| 4 | WebService::Braintree::TransparentRedirect::QueryString; | ||||||||||
| 5 | |||||||||||
| 6 | 22 | ▶ | use 5.010_001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 22 | ▶ | use strictures 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 22 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 22 | ▶ | use WebService::Braintree::Digest qw(hexdigest); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 22 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 22 | ▶ | use Carp qw(confess); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 0 | ▶ | has 'config' => ( is => 'rw', default => sub { WebService::Braintree->configuration}); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 15 | |||||||||||
| 16 | 12 | ▶ | sub validate { | ||||||||
|
Subroutine
validate: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 17 | 12 | my($self, $query_string) = @_; | |||||||||
| 18 | 12 | $self->check_http_status($query_string); | |||||||||
| 19 | 5 | ▶ | confess "ForgedQueryString" if $self->hash_is_forged($query_string); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 2 | return 1; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 13 | ▶ | sub parse { | ||||||||
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | 13 | my ($self, $query_string) = @_; | |||||||||
| 25 | 13 | my $uri = URI->new; | |||||||||
| 26 | 13 | $uri->query($query_string); | |||||||||
| 27 | 13 | return { $uri->query_form}; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 5 | ▶ | sub hash_is_forged { | ||||||||
|
Subroutine
hash_is_forged: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 31 | 5 | my ($self, $query_string) = @_; | |||||||||
| 32 | 5 | ▶ | if ($query_string =~ /(.*)(&|;)hash=(.*)/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 3 | my $query_string_without_hash = $1; | |||||||||
| 34 | 3 | my $hash = $3; | |||||||||
| 35 | 3 | return $hash ne hexdigest($self->config->private_key, $query_string_without_hash); | |||||||||
| 36 | } | ||||||||||
| 37 | 2 | return 1; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 12 | ▶ | sub check_http_status { | ||||||||
|
Subroutine
check_http_status: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||
| 41 | 12 | my($self, $query_string) = @_; | |||||||||
| 42 | 12 | my $params = $self->parse($query_string); | |||||||||
| 43 | 12 | ▶ | confess "UnexpectedError: expected query string to have an http_status param" unless $params->{'http_status'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 11 | ▶ | confess "AuthenticationError" if $params->{'http_status'} eq '401'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 10 | ▶ | confess "AuthorizationError" if $params->{'http_status'} eq '403'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 8 | ▶ | confess "ServerError" if $params->{'http_status'} eq '500'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 7 | ▶ | confess "DownForMaintenance" if $params->{'http_status'} eq '503'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 6 | ▶ | confess "UnexpectedError" if $params->{'http_status'} ne '200'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 22 | __PACKAGE__->meta->make_immutable; | |||||||||
| 52 | |||||||||||
| 53 | 22 | 1; | |||||||||
| 54 | __END__ | ||||||||||