Added information on common failure causes to the perldoc.
[freeside.git] / FS / FS / part_export / domreg_opensrs.pm
index ec73d3c..0ef371a 100644 (file)
@@ -7,7 +7,6 @@ use FS::Conf;
 use FS::part_export::null;
 use FS::svc_domain;
 use FS::part_pkg;
-use Net::OpenSRS;
 
 =head1 NAME
 
@@ -32,6 +31,10 @@ on the setting of the svc_domain's action field.
 
 =back
 
+This export uses Net::OpenSRS.  Registration and transfer attempts will fail unless Net::OpenSRS is installed
+and LWP::UserAgent is able to make HTTPS posts.  You can turn on debugging messages and use the OpenSRS test
+gateway when setting up this export.
+
 =cut
 
 @ISA = qw(FS::part_export::null);
@@ -51,12 +54,12 @@ tie %options, 'Tie::IxHash',
                       type => 'select',
                       options => [ 0, 1, 2, 3 ],
                      default => 0 },
-  'register'     => { label => 'Use for registration',
-                      type => 'checkbox',
-                      default => '1' },
-  'transfer'     => { label => 'Use for transfer',
-                      type => 'checkbox',
-                      default => '1' },
+#  'register'     => { label => 'Use for registration',
+#                      type => 'checkbox',
+#                      default => '1' },
+#  'transfer'     => { label => 'Use for transfer',
+#                      type => 'checkbox',
+#                      default => '1' },
   'tlds'         => { label => 'Use this export for these top-level domains (TLDs)',
                       type => 'select',
                       multi => 1,
@@ -154,6 +157,32 @@ sub gen_contact_info
   return $c;
 }
 
+sub validate_contact_info {
+  my $c = shift;
+
+  my %fields = (
+    firstname => "first name",
+    lastname => "last name",
+    address => "street address",
+    city => "city", 
+    state => "state",
+    zip => "ZIP/postal code",
+    country => "country",
+    email => "email address",
+    phone => "phone number",
+  );
+  my @err = ();
+  foreach (keys %fields) {
+    if (!defined($c->{$_}) || !$c->{$_}) {
+      push @err, $fields{$_};
+    }
+  }
+  if (scalar(@err) > 0) {
+    return "Contact information needs: " . join(', ', @err);
+  }
+  undef;
+}
+
 sub testmode {
   my $self = shift;
 
@@ -167,6 +196,9 @@ sub _export_insert {
 
   return if $svc_domain->action eq 'I';  # Ignoring registration, just doing DNS
 
+  eval "use Net::OpenSRS;";
+  return $@ if $@;
+
   # Get the TLD of the new domain
   my @bits = split /\./, $svc_domain->domain;
 
@@ -183,6 +215,9 @@ sub _export_insert {
 
   my $c = gen_contact_info($cust_main);
 
+  my $err = validate_contact_info($c);
+  return $err if $err;
+
   my $srs = Net::OpenSRS->new();
 
   $srs->debug_level( $self->option('debug_level') ); # Output should be in the Apache error log
@@ -198,10 +233,10 @@ sub _export_insert {
   }
 
   if ($svc_domain->action eq 'N') {
-    return "Domain registration not enabled" if !$self->option('register');
+#    return "Domain registration not enabled" if !$self->option('register');
     return $srs->last_response() if !$srs->register_domain( $svc_domain->domain, $c);
   } elsif ($svc_domain->action eq 'M') {
-    return "Domain transfer not enabled" if !$self->option('transfer');
+#    return "Domain transfer not enabled" if !$self->option('transfer');
     return $srs->last_response() if !$srs->transfer_domain( $svc_domain->domain, $c);
   } else {
     return "Unknown domain action " . $svc_domain->action;
@@ -236,9 +271,10 @@ sub registrar {
 
 =head1 SEE ALSO
 
-L<FS::part_export_option>, L<FS::export_svc>, L<FS::svc_domain>,
+L<Net::OpenSRS>, L<FS::part_export_option>, L<FS::export_svc>, L<FS::svc_domain>,
 L<FS::Record>, schema.html from the base documentation.
 
+
 =cut
 
 1;