Skip to content

Commit

Permalink
Update Cord.php
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbj authored Feb 8, 2024
1 parent 3804768 commit 879ae70
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Cord.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,16 @@ public function addAddress(array $addressDetails): self
throw new \Exception('You must call an organization before adding an address. Use organization (CODE HERE) before calling this method.');
}

$capabilities = $addressDetails['capabilities'] ?? [];

// Validate required fields in $addressDetails array
$requiredFields = ['code', 'addressOne', 'country', 'city'];
foreach ($requiredFields as $field) {
if (! isset($capabilities[$field])) {
if (! isset($addressDetails[$field])) {
throw new \Exception("Missing required field '{$field}' in address details.");
}
}

$capabilities = $addressDetails['capabilities'] ?? [];

$this->address = [
'_attributes' => ['Action' => 'INSERT'],
'Code' => $addressDetails['code'],
Expand All @@ -191,7 +191,7 @@ public function addAddress(array $addressDetails): self
'Mobile' => $addressDetails['mobile'] ?? null,
'Email' => $addressDetails['email'] ?? null,
'SuppressAddressValidationError' => 'true',
'OrgAddressCapabilityCollection' => $formattedCapabilities,
'OrgAddressCapabilityCollection' => $capabilities,
];

return $this;
Expand Down

0 comments on commit 879ae70

Please sign in to comment.