diff --git a/.gitignore b/.gitignore index 055888c572..8d1568bfd6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ SCCS .git _darcs .cvsignore +.vscode Descrip.MMS DESCRIP.MMS descrip.mms diff --git a/debian/control b/debian/control index 95dc5a2b93..5ef37f0e8e 100644 --- a/debian/control +++ b/debian/control @@ -130,8 +130,6 @@ Depends: sox, ${misc:Depends}, ${perl:Depends}, -Recommends: - libngcp-rating-inew-perl, Description: catalyst based panel application for NGCP A completely overhauled provisioning interface for the NGCP system. diff --git a/lib/NGCP/Panel/Controller/API/SMS.pm b/lib/NGCP/Panel/Controller/API/SMS.pm index 05ddf41bcc..b5199bb455 100644 --- a/lib/NGCP/Panel/Controller/API/SMS.pm +++ b/lib/NGCP/Panel/Controller/API/SMS.pm @@ -7,6 +7,7 @@ use HTTP::Status qw(:constants); use NGCP::Panel::Utils::Utf8; use NGCP::Panel::Utils::SMS; use NGCP::Panel::Utils::Preferences; +use UUID; __PACKAGE__->set_config(); @@ -116,21 +117,25 @@ sub create_item { return; } my $test_mode = $c->request->params->{test_mode} // ''; - my $session; + + my ($uuid, $session_id); + UUID::generate($uuid); + UUID::unparse($uuid, $session_id); + + my $session = { + caller => $resource->{caller}, + callee => $resource->{callee}, + status => 'ok', + reason => 'accepted', + parts => [], + sid => $session_id, + rpc => $parts, + coding => undef, + }; + my $smsc_peer = 'default'; - my $pp_billing_performed = 0; try { - my $parts = NGCP::Panel::Utils::SMS::get_number_of_parts($resource->{text}); - $session = NGCP::Panel::Utils::SMS::init_prepaid_billing(c => $c, - prov_subscriber => $subscriber, - parts => $parts, - caller => $resource->{caller}, - callee => $resource->{callee} - ); - unless ($session && $session->{status} eq 'ok') { - die($session->{reason} // - "Internal server error when preparing sms billing"); - } + $session->{parts} = NGCP::Panel::Utils::SMS::get_number_of_parts($resource->{text}); $session->{coding} = NGCP::Panel::Utils::SMS::get_coding($resource->{text}); @@ -159,22 +164,11 @@ sub create_item { } - NGCP::Panel::Utils::SMS::perform_prepaid_billing(c => $c, - session => $session - ); - $pp_billing_performed = 1; - if ($session->{status} eq 'failed') { die $session->{reason}."\n"; } - } catch($e) { $c->log->error($e); - unless ($pp_billing_performed) { - NGCP::Panel::Utils::SMS::cancel_prepaid_billing(c => $c, - session => $session - ); - } if ($session && $session->{reason} eq 'insufficient credit') { $self->error($c, HTTP_PAYMENT_REQUIRED, "Not enough credit to send the sms"); } else { diff --git a/lib/NGCP/Panel/Form/BillingProfile/Reseller.pm b/lib/NGCP/Panel/Form/BillingProfile/Reseller.pm index f829c17d88..04012f54b6 100644 --- a/lib/NGCP/Panel/Form/BillingProfile/Reseller.pm +++ b/lib/NGCP/Panel/Form/BillingProfile/Reseller.pm @@ -58,7 +58,6 @@ has_field 'prepaid_library' => ( type => 'Select', options => [ { value => 'libswrate', label => 'libswrate' }, - { value => 'libinewrate', label => 'libinewrate' }, ], element_attr => { rel => ['tooltip'], diff --git a/lib/NGCP/Panel/I18N/de.po b/lib/NGCP/Panel/I18N/de.po index 1820c7a71c..09575af8cf 100644 --- a/lib/NGCP/Panel/I18N/de.po +++ b/lib/NGCP/Panel/I18N/de.po @@ -15195,10 +15195,6 @@ msgstr "tippt gerade …" msgid "left" msgstr "hat den Chat verlassen" -#: lib/NGCP/Panel/Utils/DbStrings.pm -msgid "libinewrate" -msgstr "libinewrate" - #: lib/NGCP/Panel/Utils/DbStrings.pm msgid "libswrate" msgstr "libswrate" diff --git a/lib/NGCP/Panel/I18N/messages.pot b/lib/NGCP/Panel/I18N/messages.pot index 6a8390ece7..7cc4878a16 100644 --- a/lib/NGCP/Panel/I18N/messages.pot +++ b/lib/NGCP/Panel/I18N/messages.pot @@ -15090,10 +15090,6 @@ msgstr "" msgid "left" msgstr "" -#: lib/NGCP/Panel/Utils/DbStrings.pm -msgid "libinewrate" -msgstr "" - #: lib/NGCP/Panel/Utils/DbStrings.pm msgid "libswrate" msgstr "" diff --git a/lib/NGCP/Panel/Utils/SMS.pm b/lib/NGCP/Panel/Utils/SMS.pm index 5f8e0a8794..c1f8dba7d6 100644 --- a/lib/NGCP/Panel/Utils/SMS.pm +++ b/lib/NGCP/Panel/Utils/SMS.pm @@ -4,7 +4,6 @@ use Sipwise::Base; use LWP::UserAgent; use URI; use POSIX; -use UUID; use Module::Load::Conditional qw/can_load/; use NGCP::Panel::Utils::Utf8; @@ -184,148 +183,6 @@ sub get_number_of_parts { return ceil(length($text) / $maxlen); } -sub init_prepaid_billing { - my (%args) = @_; - my $c = $args{c}; - my $prov_subscriber = $args{prov_subscriber}; - my $parts = $args{parts}; - my $caller = $args{caller}; - my $callee = $args{callee}; - - my ($uuid, $session_id); - UUID::generate($uuid); - UUID::unparse($uuid, $session_id); - - my $session = { - caller => $caller, - callee => $callee, - status => 'ok', - reason => 'accepted', - parts => [], - sid => $session_id, - rpc => $parts, - }; - - my ($prepaid_lib, $is_prepaid); - my $bm_actual = NGCP::Panel::Utils::BillingMappings::get_actual_billing_mapping(c => $c, contract => $prov_subscriber->contract, ); - $prepaid_lib = $bm_actual->billing_profile->prepaid_library if $bm_actual; - $is_prepaid = ($bm_actual->billing_profile->prepaid ? 1 : 0) if $bm_actual; - - # currently only inew rating supported, let others pass - unless ($is_prepaid && $prepaid_lib && $prepaid_lib eq "libinewrate") { - $session->{reason} = 'not prepaid/libinewrate'; - return $session; - } - - my $use_list = { 'NGCP::Rating::Inew::SmsSession' => undef }; - unless(can_load(modules => $use_list, nocache => 0, autoload => 0)) { - $c->log->error(sprintf("Failed to load NGCP::Rating::Inew::SmsSession for sms=%s from=%s to=%s",$session_id, $c->qs($caller), $c->qs($callee))); - $session->{status} = 'failed'; - $session->{reason} = - sprintf 'failed to init sms session sid=%s from=%s to=%s', - $session_id, $c->qs($caller), $c->qs($callee); - return; - } - my $amqr = NGCP::Rating::Inew::SmsSession::init( - $c->config->{libinewrate}->{soap_uri}, - $c->config->{libinewrate}->{openwire_uri}, - ); - unless($amqr) { - $c->log->error(sprintf("Failed to create sms amqr handle for sms sid=%s from=%s to=%s",$session_id, $c->qs($caller), $c->qs($callee))); - $session->{status} = 'failed'; - $session->{reason} = - sprintf 'failed to create sms session sid=%s from=%s to=%s', - $session_id, $c->qs($caller), $c->qs($callee); - return; - } - $session->{amqr_h} = $amqr; - - # Reserve credit for each part, and then commit each reservation. - # If we can charge multiple times within one session - perfect. - # Otherwise we have to create one session per part, store it in an - # array, then after all reservations were successful, commit each - # of them! - for(my $i = 0; $i < $parts; ++$i) { - my $has_credit = 1; - my $this_session_id = $session_id."-".$i; - - my $sess = NGCP::Rating::Inew::SmsSession::session_create( - $amqr, $this_session_id, $caller, $callee, sub { - $has_credit = 0; - }); - - if (not defined $sess or $sess == -1) { - $c->log->error("Failed to create sms rating session from " . $c->qs($caller) . ' to ' . $c->qs($callee) . " with session id $this_session_id"); - $session->{status} = 'failed'; - $session->{reason} = 'failed to create sms session'; - last; - } elsif ($sess == 0) { - $c->log->error("Remote denied sms rating session from " . $c->qs($caller) . ' to ' . $c->qs($callee) . " with session id $this_session_id (subscriber=inactive)"); - $session->{status} = 'failed'; - $session->{reason} = 'remote denied sms session (subscriber=inactive)'; - last; - } - - unless($has_credit) { - $c->log->info("No credit for sms from " . $c->qs($caller) . ' to ' . $c->qs($callee) . " with session id $this_session_id"); - $session->{status} = 'failed'; - $session->{reason} = 'insufficient credit'; - NGCP::Rating::Inew::SmsSession::session_destroy($sess); - last; - } - - push @{$session->{parts}}, $sess; - - unless(NGCP::Rating::Inew::SmsSession::session_sms_reserve($sess)) { - $c->log->error("Failed to reserve sms session from " . $c->qs($caller) . ' to ' . $c->qs($callee) . " with session id $this_session_id"); - $session->{status} = 'failed'; - $session->{reason} = 'failed to reserve sms session'; - last; - } - } - return $session; -} - -sub perform_prepaid_billing { - my (%args) = @_; - my $c = $args{c}; - my $session = $args{session} // return; - my $amqr = $session->{amqr_h} // return; - my ($rpc, $status, $reason, $parts) = - @{$session}{qw(rpc status reason parts)}; - - if ($status eq 'ok' && $rpc == $#{$parts}+1) { - foreach my $sess (@{$parts}) { - NGCP::Rating::Inew::SmsSession::session_sms_commit($sess); - NGCP::Rating::Inew::SmsSession::session_destroy($sess); - } - NGCP::Rating::Inew::SmsSession::destroy($amqr); - } else { - cancel_prepaid_billing(%args); - } - return; -} - -sub cancel_prepaid_billing { - my (%args) = @_; - my $c = $args{c}; - my $session = $args{session} // return; - my $amqr = $session->{amqr_h} // return; - my ($rpc, $status, $reason, $parts) = - @{$session}{qw(rpc status reason parts)}; - - $reason //= 'unknown'; - - foreach my $sess (@{$parts}) { - NGCP::Rating::Inew::SmsSession::session_set_cancel_reason($sess, $reason); - NGCP::Rating::Inew::SmsSession::session_sms_discard($sess); - NGCP::Rating::Inew::SmsSession::session_destroy($sess); - } - NGCP::Rating::Inew::SmsSession::destroy($amqr); - - return; -} - sub add_journal_record { my (%args) = @_; my $c = $args{c};