@@ -311,7 +311,9 @@ public function resume($subscriberId, $subscriptionId = '')
311
311
*/
312
312
public function getProducts ()
313
313
{
314
- $ products = $ this ->request ('getproducts ' );
314
+ //INFO The GetProducts method do not work with POST. Also, using GET we should not use `Accept` header as in
315
+ // post case.
316
+ $ products = $ this ->request ('getproducts ' , [], true );
315
317
316
318
return array_map (
317
319
function ($ e ) {
@@ -348,19 +350,26 @@ public function getInfo($subscriberId, $subscriptionId = '')
348
350
);
349
351
}
350
352
351
- protected function request ($ method , $ data = [])
353
+ protected function request ($ method , $ data = [], $ forceGet = false )
352
354
{
353
355
$ headers = [];
354
356
355
- $ curl = curl_init (self ::BASE_URL . $ method );
356
- curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , 1 );
357
- curl_setopt ($ curl , CURLOPT_POST , true );
358
- if (!empty ($ data )) {
359
- curl_setopt ($ curl , CURLOPT_POSTFIELDS , urldecode (http_build_query ($ data )));
357
+ $ url = self ::BASE_URL . $ method ;
358
+ if ($ forceGet && !empty ($ data )) {
359
+ $ url .= '? ' . http_build_query ($ data );
360
+ };
361
+
362
+ $ curl = curl_init ($ url );
363
+ if (!$ forceGet ) {
364
+ curl_setopt ($ curl , CURLOPT_POST , true );
365
+ if (!empty ($ data )) {
366
+ curl_setopt ($ curl , CURLOPT_POSTFIELDS , urldecode (http_build_query ($ data )));
367
+ }
368
+ curl_setopt ($ curl , CURLOPT_HTTPHEADER , ['Accept: application/json ' ]);
360
369
}
370
+ curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , 1 );
361
371
curl_setopt ($ curl , CURLOPT_FOLLOWLOCATION , 1 );
362
372
curl_setopt ($ curl , CURLOPT_TIMEOUT , 30 );
363
- curl_setopt ($ curl , CURLOPT_HTTPHEADER , ['Accept: application/json ' ]);
364
373
curl_setopt ($ curl , CURLOPT_HEADER , 0 );
365
374
curl_setopt ($ curl , CURLOPT_USERPWD , $ this ->authToken );
366
375
curl_setopt ($ curl , CURLOPT_HEADERFUNCTION , function ($ ch , $ headerLine ) use (&$ headers ) {
@@ -385,7 +394,6 @@ protected function request($method, $data = [])
385
394
throw new Exception ($ error , self ::ERROR_UNKNOWN_ERROR );
386
395
}
387
396
curl_close ($ curl );
388
-
389
397
if ($ code !== 200 ) {
390
398
throw new Exception ($ headers ['ErrorMessage ' ], (int )$ headers ['ErrorCode ' ]);
391
399
}
0 commit comments