/** * @inheritdoc * @return ResponsePayload response payload instance * @throws InvalidReceiptException when unknown status code found * @throws InvalidArgumentException when not iOS7 receipt string */ public static function initializeByString($string) { $Object = json_decode($string); if (isset($Object->receipt->in_app)) { $result = Status::checkStatus($Object->status); if ($result === true) { $Response = new self(); $Response->AppReceipt = AppReceipt::initializeByObject($Object->receipt); $Response->environment = (string) $Object->environment; $Response->status = (int) $Object->status; return $Response; } else { $Exception = new $result($string, $Object->status); throw $Exception; } } else { throw new InvalidArgumentException('not found in_app receipt field in iOS7 receipt'); } }
/** * Define exception class by receipt status code * @param int $status receipt status code * @return bool|string exception class name for inalid status codes or TRUE for correct code */ public static function checkStatus($status) { switch ($status) { case self::STATUS_UNMATCHED_SHARED_SECRET: return UnmatchedSharedSecretException::getClass(); default: return parent::checkStatus($status); } }