Finance-Bank-NetBranch

 view release on metacpan or  search on metacpan

lib/Finance/Bank/NetBranch.pm  view on Meta::CPAN

=head1 NAME

Finance::Bank::NetBranch - Manage your NetBranch accounts with Perl

=cut
package Finance::Bank::NetBranch;

use strict;
use warnings;

use Alias 'attr';
use Carp;
use Date::Parse;
use DateTime;
use HTML::Entities qw(%entity2char _decode_entities);
use HTML::TreeBuilder;
use WWW::Mechanize;
$Alias::AttrPrefix = "main::";	# make use strict 'vars' palatable

=head1 VERSION

Version 0.07

=cut

our $VERSION = 0.07;

=head1 SYNOPSIS

  use Finance::Bank::NetBranch;
  my $nb = Finance::Bank::NetBranch->new(
      url      => 'https://nbp1.cunetbranch.com/valley/',
      account  => '12345',
      password => 'abcdef',
  );

  my @accounts = $nb->accounts;

  foreach (@accounts) {
      printf "%20s : %8s : USD %9.2f of %9.2f\n",
          $_->name, $_->account_no, $_->available, $_->balance;
      my $days = 20;
      for ($_->transactions(from => time - (86400 * $days), to => time)) {
          printf "%10s | %20s | %80s : %9.2f, %9.2f\n",
              $_->date->ymd, $_->type, $_->description, $_->amount, $_->balance;
      }
  }

=head1 DESCRIPTION

This module provides a rudimentary interface to NetBranch online banking. This
module was originally implemented to interface with Valley Communities Credit
Union's page at C<https://nbp1.cunetbranch.com/valley/>, but the behavior of
the module is theoretically generalized to "NetBranch" type online access.
However, I do not have access to another NetBranch account with another bank,
and so any feedback on the actual behavior of this module would be greatly
appreciated.

You will need either C<Crypt::SSLeay> or C<IO::Socket::SSL> installed for HTTPS
support to work.

=head1 CLASS METHODS

=head2 Finance::Bank::NetBranch

=over 4

=item new

Creates a new C<Finance::Bank::NetBranch> object; does not connect to the server.

=cut
sub new {
	my $type = shift;
	bless {	@_ }, $type;
}

=back

=head1 OBJECT METHODS

=head2 Finance::Bank::NetBranch

=over 4

=item accounts

Retrieves cached accounts information, connecting to the server if necessary.

=cut
sub accounts {
	my $self = attr shift;
	@::accounts || @{ $self->_get_balances }
}

=item _login

Logs into the NetBranch site (internal use only)

=cut
sub _login {
	my $self = attr shift;

	$::mech ||= WWW::Mechanize->new;
	$::mech->get($::url)
		or die "Could not fetch login page URL '$::url'";
	my $result = $::mech->submit_form(
		form_name => 'frmLogin',
		fields	=> {
			USERNAME	=> $::account,
			password	=> $::password,
		},
		button    => 'Login'
	) or die "Could not submit login form as account '$::account'";

	$::mech->uri =~ /welcome/i
		or die "Failed to log in as account '$::account'";

	$::logged_in = 1;



( run in 3.097 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )