| 1 | package Finance::Bank::Bankwest::SessionFromLogin; | ||||||||||||||||||||||
| 2 | # ABSTRACT: create a session using a PAN and access code | ||||||||||||||||||||||
| 3 | 2 | $Finance::Bank::Bankwest::SessionFromLogin::VERSION = '1.2.8'; | |||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | ## no critic (RequireUseStrict, RequireUseWarnings, RequireEndWithOne) | ||||||||||||||||||||||
| 6 | 4 | ▶ | use MooseX::Declare; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | 4 | ▶ | class Finance::Bank::Bankwest::SessionFromLogin { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.4
| |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | 4 | ▶ | use Finance::Bank::Bankwest::Parsers (); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | 4 | ▶ | use Finance::Bank::Bankwest::Session (); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | 4 | ▶ | use MooseX::StrictConstructor; # no exports | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | 4 | ▶ | use TryCatch; # for "try" and "catch" | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | 4 | ▶ | use WWW::Mechanize (); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 14 | |||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | 4 | has 'pan' => ( | |||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||
| 18 | isa => 'Str', | ||||||||||||||||||||||
| 19 | required => 1, | ||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | |||||||||||||||||||||||
| 23 | 4 | has 'access_code' => ( | |||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||
| 25 | isa => 'Str', | ||||||||||||||||||||||
| 26 | required => 1, | ||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||
| 28 | |||||||||||||||||||||||
| 29 | |||||||||||||||||||||||
| 30 | 4 | has 'session' => ( | |||||||||||||||||||||
| 31 | init_arg => undef, | ||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||
| 33 | isa => 'Finance::Bank::Bankwest::Session', | ||||||||||||||||||||||
| 34 | lazy_build => 1, | ||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||
| 36 | 0 | ▶ | method _build_session { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
__ANON__: not called CC=5 SCAR=20.5
Subroutine
_build_session: called CC=5 SCAR=20.5
| |||||||||||||||||||||||
| 37 | 0 | my $ua = WWW::Mechanize->new( | |||||||||||||||||||||
| 38 | stack_depth => 0, | ||||||||||||||||||||||
| 39 | cookie_jar => { hide_cookie2 => 1 }, | ||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||
| 41 | 0 | $ua->get($self->login_uri); | |||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | # Is this actually a login page? | ||||||||||||||||||||||
| 44 | 0 | ▶ | try { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.8
| |||||||||||||||||||||||
| 45 | 0 | Finance::Bank::Bankwest::Parsers->handle($ua->res); | |||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||
| 47 | 0 | ▶ | catch (Finance::Bank::Bankwest::Error::NotLoggedIn $e) { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.4
Branch: 4 branches
| |||||||||||||||||||||||
| 48 | # Generally the appearance of a login page is a bad thing, | ||||||||||||||||||||||
| 49 | # but because we are currently trying to log in, it's not. | ||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | 0 | # The "__EVENTTARGET" parameter is normally set via JavaScript. | |||||||||||||||||||||
| 53 | $ua->submit_form( | ||||||||||||||||||||||
| 54 | form_id => 'Form1', | ||||||||||||||||||||||
| 55 | fields => { | ||||||||||||||||||||||
| 56 | 'AuthUC$txtUserID' => $self->pan, | ||||||||||||||||||||||
| 57 | 'AuthUC$txtData' => $self->access_code, | ||||||||||||||||||||||
| 58 | '__EVENTTARGET' => 'AuthUC$btnLogin', | ||||||||||||||||||||||
| 59 | }, | ||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | # In most cases the Account Balances page will be returned. | ||||||||||||||||||||||
| 63 | # Handle the occasional "service message" popping up first, but | ||||||||||||||||||||||
| 64 | 0 | ▶ | # let any other exception be determined and propagated. | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.8
| |||||||||||||||||||||||
| 65 | 0 | try { | |||||||||||||||||||||
| 66 | Finance::Bank::Bankwest::Parsers->handle( | ||||||||||||||||||||||
| 67 | $ua->res, | ||||||||||||||||||||||
| 68 | qw{ Accounts ServiceMessage }, | ||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||
| 70 | 0 | ▶ | } | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.0
Branch: 4 branches
| |||||||||||||||||||||||
| 71 | 0 | catch (Finance::Bank::Bankwest::Error::ServiceMessage $e) { | |||||||||||||||||||||
| 72 | 0 | $ua->click('btnStartBanking'); | |||||||||||||||||||||
| 73 | Finance::Bank::Bankwest::Parsers->handle( | ||||||||||||||||||||||
| 74 | $ua->res, | ||||||||||||||||||||||
| 75 | qw{ Accounts }, | ||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||
| 78 | 0 | ||||||||||||||||||||||
| 79 | 4 | # If this point is reached, the session is established. | |||||||||||||||||||||
| 80 | return Finance::Bank::Bankwest::Session->new( $ua ); | ||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||
| 82 | 4 | ||||||||||||||||||||||
| 83 | |||||||||||||||||||||||
| 84 | has 'login_uri' => ( | ||||||||||||||||||||||
| 85 | is => 'ro', | ||||||||||||||||||||||
| 86 | isa => 'Str', | ||||||||||||||||||||||
| 87 | 4 | ▶ | default => 'https://ibs.bankwest.com.au/BWLogin/rib.aspx', | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||||