@@ -174,6 +174,27 @@ public function setIdempotencyKeyHeader($value)
174174 return $ this ->setParameter ('idempotencyKey ' , $ value );
175175 }
176176
177+ /**
178+ * @return array
179+ */
180+ public function getExpand ()
181+ {
182+ return $ this ->getParameter ('expand ' );
183+ }
184+
185+ /**
186+ * Specifies which object relations (IDs) in the response should be expanded to include the entire object.
187+ *
188+ * @see https://stripe.com/docs/api/expanding_objects
189+ *
190+ * @param array $value
191+ * @return AbstractRequest
192+ */
193+ public function setExpand ($ value )
194+ {
195+ return $ this ->setParameter ('expand ' , $ value );
196+ }
197+
177198 abstract public function getEndpoint ();
178199
179200 /**
@@ -221,17 +242,42 @@ public function sendData($data)
221242 );
222243
223244 $ body = $ data ? http_build_query ($ data , '' , '& ' ) : null ;
224- $ httpResponse = $ this ->httpClient ->request ($ this ->getHttpMethod (), $ this ->getEndpoint (), $ headers , $ body );
245+ $ httpResponse = $ this ->httpClient ->request (
246+ $ this ->getHttpMethod (),
247+ $ this ->getExpandedEndpoint (),
248+ $ headers ,
249+ $ body
250+ );
225251
226252 return $ this ->createResponse ($ httpResponse ->getBody ()->getContents (), $ httpResponse ->getHeaders ());
227253 }
228254
255+ /**
256+ * Appends the `expand` properties to the endpoint as a querystring.
257+ *
258+ * @return string
259+ */
260+ public function getExpandedEndpoint ()
261+ {
262+ $ endpoint = $ this ->getEndpoint ();
263+ $ expand = $ this ->getExpand ();
264+ if (is_array ($ expand ) && count ($ expand ) > 0 ) {
265+ $ queryParams = [];
266+ foreach ($ expand as $ key ) {
267+ $ queryParams [] = 'expand[]= ' . $ key ;
268+ }
269+ $ queryString = join ('& ' , $ queryParams );
270+ $ endpoint .= '? ' . $ queryString ;
271+ }
272+
273+ return $ endpoint ;
274+ }
229275
230276 protected function createResponse ($ data , $ headers = [])
231277 {
232278 return $ this ->response = new Response ($ this , $ data , $ headers );
233279 }
234-
280+
235281 /**
236282 * @return mixed
237283 */
0 commit comments