From 54bfa88e4defbcfca91fac446d2e95da6fc0973e Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Thu, 6 Aug 2020 14:55:16 +0200 Subject: [PATCH] TT#88600 charge LNP number by type so far, a fee with destination "lnp:" allows to charge a call of a ported number by its lnp_provider_id. the problem with this is that the lnp_provider_id changes each time you purge&upload new lnp numbers. this change adds supports for fee destinations such as "lnpnumbertype:" to match the lnp number's 'type' field. it is a free text field, that can be set individually per lnp number. Change-Id: Ic791ffc8d2a3ed63d5bf4d4a0812d8ac01529925 --- rate-o-mat.pl | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/rate-o-mat.pl b/rate-o-mat.pl index be51793..21a660a 100755 --- a/rate-o-mat.pl +++ b/rate-o-mat.pl @@ -508,7 +508,7 @@ EOS ) or FATAL "Error preparing billing info statement: ".$billdbh->errstr; $sth_lnp_number = $billdbh->prepare( - "SELECT lnp_provider_id FROM billing.lnp_numbers WHERE id = billing.get_lnp_number_id(?,?)" + "SELECT lnp_provider_id,type FROM billing.lnp_numbers WHERE id = billing.get_lnp_number_id(?,?)" ) or FATAL "Error preparing LNP number statement: ".$billdbh->errstr; $sth_profile_info = $billdbh->prepare( @@ -1856,25 +1856,35 @@ sub get_profile_info { my @res; - if(defined $lnp_number and $lnp_number =~ /^\d+$/) { + if (defined $lnp_number and $lnp_number =~ /^\d+$/) { # let's see if we find the number in our LNP database $sth_lnp_number->execute($lnp_number, $start_time) or FATAL "Error executing LNP number statement: ".$sth_lnp_number->errstr; - my ($lnppid) = $sth_lnp_number->fetchrow_array(); + my ($lnppid,$lnpnumbertype) = $sth_lnp_number->fetchrow_array(); - if(defined $lnppid and $lnppid =~ /^\d+$/) { + if ($lnppid) { # let's see if we have a billing fee entry for the LNP provider ID $sth_lnp_profile_info->execute($bpid, $type, $direction, 'lnp:'.$lnppid) or FATAL "Error executing LNP profile info statement: ".$sth_lnp_profile_info->errstr; @res = $sth_lnp_profile_info->fetchrow_array(); FATAL "Error fetching LNP profile info: ".$sth_lnp_profile_info->errstr if $sth_lnp_profile_info->err; + + unless (@res) { + if (length($lnpnumbertype)) { + $sth_lnp_profile_info->execute($bpid, $type, $direction, 'lnpnumbertype:'.$lnpnumbertype) + or FATAL "Error executing LNP profile info statement: ".$sth_lnp_profile_info->errstr; + @res = $sth_lnp_profile_info->fetchrow_array(); + FATAL "Error fetching LNP profile info: ".$sth_lnp_profile_info->errstr + if $sth_lnp_profile_info->err; + } + } } } my $sth = $sth_profile_info; - unless(@res) { + unless (@res) { $sth->execute($bpid, $type, $direction, $source, $destination) or FATAL "Error executing profile info statement: ".$sth->errstr; @res = $sth->fetchrow_array();