| 1 | package PagSeguro::API::Checkout; | ||||||||||||||||||||||
| 2 | 6 | ▶ | use base 'PagSeguro::API::Base'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 3 | |||||||||||||||||||||||
| 4 | 6 | ▶ | use XML::Simple; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | # constructor | ||||||||||||||||||||||
| 7 | sub new { | ||||||||||||||||||||||
| 8 | 2 | ▶ | my $class = shift; | ||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||
| 9 | 2 | ▶ | my %args = @_ if ( @_ % 2 ) == 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 10 | |||||||||||||||||||||||
| 11 | return bless { | ||||||||||||||||||||||
| 12 | email => $args{email} || undef, | ||||||||||||||||||||||
| 13 | token => $args{token} || undef, | ||||||||||||||||||||||
| 14 | |||||||||||||||||||||||
| 15 | 2 | ▶ | _code => undef, | ||||||||||||||||||||
|
Condition50%2/4
$args{'email'} || undef
$args{'token'} || undef
MC/DC0%0/1
$args{'email'} || undef
$args{'email'}
MC/DC0%0/1
$args{'token'} || undef
$args{'token'}
Truth table50%1/2
A
A= $args{'email'}
Truth table50%1/2
A
A= $args{'token'}
| |||||||||||||||||||||||
| 16 | _transaction => undef, | ||||||||||||||||||||||
| 17 | }, $class; | ||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | # accessors | ||||||||||||||||||||||
| 21 | sub code { | ||||||||||||||||||||||
| 22 | 0 | ▶ | return $_[0]->{_code} if $_[0]->{_code}; | ||||||||||||||||||||
|
Subroutine
code: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||
| 24 | |||||||||||||||||||||||
| 25 | # methods | ||||||||||||||||||||||
| 26 | sub send { | ||||||||||||||||||||||
| 27 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
send: called CC=10 SCAR=40.4
Pod
undocumented
| |||||||||||||||||||||||
| 28 | 1 | ▶ | my %args = ( @_ % 2 ) == 0 ? @_ : undef; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 29 | |||||||||||||||||||||||
| 30 | 1 | $self->{_code} = undef; | |||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | 1 | ▶ | if ( scalar(%args) ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 33 | |||||||||||||||||||||||
| 34 | # parse and return by file | ||||||||||||||||||||||
| 35 | 1 | ▶ | return XMLin( $args{file} ) if $args{file}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 36 | |||||||||||||||||||||||
| 37 | # default parameters that you dont have to pass | ||||||||||||||||||||||
| 38 | 0 | ▶ | $args{email} = $args{email} || $self->{email}; | ||||||||||||||||||||
|
Condition0%0/3
$args{'email'} || $self->{'email'}
MC/DC0%0/2
$args{'email'} || $self->{'email'}
$args{'email'}
$self->{'email'}
Truth table0%0/3
A || B
A= $args{'email'}B= $self->{'email'}
| |||||||||||||||||||||||
| 39 | 0 | ▶ | $args{token} = $args{token} || $self->{token}; | ||||||||||||||||||||
|
Condition0%0/3
$args{'token'} || $self->{'token'}
MC/DC0%0/2
$args{'token'} || $self->{'token'}
$args{'token'}
$self->{'token'}
Truth table0%0/3
A || B
A= $args{'token'}B= $self->{'token'}
| |||||||||||||||||||||||
| 40 | 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'}
| |||||||||||||||||||||||
| 41 | 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'}
| |||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | 0 | my $uri = $self->_checkout_uri( \%args ); | |||||||||||||||||||||
| 44 | 0 | my $response = $self->post( $uri, \%args ); | |||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | # debug | ||||||||||||||||||||||
| 47 | warn "[Debug] Checkout Response: $response\n" | ||||||||||||||||||||||
| 48 | 0 | ▶ | if $ENV{PAGSEGURO_API_DEBUG}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | 0 | my $xml = XMLin($response); | |||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | # save code for payment url | ||||||||||||||||||||||
| 53 | 0 | ▶ | $self->{_code} = $xml->{code} if $xml->{code}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 54 | |||||||||||||||||||||||
| 55 | 0 | return $xml; | |||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||||
| 58 | # error | ||||||||||||||||||||||
| 59 | 0 | die "Error: invalid paramether bound"; | |||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||
| 62 | |||||||||||||||||||||||
| 63 | sub payment_url { | ||||||||||||||||||||||
| 64 | 0 | ▶ | my ($self, $code) = @_; | ||||||||||||||||||||
|
Subroutine
payment_url: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||
| 65 | |||||||||||||||||||||||
| 66 | 0 | ▶ | $code = $self->code unless $code; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 67 | |||||||||||||||||||||||
| 68 | my $uri = join '', | ||||||||||||||||||||||
| 69 | ( | ||||||||||||||||||||||
| 70 | $self->resource( | ||||||||||||||||||||||
| 71 | 0 | ▶ | ( $ENV{PAGSEGURO_API_SANDBOX} ? 'SANDBOX_CHECKOUT_PAYMENT' : 'CHECKOUT_PAYMENT' ) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 72 | ), | ||||||||||||||||||||||
| 73 | "?code=", | ||||||||||||||||||||||
| 74 | $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->{email}; | ||||||||||||||||||||
|
Condition33%1/3
$args->{'email'} || $self->{'email'}
MC/DC0%0/2
$args->{'email'} || $self->{'email'}
$args->{'email'}
$self->{'email'}
Truth table33%1/3
A || B
A= $args->{'email'}B= $self->{'email'}
| |||||||||||||||||||||||
| 86 | 1 | ▶ | $args->{token} = $args->{token} || $self->{token}; | ||||||||||||||||||||
|
Condition33%1/3
$args->{'token'} || $self->{'token'}
MC/DC0%0/2
$args->{'token'} || $self->{'token'}
$args->{'token'}
$self->{'token'}
Truth table33%1/3
A || B
A= $args->{'token'}B= $self->{'token'}
| |||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | # build query string | ||||||||||||||||||||||
| 89 | 1 | my $query_string = join '&', map { "$_=$args->{$_}" } keys %$args; | |||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | my $uri = join '', | ||||||||||||||||||||||
| 92 | ( | ||||||||||||||||||||||
| 93 | $self->resource( | ||||||||||||||||||||||
| 94 | 1 | ▶ | ( $ENV{PAGSEGURO_API_SANDBOX} ? 'SANDBOX_URI' : 'BASE_URI' ) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 95 | ), | ||||||||||||||||||||||
| 96 | $self->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; | |||||||||||||||||||||