| 1 | package Business::iDEAL::Mollie; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use LWP::UserAgent; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use XML::Simple; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 1 | our $VERSION = '0.01'; | |||||||||||
| 10 | |||||||||||||
| 11 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 12 | 0 | my ($class, $args) = @_; | |||||||||||
| 13 | 0 | ▶ | $args ||= {}; | ||||||||||
|
Condition0%0/2
$args ||= {}
MC/DC0%0/1
$args ||= {}
$args
Truth table0%0/2
A
A= $args
| |||||||||||||
| 14 | 0 | ▶ | $class->_croak("Options must be a hash reference") | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 15 | if ref($args) ne 'HASH'; | ||||||||||||
| 16 | 0 | my $self = {}; | |||||||||||
| 17 | 0 | bless $self, $class; | |||||||||||
| 18 | 0 | ▶ | $self->_init($args) or return undef; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 19 | |||||||||||||
| 20 | 0 | return $self; | |||||||||||
| 21 | } | ||||||||||||
| 22 | |||||||||||||
| 23 | 0 | ▶ | sub _init { | ||||||||||
|
Subroutine
_init: not called CC=2 SCAR=17.9
| |||||||||||||
| 24 | 0 | my ($self, $args) = @_; | |||||||||||
| 25 | |||||||||||||
| 26 | 0 | my $ua = LWP::UserAgent->new( | |||||||||||
| 27 | agent => __PACKAGE__." v. $VERSION", | ||||||||||||
| 28 | ); | ||||||||||||
| 29 | my %options = ( | ||||||||||||
| 30 | baseurl => 'http://www.mollie.nl/xml/ideal', | ||||||||||||
| 31 | ua => $ua, | ||||||||||||
| 32 | 0 | %{ $args }, | |||||||||||
| 33 | ); | ||||||||||||
| 34 | 0 | $self->{"_$_"} = $options{$_} foreach (%options); | |||||||||||
| 35 | 0 | return $self; | |||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 0 | ▶ | sub banklist { | ||||||||||
|
Subroutine
banklist: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||
| 40 | |||||||||||||
| 41 | 0 | my $res = $self->{'_ua'}->get($self->{'_baseurl'}.'?a=banklist'); | |||||||||||
| 42 | 0 | ▶ | if ($res->is_success) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 0 | return _parse_output($res->decoded_content)->{'bank'}; | |||||||||||
| 44 | } else { | ||||||||||||
| 45 | 0 | $self->{'_error'} = $res->status_line; | |||||||||||
| 46 | } | ||||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 0 | ▶ | sub fetch { | ||||||||||
|
Subroutine
fetch: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||
| 50 | 0 | my ($self, $parms) = @_; | |||||||||||
| 51 | 0 | ▶ | $parms ||= {}; | ||||||||||
|
Condition0%0/2
$parms ||= {}
MC/DC0%0/1
$parms ||= {}
$parms
Truth table0%0/2
A
A= $parms
| |||||||||||||
| 52 | 0 | ▶ | $self->_croak("Parameters must be in a hash reference") | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | if ref($parms) ne 'HASH'; | ||||||||||||
| 54 | |||||||||||||
| 55 | # Check for mandatory input | ||||||||||||
| 56 | 0 | foreach(qw/partnerid amount bank_id description reporturl returnurl/) { | |||||||||||
| 57 | 0 | ▶ | $self->_croak("Mandatory parameter $_ not found!") unless($parms->{$_}); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | # Make sure amount is in cents | ||||||||||||
| 61 | 0 | $parms->{'amount'} =~ s/[\.,]//g; | |||||||||||
| 62 | |||||||||||||
| 63 | # Put the action value in $parms | ||||||||||||
| 64 | 0 | $parms->{'a'} = 'fetch'; | |||||||||||
| 65 | 0 | my $res = $self->{'_ua'}->post($self->{'_baseurl'}, $parms); | |||||||||||
| 66 | |||||||||||||
| 67 | 0 | ▶ | if ($res->is_success) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | 0 | return _parse_output($res->decoded_content)->{'order'}; | |||||||||||
| 69 | } else { | ||||||||||||
| 70 | 0 | $self->{'_error'} = $res->status_line; | |||||||||||
| 71 | } | ||||||||||||
| 72 | } | ||||||||||||
| 73 | |||||||||||||
| 74 | 0 | ▶ | sub check { | ||||||||||
|
Subroutine
check: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||
| 75 | 0 | my ($self, $parms) = @_; | |||||||||||
| 76 | 0 | ▶ | $parms ||= {}; | ||||||||||
|
Condition0%0/2
$parms ||= {}
MC/DC0%0/1
$parms ||= {}
$parms
Truth table0%0/2
A
A= $parms
| |||||||||||||
| 77 | 0 | ▶ | $self->_croak("Parameters must be in a hash reference") | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | if ref($parms) ne 'HASH'; | ||||||||||||
| 79 | |||||||||||||
| 80 | # Check for mandatory input | ||||||||||||
| 81 | 0 | foreach(qw/partnerid transaction_id/) { | |||||||||||
| 82 | 0 | ▶ | $self->_croak("Mandatory parameter $_ not found!") unless($parms->{$_}); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | # Put the action value in $parms | ||||||||||||
| 86 | 0 | $parms->{'a'} = 'check'; | |||||||||||
| 87 | 0 | my $res = $self->{'_ua'}->post($self->{'_baseurl'}, $parms); | |||||||||||
| 88 | |||||||||||||
| 89 | 0 | ▶ | if ($res->is_success) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 90 | 0 | return _parse_output($res->decoded_content)->{'order'}; | |||||||||||
| 91 | } else { | ||||||||||||
| 92 | 0 | $self->{'_error'} = $res->status_line; | |||||||||||
| 93 | } | ||||||||||||
| 94 | } | ||||||||||||
| 95 | |||||||||||||
| 96 | 0 | ▶ | sub is_payed { | ||||||||||
|
Subroutine
is_payed: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 97 | 0 | my ($self, $parms) = @_; | |||||||||||
| 98 | 0 | my $resp = $self->check($parms); | |||||||||||
| 99 | 0 | ▶ | return ($resp->{'payed'} eq 'true') ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | 0 | ▶ | sub error { | ||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 103 | 0 | my $self = shift; | |||||||||||
| 104 | 0 | return $self->{'_error'}; | |||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | |||||||||||||
| 108 | 0 | ▶ | sub _parse_output { | ||||||||||
|
Subroutine
_parse_output: not called CC=2 SCAR=17.9
| |||||||||||||
| 109 | 0 | my $input = shift; | |||||||||||
| 110 | 0 | ▶ | return unless($input); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | 0 | my $xso = new XML::Simple(); | |||||||||||
| 112 | 0 | return $xso->XMLin($input); | |||||||||||
| 113 | } | ||||||||||||
| 114 | |||||||||||||
| 115 | 0 | ▶ | sub _croak { | ||||||||||
|
Subroutine
_croak: not called CC=1 SCAR=6.9
| |||||||||||||
| 116 | 0 | my ($self, @error) = @_; | |||||||||||
| 117 | 0 | Carp::croak(@error); | |||||||||||
| 118 | } | ||||||||||||
| 119 | |||||||||||||
| 120 | 1 | 1; | |||||||||||
| 121 | __END__ | ||||||||||||