@@ -55,7 +55,6 @@ public function __construct(string $key, string $secret, string $platform)
5555 }
5656
5757 $ this ->_curlHandle = curl_init ();
58- curl_setopt ($ this ->_curlHandle , CURLOPT_CUSTOMREQUEST , 'GET ' );
5958 curl_setopt ($ this ->_curlHandle , CURLOPT_RETURNTRANSFER , true );
6059 curl_setopt ($ this ->_curlHandle , CURLOPT_CONNECTTIMEOUT , 2 );
6160 curl_setopt ($ this ->_curlHandle , CURLOPT_TIMEOUT , 5 );
@@ -275,6 +274,57 @@ public function getCountry(string $country): array
275274 return $ this ->_performApiCall (implode ('/ ' , $ urlParts ), null );
276275 }
277276
277+ /**
278+ * @see https://developer.postcode.eu/documentation/reseller/v1/Reseller/createClientAccount
279+ */
280+ public function createClientAccount (
281+ string $ companyName ,
282+ string $ countryIso ,
283+ string $ vatNumber ,
284+ string $ contactEmail ,
285+ int $ subscriptionAmount ,
286+ array $ siteUrls ,
287+ string $ invoiceEmail ,
288+ string $ invoiceReference ,
289+ string $ invoiceAddressLine1 ,
290+ string $ invoiceAddressLine2 ,
291+ string $ invoiceAddressPostalCode ,
292+ string $ invoiceAddressLocality ,
293+ string $ invoiceAddressRegion ,
294+ string $ invoiceAddressCountryIso ,
295+ ?string $ invoiceContactName = null ,
296+ bool $ isTest = false
297+ ): array
298+ {
299+ $ postData = [
300+ 'companyName ' => $ companyName ,
301+ 'countryIso ' => $ countryIso ,
302+ 'vatNumber ' => $ vatNumber ,
303+ 'contactEmail ' => $ contactEmail ,
304+ 'subscriptionAmount ' => $ subscriptionAmount ,
305+ 'siteUrls ' => $ siteUrls ,
306+ 'invoiceEmail ' => $ invoiceEmail ,
307+ 'invoiceReference ' => $ invoiceReference ,
308+ 'invoiceAddressLine1 ' => $ invoiceAddressLine1 ,
309+ 'invoiceAddressLine2 ' => $ invoiceAddressLine2 ,
310+ 'invoiceAddressPostalCode ' => $ invoiceAddressPostalCode ,
311+ 'invoiceAddressLocality ' => $ invoiceAddressLocality ,
312+ 'invoiceAddressRegion ' => $ invoiceAddressRegion ,
313+ 'invoiceAddressCountryIso ' => $ invoiceAddressCountryIso ,
314+ ];
315+
316+ if ($ invoiceContactName !== null )
317+ {
318+ $ postData ['invoiceContactName ' ] = $ invoiceContactName ;
319+ }
320+ if ($ isTest )
321+ {
322+ $ postData ['isTest ' ] = true ;
323+ }
324+
325+ return $ this ->_performPostApiCall ('reseller/v1/client ' , $ postData );
326+ }
327+
278328 /**
279329 * @see https://developer.postcode.eu/documentation/account/v1/Account/getInfo
280330 */
@@ -325,15 +375,31 @@ protected function _validateSessionHeader(string $session): void
325375 protected function _performApiCall (string $ path , ?string $ session ): array
326376 {
327377 $ url = static ::SERVER_URL . $ path ;
328- curl_setopt ($ this ->_curlHandle , CURLOPT_URL , $ url );
329- curl_setopt ($ this ->_curlHandle , CURLOPT_HTTPAUTH , CURLAUTH_BASIC );
330- curl_setopt ($ this ->_curlHandle , CURLOPT_USERPWD , $ this ->_key .': ' . $ this ->_secret );
331378 if ($ session !== null )
332379 {
333380 curl_setopt ($ this ->_curlHandle , CURLOPT_HTTPHEADER , [
334381 static ::SESSION_HEADER_KEY . ': ' . $ session ,
335382 ]);
336383 }
384+ curl_setopt ($ this ->_curlHandle , CURLOPT_HTTPGET , true );
385+
386+ return $ this ->_performCurlCall ($ url );
387+ }
388+
389+ protected function _performPostApiCall (string $ path , array $ postData = []): array
390+ {
391+ $ url = static ::SERVER_URL . $ path ;
392+ curl_setopt ($ this ->_curlHandle , CURLOPT_POST , true );
393+ curl_setopt ($ this ->_curlHandle , CURLOPT_POSTFIELDS , http_build_query ($ postData ));
394+
395+ return $ this ->_performCurlCall ($ url );
396+ }
397+
398+ protected function _performCurlCall (string $ url ): array
399+ {
400+ curl_setopt ($ this ->_curlHandle , CURLOPT_URL , $ url );
401+ curl_setopt ($ this ->_curlHandle , CURLOPT_HTTPAUTH , CURLAUTH_BASIC );
402+ curl_setopt ($ this ->_curlHandle , CURLOPT_USERPWD , $ this ->_key .': ' . $ this ->_secret );
337403
338404 $ this ->_mostRecentResponseHeaders = [];
339405 $ response = curl_exec ($ this ->_curlHandle );
@@ -362,9 +428,9 @@ protected function _performApiCall(string $path, ?string $session): array
362428 case 401 :
363429 throw new AuthenticationException ('Could not authenticate your request, please make sure your API credentials are correct. ' );
364430 case 403 :
365- throw new ForbiddenException (' Your account currently has no access to the international API, make sure you have an active subscription. ' );
431+ throw new ForbiddenException (sprintf ( ' API access not allowed: `%s` ' , $ jsonResponse [ ' exception ' ]) );
366432 case 404 :
367- throw new NotFoundException ('The requested address could not be found. ' );
433+ throw new NotFoundException ('The request was valid, but nothing could be found. ' );
368434 case 429 :
369435 throw new TooManyRequestsException ('Too many requests made, please slow down: ' . $ response );
370436 case 503 :
0 commit comments