Finance-Bank-IE-PermanentTSB

 view release on metacpan or  search on metacpan

lib/Finance/Bank/IE/PermanentTSB.pm  view on Meta::CPAN

    DEPOSIT        => 2, # shows only the DEPOSITs

    # account types
    VISA_ACCOUNT   => 'Visa Card', # visa card account
    SWITCH_ACCOUNT => 'Switch Current A/C', # switch current account

};

=head1 METHODS / FUNCTIONS

Every function in this module requires, as the first argument, a reference 
to an hash which contains the configuration:

    my %config = (
        "open24numba" => "your open24 number",
        "password" => "your internet password",
        "pan" => "your personal access number",
        "debug" => 1,
    );

=head2 C<$boolean = login($config_ref)> - B<private>

B<This is a private function used by other function within the module.
You don't need to call it directly from you code!>

This function performs the login. It takes just one required argument,
which is an hash reference for the configuration.
The function returns true (1) if success or undef for any other
state.
If debug => 1 then it will dump the html page on the current working
directory. 
Please be aware that this has a security risk. The information will
persist on your filesystem until you reboot your machine (and /var/tmp
get clean at boot time).

=cut

sub login {
    my $self = shift;
    my $config_ref = shift;
    my $content;

    $config_ref ||= \%cached_cfg;

    my $croak = ($config_ref->{croak} || 1);

    for my $reqfield ("open24numba", "password", "pan") {
        if (! defined( $config_ref->{$reqfield})) {
            if ($croak) {
                carp("$reqfield not there!");
                return undef;
            } else {
                carp("$reqfield not there!");
                return undef;
            }
        }
    }

    if(!defined($agent)) {
        $agent = WWW::Mechanize->new( env_proxy => 1, autocheck => 1,
                                      keep_alive => 10);
        $agent->env_proxy;
        $agent->quiet(0);
        $agent->agent('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20071126 Fedora/1.5.0.12-7.fc6 Firefox/1.5.0.12' );
        my $jar = $agent->cookie_jar();
        $jar->{hide_cookie2} = 1;
        $agent->add_header('Accept' =>
            'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5');
        $agent->add_header('Accept-Language' => 'en-US,en;q=0.5');
        $agent->add_header( 'Accept-Charset' =>
            'ISO-8859-1,utf-8;q=0.7,*;q=0.7' );
        $agent->add_header( 'Accept-Encoding' => 'gzip,deflate' );
    } else {
        # simple check to see if the login is live
        # this based on Waider Finance::Bank::IE::BankOfIreland.pm!
        if ( time - $lastop < 60 ) {
            carp "Last operation 60 seconds ago, reusing old session"
                if $config_ref->{debug};
            $lastop = time;
            return 1;
        }
        my $res = $agent->get( $BASEURL . '/online/Account.aspx' );
        if ( $res->is_success ) {
            $content = $agent->content;
            if($agent->content =~ /ACCOUNT SUMMARY/is) {
                $lastop = time;
                carp "Short-circuit: session still valid"
                    if $config_ref->{debug};
                return 1;
            }
        }
        carp "Session has timed out, redoing login"
            if $config_ref->{debug};
    }

    # retrieve the login page
    my $res = $agent->get($BASEURL . '/online/login.aspx');
    $agent->save_content('./loginpage.html') if $config_ref->{debug};

    # something wrong?
    if(!$res->is_success) {
        carp("Unable to get page!");
        return undef;
    }

    # 2nd agent->content call
    $content = $agent->content;
    if($content =~ /Interruption Page/is) {
        carp "Cannot authenticate on Open24.ie: site mantainance";
        $error = 1;
        return undef;
    }

    # page not found?
    if($content =~ /Page Not Found/is) {
        carp("HTTP ERROR 404: Page Not Found");
        return undef;
    }

    # Login - Step 1 of 2
    $agent->field('txtLogin', $config_ref->{open24numba});



( run in 4.992 seconds using v1.01-cache-2.11-cpan-14f38c9f855 )