Business-OnlinePayment-PayPal

 view release on metacpan or  search on metacpan

lib/Business/OnlinePayment/PayPal.pm  view on Meta::CPAN

            Country         => "country",
            PostalCode      => "zip",
        }
    );
}

sub transactionid { shift()->authorization(@_); }

sub order_number { shift()->correlationid(@_); }

=head2 get_credentials()

Get the credential information for Business::PayPal::API that was
provided to Business::OnlinePayment::new().  The supported arguments
are:

=over 4

=item * Username Password PKCS12File PKCS12Password

=item * Username Password CertFile KeyFile

lib/Business/OnlinePayment/PayPal.pm  view on Meta::CPAN

example, if the argument "login" were passed to new() the module could
potentially try to identify that and map that to "Username".

NOTE: This requirement/capability seems to be more of a
Business::OnlinePayment issue than a backend issue and it isn't clear
if behavior like this is needed in this module so I will wait for user
feedback to determine if we need/want to implement this.

=cut

sub get_credentials {
    my $self = shift;

    my %credentials;
    my @cred_vars = (
        [qw(PKCS12File PKCS12Password)],
        [qw(CertFile KeyFile)], [qw(Signature)],
    );

    foreach my $aref (@cred_vars) {
        my $need = 0;
        my @vars = ( qw(Username Password), @$aref );

        foreach my $var (@vars) {

            # HACK: Business::OnlinePayment makes method lower case
            my $method = lc($var);
            if ( $self->can($method) ) {
                $credentials{$var} = $self->$method;
            }
            else {
                $need++;
            }
        }

        if ($need) {
            undef %credentials;
        }
        else {
            last;
        }
    }
    return %credentials;
}

=head2 get_request_data()

Return a hash %data with all the data from content() that we will try
to use in our request to PayPal.  Tasks performed:

=over 4

=item *

lib/Business/OnlinePayment/PayPal.pm  view on Meta::CPAN


=head2 submit()

Method that overrides the superclass stub.  This method performs the
following tasks:

=over 4

=item *

Get credentials to be used for authentication with PayPal by calling
L</get_credentials()>.

=item *

Get request data to be passed to PayPal by calling
L</get_request_data()>.

=item *

Connect to PayPal and perform a DirectPaymentRequest.  The request
will be run in test mode (i.e. go to PayPal's "sandbox") if

lib/Business/OnlinePayment/PayPal.pm  view on Meta::CPAN

failure, set error_message() with a string containing all ErrorCode
and LongMessage values joined together.

=back

=cut

sub submit {
    my $self = shift;

    my %credentials = $self->get_credentials;
    my %request     = $self->get_request_data;

    my $pp =
      Business::PayPal::API->new( %credentials,
        sandbox => $self->test_transaction, );

    my %resp = $pp->DoDirectPaymentRequest(%request);

    $self->server_response( \%resp );
    $self->result_code( $resp{Errors} ? $resp{Errors}->[0]->{ErrorCode} : "" );
    $self->avs_code( $resp{AVSCode} );
    $self->cvv2_code( $resp{CVV2Code} );

    if ( $resp{Ack} and $resp{Ack} eq "Success" ) {

t/Business-OnlinePayment-PayPal.t  view on Meta::CPAN

{    # convenience methods
    my $obj = $package->new($driver);
    can_ok(
        $obj, qw(authorization transactionid
          order_number correlationid
          server_response result_code avs_code cvv2_code
          is_success error_message set_defaults __map_fields_data)
    );
}

{    # get_credentials
    my ( $obj, %auth );

    $obj = $package->new( $driver );
    %auth = $obj->get_credentials;
    is_deeply( \%auth, {}, "get_credentials with no data" );

    $obj = $package->new( $driver, %new_args );
    %auth = $obj->get_credentials;

    my ( $uA, $pA, $sA ) = @auth{qw(Username Password Signature)};
    my ( $uW, $pW, $sW ) = @new_args{qw(username password signature)};
    is( $uA, $uW, "get_credentials: test Username:  '$uA' eq '$uW'" );
    is( $pA, $pW, "get_credentials: test Password:  '$pA' eq '$pW'" );
    is( $sA, $sW, "get_credentials: test Signature: '$sA' eq '$sW'" );
}

{    # get_request_data
    my $obj = $package->new($driver);
    my %in  = (
        "action"     => "Normal Authorization",
	"type"       => "visa",
	"expiration" => "9/2011",
	"cvv2"       => "123",
        "name"       => "Phil Lobbes",



( run in 0.255 second using v1.01-cache-2.11-cpan-4d50c553e7e )