BancaSella/Encode/Gestpay.pm

filter: Statementstmt 98.5% 70 / 71 Branchbran 80.0% 16 / 20 Conditioncond 54.5% 6 / 11 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 92.8% 13 / 14 Podpod 33.3% 3 / 9 totaltotal 82.5% 109 / 132 CC 17 SCAR 13.3
CC
17
Cov
90%
getB
7.0
init
6.0
base_url
2.1
CRAP 3.8
« BancaSella/Decode.pm ↑ Summary BancaSella/Decode/Gateway.pm »
1 package Business::BancaSella::Encode::Gestpay;
2  
3 2 push @ISA,'Business::BancaSella::Gestpay';
4 2 ▶use Business::BancaSella::Gestpay;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 $VERSION = "0.13";
10  
11  
12 2 my $bKeys = {
13 currency => 'PAY1_UICCODE',
14 amount => 'PAY1_AMOUNT',
15 id => 'PAY1_SHOPTRANSACTIONID',
16 otp => 'PAY1_OTP',
17 cardnumber => 'PAY1_CARDNUMBER',
18 expmonth => 'PAY1_EXPMONTH',
19 expyear => 'PAY1_EXPYEAR',
20 name => 'PAY1_CHNAME',
21 mail => 'PAY1_CHMAIL',
22 language => 'PAY1_IDLANGUAGE',
23 };
24  
25  
26 0 ▶sub Version { $VERSION; }
Subroutine Version: not called CC=1 SCAR=6.9
Pod undocumented
27 2 require 5.004;
28 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 2 my %fields =
31 (
32 base_url => 'https://ecomm.sella.it/gestpay/pagam.asp',
33 currency => 'eur',
34 );
35
36 2 my @fields_req = qw/shopping amount id otp/;
37
38 sub new
39 1 ▶{
Subroutine new: called CC=2 SCAR=7.1
Pod documented
40 1 my $proto = shift;
41 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
42 1 my $self = {};
43 1 bless $self,$class;
44 1 $self->init(@_);
45 1 return $self;
46 }
47  
48 2 ▶sub init {
Subroutine init: called CC=6 SCAR=18.0
Pod undocumented
49 2 my $self = shift;
50 2 my (%options) = @_;
51 2 $self->SUPER::init(@_);
52 # Assign default options
53 2 ▶ while (my ($key,$value) = each(%fields)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %fields) 4 2 6
54 4 ▶ $self->{$key} = $self->{$key} || $value;
Condition66%2/3
$self->{$key} || $value
l!l&&r!l&&!r
130
MC/DC0%0/2
$self->{$key} || $value
$self->{$key} $value
Truth table66%2/3
A || B
A= $self->{$key}B= $value
ABresult
1X1
011
000
55 }
56 # Assign options
57 2 ▶ while (my ($key,$value) = each(%options)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %options) 17 2 19
58 17 $self->{$key} = $value
59 }
60 # Check required params
61 2 foreach (@fields_req) {
62 croak "You must declare '$_' in " . ref($self) . "::new"
63 8 ▶ if (!defined $self->{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$_} 0 8 8
64 }
65 }
66  
67 2 ▶sub uri {
Subroutine uri: called CC=1 SCAR=0.0
Pod documented
68 2 my $self = shift;
69 2 my $uri = 'a=' . $self->shopping . '&b=' . $self->getB;
70 #$uri = uri_escape($uri);
71 2 return $self->base_url . '?' . $uri;
72 }
73  
74 2 ▶sub form {
Subroutine form: called CC=2 SCAR=7.0
Pod documented
75 2 my $self = shift;
76 2 ▶ my $frmName = shift || '';
Condition50%1/2
shift() || ''
l!l
02
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
77 2 my $ret = '<FORM NAME="' . $frmName . '" METHOD="POST" ACTION="' .
78 $self->base_url . '">' . "\n";
79 2 $ret .= '<input type="hidden" name="a" value="' . $self->shopping .
80 '">' . "\n";
81 2 $ret .= '<input type="hidden" name="b" value="' .
82 encode_entities($self->getB) . '">' . "\n";
83 2 $ret .= "</FORM>\n";
84 }
85  
86 4 ▶sub getB {
Subroutine getB: called CC=7 SCAR=19.5
Pod undocumented
87 4 my $self = shift;
88 4 my @b;
89 4 foreach (keys(%{$bKeys})) {
90 40 my $addValue;
91 40 ▶ if (exists($self->{$_}) && defined($self->{$_}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$_} and defined $self->{$_}) 28 12 40
Condition66%2/3
exists $self->{$_} and defined $self->{$_}
!ll&&!rl&&r
01228
MC/DC50%1/2
exists $self->{$_} and defined $self->{$_}
exists $self->{$_} defined $self->{$_}
Truth table66%2/3
A and B
A= exists $self->{$_}B= defined $self->{$_}
ABresult
0X0
100
111
92 28 $addValue = $self->$_;
93 28 ▶ $addValue = valuta_encode($addValue) if ($_ eq 'currency');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "currency" 4 24 28
94 28 ▶ $addValue = lingua_encode($addValue) if ($_ eq 'language');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "language" 2 26 28
95 28 push @b,$bKeys->{$_} . '=' . $addValue;
96 }
97 }
98 # add user personal parameters
99 4 ▶ while (my ($key,$val) = each %{$self->{user_params}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"user_params"};}) 4 4 8
100 4 push @b, "$key=$val";
101 }
102 #return join('*P1*',@b);
103 4 return uri_escape(join('*P1*',@b));
104 }
105  
106 4 ▶sub valuta_encode {
Subroutine valuta_encode: called CC=2 SCAR=7.0
Pod undocumented
107 4 my $valuta = lc(shift);
108 4 my %vd = (
109 'eur' => 242,
110 'itl' => 18,
111 'usd' => 1,
112 'uk' => 2,
113 'yen' => 71,
114 'hkd' => 103,
115 'real' => 234
116 );
117 4 ▶ die "Unable to encode you currency '$valuta'" if (!exists $vd{$valuta});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $vd{$valuta} 0 4 4
118 4 return $vd{$valuta};
119 }
120  
121 2 ▶sub lingua_encode {
Subroutine lingua_encode: called CC=2 SCAR=7.0
Pod undocumented
122 2 my $lingua = lc(shift);
123 2 my %ld = (
124 'italian' => 1,
125 'english' => 2,
126 'spanish' => 3,
127 'french' => 4
128 );
129 2 ▶ return $ld{'english'} if (!exists $ld{$lingua});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ld{$lingua} 0 2 2
130 2 return $ld{$lingua};
131 }
132  
133 4 ▶sub base_url { my $s=shift; return @_ ? ($s->{base_url}=shift) : $s->{base_url} }
Subroutine base_url: called CC=2 SCAR=7.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 4 4
134  
135 2 1;
« BancaSella/Decode.pm ↑ Summary BancaSella/Decode/Gateway.pm »