/** * @param string $postBody * @return Pencepay_Event */ public static function parse($postBody, $checkAuthenticity = false) { $event = Pencepay_Util_Json::fromJson($postBody); if ($event != null && $checkAuthenticity) { $event = self::find($event->uid); } return $event; }
private static function _sendRequest($httpMethod, $url, $requestParams = array()) { $curl = curl_init(); curl_setopt($curl, CURLOPT_TIMEOUT, 120); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $httpMethod); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_ENCODING, 'gzip'); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8', 'User-Agent: Pencepay PHP Library ' . Pencepay_Version::get(), 'X-ApiVersion: ' . Pencepay_Context::SERVER_API_VERSION)); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, self::_getAuthCredentials()); if (count($requestParams) > 0) { curl_setopt($curl, CURLOPT_POSTFIELDS, self::encodeParameters($requestParams)); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:')); // Not supported by gateway $responseBody = curl_exec($curl); $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if (self::_isErrorResponse($httpStatus)) { switch ($httpStatus) { case 400: $error = Pencepay_Util_Json::fromJson($responseBody); throw new Pencepay_Exception_InvalidRequest($error->message, $error->code, $error->parameter); case 401: throw new Pencepay_Exception_ApiAuthentication($responseBody); case 402: $error = Pencepay_Util_Json::fromJson($responseBody); throw new Pencepay_Exception_Processing($error->message, $error->code, $error->parameter); case 403: $error = Pencepay_Util_Json::fromJson($responseBody); throw new Pencepay_Exception_Authorization($error->message, $error->code); case 404: $error = Pencepay_Util_Json::fromJson($responseBody); throw new Pencepay_Exception_ItemNotFound($error->message, $error->code); case 501: case 502: $error = Pencepay_Util_Json::fromJson($responseBody); throw new Pencepay_Exception_ServerSide($error->message, $error->code); default: throw new Pencepay_Exception_Unexpected("Unexpected response received from server", $httpStatus); } } return Pencepay_Util_Json::fromJson($responseBody); }