Business-OnlinePayment-Litle

 view release on metacpan or  search on metacpan

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

        $self->is_duplicate(1);
    }
    else {
        $self->is_duplicate(0);
    }

    if( defined $resp->{tokenResponse} ) {
        $self->card_token($resp->{tokenResponse}->{litleToken});
        $self->card_token_response($resp->{tokenResponse}->{tokenResponseCode});
        $self->card_token_message($resp->{tokenResponse}->{tokenMessage});
    }

    if( $resp->{enhancedAuthResponse}
        && $resp->{enhancedAuthResponse}->{affluence}
      ){
      $self->get_affluence( $resp->{enhancedAuthResponse}->{affluence} );
    }
    $self->is_success( $self->result_code() eq '000' ? 1 : 0 );
    if(
           $self->result_code() eq '010' # Partial approval, if they chose that option
        || ($self->result_code() eq '802' && $self->card_token) # Card is already a token
    ) {
      $self->is_success(1);
    }

    ##Failure Status for 3.0 users
    if ( !$self->is_success ) {
        my $f_status =
            $ERRORS{ $self->result_code }->{'failure'}
          ? $ERRORS{ $self->result_code }->{'failure'}
          : 'decline';
        $self->failure_status($f_status);
    }

    unless ( $self->is_success() ) {
        unless ( $self->error_message() ) {
            $self->error_message( "(HTTPS response: $status_code) "
                  . "(HTTPS headers: "
                  . join( ", ", map { "$_ => " . $headers{$_} } keys %headers )
                  . ") "
                  . "(Raw HTTPS content: ".$self->server_response().")" );
        }
    }

}


sub chargeback_retrieve_support_doc {
    my ( $self ) = @_;
    $self->_litle_support_doc('RETRIEVE');
    if ($self->is_success) { $self->{'fileContent'} = $self->{'server_response_dangerous'}; } else { $self->{'fileContent'} = undef; }
}


sub chargeback_delete_support_doc {
    my ( $self ) = @_;
    $self->_litle_support_doc('DELETE' );
}


sub chargeback_upload_support_doc {
    my ( $self ) = @_;
    $self->_litle_support_doc('UPLOAD' );
}


sub chargeback_replace_support_doc {
    my ( $self ) = @_;
    $self->_litle_support_doc('REPLACE' );
}

