| 1 | package PagSeguro::API::Checkout; | ||||||||||||||||||||
| 2 | 6 | ▶ | use base 'PagSeguro::API::Base'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 6 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 6 | ▶ | use Try::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 6 | ▶ | use XML::Simple; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | # constructor | ||||||||||||||||||||
| 9 | sub new { | ||||||||||||||||||||
| 10 | 3 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||||||||||
| 11 | 3 | ▶ | my $args = (@_ % 2 == 0)? {@_} : shift; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | return bless { | ||||||||||||||||||||
| 14 | _code => undef, | ||||||||||||||||||||
| 15 | 3 | ▶ | _context => ($args->{context})? $args->{context} : $args, | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 16 | _transaction => undef, | ||||||||||||||||||||
| 17 | }, $class; | ||||||||||||||||||||
| 18 | } | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | # accessors | ||||||||||||||||||||
| 21 | sub _context { | ||||||||||||||||||||
| 22 | 4 | ▶ | return $_[0]->{_context} if $_[0]->{_context}; | ||||||||||||||||||
|
Subroutine
_context: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | sub code { | ||||||||||||||||||||
| 25 | 0 | ▶ | return $_[0]->{_code} if $_[0]->{_code}; | ||||||||||||||||||
|
Subroutine
code: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | # methods | ||||||||||||||||||||
| 29 | sub send { | ||||||||||||||||||||
| 30 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
send: called CC=8 SCAR=35.0
Pod
undocumented
| |||||||||||||||||||||
| 31 | 1 | ▶ | my $args = (@_ % 2 == 0) ? {@_} : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 1 | $self->{_code} = undef; | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 1 | ▶ | if ($args) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | # parse and return by file | ||||||||||||||||||||
| 38 | 1 | ▶ | return XMLin( $args->{file} ) if $args->{file}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | $args->{email} = $self->_context->email; | |||||||||||||||||||
| 41 | 0 | $args->{token} = $self->_context->token; | |||||||||||||||||||
| 42 | 0 | ▶ | $args->{currency} = $args->{currency} || 'BRL'; | ||||||||||||||||||
|
Condition0%0/2
$args->{'currency'} || 'BRL'
MC/DC0%0/1
$args->{'currency'} || 'BRL'
$args->{'currency'}
Truth table0%0/2
A
A= $args->{'currency'}
| |||||||||||||||||||||
| 43 | 0 | ▶ | $args->{shippingType} = $args->{shippingType} || '3'; | ||||||||||||||||||
|
Condition0%0/2
$args->{'shippingType'} || '3'
MC/DC0%0/1
$args->{'shippingType'} || '3'
$args->{'shippingType'}
Truth table0%0/2
A
A= $args->{'shippingType'}
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | # getting response | ||||||||||||||||||||
| 46 | 0 | my $uri = $self->_checkout_uri( $args ); | |||||||||||||||||||
| 47 | 0 | my $response = $self->post( $uri, $args ); | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | # debug | ||||||||||||||||||||
| 50 | warn "[Debug] Checkout Response: $response\n" | ||||||||||||||||||||
| 51 | 0 | ▶ | if $ENV{PAGSEGURO_API_DEBUG}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | my $xml = XMLin($response); | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | ▶ | $self->{_code} = $xml->{code} if $xml->{code}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 0 | return $xml; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||
| 59 | # error | ||||||||||||||||||||
| 60 | 0 | croak "Error: invalid paramether bound"; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | sub payment_url { | ||||||||||||||||||||
| 65 | 0 | ▶ | my ($self, $code) = @_; | ||||||||||||||||||
|
Subroutine
payment_url: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 0 | ▶ | $code = $self->code unless $code; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | my $uri = join '', | ||||||||||||||||||||
| 70 | ( | ||||||||||||||||||||
| 71 | $self->_context->resource($ENV{PAGSEGURO_API_SANDBOX} | ||||||||||||||||||||
| 72 | 0 | ▶ | ? 'SANDBOX_CHECKOUT_PAYMENT' | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | : 'CHECKOUT_PAYMENT'), | ||||||||||||||||||||
| 74 | "?code=", $code | ||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 0 | ▶ | warn "[Debug] URI: $uri\n" if $ENV{PAGSEGURO_API_DEBUG}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | 0 | return $uri; | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | sub _checkout_uri { | ||||||||||||||||||||
| 82 | 1 | ▶ | my ( $self, $args ) = @_; | ||||||||||||||||||
|
Subroutine
_checkout_uri: called CC=5 SCAR=17.8
| |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | # add email and token | ||||||||||||||||||||
| 85 | 1 | ▶ | $args->{email} = $args->{email} || $self->_context->email; | ||||||||||||||||||
|
Condition33%1/3
$args->{'email'} || $self->_context->email
MC/DC0%0/2
$args->{'email'} || $self->_context->email
$args->{'email'}
$self->_context->email
Truth table33%1/3
A || B
A= $args->{'email'}B= $self->_context->email
| |||||||||||||||||||||
| 86 | 1 | ▶ | $args->{token} = $args->{token} || $self->_context->token; | ||||||||||||||||||
|
Condition33%1/3
$args->{'token'} || $self->_context->token
MC/DC0%0/2
$args->{'token'} || $self->_context->token
$args->{'token'}
$self->_context->token
Truth table33%1/3
A || B
A= $args->{'token'}B= $self->_context->token
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | # build query string | ||||||||||||||||||||
| 89 | 1 | my $query_string = join '&', map { "$_=$args->{$_}" } keys %$args; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | my $uri = join '', | ||||||||||||||||||||
| 92 | ( | ||||||||||||||||||||
| 93 | $self->_context->resource( | ||||||||||||||||||||
| 94 | 1 | ▶ | ( $ENV{PAGSEGURO_API_SANDBOX} ? 'SANDBOX_URI' : 'BASE_URI' ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | ), | ||||||||||||||||||||
| 96 | $self->_context->resource('CHECKOUT'), | ||||||||||||||||||||
| 97 | "?", | ||||||||||||||||||||
| 98 | $query_string | ||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 1 | ▶ | warn "[Debug] URI: $uri\n" if $ENV{PAGSEGURO_API_DEBUG}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | 1 | return $uri; | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 6 | 1; | |||||||||||||||||||