Finance-Bank-AU-StGeorge

 view release on metacpan or  search on metacpan

lib/Finance/Bank/AU/StGeorge.pm  view on Meta::CPAN

use WWW::Mechanize;
use strict;

use vars qw($VERSION $IBANK_URL $ERROR);

$VERSION = '0.01';
$IBANK_URL = "https://ibank.stgeorge.com.au/scripts/ibank.dll?ibank";
$ERROR = '';

sub new
{
    my ($class, %args) = @_;

    my $self = bless {
	_ua   => WWW::Mechanize->new(autocheck => 1),
	card  => "",
	pin   => "",
	pass  => "",
	issue => 1,
    }, $class;

    return $self->_set(%args);
}

sub _set
{
    my ($self, %args) = @_;

    $self->{lc $_} = $args{$_}
	foreach grep !/^_/ && exists $self->{lc $_}, keys %args;

    return $self;
}

sub logged_in
{
    my ($self) = @_;
    return unless $self->{_params};
    return unless $self->{_params}{Session};
}

sub login
{
    my ($self, %args) = @_;

    $self = $self->new(%args) unless ref $self;

    my $params = $self->{_params} ||= {
	Route   => "IBS",
	Id      => "JBANK.12.P",
	origin  => "ABA",
	Session => "",
    };

    return $self if $params->{Session};

    my $ua = $self->{_ua};
    $ua->env_proxy;
    $ua->get("https://ibank.stgeorge.com.au/html/index.asp");

    my ($popup_url) = $ua->content =~ m|window\.open\(\"([^\"]+)\"|;

    $ua->get($popup_url);

    # one-time warnings
    $ua->form(1);
    $ua->submit();

    # login
    my $form = $ua->form(1);
    $form->value(Card     => $self->{card});
    $form->value(Pin      => $self->{pin});
    $form->value(LastName => $self->{pass});
    $form->value(hWidth   => 800);
    $form->value(hHeight  => 600);
    $form->value(Issue    => $self->{issue});
    $ua->click();

    # scrape out session id's and stuff
    for ($ua->content)
    {
	($params->{Route})   = $1 if /route=([^\&]+)/m;
	($params->{Id})      = $1 if /clid=([^\&]+)/m;
	($params->{origin})  = $1 if /origin=([^\&]+)/m;
	($params->{Session}) = $1 if /Session=([a-f0-9]{32})/m;
    }

    return $self if $params->{Session};
    return;
}

sub logout
{
    my ($self) = @_;

    $self->logged_in or return;

    my $ua = $self->{_ua};

    $ua->request(POST $IBANK_URL, [
	route  => "IBS",
	params => _format_params(%{ $self->{_params} }, Tran => "Logout"),
    ]);

    return 1;
}

sub accounts
{
    my ($self, %args) = @_;

    $self = $self->new(%args) unless ref $self;
    $self->login or return;

    my $ua = $self->{_ua};

    my $accounts = $self->{_accounts};

    if (not $accounts or $args{reload})
    {
	$ua->request(POST $IBANK_URL, [
	    route  => "IBS",
	    params => _format_params(%{ $self->{_params} }, Tran => "BrowseAccounts"),



( run in 1.587 second using v1.01-cache-2.11-cpan-54e63673c56 )