1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ShippoClient\Entity; |
4
|
|
|
|
5
|
|
|
use TurmericSpice\ReadableAttributes; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @property \TurmericSpice\Container attributes |
9
|
|
|
*/ |
10
|
|
|
class Transaction extends ObjectInformation |
11
|
|
|
{ |
12
|
|
|
use ReadableAttributes { |
13
|
|
|
mayHaveAsString as public getCustomsNote; |
14
|
|
|
mayHaveAsString as public getSubmissionNote; |
15
|
|
|
mayHaveAsString as public getMetadata; |
16
|
|
|
toArray as public __toArray; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Indicates the status of the Transaction. |
21
|
|
|
* - "WAITING" |
22
|
|
|
* - "QUEUED" |
23
|
|
|
* - "SUCCESS" |
24
|
|
|
* - "ERROR" |
25
|
|
|
* - "REFUNDED" |
26
|
|
|
* - "REFUNDPENDING" |
27
|
|
|
* - "REFUNDREJECTED" |
28
|
|
|
* |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
public function getObjectStatus() |
32
|
|
|
{ |
33
|
|
|
return $this->attributes->mayHave('object_status')->asString(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Indicates whether the transaction has been sent to the corresponding carrier's test or production server. |
38
|
|
|
* |
39
|
|
|
* @return bool |
40
|
|
|
*/ |
41
|
|
|
public function getWasTest() |
42
|
|
|
{ |
43
|
|
|
return $this->attributes->mayHave('was_test')->asBoolean(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Rate object id. |
48
|
|
|
* |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
public function getRate() |
52
|
|
|
{ |
53
|
|
|
return $this->attributes->mayHave('rate')->asString(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The carrier-specific tracking number that can be used to track the Shipment. |
58
|
|
|
* A value will only be returned if the Rate is for a trackable Shipment and if the Transactions has been processed successfully. |
|
|
|
|
59
|
|
|
* |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
public function getTrackingNumber() |
63
|
|
|
{ |
64
|
|
|
return $this->attributes->mayHave('tracking_number')->asString(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* The tracking information we currently have on file for this shipment. We regularly update this information. |
69
|
|
|
* |
70
|
|
|
* @return TrackingStatus |
71
|
|
|
*/ |
72
|
|
|
public function getTrackingStatus() |
73
|
|
|
{ |
74
|
|
|
return new TrackingStatus($this->attributes->mayHave('tracking_status')->asArray()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return TrackingHistory |
79
|
|
|
*/ |
80
|
|
|
public function getTrackingHistory() |
81
|
|
|
{ |
82
|
|
|
$entities = $this->attributes->mayHave('tracking_history') |
83
|
|
|
->asInstanceArray('ShippoClient\\Entity\\TrackingStatus'); |
84
|
|
|
|
85
|
|
|
return new TrackingHistory($entities); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* A link to track this item on the carrier-provided tracking website. |
90
|
|
|
* A value will only be returned if tracking is available and the carrier provides such a service. |
91
|
|
|
* |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
|
|
public function getTrackingUrlProvider() |
95
|
|
|
{ |
96
|
|
|
return $this->attributes->mayHave('tracking_url_provider')->asString(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* A URL pointing directly to the label in the format you've set in your settings. |
101
|
|
|
* A value will only be returned if the Transactions has been processed successfully. |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function getLabelUrl() |
106
|
|
|
{ |
107
|
|
|
return $this->attributes->mayHave('label_url')->asString(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* A URL pointing to the commercial invoice as a 8.5x11 inch PDF file. |
112
|
|
|
* A value will only be returned if the Transactions has been processed successfully and if the shipment is international. |
|
|
|
|
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function getCommercialInvoiceUrl() |
117
|
|
|
{ |
118
|
|
|
return $this->attributes->mayHave('commercial_invoice_url')->asString(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* An array containing elements of the following schema: |
123
|
|
|
* "code" (string): an identifier for the corresponding message (not always available") |
124
|
|
|
* "message" (string): a publishable message containing further information. |
125
|
|
|
* |
126
|
|
|
* @return array |
127
|
|
|
*/ |
128
|
|
|
public function getMessages() |
129
|
|
|
{ |
130
|
|
|
return $this->attributes->mayHave('messages')->asArray(); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return mixed|null |
135
|
|
|
*/ |
136
|
|
|
public function getOrder() |
137
|
|
|
{ |
138
|
|
|
return $this->attributes->mayHave('order')->value(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
|
|
public function getMetadata() |
145
|
|
|
{ |
146
|
|
|
return $this->attributes->mayHave('metadata')->asString(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function toArray() |
150
|
|
|
{ |
151
|
|
|
$array = $this->__toArray(); |
152
|
|
|
$array['tracking_status'] = $this->getTrackingStatus()->toArray(); |
153
|
|
|
$array['tracking_history'] = $this->getTrackingHistory()->toArray(); |
154
|
|
|
|
155
|
|
|
return $array; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.