1: <?php
2:
3: namespace ShippoClient\Entity;
4:
5: use TurmericSpice\ReadableAttributes;
6:
7: 8: 9: 10: 11:
12: class WebhookTracks
13: {
14: use ReadableAttributes {
15:
16: mayHaveAsString as public getCarrier;
17: mayHaveAsString as public getEta;
18:
19: mayHaveAsString as public getObjectState;
20: mayHaveAsString as public getObjectStatus;
21: mayHaveAsString as public getObjectId;
22: mayHaveAsString as public getObjectOwner;
23: mayHaveAsString as public getLabelUrl;
24: mayHaveAsString as public getTrackingUrlProvider;
25: mayHaveAsString as public getCommercialInvoiceUrl;
26: mayHaveAsString as public getCustomsNote;
27: mayHaveAsString as public getSubmissionNote;
28: mayHaveAsString as public getMetadata;
29: mayHaveAsArray as public getMessages;
30:
31: mayHaveAsString as public getTrackingNumber;
32: toArray as public __toArray;
33: }
34:
35: 36: 37: 38: 39:
40: public function getObjectCreated()
41: {
42: return $this->attributes->mayHave('object_created')->asInstanceOf('\\DateTime');
43: }
44:
45: 46: 47: 48: 49:
50: public function getObjectUpdated()
51: {
52: return $this->attributes->mayHave('object_updated')->asInstanceOf('\\DateTime');
53: }
54:
55: 56: 57: 58: 59:
60: public function getAddressFrom()
61: {
62: $addressFrom = $this->attributes->mayHave('address_from')->asArray();
63:
64: return new Location($addressFrom);
65: }
66:
67: 68: 69: 70: 71:
72: public function getAddressTo()
73: {
74: $addressTo = $this->attributes->mayHave('address_to')->asArray();
75:
76: return new Location($addressTo);
77: }
78:
79: 80: 81: 82: 83:
84: public function getServiceLevel()
85: {
86: $serviceLevel = $this->attributes->mayHave('servicelevel')->asArray();
87:
88: return new ServiceLevel($serviceLevel);
89: }
90:
91: 92: 93: 94: 95:
96: public function getTrackingStatus()
97: {
98: return new TrackingStatus($this->attributes->mayHave('tracking_status')->asArray());
99: }
100:
101: 102: 103: 104: 105:
106: public function getTrackingHistory()
107: {
108: $entities = $this->attributes->mayHave('tracking_history')
109: ->asInstanceArray('ShippoClient\\Entity\\TrackingStatus');
110:
111: return new TrackingHistory($entities);
112: }
113:
114: public function toArray()
115: {
116: return [
117:
118: 'carrier' => $this->getCarrier(),
119: 'tracking_number' => $this->getTrackingNumber(),
120: 'tracking_status' => $this->getTrackingStatus()->toArray(),
121: 'tracking_history' => $this->getTrackingHistory()->toArray(),
122: 'eta' => $this->getEta(),
123: 'address_from' => $this->getAddressFrom()->toArray(),
124: 'address_to' => $this->getAddressTo()->toArray(),
125: 'servicelevel' => $this->getServiceLevel()->toArray(),
126:
127: 'object_state' => $this->getObjectState(),
128: 'object_status' => $this->getObjectStatus(),
129: 'object_created' => $this->getObjectCreated(),
130: 'object_updated' => $this->getObjectUpdated(),
131: 'object_id' => $this->getObjectId(),
132: 'object_owner' => $this->getObjectOwner(),
133: 'label_url' => $this->getLabelUrl(),
134: 'tracking_url_provider' => $this->getTrackingUrlProvider(),
135: 'commercial_invoice_url' => $this->getCommercialInvoiceUrl(),
136: 'customs_note' => $this->getCustomsNote(),
137: 'submission_note' => $this->getSubmissionNote(),
138: 'metadata' => $this->getMetadata(),
139: 'messages' => $this->getMessages(),
140: ];
141: }
142: }
143: