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