| 1 | package PagSeguro::API::Payment; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 3 | extends 'PagSeguro::API::Base'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use PagSeguro::API::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use PagSeguro::API::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use PagSeguro::API::Payment::Sender; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # attributes | ||||||||||||||||||||||||||||
| 11 | 3 | has reference => (is => 'rw'); | |||||||||||||||||||||||||||
| 12 | 3 | has redirect_url => (is => 'rw'); | |||||||||||||||||||||||||||
| 13 | 3 | has notification_url => (is => 'rw'); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # sender | ||||||||||||||||||||||||||||
| 16 | 5 | ▶ | has sender => (is => 'rw', default => sub{ PagSeguro::API::Payment::Sender->new }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # item list | ||||||||||||||||||||||||||||
| 19 | 5 | ▶ | has items => (is => 'rw', default => sub { [] }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # methods | ||||||||||||||||||||||||||||
| 23 | 1 | ▶ | sub item { | ||||||||||||||||||||||||||
|
Subroutine
item: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 1 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 25 | 1 | ▶ | do{ return $_ if $_->{id} eq $id } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 1 | for @{$self->items}; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | sub add_item { | ||||||||||||||||||||||||||
|
Subroutine
add_item: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 31 | 2 | ▶ | my $args = (@_ % 2 == 0)? {@_} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # required | ||||||||||||||||||||||||||||
| 34 | 2 | ▶ | $args->{quantity} = 1 unless $args->{quantity}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 2 | push @{$self->items}, $args; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | ▶ | sub request { | ||||||||||||||||||||||||||
|
Subroutine
request: called CC=3 SCAR=13.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # build http post params | ||||||||||||||||||||||||||||
| 43 | 1 | my $params = $self->_build_params; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | my $req = PagSeguro::API::Request->new; | |||||||||||||||||||||||||||
| 46 | 1 | my $res = $req->post( | |||||||||||||||||||||||||||
| 47 | url => $self->api_uri . '/checkout/', | ||||||||||||||||||||||||||||
| 48 | params => $params | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # parse response | ||||||||||||||||||||||||||||
| 52 | 1 | ▶ | if($res && !$res->error){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$res and not $res->error
MC/DC0%0/2
$res and not $res->error
$res
not $res->error
Truth table33%1/3
A and not(B)
A= $resB= not $res->error
| |||||||||||||||||||||||||||||
| 53 | 0 | my $data = $res->data; | |||||||||||||||||||||||||||
| 54 | 0 | my $result = $self->_parse_request($data); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | $res->data($result); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | return $res; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub request_form { | ||||||||||||||||||||||||||
|
Subroutine
request_form: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $args = (@_ % 2 == 0)? {@_} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # default button | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my $btn_name = delete $args->{text} || 'Checkout'; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args->{'text'} || 'Checkout'
MC/DC0%0/1
delete $args->{'text'} || 'Checkout'
delete $args->{'text'}
Truth table0%0/2
A
A= delete $args->{'text'}
| |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | $args->{type} = 'submit' unless $args->{type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # build http post params | ||||||||||||||||||||||||||||
| 72 | 0 | my $params = $self->_build_params; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # remove sensitive data | ||||||||||||||||||||||||||||
| 75 | 0 | delete $params->{token}; | |||||||||||||||||||||||||||
| 76 | 0 | delete $params->{email}; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | my $base_uri = $self->base_uri; | |||||||||||||||||||||||||||
| 80 | 0 | my $html = qq{<form method="post" target="pagseguro" action="$base_uri/v2/checkout/payment.html">\n}; | |||||||||||||||||||||||||||
| 81 | $html .= qq{<input type="hidden" name="$_" value="$params->{$_}" /> \n} | ||||||||||||||||||||||||||||
| 82 | 0 | for keys %$params; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | my $btn_params = join ' ', map { "$_=\"$args->{$_}\"" } keys %$args; | |||||||||||||||||||||||||||
| 85 | 0 | $html .= qq{<button $btn_params>$btn_name</button>\n}; | |||||||||||||||||||||||||||
| 86 | 0 | $html .= qq{</form>}; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | return $html; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1 | ▶ | sub _build_params { | ||||||||||||||||||||||||||
|
Subroutine
_build_params: called CC=9 SCAR=22.6
| |||||||||||||||||||||||||||||
| 92 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # prapare parameters | ||||||||||||||||||||||||||||
| 95 | 1 | my $params = {}; | |||||||||||||||||||||||||||
| 96 | 1 | $params->{email} = $self->email; | |||||||||||||||||||||||||||
| 97 | 1 | $params->{token} = $self->token; | |||||||||||||||||||||||||||
| 98 | 1 | $params->{receiverEmail} = $self->email; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # payment information | ||||||||||||||||||||||||||||
| 101 | 1 | $params->{reference} = $self->reference; | |||||||||||||||||||||||||||
| 102 | 1 | $params->{currency} = 'BRL'; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1 | ▶ | $params->{redirectURL} = $self->redirect_url | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | if $self->redirect_url; | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 1 | ▶ | $params->{notificationURL} = $self->notification_url | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | if $self->notification_url; | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | # sender information | ||||||||||||||||||||||||||||
| 111 | 1 | ▶ | if($self->sender){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 1 | my $s = $self->sender; | |||||||||||||||||||||||||||
| 113 | 1 | ▶ | $params->{senderName} = $s->name if $s->name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 1 | ▶ | $params->{senderEmail} = $s->email if $s->email; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 1 | ▶ | $params->{senderPhone} = $s->phone if $s->phone; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 1 | ▶ | $params->{senderAreaCode} = $s->area_code if $s->area_code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # items information | ||||||||||||||||||||||||||||
| 120 | 1 | my $c = 1; | |||||||||||||||||||||||||||
| 121 | 1 | for my $i (@{$self->items}){ | |||||||||||||||||||||||||||
| 122 | 2 | map { my $k=camelize($_).$c;$params->{"item$k"}=$i->{$_} } keys %$i; | |||||||||||||||||||||||||||
| 123 | 2 | $c++; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 1 | return $params; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub _parse_request { | ||||||||||||||||||||||||||
|
Subroutine
_parse_request: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 130 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | # read xml | ||||||||||||||||||||||||||||
| 133 | 0 | ▶ | my $xml = $self->xml($_[0]) if $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | # getting /checkout/code | ||||||||||||||||||||||||||||
| 136 | 0 | my $code = $xml->find('/checkout/code')->string_value; | |||||||||||||||||||||||||||
| 137 | 0 | my $date = $xml->find('/checkout/date')->string_value; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | return { | ||||||||||||||||||||||||||||
| 140 | 0 | code => $code, | |||||||||||||||||||||||||||
| 141 | date => $date, | ||||||||||||||||||||||||||||
| 142 | payment_url => $self->base_uri . "/v2/checkout/payment.html?code=$code" | ||||||||||||||||||||||||||||
| 143 | }; | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 3 | 1; | |||||||||||||||||||||||||||
| 147 | __END__ | ||||||||||||||||||||||||||||