MT#13903 Add voucher/cash topup forms for API

Change-Id: I0a32d1239ca011b46ee69e5b095d364802b92565
changes/59/2259/1
Andreas Granig 10 years ago committed by Rene Krenn
parent c378681a24
commit 9a9d5772ce

@ -16,6 +16,8 @@ require Catalyst::ActionRole::CheckTrailingSlash;
require Catalyst::ActionRole::HTTPMethods;
require Catalyst::ActionRole::RequireSSL;
use NGCP::Panel::Form::Topup::CashAPI;
with 'NGCP::Panel::Role::API';
class_has 'api_description' => (
@ -91,13 +93,18 @@ sub POST :Allow {
c => $c,
resource => $resource,
form => $form,
# due to the _id suffix, it would be converted to package.id and subscriber.id in
# the validation, so exclude them here
exceptions => [qw/package_id subscriber_id/],
);
if($c->user->roles eq "admin") {
} elsif($c->user->roles eq "reseller") {
$resource->{reseller_id} = $c->user->reseller_id;
}
# subscriber_id, voucher_code
# subscriber_id, package_id, amount
# if reseller, check if subscriber_id belongs to the calling reseller
try {
# update contract balance, update customer package_id, billing profile mappings etc.
@ -123,12 +130,7 @@ sub end : Private {
sub get_form {
my ($self, $c) = @_;
# TODO: use correct Form
if($c->user->roles eq "admin") {
#return NGCP::Panel::Form::Voucher::AdminAPI->new;
} elsif($c->user->roles eq "reseller") {
#return NGCP::Panel::Form::Voucher::ResellerAPI->new;
}
return NGCP::Panel::Form::Topup::CashAPI->new(ctx => $c);
}
# vim: set tabstop=4 expandtab:

@ -19,6 +19,8 @@ require Catalyst::ActionRole::RequireSSL;
use NGCP::Panel::Utils::Voucher;
use NGCP::Panel::Utils::DateTime;
use NGCP::Panel::Form::Topup::VoucherAPI;
with 'NGCP::Panel::Role::API';
class_has 'api_description' => (
@ -94,6 +96,7 @@ sub POST :Allow {
c => $c,
resource => $resource,
form => $form,
exceptions => [qw/subscriber_id/],
);
if($c->user->roles eq "admin") {
} elsif($c->user->roles eq "reseller") {
@ -102,8 +105,6 @@ sub POST :Allow {
my $code = NGCP::Panel::Utils::Voucher::encrypt_code($c, $resource->{code});
# subscriber_id, voucher_code
try {
# TODO: add billing.vouchers.active flag for internal/emergency use
@ -166,12 +167,7 @@ sub end : Private {
sub get_form {
my ($self, $c) = @_;
# TODO: use correct Form
if($c->user->roles eq "admin") {
#return NGCP::Panel::Form::Voucher::AdminAPI->new;
} elsif($c->user->roles eq "reseller") {
#return NGCP::Panel::Form::Voucher::ResellerAPI->new;
}
return NGCP::Panel::Form::Topup::VoucherAPI->new(ctx => $c);
}
# vim: set tabstop=4 expandtab:

@ -0,0 +1,47 @@
package NGCP::Panel::Form::Topup::CashAPI;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
has '+widget_wrapper' => ( default => 'Bootstrap' );
has_field 'submitid' => ( type => 'Hidden' );
sub build_render_list {[qw/submitid fields actions/]}
sub build_form_element_class { [qw/form-horizontal/] }
has_field 'id' => (
type => 'Hidden'
);
has_field 'subscriber_id' => (
type => 'PosInteger',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['The subscriber for which to topup the balance.']
},
);
has_field 'package_id' => (
type => 'PosInteger',
required => 0,
element_attr => {
rel => ['tooltip'],
title => ['The billing packge to switch to after topup.']
},
);
has_field 'amount' => (
type => 'Money',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['The amount to top up in cents of Euro/USD/etc.']
},
default => '0',
);
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,38 @@
package NGCP::Panel::Form::Topup::VoucherAPI;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
has '+widget_wrapper' => ( default => 'Bootstrap' );
has_field 'submitid' => ( type => 'Hidden' );
sub build_render_list {[qw/submitid fields actions/]}
sub build_form_element_class { [qw/form-horizontal/] }
has_field 'id' => (
type => 'Hidden'
);
has_field 'subscriber_id' => (
type => 'PosInteger',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['The subscriber for which to topup the balance.']
},
);
has_field 'amount' => (
type => 'Text',
required => 1,
maxlength => 128,
element_attr => {
rel => ['tooltip'],
title => ['The voucher code for the topup.']
},
);
1;
# vim: set tabstop=4 expandtab:
Loading…
Cancel
Save