sub _litle_support_doc {
    my ( $self, $action ) = @_;

    local $SCRUBBER=1;
    $self->_litle_init;

    my %content = $self->content();

    my $requiredargs = ['case_id','filename','merchantid'];
    if ($action =~ /(?:UPLOAD|REPLACE)/) { push @$requiredargs, 'filecontent', 'mimetype'; }
    foreach my $key (@$requiredargs) {
        croak "Missing arg $key" unless $content{$key};
    }

    my $actionRESTful = {
        'DELETE' => 'DELETE',
        'RETRIEVE' => 'GET',
        'UPLOAD' => 'POST',
        'REPLACE' => 'PUT',
    };
    die "UNDEFINED ACTION: $action" unless defined $actionRESTful->{$action};

    {
      use bytes;
      if ( defined $content{'filecontent'} ) {
          if ( length($content{'filecontent'}) > 2097152 ) { # file limit of 2M
              my $msg = 'Filesize Exceeds Limit Of 2MB';
              $self->result_code( 012 ); ## no critic
              $self->error_message( $msg );
              croak $msg;
          }
          my $allowedTypes = {
              'application/pdf' => 1,
              'image/gif' => 1,
              'image/jpeg' => 1,
              'image/png' => 1,
              'image/tiff' => 1,
          };
          if ( ! defined $allowedTypes->{$content{'mimetype'}||''} ) {
              croak "File must be one of PDF/GIF/JPG/PNG/TIFF".$content{'mimetype'};
          }
      }
    }

    my $caseidURI = $content{'case_id'};
    my $filenameURI = $content{'filename'};
    my $merchantidURI = $content{'merchantid'};
    foreach ( $caseidURI, $filenameURI, $merchantidURI ) {
        s/([^a-z0-9\.\-])/sprintf('%%%X',ord($1))/ige;
    }

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


=head2 set_defaults

=head2 test_transaction

Get/set the server used for processing transactions.  Possible values are Live, Certification, and Sandbox
Default: Live

  #Live
  $self->test_transaction(0);

  #Certification
  $self->test_transaction(1);

  #Sandbox
  $self->test_transaction('sandbox');

  #Read current value
  $val = $self->test_transaction();

=head2 map_fields

=head2 format_misc_field

A new method not directly supported by BOP.
Used internally to guarantee that XML data will conform to the Litle spec.
  field  - The hash key we are checking against
  maxLen - The maximum length allowed (extra bytes will be truncated)
  minLen - The minimum length allowed
  errorOnLength - boolean
    0 - truncate any extra bytes
    1 - error if the length is out of bounds
  isRequired - boolean
    0 - ignore undefined values
    1 - error if the value is not defined

 $tx->format_misc_field( \%content, [field, maxLen, minLen, errorOnLength, isRequired] );
 $tx->format_misc_field( \%content, ['amount',   0,     12,             0,          0] );

=head2 format_amount_field

A new method not directly supported by BOP.
Used internally to change amounts from the BOP "5.00" format to the format expected by Litle "500"

$tx->format_amount_field( \%content, 'amount' );

=head2 format_phone_field

A new method not directly supported by BOP.
Used internally to strip invalid characters from phone numbers. IE "1 (800).TRY-THIS" becomes "18008788447"

$tx->format_phone_field( \%content, 'company_phone' );

=head2 map_request

Converts the BOP data to something that Litle can use.

=head2 chargeback_retrieve_support_doc

A new method not directly supported by BOP.
Retrieve a currently uploaded file

 $tx->content(
  login       => 'testdrive',
  password    => '123qwe',
  merchantid  => '123456',
  case_id     => '001',
  filename    => 'mydoc.pdf',
 );
 $tx->chargeback_retrieve_support_doc();
 $myFileData = $tx->{'fileContent'};

=head2 chargeback_delete_support_doc

A new method not directly supported by BOP.
Delete a currently uploaded file.  Follows the same format as chargeback_retrieve_support_doc

=head2 chargeback_upload_support_doc

A new method not directly supported by BOP.
Upload a new file

 $tx->content(
  login       => 'testdrive',
  password    => '123qwe',
  merchantid  => '123456',
  case_id     => '001',
  filename    => 'mydoc.pdf',
  filecontent => $binaryPdfData,
  mimetype    => 'application/pdf',
 );
 $tx->chargeback_upload_support_doc();

=head2 chargeback_replace_support_doc

A new method not directly supported by BOP.
Replace a previously uploaded file.  Follows the same format as chargeback_upload_support_doc

=head2 chargeback_list_support_docs

A new method not directly supported by BOP.
Return a hashref that contains a list of files that already exist on the server.

 $tx->content(
  login       => 'testdrive',
  password    => '123qwe',
  merchantid  => '123456',
  case_id     => '001',
 );
 my $ret = $tx->chargeback_list_support_docs();

Currently this returns in this format

 $ret = {
   'file1' => {},
   'file2' => {},
 };

Litle does not currently send any file attributes.  However the hash is built for future expansion.

=head2 add_item

A new method not directly supported by BOP.
Interface to adding multiple entries, so we can write and interface with batches

 my %content = (
   action          =>  'Account Update',
   card_number     =>  4111111111111111,
   expiration      =>  1216,
   customer_id     =>  $card->{'uid'},
   invoice_number  =>  123,
   type            =>  'VI',
   login           =>  $merchant->{'login'},
 );
 $tx->add_item( \%content );

=head2 create_batch

A new method not directly supported by BOP.
Send the current batch to Litle.

 $tx->add_item( $item1 );
 $tx->add_item( $item2 );
 $tx->add_item( $item3 );

 my $opts = {
  login       => 'testdrive',
  password    => '123qwe',
  merchantid  => '123456',
  batch_id    => '001',
  method      => 'https', # sftp or https
  ftp_username=> 'fred',
  ftp_password=> 'pancakes',
 };

 $tx->content();



( run in 2.176 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )