Skip to content

Commit

Permalink
Broadband - make list default action and add event for MAC request. S…
Browse files Browse the repository at this point in the history
…sl - clearer code
  • Loading branch information
ukfsn committed Aug 27, 2010
1 parent 02904ad commit c526223
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
16 changes: 15 additions & 1 deletion Kirin/Plugin/Broadband.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ use strict;
use base 'Kirin::Plugin';
use Net::DSLProvider;
sub user_name { "Broadband" }
sub default_action { "view" }
sub default_action { "list" }
use constant MAC_RE => qr/[A-Z0-9]{12,14}\/[A-Z]{2}[0-9]{2}[A-Z]/;
my $murphx;

sub list {
my ($self, $mm) = @_;

my @bbs = Kirin::DB::Broadband->search(customer => $mm->{customer});
$mm->respond("plugins/broadband/list", bbs => \@bbs);
}

sub order {
my ($self, $mm) = @_;
my $clid = $mm->param("clid");
Expand Down Expand Up @@ -88,6 +95,13 @@ sub request_mac {
if ($@) {
$mm->message("An error occurred and your request could not be completed");
}
Kirin::DB::BroadbandEvent->create({
broadband => $bb,
timestamp => Time::Piece->new(),
class => "mac",
token => $out,
description => "Request for MAC"
});
$mm->respond("plugins/broadband/mac-requested",
mac_information => \%out # Template will sort out requested/got
);
Expand Down
19 changes: 8 additions & 11 deletions Kirin/Plugin/Ssl.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ sub order {
use Data::Dumper; warn Dumper($request);
$request->{CSR} = $csr;

# XXX Raise an invoice for the order and get payment.

my $order = undef;
if ( ! $params->{order} || ! ( $order = Kirin::DB::Orders->retrieve($params->{order}) ) ) {
my @product = Kirin::DB::SslProducts->search( name => $params->{ProductType} );
Expand All @@ -82,8 +80,6 @@ sub order {
cost => $product[0]->price
} );

my $json = JSON->new->allow_blessed;

$order = Kirin::DB::Orders->insert( {
customer => $mm->{customer},
order_type => 'SSL Certificate',
Expand All @@ -96,8 +92,8 @@ sub order {
request => $request
}),
invoice => $invoice->id,
status => 'New Order'
});
$order->set_status("New Order");

$order->set_status("Invoiced");
$mm->{order} = $order->id;
Expand All @@ -112,7 +108,7 @@ sub order {

$self->view($mm, $order->id);
}

sub view {
my ($self, $mm, $id) = @_;

Expand All @@ -133,12 +129,11 @@ sub view {

sub process {
my ($self, $id) = @_;
return if ! $id;
if ( ! $id ) { return; }

my $order = Kirin::DB::Orders->retrieve($id);
return if ! $order;

return if ! $order->invoice->paid;
if ( ! $order ) { return; }
if ( ! $order->invoice->paid ) { return; }

my $op = $json->decode($order->parameters);

Expand Down Expand Up @@ -188,14 +183,16 @@ sub download {
}

sub _setup_db { # Piggyback on this method as it's called when ->args is ready
my $db = shift;
Kirin->args->{$_}
|| die "You need to configure $_ in your Kirin configuration"
for qw/enom_reseller_username enom_reseller_password/;
$enom = Net::eNom->new(
username => Kirin->args->{enom_reseller_username},
password => Kirin->args->{enom_reseller_password},
test => 1); # XXX
shift->_ensure_table("ssl_certificate");
$db->_ensure_table("ssl_certificate");
$db->_ensure_table("ssl_products");
Kirin::DB::SslCertificate->has_a(customer => "Kirin::DB::Customer");
Kirin::DB::Customer->has_many(ssls => "Kirin::DB::SslCertificate");
}
Expand Down

0 comments on commit c526223

Please sign in to comment.