PagOnline.pm

filter: Statementstmt 42.6% 26 / 61 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 63.6% 7 / 11 Podpod 0.0% 0 / 3 totaltotal 37.0% 33 / 89 CC 10 SCAR 31.8
CC
10
Cov
35%
payment_init
56.0
payment_verify
20.0
__ANON__
2.0
CRAP 24.1
↑ Summary PagOnline_ok.pm »
1 1 package Business::PagOnline {
2 #use SOAP::Lite +trace => [qw/all -objects/];
3 1 ▶ use SOAP::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶ use Digest::SHA qw/hmac_sha256 hmac_sha256_hex hmac_sha256_base64/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶ use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶ use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = qv("v0.2.0");
12  
13 has soapclient => (
14 is => 'ro',
15 0 ▶ default => sub { SOAP::Lite->new() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
16 1 );
17  
18 1 has tid => ( is => 'ro' );
19 1 has kSig => ( is => 'ro' );
20  
21 0 ▶ sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
22 0 my ($self, $args) = @_;
23 #$self->soapclient->serializer->readable(1);
24 #$self->soapclient->envprefix('soapenv'); # As per example
25 0 $self->soapclient->proxy($args->{url});
26 0 $self->soapclient->ns('http://services.api.web.cg.igfs.apps.netsw.it/', 'ser');
27 }
28  
29 0 ▶ sub payment_init {
Subroutine payment_init: not called CC=7 SCAR=40.3
Pod undocumented
30 0 my ($self, $args) = @_;
31  
32 0 $args->{amount} = int ($args->{amount} * 100);
33 0 ▶ die 'Invalid-amount' if $args->{amount} !~ m/^\d+$/xs;
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"amount"} =~ /^\d+$/sux 0 0 0
34 0 ▶ die 'Invalid-shopID' if $args->{shopID} !~ m/^\w+$/xs;
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"shopID"} =~ /^\w+$/sux 0 0 0
35 0 ▶ die 'Invalid-shopUserRef' if !$args->{shopUserRef};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"shopUserRef"} 0 0 0
36  
37 my %reqargs = (
38 langID => $args->{lang},
39 tid => $self->tid,
40 kSig => $self->kSig,
41 trType => 'PURCHASE',
42 shopID => $args->{shopID},
43 shopUserRef => $args->{shopUserRef},
44 amount => $args->{amount},
45 currencyCode => 'EUR',
46 errorURL => $args->{errorURL}.'',
47 0 notifyURL => $args->{notifyURL}.'',
48 );
49  
50 0 my $signature_str = join('', map { ''.$reqargs{$_} } qw/
51 tid shopID shopUserRef shopUserName shopUserAccount
52 trType amount currencyCode langID notifyURL
53 errorURL addInfo1 addInfo2 addInfo3 addInfo4
54 addInfo5 description recurrent paymentReason freeText
55 validityExpire
56 /);
57 0 $reqargs{signature} = hmac_sha256_base64($signature_str, $self->kSig) . '=';
58 #die "$reqargs{kSig} - " . $reqargs{signature};
59 #die Data::Dump::dump(\%reqargs);
60  
61 0 my @soapdata;
62 0 for my $sk(keys %reqargs) {
63 0 ▶ next if $sk eq 'kSig'; # This is used to calculate signature but MUST NOT BE SENT or we'll get 500 Error
Branch: 1 branch
BranchTrueFalseTotal
if $sk eq "kSig" 0 0 0
64 0 my $sd = SOAP::Data->new(name => $sk, value => $reqargs{$sk});
65 # $sd->type(''); # As per example
66 0 push @soapdata, $sd;
67 }
68  
69 # die Data::Dump::dump(\@soapdata);
70 0 my $sd_req = SOAP::Data->new(name => 'request', value => \@soapdata);
71 # $sd_req->type('');
72 0 my $res = $self->soapclient->call('ser:Init',
73 $sd_req
74 )->result;
75 # die Data::Dump::dump($res);
76 0 ▶ confess Data::Dump::dump($res) if $res->{error} ne 'false';
Branch: 1 branch
BranchTrueFalseTotal
if $res->{"error"} ne "false" 0 0 0
77  
78 0 return $res;
79 }
80  
81 0 ▶ sub payment_verify {
Subroutine payment_verify: not called CC=4 SCAR=30.0
Pod undocumented
82 0 my ($self, $args) = @_;
83  
84 0 ▶ die 'Invalid-shopID' if $args->{shopID} !~ m/^\w+$/xs;
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"shopID"} =~ /^\w+$/sux 0 0 0
85 my %reqargs = (
86 tid => $self->tid,
87 kSig => $self->kSig,
88 shopID => $args->{shopID},
89 paymentID => $args->{paymentID},
90 0 );
91  
92 0 my $signature_str = join('', map { ''.$reqargs{$_} } qw/
93 tid shopID paymentID
94 /);
95 0 $reqargs{signature} = hmac_sha256_base64($signature_str, $self->kSig) . '=';
96  
97 0 my @soapdata;
98 0 for my $sk(keys %reqargs) {
99 0 ▶ next if $sk eq 'kSig'; # This is used to calculate signature but MUST NOT BE SENT or we'll get 500 Error
Branch: 1 branch
BranchTrueFalseTotal
if $sk eq "kSig" 0 0 0
100 0 my $sd = SOAP::Data->new(name => $sk, value => $reqargs{$sk});
101 0 push @soapdata, $sd;
102 }
103  
104 0 my $res = $self->soapclient->call('ser:Verify',
105 SOAP::Data->new(name => 'request', value => \@soapdata)
106 )->result;
107  
108 0 return $res;
109 }
110 }
111  
112 1 1;
113  
114 =head1 NAME
115  
116 Business::PagOnline - Perl library for Unicredit's PagOnline payment system
117  
118 =head1 SYNOPSIS
119  
120 use Business::PagOnline;
121  
122 # TODO
123  
124 =head1 DESCRIPTION
125  
126 This is HIGHLY EXPERIMENTAL and in the works, do not use for now.
127  
128 =head1 AUTHOR
129  
130 Michele Beltrame, C<mb@blendgroup.it>
131  
132 =head1 LICENSE
133  
134 This library is free software under the Artistic License 2.0.
135  
136 =cut
↑ Summary PagOnline_ok.pm »