--- /dev/null
+package SL::DB::Helper::ReplaceSpecialChars;
+
+use strict;
+use utf8;
+
+use parent qw(Exporter);
+our @EXPORT = qw(replace_special_chars);
+
+use Carp;
+use Text::Unidecode qw(unidecode);
+
+
+
+
+sub replace_special_chars {
+ my $text = shift;
+
+ return unless $text;
+
+ my %special_chars = (
+ 'ä' => 'ae',
+ 'ö' => 'oe',
+ 'ü' => 'ue',
+ 'Ä' => 'Ae',
+ 'Ö' => 'Oe',
+ 'Ü' => 'Ue',
+ 'ß' => 'ss',
+ '&' => '+',
+ '`' => '\'',
+ );
+
+ map { $text =~ s/$_/$special_chars{$_}/g; } keys %special_chars;
+
+ # for all other non ascii chars 'OLÉ S.L.' and 'Årdberg AB'!
+ $text = unidecode($text);
+
+ return $text;
+}
+
+1;
+__END__
+
+=pod
+
+=encoding utf8
+
+=head1 NAME
+
+SL::DB::Helper::ReplaceSpecialChars - Helper functions for replacing non-ascii characaters
+
+=head1 SYNOPSIS
+
+ use SL::DB::Helper::ReplaceSpecialChars qw(replace_special_chars);
+ my $ansi_string = replace_special_chars("Überhaupt, with Olé \x{5317}\x{4EB0}"); # hint perldoc may already convert
+ print $ansi_string;
+ # Ueberhaupt, with Ole Bei Jing
+
+=head1 FUNCTIONS
+
+=over 4
+
+=item C<replace_special_chars $text>
+
+Given a text string this method replaces the most common german umlaute,
+transforms '&' to '+' and escapes a single quote (').
+If there are still some non-ascii chars, we use unidecode to guess
+a sensible ascii presentation, C<perldoc Text::Unidecode>
+
+=back
+
+=head1 BUGS
+
+Nothing here yet.
+
+=head1 AUTHOR
+
+M.Bunkus
+J.Büren (Unidecode added)
+
+=cut
+
+
use SL::Iconv;
use SL::SEPA::XML::Transaction;
+use SL::DB::Helper::ReplaceSpecialChars qw(replace_special_chars);
sub new {
my $class = shift;
croak "Missing parameter: $missing_parameter" if ($missing_parameter);
croak "Missing parameter: creditor_id" if !$self->{creditor_id} && $self->{collection};
- map { $self->{$_} = $self->_replace_special_chars($self->{iconv}->convert($self->{$_})) } qw(company message_id creditor_id);
+ map { $self->{$_} = replace_special_chars($self->{iconv}->convert($self->{$_})) } qw(company message_id creditor_id);
}
sub add_transaction {
return 1;
}
-sub _replace_special_chars {
- my $self = shift;
- my $text = shift;
-
- my %special_chars = (
- 'ä' => 'ae',
- 'ö' => 'oe',
- 'ü' => 'ue',
- 'Ä' => 'Ae',
- 'Ö' => 'Oe',
- 'Ü' => 'Ue',
- 'ß' => 'ss',
- '&' => '+',
- '`' => '\'',
- );
-
- map { $text =~ s/$_/$special_chars{$_}/g; } keys %special_chars;
-
- # for all other non ascii chars 'OLÉ S.L.' and 'Årdberg AB'!
- use Text::Unidecode qw(unidecode);
- $text = unidecode($text);
-
- return $text;
-}
-
sub _format_amount {
my $self = shift;
my $amount = shift;
use strict;
+use SL::DB::Helper::ReplaceSpecialChars qw(replace_special_chars);
+
use Carp;
use Encode;
use List::Util qw(first);
map { $self->{$_} = $self->{sepa}->{iconv}->convert($params{$_}) } keys %params;
map { $self->{$_} =~ s/\s+//g } qw(src_iban src_bic dst_iban dst_bic);
- map { $self->{$_} = $self->{sepa}->_replace_special_chars($self->{$_}) } qw(company reference end_to_end_id);
+ map { $self->{$_} = replace_special_chars($self->{$_}) } qw(company reference end_to_end_id);
}
sub get {
-use Test::More tests => 137;
+use Test::More tests => 138;
use strict;
)->save;
$customer = new_customer(
- name => 'Test Customer',
+ name => 'Test Customer OLÉ S.L. Årdbärg AB',
iban => 'DE12500105170648489890',
bic => 'TESTBIC',
account_number => '648489890',
vc_depositor => $customer->depositor,
amount => $ar_transaction->amount,
);
+ require SL::SEPA::XML;
+ my $sepa_xml = SL::SEPA::XML->new('company' => $customer->name,
+ 'creditor_id' => "id",
+ 'src_charset' => 'UTF-8',
+ 'message_id' => "test",
+ 'grouped' => 1,
+ 'collection' => 1,
+ );
+ is($sepa_xml->{company} , 'Test Customer OLE S.L. Ardbaerg AB');
$ar_transaction->load;
$bt->load;