| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Finance::Bank::IE::AIB - Finance::Bank interface for Allied Irish Bank | ||
| 4 | |||
| 5 | =cut | ||
| 6 | package Finance::Bank::IE::AIB; | ||
| 7 | |||
| 8 | use base qw( Finance::Bank::IE ); | ||
| 9 | |||
| 10 | use warnings; | ||
| 11 | use strict; | ||
| 12 | |||
| 13 | our $VERSION = '0.30'; | ||
| 14 | |||
| 15 | my %pages = ( | ||
| 16 | login => { | ||
| 17 | url => 'https://aibinternetbanking.aib.ie/inet/roi/login.htm', | ||
| 18 | sentinel => 'Log In.*Step 1 of 2', | ||
| 19 | }, | ||
| 20 | login2 => { | ||
| 21 | url => '', | ||
| 22 | sentinel => 'Log In.*Step 2 of 2', | ||
| 23 | }, | ||
| 24 | accounts => { | ||
| 25 | url => 'https://aibinternetbanking.aib.ie/inet/roi/accountoverview.htm', | ||
| 26 | sentinel => 'your accounts', | ||
| 27 | }, | ||
| 28 | ); | ||
| 29 | |||
| 30 | sub _pages { | ||
| 31 | my $self = shift; | ||
| 32 | return \%pages; | ||
| 33 | } | ||
| 34 | |||
| 35 | |||
| 36 | sub _submit_first_login_page { | ||
| 37 | my $self = shift; | ||
| 38 | my $confref = shift || $self->cached_config(); | ||
| 39 | my $form = $self->_agent()->form_name('form1'); | ||
| 40 | $self->_agent()->field( "regNumber", $confref->{reg_no} ); | ||
| 41 | return $self->_agent()->submit_form(); | ||
| 42 | } | ||
| 43 | |||
| 44 | sub _submit_second_login_page { | ||
| 45 | my $self = shift; | ||
| 46 | my $confref = shift || $self->cached_config(); | ||
| 47 | |||
| 48 | my $form = $self->_agent()->form_name('loginstep2'); | ||
| 49 | for my $digit ( 1..3 ) { | ||
| 50 | (my $wanted = $self->_agent()->content()) =~ s/^.*for="digit$digit">//s; | ||
| 51 | $wanted =~ s/^.*?Digit //s; | ||
| 52 | $wanted =~ s/<.*$//s; | ||
| 53 | $self->_dprintf("Setting digit $digit to char $wanted of PIN\n"); | ||
| 54 | $self->_agent()->field( "pacDetails.pacDigit$digit", substr( $confref->{pin}, $wanted - 1, 1 )); | ||
| 55 | } | ||
| 56 | |||
| 57 | if ( $self->_agent()->content() =~ /last four digits/ ) { | ||
| 58 | $self->_agent()->field("challengeDetails.challengeEntered", $confref->{phone}); | ||
| 59 | } else { | ||
| 60 | die "asked for unknown challenge - failed"; | ||
| 61 | } | ||
| 62 | |||
| 63 | return $self->_agent()->submit_form(); | ||
| 64 | } | ||
| 65 | |||
| 66 | sub _parse_account_balance_page { | ||
| 67 | my $self = shift; | ||
| 68 | my $content = $self->_agent()->content(); | ||
| 69 | my $parser = new HTML::TokeParser( \$content ); | ||
| 70 | |||
| 71 | my @accounts; | ||
| 72 | |||
| 73 | while ( my $tag = $parser->get_tag("div")) { | ||
| 74 | if ( $self->_streq( $tag->[1]{class}, 'account-overview' )) { | ||
| 75 | my %account; | ||
| 76 | $parser->get_tag("span"); | ||
| 77 | $account{nick} = $parser->get_trimmed_text("/span"); | ||
| 78 | $parser->get_tag("h3"); | ||
| 79 | $account{balance} = $parser->get_trimmed_text("/h3"); | ||
| 80 | |||
| 81 | # wiggly | ||
| 82 | $account{currency} = 'EUR'; | ||
| 83 | ( $account{type}, $account{account_no}) = split( /-/, $account{nick}); | ||
| 84 | |||
| 85 | $account{balance} = "-" . $account{balance} if $account{balance} =~ /DR/; | ||
| 86 | $account{balance} =~ s/[^0-9.-]//g; | ||
| 87 | |||
| 88 | push @accounts, bless \%account, | ||
| 89 | "Finance::Bank::IE::AIB::Account"; | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | return @accounts; | ||
| 94 | } | ||
| 95 | |||
| 96 | package Finance::Bank::IE::AIB::Account; | ||
| 97 | |||
| 98 | no strict; | ||
| 99 | sub AUTOLOAD { my $self=shift; $AUTOLOAD =~ s/.*:://; $self->{$AUTOLOAD} } | ||
| 100 | |||
| 101 | 1; |