@@ -14,6 +14,7 @@ class Ship extends Auth
1414 private ShipQuery $ query ;
1515 private ShipmentRequest $ shipmentRequest ;
1616 private bool $ onlyLabel ;
17+ private object $ apiResponse ;
1718
1819 public function __construct ()
1920 {
@@ -65,10 +66,10 @@ public function createShipment(string $client_id, string $client_secret): array
6566 "transId: string " ,
6667 "transactionSrc: testing "
6768 ]);
68- $ httpClient ->setPayload (json_encode ( $ this ->getPayload () ));
69+ $ httpClient ->setPayload ($ this ->getRequest ( ));
6970 $ httpClient ->setUrl ($ this ->_getAPIBaseURL () . "/api/shipments/ " . self ::VERSION . "/ship " . $ queryParams );
7071 $ httpClient ->setMethod ("POST " );
71- $ res = $ httpClient ->fetch ();
72+ $ this -> apiResponse = $ res = $ httpClient ->fetch ();
7273
7374 if (!isset ($ res ->ShipmentResponse )) {
7475 if (isset ($ res ->response )) {
@@ -101,13 +102,6 @@ public function createShipment(string $client_id, string $client_secret): array
101102 return ['status ' => 'success ' , 'data ' => $ res ];
102103 }
103104
104- private function getPayload (): array
105- {
106- return [
107- "ShipmentRequest " => $ this ->shipmentRequest ->toArray ()
108- ];
109- }
110-
111105 public function setMode (string $ mode ): self
112106 {
113107 parent ::setMode ($ mode );
@@ -119,4 +113,16 @@ public function setOnlyLabel(bool $onlyLabel): self
119113 $ this ->onlyLabel = $ onlyLabel ;
120114 return $ this ;
121115 }
116+
117+ public function getRequest (): string
118+ {
119+ return json_encode ([
120+ "ShipmentRequest " => $ this ->shipmentRequest ->toArray ()
121+ ]);
122+ }
123+
124+ public function getResponse (): string
125+ {
126+ return json_encode ($ this ->apiResponse );
127+ }
122128}
0 commit comments