Business-iDEAL-Adyen

 view release on metacpan or  search on metacpan

lib/Business/iDEAL/Adyen.pm  view on Meta::CPAN


    # return the test or production url based on $type input
    return ($self->{_test} ? $self->{_test_base_url} 
                           : $self->{_prod_base_url}).
            $path;
}

sub _parse_xml {
    my ($self, $input) = @_;
    return unless($input);

    return $self->{_xso}->XMLin($input);    
}

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

    my $plaintext = '';
    if($args->{paymentAmount}) {
        # Initial signature (the one we _send_)
        for(qw/paymentAmount currencyCode shipBeforeDate merchantReference 
               skinCode merchantAccount sessionValidity shopperEmail 
               shopperReference allowedMethods blockedMethods/) {
            $plaintext .= ( defined $self->{"_$_"} ) 
                       ? $self->{"_$_"} : ( $args->{$_} || "" );
        }
    } else {
        # Second signature (the one we _receive_)
        for(qw/authResult pspReference merchantReference skinCode/) {
            $plaintext .= ( defined $self->{"_$_"} ) 
                       ? $self->{"_$_"} : ( $args->{$_} || "" );
        }
    }

    $self->{_hmac}->add($plaintext);
    my $b64_digest = $self->{_hmac}->b64digest;
       $b64_digest .= '=' while (length($b64_digest) % 4);

    return $b64_digest; 
}

=pod

=head3 banklist

In order to offer all iDEAL banks, you will have to fetch a list
with their names and codes. This list is subject to change, so check
this often (Adyen recommends "regularly (e.g. once a day)").
I'd suggest to always check this before a payment.

This method will return an arrayref with the bank_ids and bank_names,
or undef in case an error occured (see L<"error">)

=cut

sub banklist {
    my $self = shift;

    my $res = $self->{_ua}->get($self->_url('banklist'));
    if ($res->is_success) {
        return $self->_parse_xml($res->decoded_content)->{'bank'};
    } else {
        $self->{_error} = $res->status_line;
        return undef;
    }
}

=pod

=head3 fetch

After you've retrieved the L<"banklist">, your users may choose the preferred
bank. Now you can feed that 'bank_id', together with the other mandatory
options to this method.

C<fetch> will return an URL to the bank's iDEAL page that the user should
be directed to.

Some fields are mandatory, while others have somewhat sane defaults and
may be skipped.

=head4 options

=over 5

=item B<bank_id> I<[mandatory]>

This is the bank ID chose by the user and provided by the L<"banklist">
method.

=item B<paymentAmount> I<[mandatory]>

How much would you like to charge your user? Note that this is in
cents, so 12,50 EUR should be inserted as 1250. If a dot or comma
is found in this value, it will be stripped. Don't count on this being
perfect, so sanitize your own input.

=item B<merchantReference>

This will normally be set to your order number, or anything that's useful
to identify the order with. If not set, a semi-random number is generated.

=item B<currencyCode>

Defaults to 'EUR', since iDEAL is a Dutch system and we Dutchmen "embraced"
the euro.

=item B<shopperLocale>

Defaults to 'nl'. Again, iDEAL is a Dutch system.

=item B<shipBeforeDate>

To make matters easy, we set a I<shipBeforeDate> of today + 1 month.

=item B<sessionValidity>

By default, we set this value to now + 1 hour, UTC. A user should
be able to finish his/her transaction within an hour.

=back



( run in 0.794 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )