@@ -358,6 +358,45 @@ private function sendGetRequest(string $url): array
358358 return $ resp ;
359359 }
360360
361+ /**
362+ * Builds a multipart/form-data payload.
363+ *
364+ * @param array $postFields Fields to send.
365+ * @param array $webhooksIds List of webhook IDs.
366+ * @return array Array containing 'boundary' and 'body'.
367+ */
368+ protected function buildMultipartPayload (array $ postFields , array $ webhooksIds ): array
369+ {
370+ $ boundary = uniqid ('' , true );
371+ $ body = '' ;
372+
373+ foreach ($ postFields as $ name => $ content ) {
374+ $ body .= "-- $ boundary \r\n" ;
375+ if ($ content instanceof \CURLFile) {
376+ $ body .= "Content-Disposition: form-data; name= \"$ name \"; " ;
377+ $ body .= "filename= \"{$ content ->getPostFilename ()}\"\r\n" ;
378+ $ body .= "Content-Type: {$ content ->getMimeType ()}\r\n\r\n" ;
379+ $ body .= file_get_contents ($ content ->getFilename ()) . "\r\n" ;
380+ } else {
381+ $ body .= "Content-Disposition: form-data; name= \"$ name \"\r\n\r\n" ;
382+ $ body .= "$ content \r\n" ;
383+ }
384+ }
385+
386+ foreach ($ webhooksIds as $ webhookId ) {
387+ $ body .= "-- $ boundary \r\n" ;
388+ $ body .= "Content-Disposition: form-data; name= \"webhook_ids \"\r\n\r\n" ;
389+ $ body .= "$ webhookId \r\n" ;
390+ }
391+
392+ $ body .= "-- $ boundary-- \r\n" ;
393+
394+ return [
395+ 'boundary ' => $ boundary ,
396+ 'body ' => $ body ,
397+ ];
398+ }
399+
361400 /**
362401 * Starts a CURL session using POST.
363402 *
@@ -373,16 +412,28 @@ private function documentEnqueuePost(
373412 /** @var CurlHandle $ch */
374413 $ ch = $ this ->initChannel ();
375414 $ postFields = $ params ->asHash ();
376-
415+ foreach (array_keys ($ postFields ) as $ key ) {
416+ if (is_string ($ key ) && str_starts_with ($ key , 'webhook_ids ' )) {
417+ unset($ postFields [$ key ]);
418+ }
419+ }
420+ $ webhooksIds = $ params ->webhooksIds ;
377421 if ($ inputSource instanceof URLInputSource) {
378422 $ postFields ['url ' ] = $ inputSource ->url ;
379423 } elseif ($ inputSource instanceof LocalInputSource) {
380424 $ inputSource ->checkNeedsFix ();
381425 $ postFields ['file ' ] = $ inputSource ->fileObject ;
382426 }
383427 $ url = $ this ->baseUrl . "/products/ {$ params ::$ slug }/enqueue " ;
428+ $ multipart = $ this ->buildMultipartPayload ($ postFields , $ webhooksIds );
429+
384430 curl_setopt ($ ch , CURLOPT_URL , $ url );
385- curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ postFields );
431+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , [
432+ 'Authorization: ' . $ this ->apiKey ,
433+ 'Content-Type: multipart/form-data; boundary= ' . $ multipart ['boundary ' ],
434+ ]);
435+
436+ curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ multipart ['body ' ]);
386437 $ resp = [
387438 'data ' => curl_exec ($ ch ),
388439 'code ' => curl_getinfo ($ ch , CURLINFO_HTTP_CODE ),
0 commit comments