diff options
author | Mark Wells <mark@freeside.biz> | 2015-03-25 11:20:35 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2015-03-25 11:20:35 -0700 |
commit | eee17f9ca705b7f5b276226fdef80b48977071d6 (patch) | |
tree | 104593c00cabbd0e6dbf768bcf7a079b6f179914 | |
parent | 39c50bd135813d015fc2c0a3e6d3e9b57f3d7a96 (diff) |
enforce field lengths in raw bytes
-rw-r--r-- | Paymentech.pm | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/Paymentech.pm b/Paymentech.pm index 19277cc..31a28ee 100644 --- a/Paymentech.pm +++ b/Paymentech.pm @@ -65,6 +65,8 @@ use Moose; with 'Business::BatchPayment::Processor'; with 'Business::BatchPayment::TestMode'; +use Encode; + # could have some validation on all of these has [ qw(merchantID terminalID bin industryType login password) ] => ( is => 'ro', @@ -108,6 +110,7 @@ sub format_request { OUTPUT => \$output, DATA_MODE => 1, DATA_INDENT => 2, + ENCODING => 'utf-8', ); $self->format_header($batch, $xml); my $count = 1; @@ -127,6 +130,7 @@ sub format_header { my ($self, $batch, $xml) = @_; my $num_items = $batch->count; + $xml->xmlDecl(); $xml->startTag('transRequest', RequestCount => $num_items + 1); $xml->startTag('batchFileID'); $xml->dataElement(userID => $self->login); @@ -167,11 +171,11 @@ sub format_item { } push @order, ( avsZip => $item->zip, - avsAddress1 => substr($item->address, 0, 30), - avsAddress2 => substr($item->address2, 0, 30), - avsCity => substr($item->city, 0, 20), - avsState => substr($item->state, 0, 2), - avsName => substr($item->first_name. ' '. $item->last_name, 0, 30), + avsAddress1 => bytes_substr($item->address, 0, 30), + avsAddress2 => bytes_substr($item->address2, 0, 30), + avsCity => bytes_substr($item->city, 0, 20), + avsState => bytes_substr($item->state, 0, 2), + avsName => bytes_substr($item->first_name. ' '. $item->last_name, 0, 30), ( $paymentech_countries{ $item->country } ? ( avsCountryCode => $item->country ) : () @@ -393,6 +397,19 @@ sub _info { } } +# internal use + +sub bytes_substr { + my ($string, $offset, $length, $repl) = @_; + my $bytes = substr( + Encode::encode('utf8', $string), + $offset, + $length, + Encode::encode('utf8', $repl) + ); + return Encode::decode('utf8', $bytes, Encode::FB_QUIET); +} + =head1 AUTHOR Mark Wells, C<< <mark at freeside.biz> >> |