<?php
 declare(strict_types=1); namespace Square\Apis; use Square\Exceptions\ApiException; use Square\ConfigurationInterface; use Square\ApiHelper; use Square\Models; use Square\Http\ApiResponse; use Square\Http\HttpRequest; use Square\Http\HttpResponse; use Square\Http\HttpMethod; use Square\Http\HttpContext; use Square\Http\HttpCallBack; use Unirest\Request; class MobileAuthorizationApi extends BaseApi { public function __construct(ConfigurationInterface $config, array $authManagers, ?HttpCallBack $httpCallBack) { parent::__construct($config, $authManagers, $httpCallBack); } public function createMobileAuthorizationCode(Models\CreateMobileAuthorizationCodeRequest $body): ApiResponse { $_queryUrl = $this->config->getBaseUri() . '/mobile/authorization-code'; $_headers = [ 'user-agent' => $this->internalUserAgent, 'Accept' => 'application/json', 'Square-Version' => $this->config->getSquareVersion(), 'Content-Type' => 'application/json' ]; $_headers = ApiHelper::mergeHeaders($_headers, $this->config->getAdditionalHeaders()); $_bodyJson = ApiHelper::serialize($body); $_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl); $this->getAuthManager('global')->apply($_httpRequest); if ($this->getHttpCallBack() != null) { $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); } try { $response = Request::post($_httpRequest->getQueryUrl(), $_httpRequest->getHeaders(), $_bodyJson); } catch (\Unirest\Exception $ex) { throw new ApiException($ex->getMessage(), $_httpRequest); } $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); $_httpContext = new HttpContext($_httpRequest, $_httpResponse); if ($this->getHttpCallBack() != null) { $this->getHttpCallBack()->callOnAfterRequest($_httpContext); } if (!$this->isValidResponse($_httpResponse)) { return ApiResponse::createFromContext($response->body, null, $_httpContext); } $deserializedResponse = ApiHelper::mapClass( $_httpRequest, $_httpResponse, $response->body, 'CreateMobileAuthorizationCodeResponse' ); return ApiResponse::createFromContext($response->body, $deserializedResponse, $_httpContext); } } 