5 use Net::Ikano::XMLUtil;
11 Net::Ikano - Interface to Ikano wholesale DSL API
19 our $VERSION = '0.01';
21 our $URL = 'https://orders.value.net/OsirisWebService/XmlApi.aspx';
23 our $SCHEMA_ROOT = 'https://orders.value.net/osiriswebservice/schema/v1';
25 our $API_VERSION = "1.0";
27 our @orderType = qw( NEW CANCEL CHANGE );
29 our @orderStatus = qw( NEW PENDING CANCELLED COMPLETED ERROR );
37 my $ikano = Net::Ikano->new(
38 'keyid' => $your_ikano_api_keyid,
39 'password' => $your_ikano_admin_user_password,
40 'debug' => 1 # remove this for prod
41 'reqpreviewonly' => 1 # remove this for prod
42 'minimalQualResp' => 1 # on quals, return pairs of ProductCustomId+TermsId only
43 'minimalOrderResp' => 1 # return minimal data on order responses
46 =head1 SUPPORTED API METHODS
50 NOTE: supports orders by ProductCustomId only
55 ProductCustomId => 'abc123',
57 DSLPhoneNumber => '4167800000',
60 CompanyName => 'abc co',
64 ContactMethod => 'PHONE',
65 ContactPhoneNumber => '4167800000',
66 ContactEmail => 'x@x.ca',
68 DateToOrder => '2010-11-29',
69 RequestClientIP => '127.0.0.1',
72 CurrentProvider => '',
87 AddressLine1 => '123 Test Rd',
88 AddressUnitType => '',
89 AddressUnitValue => '',
90 AddressCity => 'Toronto',
92 ZipCode => 'M6C 2J9', # or 12345
93 Country => 'CA', # or US
94 LocationType => 'R', # or B
95 PhoneNumber => '4167800000',
96 RequestClientIP => '127.0.0.1',
97 CheckNetworks => 'ATT,BELLCA,VER', # either one or command-separated like this
110 $ikano->PASSWORDCHANGE( {
111 DSLPhoneNumber => '4167800000',
112 NewPassword => 'xxx',
118 $ikano->CUSTOMERLOOKUP( { PhoneNumber => '4167800000' } );
121 =item ACCOUNTSTATUSCHANGE
123 $ikano->ACCOUNTSTATUSCHANGE(( {
125 DSLPhoneNumber => '4167800000',
132 my ($class,%data) = @_;
133 die "missing keyid and/or password"
134 unless defined $data{'keyid'} && defined $data{'password'};
136 'keyid' => $data{'keyid'},
137 'password' => $data{'password'},
138 'username' => $data{'username'} ? $data{'username'} : 'admin',
139 'debug' => $data{'debug'} ? $data{'debug'} : 0,
140 'reqpreviewonly' => $data{'reqpreviewonly'} ? $data{'reqpreviewonly'} : 0,
148 my ($self, $args) = (shift, shift);
150 return "invalid order data" unless defined $args->{orderType}
151 && defined $args->{ProductCustomId} && defined $args->{DSLPhoneNumber};
152 return "invalid order type ".$args->{orderType}
153 unless grep($_ eq $args->{orderType}, @orderType);
155 # XXX: rewrite this uglyness?
156 my @ignoreFields = qw( orderType ProductCustomId );
158 while ( my ($k,$v) = each(%$args) ) {
159 $orderArgs{$k} = [ $v ] unless grep($_ eq $k,@ignoreFields);
163 type => $args->{orderType},
165 ProductCustomId => [ split(',',$args->{ProductCustomId}) ],
170 my ($self, $resphash, $reqhash) = (shift, shift);
171 return "invalid order response" unless defined $resphash->{OrderResponse};
172 return $resphash->{OrderResponse};
176 my ($self, $args) = (shift, shift);
178 return "no order id for cancel" unless defined $args->{OrderId};
181 OrderId => [ $args->{OrderId} ],
186 my ($self, $resphash, $reqhash) = (shift, shift);
187 return "invalid cancel response" unless defined $resphash->{OrderResponse};
188 return $resphash->{OrderResponse};
191 sub req_ORDERSTATUS {
192 my ($self, $args) = (shift, shift);
194 return "ORDERSTATUS is supported by OrderId only"
195 if defined $args->{PhoneNumber} || !defined $args->{OrderId};
197 return OrderStatus => {
198 OrderId => [ $args->{OrderId} ],
202 sub resp_ORDERSTATUS {
203 my ($self, $resphash, $reqhash) = (shift, shift);
204 return "invalid order response" unless defined $resphash->{OrderResponse};
205 return $resphash->{OrderResponse};
208 sub req_ACCOUNTSTATUSCHANGE {
209 my ($self, $args) = (shift, shift);
210 return "invalid account status change request" unless defined $args->{type}
211 && defined $args->{DSLServiceId} && defined $args->{DSLPhoneNumber};
213 return AccountStatusChange => {
214 type => $args->{type},
215 DSLPhoneNumber => [ $args->{DSLPhoneNumber} ],
216 DSLServiceId => [ $args->{DSLServiceId} ],
220 sub resp_ACCOUNTSTATUSCHANGE {
221 my ($self, $resphash, $reqhash) = (shift, shift);
222 return "invalid account status change response"
223 unless defined $resphash->{AccountStatusChangeResponse}
224 && defined $resphash->{AccountStatusChangeResponse}->{Customer};
225 return $resphash->{AccountStatusChangeResponse}->{Customer};
228 sub req_CUSTOMERLOOKUP {
229 my ($self, $args) = (shift, shift);
230 return "invalid customer lookup request" unless defined $args->{PhoneNumber};
231 return CustomerLookup => {
232 PhoneNumber => [ $args->{PhoneNumber} ],
236 sub resp_CUSTOMERLOOKUP {
237 my ($self, $resphash, $reqhash) = (shift, shift);
238 return "invalid customer lookup response"
239 unless defined $resphash->{CustomerLookupResponse}
240 && defined $resphash->{CustomerLookupResponse}->{Customer};
241 return $resphash->{CustomerLookupResponse}->{Customer};
244 sub req_PASSWORDCHANGE {
245 my ($self, $args) = (shift, shift);
246 return "invalid arguments to PASSWORDCHANGE"
247 unless defined $args->{DSLPhoneNumber} && defined $args->{NewPassword};
249 return PasswordChange => {
250 DSLPhoneNumber => [ $args->{DSLPhoneNumber} ],
251 NewPassword => [ $args->{NewPassword} ],
255 sub resp_PASSWORDCHANGE {
256 my ($self, $resphash, $reqhash) = (shift, shift);
257 return "invalid change password response"
258 unless defined $resphash->{ChangePasswordResponse};
259 return $resphash->{ChangePasswordResponse};
263 my ($self, $args) = (shift, shift);
266 map { $_ => [ $args->{$_} ] }
267 qw( AddressLine1 AddressUnitType AddressUnitValue AddressCity
268 AddressState ZipCode LocationType Country )
270 ( map { $_ => [ $args->{$_} ] } qw( PhoneNumber RequestClientIP ) ),
272 Network => [ split(',',$args->{CheckNetworks}) ]
278 my ($self, $resphash, $reqhash) = (shift, shift);
279 return "invalid prequal response" unless defined $resphash->{PreQualResponse};
280 return $resphash->{PreQualResponse};
286 $AUTOLOAD =~ /(^|::)(\w+)$/ or die "invalid AUTOLOAD: $AUTOLOAD";
288 return if $cmd eq 'DESTROY';
290 my $reqsub = "req_$cmd";
291 my $respsub = "resp_$cmd";
292 die "invalid request type $cmd"
293 unless defined &$reqsub && defined &$respsub;
297 my $xs = new Net::Ikano::XMLUtil(RootName => undef, SuppressEmpty => 1 );
301 keyid => $self->{keyid},
302 username => $self->{username},
303 password => $self->{password},
304 version => $API_VERSION,
305 xmlns => "$SCHEMA_ROOT/osirisrequest.xsd",
306 $self->$reqsub($reqargs),
311 my $reqxml = "<?xml version=\"1.0\"?>\n".$xs->XMLout($reqhash, NoSort => 1);
313 # XXX: validate against their schema to ensure we're not sending invalid XML?
315 warn "DEBUG REQUEST\n\tHASH:\n ".Dumper($reqhash)."\n\tXML:\n $reqxml \n\n"
318 my $ua = LWP::UserAgent->new;
320 return "posting disabled for testing" if $self->{reqpreviewonly};
322 my $resp = $ua->post($URL, Content_Type => 'text/xml', Content => $reqxml);
323 return "invalid HTTP response from Ikano: " . $resp->status_line
324 unless $resp->is_success;
325 my $respxml = $resp->decoded_content;
327 $xs = new Net::Ikano::XMLUtil(RootName => undef, SuppressEmpty => '',
328 ForceArray => [ 'Address', 'Product', 'StaticIp', 'OrderNotes' ] );
329 my $resphash = $xs->XMLin($respxml);
331 warn "DEBUG RESPONSE\n\tHASH:\n ".Dumper($resphash)."\n\tXML:\n $respxml"
334 # XXX: validate against their schema to ensure they didn't send us invalid XML?
336 return "invalid response received from Ikano"
337 unless defined $resphash->{responseid} && defined $resphash->{version}
338 && defined $resphash->{type};
340 return "FAILURE response received from Ikano: "
341 . $resphash->{FailureResponse}->{FailureMessage}
342 if $resphash->{type} eq 'FAILURE';
344 my $validRespTypes = {
345 'PREQUAL' => qw( PREQUAL ),
346 'ORDERSTATUS' => qw( ORDERSTATUS ),
347 'ORDER' => qw( NEWORDER CHANGEORDER CANCELORDER ),
348 'CANCEL' => qw( ORDERCANCEL ),
349 'PASSWORDCHANGE' => qw( PASSWORDCHANGE ),
350 'ACCOUNTSTATUSCHANGE' => qw( ACCOUNTSTATUSCHANGE ),
351 'CUSTOMERLOOKUP' => qw( CUSTOMERLOOKUP ),
354 return "invalid response type ".$resphash->{type}." for request type $cmd"
355 unless grep( $_ eq $resphash->{type}, $validRespTypes->{$cmd});
357 return $self->$respsub($resphash,$reqhash);
363 Erik Levinson, C<< <levinse at freeside.biz> >>
367 Please report any bugs or feature requests to C<bug-net-ikano at rt.cpan.org>, or through
368 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Ikano>. I will be notified, and then you'll
369 automatically be notified of progress on your bug as I make changes.
373 You can find documentation for this module with the perldoc command.
377 You can also look for information at:
381 =item * RT: CPAN's request tracker
383 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Ikano>
385 =item * AnnoCPAN: Annotated CPAN documentation
387 L<http://annocpan.org/dist/Net-Ikano>
391 L<http://cpanratings.perl.org/d/Net-Ikano>
395 L<http://search.cpan.org/dist/Net-Ikano>
399 =head1 ACKNOWLEDGEMENTS
401 This module was developed by Freeside Internet Services, Inc.
402 If you need a complete, open-source web-based application to manage your
403 customers, billing and trouble ticketing, please visit http://freeside.biz/
405 =head1 COPYRIGHT & LICENSE
407 Copyright 2010 Freeside Internet Services, Inc.
410 This program is free software; you can redistribute it and/or modify it
411 under the same terms as Perl itself.