File Coverage

blib/lib/SRS/EPP/Command/Create/Contact.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1              
2              
3             package SRS::EPP::Command::Create::Contact;
4              
5 1     1   1969 use Moose;
  0            
  0            
6             extends 'SRS::EPP::Command::Create';
7             use MooseX::Method::Signatures;
8             use Crypt::Password;
9             use SRS::EPP::Session;
10             use XML::EPP::Contact;
11             use XML::SRS::TimeStamp;
12              
13             # for plugin system to connect
14             sub xmlns {
15             return XML::EPP::Contact::Node::xmlns();
16             }
17              
18             method process( SRS::EPP::Session $session ) {
19             $self->session($session);
20              
21             my $epp = $self->message;
22             my $message = $epp->message;
23             my $payload = $message->argument->payload;
24              
25              
26             my $epp_postal_info = $payload->postal_info();
27             if ( (scalar @$epp_postal_info) != 1 ) {
28             # The SRS doesn't support the US's idea of i18n. That is
29             # that ASCII=international, anything else=local.
30             # Instead, well accept either form of postalinfo, but throw an
31             # error if they try to provide both types (because the SRS can't
32             # have two translations for one address)
33             return $self->make_response(code => 2400);
34             }
35             my $postalInfo = $epp_postal_info->[0];
36              
37             # The SRS doesn't have a 'org' field, we don't want to lose info, so
38             if ( $postalInfo->org ) {
39             return $self->make_response(code => 2306);
40             }
41              
42             # Try to make an SRS address object...
43             my $postalInfoAddr = $postalInfo->addr();
44             my $street = $postalInfoAddr->street();
45             my $address = XML::SRS::Contact::Address->new(
46             address1 => $street->[0],
47             city => $postalInfoAddr->city,
48             region => $postalInfoAddr->sp,
49             cc => $postalInfoAddr->cc,
50             postcode => $postalInfoAddr->pc,
51             );
52             if ( $address ) {
53             if ( $street->[1] ) {
54             $address->address2($street->[1]);
55             }
56              
57             # and finally, an SRS update is (hopefully) produced..
58             my $txn = {
59             handle_id => $payload->id(),
60             name => $postalInfo->name(),
61             phone => $payload->voice()->content(),
62             address => $address,
63             email => $payload->email(),
64             action_id => $message->client_id || sprintf("auto.%x",time()),
65             };
66             if ( $payload->fax()->content() ) {
67             $txn->{fax} = $payload->fax()->content();
68             }
69             if ( my $srsTxn = XML::SRS::Handle::Create->new(%$txn) ) {
70             return $srsTxn;
71             }
72             }
73              
74             return $self->make_response(code => 2400);
75             }
76              
77              
78             method notify( SRS::EPP::SRSResponse @rs ) {
79             my $epp = $self->message;
80             my $eppMessage = $epp->message;
81             my $eppPayload = $eppMessage->argument->payload;
82              
83             my $message = $rs[0]->message;
84             my $response = $message->response;
85              
86             if ( $response->isa("XML::SRS::Handle") ) {
87             return $self->make_response(code => 1000);
88             }
89              
90             return $self->make_response(code => 2400);
91             }
92              
93             1;