ReceiptValidator\iTunes\Response::parseJsonResponse PHP Méthode

parseJsonResponse() public méthode

Parse JSON Response
public parseJsonResponse ( string $jsonResponse ) : Response
$jsonResponse string
Résultat Response
    public function parseJsonResponse($jsonResponse)
    {
        if (!is_array($jsonResponse)) {
            throw new RuntimeException('Response must be a scalar value');
        }
        // ios > 7 receipt validation
        if (array_key_exists('receipt', $jsonResponse) && is_array($jsonResponse['receipt']) && array_key_exists('in_app', $jsonResponse['receipt']) && is_array($jsonResponse['receipt']['in_app'])) {
            $this->_code = $jsonResponse['status'];
            $this->_receipt = $jsonResponse['receipt'];
            $this->_purchases = $jsonResponse['receipt']['in_app'];
            if (array_key_exists('bundle_id', $jsonResponse['receipt'])) {
                $this->_bundle_id = $jsonResponse['receipt']['bundle_id'];
            }
            if (array_key_exists('latest_receipt_info', $jsonResponse)) {
                $this->_latest_receipt_info = $jsonResponse['latest_receipt_info'];
            }
            if (array_key_exists('latest_receipt', $jsonResponse)) {
                $this->_latest_receipt = $jsonResponse['latest_receipt'];
            }
        } elseif (array_key_exists('receipt', $jsonResponse)) {
            // ios <= 6.0 validation
            $this->_code = $jsonResponse['status'];
            if (array_key_exists('receipt', $jsonResponse)) {
                $this->_receipt = $jsonResponse['receipt'];
                $this->_purchases = array($jsonResponse['receipt']);
                if (array_key_exists('bid', $jsonResponse['receipt'])) {
                    $this->_bundle_id = $jsonResponse['receipt']['bid'];
                }
            }
        } elseif (array_key_exists('status', $jsonResponse)) {
            $this->_code = $jsonResponse['status'];
        } else {
            $this->_code = self::RESULT_DATA_MALFORMED;
        }
        return $this;
    }