TT#39168 SMS: prepaid_billing fix error session closing

* perform_prepaid_billing() part of the code
      that cancels the session is moved into a new
      function cancel_prepaid_billing()
    * cancel_prepaid_billing is called in perform_prepaid_billing()
      and after init_prepaid_billing() if session status != 'ok'
    * add_journal_record() set default coding=0 if undefined

Change-Id: Id98f8e5b738953d5bb047f59657218f5fa6cab62
changes/71/22171/4
Kirill Solomko 8 years ago
parent 7198bc380d
commit a60ae36bb7

@ -118,6 +118,7 @@ sub create_item {
my $test_mode = $c->request->params->{test_mode} // '';
my $session;
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,
@ -157,14 +158,23 @@ 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 {

@ -303,13 +303,9 @@ sub perform_prepaid_billing {
my (%args) = @_;
my $c = $args{c};
my $session = $args{session} // return;
my ($amqr, $rpc, $status, $reason, $parts) =
@{$session}{qw(amqr_h rpc status reason parts)};
return unless $session;
return unless $amqr;
$reason //= 'unknown';
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}) {
@ -318,13 +314,28 @@ sub perform_prepaid_billing {
}
NGCP::Rating::Inew::SmsSession::destroy($amqr);
} else {
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);
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;
}
@ -335,6 +346,7 @@ sub add_journal_record {
$args{status} //= '';
$args{reason} //= '';
$args{coding} //= 0;
$args{subscriber_id} = $args{prov_subscriber}->id;
delete $args{c};

Loading…
Cancel
Save