return $self->compile_response if $ctx->{response}->{status};
}
-
-# Add extra info to response message
+ # Add extra info to response message
$ctx->{response}->{status} = 'OK';
if ($update_type eq 'renew') {
my $val = $cgi->param($field);
- if ($physical_addr->id eq $mailing_addr->id && $physical_addr->street1 eq $mailing_addr->street1) {
- # if one address & stays at one address, just update it
- $physical_addr->isnew(0);
- $physical_addr->ischanged(1);
- $mailing_addr->isnew(0);
- $mailing_addr->ischanged(1);
- } elsif ($physical_addr->id eq $mailing_addr->id && $physical_addr->street1 ne $mailing_addr->street1) {
- # if the addr ids are the same, but the streets don't match, create a separate address entry for mailing
- $physical_addr->isnew(0);
- $physical_addr->ischanged(1);
- $mailing_addr->isnew(1);
- $mailing_addr->ischanged(0);
- } elsif ($physical_addr->id ne $mailing_addr->id && $physical_addr->street1 eq $mailing_addr->street1) {
- # if there were previously 2 addresses, but there is only one address now, delete excess entry
- $physical_addr->isnew(0);
- $physical_addr->ischanged(1);
- $mailing_addr->isnew(0);
- $mailing_addr->ischanged(0);
- $mailing_addr->isdeleted(1);
- } else {
- # otherwise, update existing entries
- $physical_addr->isnew(0);
- $physical_addr->ischanged(1);
- $mailing_addr->isnew(0);
- $mailing_addr->ischanged(1);
- }
-
if ($field_info->{required} && !$val) {
my $msg = "Value required for field: '$field'";
$ctx->{response}->{status} = 'INVALID_PARAMS';
}
}
+ # Determine what exactly to do with addresses
+ if ($physical_addr->id eq $mailing_addr->id && $physical_addr->street1 eq $mailing_addr->street1) {
+ # if one address & stays at one address, just update it (don't need to do both physical & mailing)
+ $mailing_addr->isnew(0);
+ $mailing_addr->ischanged(1);
+ } elsif ($physical_addr->id eq $mailing_addr->id && $physical_addr->street1 ne $mailing_addr->street1) {
+ # if one address splitting to two addresses, update the first and create a second address entry
+ $physical_addr->isnew(0);
+ $physical_addr->ischanged(1);
+ $mailing_addr->isnew(1);
+ $mailing_addr->id(-1);
+ } elsif ($physical_addr->id ne $mailing_addr->id && $physical_addr->street1 eq $mailing_addr->street1) {
+ # if there were previously 2 addresses, but there is only one address now, use the updated single address entry for both
+ $physical_addr->isnew(0);
+ $physical_addr->ischanged(1);
+ $mailing_addr->isnew(0);
+ $mailing_addr->ischanged(1);
+ $mailing_addr->id($physical_addr->id);
+ } else {
+ # otherwise, update existing entries
+ $physical_addr->isnew(0);
+ $physical_addr->ischanged(1);
+ $mailing_addr->isnew(0);
+ $mailing_addr->ischanged(1);
+ }
+
# exit if there were any errors above.
return undef if $ctx->{response}->{status};