Finance-Bank-IE

 view release on metacpan or  search on metacpan

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

    my $account_selector = '';
    my $content = $self->_agent()->content();
    my $parser = new HTML::TokeParser( \$content );
    my @valid_accounts;
    while ( my $selector = $parser->get_tag( "select" )) {
        if ( $self->_streq( $selector->[1]{id}, 'form:selectPayeeDomestic')) {
            while ( my $option = $parser->get_tag( "option", "/select" )) {
                last if $option->[0] eq '/select';
                my $accountname = $parser->get_trimmed_text( "/option" );
                next if $accountname =~ /Select Payee/;
                push @valid_accounts, $accountname;

                my ( $nick, $number ) = split( /\s*~\s*/, $accountname );
                if ( $account_to eq $nick or $account_to eq $number or
                     substr( $account_to, -4 ) eq $number ) {
                    $account_selector = $option->[1]{value};
                    last;
                }
            }
            last;
        }
    }

    if ( $account_selector eq '' ) {
        croak( sprintf( "Couldn't find payee '%s', valid accounts are '%s'", $account_to, join( "', '", @valid_accounts )));
    }

    $res = $self->_agent()->submit_form(
                                        fields => {
                                                   'form:selectPayeeDomestic' => $account_selector,
                                                   'form:amount' => $amount,
                                                  },
                                        button => 'form:formActions:continue',
                                       );
    $self->_identify_page();
    # also, the destination account number appears in full on this page.
    $self->_save_page();
    croak( 'not on PIN page' ) unless $self->_agent()->content() =~ m@Enter your PIN</h2>@;

    $self->_set_creds_fields( $confref );

    $res = $self->_agent()->submit_form( button => 'form:formActions:continue' );
    $self->_identify_page();
    $self->_save_page();
    croak( 'not on Confirmation page' ) unless $self->_agent()->content() =~ m@Confirmation</h2>@s;

    # return the 'receipt'
    # extraction:
    # <h2 class="section_title">Confirmation</h2>
    # <p><span class="highlight"><strong>eur AMOUNT
    # </strong></span>
    # has been paid from <span class="highlight"><strong>SOURCE</strong></span> to
    # <span class="highlight"><strong>DEST</strong></span>
    # </p>
    return $self->_agent()->content;
}


=item * $self->_set_creds_fields( $config )

  Parse the last received page for credentials entry fields, and populate them with the data from C<$config>. Also injects the missing 'form:continue' hidden field.

=cut
sub _set_creds_fields {
    my $self = shift;
    my $confref = shift;

    my $form = $self->_agent()->current_form();
    # avoid having to restructure old config
    my @dob = split( '/', $confref->{dob} );
    my %fieldmapping = (
                        'form:dateOfBirth_year' => $dob[2],
                        'form:dateOfBirth_month' => $dob[1],
                        'form:dateOfBirth_date' => $dob[0],
                        'form:phoneNumber' => $confref->{contact},
                       );
    for my $i ( 1..6 ) {
        $fieldmapping{"form:security_number_digit$i"} = substr( $confref->{pin}, $i - 1, 1 );
        $fieldmapping{"form:pinFragment:security_number_digit$i"} = substr( $confref->{pin}, $i - 1, 1 );
    }

    for my $id ( keys %fieldmapping ) {
        my $field = $form->find_input( $id );
        if ( $field ) {
            $self->_agent()->field( $id, $fieldmapping{$id});
        }
    }

    # LOSERS.
    my $input = new HTML::Form::Input( type => 'hidden',
                                       name => 'form:continue',
                                       value => 'form:continue',
                                     );
    $input->add_to_form( $form );
}

=item * $scrubbed = $self->_scrub_page( $content )

 Scrub the supplied content for PII.

=cut
sub _scrub_page {
    my ( $self, $content ) = @_;

    my $output = "";

    my $parser = new HTML::TokeParser( \$content );
    my $page = $self->_identify_page( $content );
    my $payee_acct = 0;

    while ( my $token = $parser->get_token()) {
        my $token_string = $token->[0] eq 'T' ? $token->[1] : $token->[-1];

        if ( $token->[0] eq 'T') {
            $token_string =~ s@(Last Login.*?)\d+/\d+/\d+ \d+:\d+@${1}01/01/1970 00:00@;
            $token_string =~ s@(Last Payee Added.*?)\d+/\d+/\d+@${1}01/01/1970@;
        }

        if ( $token->[0] eq 'S' ) {
            if ( $token->[1] eq 'h2' ) {
                my $tpage = "";



( run in 0.945 second using v1.01-cache-2.11-cpan-14f38c9f855 )