MT#62084 contract_id field for /api/topupcash and /api/topupvoucher

so far the topup api rails had just a subscriber_id field.
for the AUI migration a contract_id field is required.

Change-Id: I2b53971ecd0abe06f7e0ff0e72b9bb83d12a4f6b
mr13.3
Rene Krenn 2 months ago
parent 60b3917095
commit 143bd0dba9

@ -81,6 +81,7 @@ sub POST :Allow {
last unless NGCP::Panel::Utils::Voucher::check_topup(c => $c,
now => $now,
subscriber_id => $resource->{subscriber_id},
contract_id => $resource->{contract_id},
package_id => $resource->{package_id},
resource => $resource,
entities => $entities,

@ -80,6 +80,7 @@ sub POST :Allow {
last unless NGCP::Panel::Utils::Voucher::check_topup(c => $c,
now => $now,
subscriber_id => $resource->{subscriber_id},
contract_id => $resource->{contract_id},
plain_code => $resource->{code},
resource => $resource,
entities => $entities,

@ -16,13 +16,22 @@ has_field 'id' => (
has_field 'subscriber_id' => (
type => 'PosInteger',
required => 1,
required => 0,
element_attr => {
rel => ['tooltip'],
title => ['The subscriber for which to topup the balance.']
},
);
has_field 'contract_id' => (
type => 'PosInteger',
required => 0,
element_attr => {
rel => ['tooltip'],
title => ['The contract for which to topup the balance.']
},
);
has_field 'package_id' => (
type => 'PosInteger',
required => 0,

@ -16,13 +16,22 @@ has_field 'id' => (
has_field 'subscriber_id' => (
type => 'PosInteger',
required => 1,
required => 0,
element_attr => {
rel => ['tooltip'],
title => ['The subscriber for which to topup the balance.']
},
);
has_field 'contract_id' => (
type => 'PosInteger',
required => 0,
element_attr => {
rel => ['tooltip'],
title => ['The contract for which to topup the balance.']
},
);
has_field 'code' => (
type => 'Text',
required => 1,

@ -3,6 +3,7 @@ use Sipwise::Base;
use Crypt::Rijndael;
use MIME::Base64;
use NGCP::Panel::Utils::DateTime;
use NGCP::Panel::Utils::Contract qw();
sub encrypt_code {
my ($c, $plain) = @_;
@ -44,7 +45,7 @@ sub decrypt_code {
sub check_topup {
my %params = @_;
my ($c,$plain_code,$voucher_id,$now,$subscriber_id,$contract,$package_id,$schema,$err_code,$entities,$resource) = @params{qw/c plain_code voucher_id now subscriber_id contract package_id schema err_code entities resource/};
my ($c,$plain_code,$voucher_id,$now,$subscriber_id,$contract_id,$contract,$package_id,$schema,$err_code,$entities,$resource) = @params{qw/c plain_code voucher_id now subscriber_id contract_id contract package_id schema err_code entities resource/};
$schema //= $c->model('DB');
$now //= NGCP::Panel::Utils::DateTime::current_local;
@ -70,6 +71,15 @@ sub check_topup {
}
$entities->{subscriber} = $subscriber if defined $entities;
$contract //= $subscriber->contract;
} elsif (defined $contract_id) {
$contract = NGCP::Panel::Utils::Contract::get_customer_rs(c => $c)->find($contract_id) unless $contract;
unless($contract) {
if (defined $resource) {
$resource->{contract_id} = undef if exists $resource->{contract_id};
$resource->{contract}->{id} = undef if (exists $resource->{contract} && exists $resource->{contract}->{id});
}
return 0 unless &{$err_code}("Unknown contract ID $contract_id.");
}
}
$entities->{contract} = $contract if defined $entities;

Loading…
Cancel
Save