diff --git a/src/Ups/Entity/EmailMessage.php b/src/Ups/Entity/EmailMessage.php new file mode 100644 index 00000000..765eedd7 --- /dev/null +++ b/src/Ups/Entity/EmailMessage.php @@ -0,0 +1,222 @@ +createElement('EMailMessage'); + + foreach($this->getEmailAddresses() as $email) { + $node->appendChild($document->createElement('EMailAddress', $email)); + } + + if($this->getUndeliverableEmailAddress() !== null) { + $node->appendChild($document->createElement('UndeliverableEMailAddress', $this->getUndeliverableEmailAddress())); + } + + if($this->getFromEmailAddress() !== null) { + $node->appendChild($document->createElement('FromEMailAddress', $this->getFromEmailAddress())); + } + + if($this->getFromName() !== null) { + $node->appendChild($document->createElement('FromName', $this->getFromName())); + } + + if($this->getMemo() !== null) { + $node->appendChild($document->createElement('Memo', $this->getMemo())); + } + + if($this->getSubject() !== null) { + $node->appendChild($document->createElement('Subject', $this->getSubject())); + } + + if($this->getSubjectCode() !== null) { + $node->appendChild($document->createElement('SubjectCode', $this->getSubjectCode())); + } + + return $node; + } + + /** + * @return array + */ + public function getEmailAddresses() + { + return $this->emailAddresses; + } + + /** + * @param array $emailAddress + */ + public function setEmailAddresses(array $emailAddresses) + { + if(count($emailAddresses) > 5) { + throw new \Exception('Maximum of 5 emailaddresses allowed'); + } + + $this->emailAddresses = $emailAddresses; + } + + /** + * @return mixed + */ + public function getUndeliverableEmailAddress() + { + return $this->undeliverableEmailAddress; + } + + /** + * @param mixed $undeliverableEmailAddress + */ + public function setUndeliverableEmailAddress($undeliverableEmailAddress) + { + $this->undeliverableEmailAddress = $undeliverableEmailAddress; + } + + /** + * @return mixed + */ + public function getFromEmailAddress() + { + return $this->fromEmailAddress; + } + + /** + * @param mixed $fromEmailAddress + */ + public function setFromEmailAddress($fromEmailAddress) + { + $this->fromEmailAddress = $fromEmailAddress; + } + + /** + * @return mixed + */ + public function getFromName() + { + return $this->fromName; + } + + /** + * @param mixed $fromName + */ + public function setFromName($fromName) + { + $this->fromName = $fromName; + } + + /** + * @return mixed + */ + public function getMemo() + { + return $this->memo; + } + + /** + * @param mixed $memo + */ + public function setMemo($memo) + { + if(strlen($memo) > 50) { + throw new \Exception('Memo should maximum be 50 chars'); + } + + $this->memo = $memo; + } + + /** + * @return mixed + */ + public function getSubject() + { + return $this->subject; + } + + /** + * @param mixed $subject + */ + public function setSubject($subject) + { + if(strlen($subject) > 50) { + throw new \Exception('Subject should maximum be 50 chars'); + } + + $this->subject = $subject; + } + + /** + * @return mixed + */ + public function getSubjectCode() + { + return $this->subjectCode; + } + + /** + * @param mixed $subjectCode + */ + public function setSubjectCode($subjectCode) + { + $this->subjectCode = $subjectCode; + } + +} diff --git a/src/Ups/Entity/Notification.php b/src/Ups/Entity/Notification.php new file mode 100644 index 00000000..7d32545d --- /dev/null +++ b/src/Ups/Entity/Notification.php @@ -0,0 +1,85 @@ +createElement('Notification'); + + $node->appendChild($document->createElement('NotificationCode', $this->getNotificationCode())); + if($this->getEmailMessage() !== null) { + $node->appendChild($this->emailMessage->toNode($document)); + } + + return $node; + } + + /** + * @return mixed + */ + public function getNotificationCode() + { + return $this->notificationCode; + } + + /** + * @param mixed $notificationCode + */ + public function setNotificationCode($notificationCode) + { + $this->notificationCode = $notificationCode; + } + + /** + * @return mixed + */ + public function getEmailMessage() + { + return $this->emailMessage; + } + + /** + * @param mixed $emailMessage + */ + public function setEmailMessage($emailMessage) + { + $this->emailMessage = $emailMessage; + } + +} diff --git a/src/Ups/Entity/ShipmentServiceOptions.php b/src/Ups/Entity/ShipmentServiceOptions.php index 347d11be..08d87d80 100644 --- a/src/Ups/Entity/ShipmentServiceOptions.php +++ b/src/Ups/Entity/ShipmentServiceOptions.php @@ -15,6 +15,7 @@ class ShipmentServiceOptions implements NodeInterface public $DirectDeliveryOnlyIndicator; private $internationalForms; + private $notifications = array(); function __construct($response = null) { @@ -70,6 +71,12 @@ public function toNode(DOMDocument $document = null) $node->appendChild($this->internationalForms->toNode($document)); } + if(!empty($this->notifications)) { + foreach($this->notifications as $notification) { + $node->appendChild($notification->toNode($document)); + } + } + return $node; } @@ -89,4 +96,26 @@ public function getInternationalForms() return $this->internationalForms; } + /** + * @param Notification $notification + */ + public function addNotification(Notification $notification) + { + $this->notifications[] = $notification; + + if(count($this->notifications) > 3) { + throw new \Exception('Maximum 3 notifications allowed'); + } + + return $this; + } + + /** + * @return array + */ + public function getNotifications() + { + return $this->notifications; + } + }