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 && defined $resphash->{ChangePasswordResponse}->{Customer};
260 $resphash->{ChangePasswordResponse}->{Customer};
264 my ($self, $args) = (shift, shift);
267 map { $_ => [ $args->{$_} ] }
268 qw( AddressLine1 AddressUnitType AddressUnitValue AddressCity
269 AddressState ZipCode LocationType Country )
271 ( map { $_ => [ $args->{$_} ] } qw( PhoneNumber RequestClientIP ) ),
273 Network => [ split(',',$args->{CheckNetworks}) ]
279 my ($self, $resphash, $reqhash) = (shift, shift);
280 return "invalid prequal response" unless defined $resphash->{PreQualResponse};
281 return $resphash->{PreQualResponse};
287 $AUTOLOAD =~ /(^|::)(\w+)$/ or die "invalid AUTOLOAD: $AUTOLOAD";
289 return if $cmd eq 'DESTROY';
291 my $reqsub = "req_$cmd";
292 my $respsub = "resp_$cmd";
293 die "invalid request type $cmd"
294 unless defined &$reqsub && defined &$respsub;
298 my $xs = new Net::Ikano::XMLUtil(RootName => undef, SuppressEmpty => 1 );
302 keyid => $self->{keyid},
303 username => $self->{username},
304 password => $self->{password},
305 version => $API_VERSION,
306 xmlns => "$SCHEMA_ROOT/osirisrequest.xsd",
307 $self->$reqsub($reqargs),
312 my $reqxml = "<?xml version=\"1.0\"?>\n".$xs->XMLout($reqhash, NoSort => 1);
314 # XXX: validate against their schema to ensure we're not sending invalid XML?
316 warn "DEBUG REQUEST\n\tHASH:\n ".Dumper($reqhash)."\n\tXML:\n $reqxml \n\n"
319 my $ua = LWP::UserAgent->new;
321 return "posting disabled for testing" if $self->{reqpreviewonly};
323 my $resp = $ua->post($URL, Content_Type => 'text/xml', Content => $reqxml);
324 return "invalid HTTP response from Ikano: " . $resp->status_line
325 unless $resp->is_success;
326 my $respxml = $resp->decoded_content;
328 $xs = new Net::Ikano::XMLUtil(RootName => undef, SuppressEmpty => '',
329 ForceArray => [ 'Address', 'Product', 'StaticIp', 'OrderNotes' ] );
330 my $resphash = $xs->XMLin($respxml);
332 warn "DEBUG RESPONSE\n\tHASH:\n ".Dumper($resphash)."\n\tXML:\n $respxml"
335 # XXX: validate against their schema to ensure they didn't send us invalid XML?
337 return "invalid response received from Ikano"
338 unless defined $resphash->{responseid} && defined $resphash->{version}
339 && defined $resphash->{type};
341 return "FAILURE response received from Ikano: "
342 . $resphash->{FailureResponse}->{FailureMessage}
343 if $resphash->{type} eq 'FAILURE';
345 my $validRespTypes = {
346 'PREQUAL' => qw( PREQUAL ),
347 'ORDERSTATUS' => qw( ORDERSTATUS ),
348 'ORDER' => qw( NEWORDER CHANGEORDER CANCELORDER ),
349 'CANCEL' => qw( ORDERCANCEL ),
350 'PASSWORDCHANGE' => qw( PASSWORDCHANGE ),
351 'ACCOUNTSTATUSCHANGE' => qw( ACCOUNTSTATUSCHANGE ),
352 'CUSTOMERLOOKUP' => qw( CUSTOMERLOOKUP ),
355 return "invalid response type ".$resphash->{type}." for request type $cmd"
356 unless grep( $_ eq $resphash->{type}, $validRespTypes->{$cmd});
358 return $self->$respsub($resphash,$reqhash);
364 Erik Levinson, C<< <levinse at freeside.biz> >>
368 Please report any bugs or feature requests to C<bug-net-ikano at rt.cpan.org>, or through
369 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Ikano>. I will be notified, and then you'll
370 automatically be notified of progress on your bug as I make changes.
374 You can find documentation for this module with the perldoc command.
378 You can also look for information at:
382 =item * RT: CPAN's request tracker
384 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Ikano>
386 =item * AnnoCPAN: Annotated CPAN documentation
388 L<http://annocpan.org/dist/Net-Ikano>
392 L<http://cpanratings.perl.org/d/Net-Ikano>
396 L<http://search.cpan.org/dist/Net-Ikano>
400 =head1 ACKNOWLEDGEMENTS
402 This module was developed by Freeside Internet Services, Inc.
403 If you need a complete, open-source web-based application to manage your
404 customers, billing and trouble ticketing, please visit http://freeside.biz/
406 =head1 COPYRIGHT & LICENSE
408 Copyright 2010 Freeside Internet Services, Inc.
411 This program is free software; you can redistribute it and/or modify it
412 under the same terms as Perl itself.