our $API_VERSION = "1.0";
+our @orderType = qw( NEW CANCEL CHANGE );
+
+our @orderStatus = qw( NEW PENDING CANCELLED COMPLETED ERROR );
+
our $AUTOLOAD;
=head1 SYNOPSIS
'keyid' => $your_ikano_api_keyid,
'password' => $your_ikano_admin_user_password,
'debug' => 1 # remove this for prod
- 'reqpreviewonly' => 1 # remove this for prod
- 'minimalQualResp' => 1 # on quals, return pairs of ProductCustomId+TermsId only
- 'minimalOrderResp' => 1 # return minimal data on order responses
- );
-
+ 'reqpreviewonly' => 1 # remove this for prod
+ 'minimalQualResp' => 1 # on quals, return pairs of ProductCustomId+TermsId only
+ 'minimalOrderResp' => 1 # return minimal data on order responses
+ );
+
=head1 SUPPORTED API METHODS
+=over 4
+
=item ORDER
NOTE: supports orders by ProductCustomId only
DSLServiecId => 123,
} );
+=back
+
=cut
sub new {
sub req_ORDER {
my ($self, $args) = (shift, shift);
- my @validOrderTypes = qw( NEW CHANGE CANCEL );
-
- die "invalid order data" unless defined $args->{orderType}
+ return "invalid order data" unless defined $args->{orderType}
&& defined $args->{ProductCustomId} && defined $args->{DSLPhoneNumber};
- die "invalid order type ".$args->{orderType}
- unless grep($_ eq $args->{orderType}, @validOrderTypes);
+ return "invalid order type ".$args->{orderType}
+ unless grep($_ eq $args->{orderType}, @orderType);
# XXX: rewrite this uglyness?
my @ignoreFields = qw( orderType ProductCustomId );
sub resp_ORDER {
my ($self, $resphash, $reqhash) = (shift, shift);
- die "invalid order response" unless defined $resphash->{OrderResponse};
+ return "invalid order response" unless defined $resphash->{OrderResponse};
return $resphash->{OrderResponse};
}
sub req_CANCEL {
my ($self, $args) = (shift, shift);
- die "no order id for cancel" unless defined $args->{OrderId};
+ return "no order id for cancel" unless defined $args->{OrderId};
return Cancel => {
OrderId => [ $args->{OrderId} ],
sub resp_CANCEL {
my ($self, $resphash, $reqhash) = (shift, shift);
- die "invalid cancel response" unless defined $resphash->{OrderResponse};
+ return "invalid cancel response" unless defined $resphash->{OrderResponse};
return $resphash->{OrderResponse};
}
sub req_ORDERSTATUS {
my ($self, $args) = (shift, shift);
- die "ORDERSTATUS is supported by OrderId only"
+ return "ORDERSTATUS is supported by OrderId only"
if defined $args->{PhoneNumber} || !defined $args->{OrderId};
return OrderStatus => {
sub resp_ORDERSTATUS {
my ($self, $resphash, $reqhash) = (shift, shift);
- die "invalid order response" unless defined $resphash->{OrderResponse};
+ return "invalid order response" unless defined $resphash->{OrderResponse};
return $resphash->{OrderResponse};
}
sub req_ACCOUNTSTATUSCHANGE {
my ($self, $args) = (shift, shift);
- die "invalid account status change request" unless defined $args->{type}
+ return "invalid account status change request" unless defined $args->{type}
&& defined $args->{DSLServiceId} && defined $args->{DSLPhoneNumber};
return AccountStatusChange => {
sub resp_ACCOUNTSTATUSCHANGE {
my ($self, $resphash, $reqhash) = (shift, shift);
- die "invalid account status change response"
+ return "invalid account status change response"
unless defined $resphash->{AccountStatusChangeResponse}
&& defined $resphash->{AccountStatusChangeResponse}->{Customer};
return $resphash->{AccountStatusChangeResponse}->{Customer};
sub req_CUSTOMERLOOKUP {
my ($self, $args) = (shift, shift);
- die "invalid customer lookup request" unless defined $args->{PhoneNumber};
+ return "invalid customer lookup request" unless defined $args->{PhoneNumber};
return CustomerLookup => {
PhoneNumber => [ $args->{PhoneNumber} ],
};
sub resp_CUSTOMERLOOKUP {
my ($self, $resphash, $reqhash) = (shift, shift);
- die "invalid customer lookup response"
+ return "invalid customer lookup response"
unless defined $resphash->{CustomerLookupResponse}
&& defined $resphash->{CustomerLookupResponse}->{Customer};
return $resphash->{CustomerLookupResponse}->{Customer};
sub req_PASSWORDCHANGE {
my ($self, $args) = (shift, shift);
- die "invalid arguments to PASSWORDCHANGE"
+ return "invalid arguments to PASSWORDCHANGE"
unless defined $args->{DSLPhoneNumber} && defined $args->{NewPassword};
return PasswordChange => {
sub resp_PASSWORDCHANGE {
my ($self, $resphash, $reqhash) = (shift, shift);
- die "invalid change password response" unless defined $resphash->{ChangePasswordResponse};
- return $resphash->{ChangePasswordResponse};
+ return "invalid change password response"
+ unless defined $resphash->{ChangePasswordResponse}
+ && defined $resphash->{ChangePasswordResponse}->{Customer};
+ $resphash->{ChangePasswordResponse}->{Customer};
}
sub req_PREQUAL {
sub resp_PREQUAL {
my ($self, $resphash, $reqhash) = (shift, shift);
- die "invalid prequal response" unless defined $resphash->{PreQualResponse};
+ return "invalid prequal response" unless defined $resphash->{PreQualResponse};
return $resphash->{PreQualResponse};
}
+sub orderTypes {
+ @orderType;
+}
+
sub AUTOLOAD {
my $self = shift;
# XXX: validate against their schema to ensure we're not sending invalid XML?
- print "DEBUG REQUEST\n\tHASH:\n ".Dumper($reqhash)."\n\tXML:\n $reqxml \n\n" if $self->{debug};
+ warn "DEBUG REQUEST\n\tHASH:\n ".Dumper($reqhash)."\n\tXML:\n $reqxml \n\n"
+ if $self->{debug};
my $ua = LWP::UserAgent->new;
- die "posting disabled for testing" if $self->{reqpreviewonly};
+ return "posting disabled for testing" if $self->{reqpreviewonly};
my $resp = $ua->post($URL, Content_Type => 'text/xml', Content => $reqxml);
- die $resp->status_line unless $resp->is_success;
+ return "invalid HTTP response from Ikano: " . $resp->status_line
+ unless $resp->is_success;
my $respxml = $resp->decoded_content;
+
+ $xs = new Net::Ikano::XMLUtil(RootName => undef, SuppressEmpty => '',
+ ForceArray => [ 'Address', 'Product', 'StaticIp', 'OrderNotes' ] );
my $resphash = $xs->XMLin($respxml);
- print "DEBUG RESPONSE\n\tHASH:\n ".Dumper($resphash)."\n\tXML:\n $respxml" if $self->{debug};
+ warn "DEBUG RESPONSE\n\tHASH:\n ".Dumper($resphash)."\n\tXML:\n $respxml"
+ if $self->{debug};
# XXX: validate against their schema to ensure they didn't send us invalid XML?
- die "invalid response" unless defined $resphash->{responseid}
- && defined $resphash->{version} && defined $resphash->{type};
+ return "invalid response received from Ikano"
+ unless defined $resphash->{responseid} && defined $resphash->{version}
+ && defined $resphash->{type};
- die "FAILURE response received: ".$resphash->{FailureResponse}->{FailureMessage}
+ return "FAILURE response received from Ikano: "
+ . $resphash->{FailureResponse}->{FailureMessage}
if $resphash->{type} eq 'FAILURE';
my $validRespTypes = {
'CUSTOMERLOOKUP' => qw( CUSTOMERLOOKUP ),
};
- die "invalid response type for request type"
+ return "invalid response type ".$resphash->{type}." for request type $cmd"
unless grep( $_ eq $resphash->{type}, $validRespTypes->{$cmd});
return $self->$respsub($resphash,$reqhash);