aporat / store-receipt-validator

PHP receipt validator for Apple iTunes, Google Play and Amazon App Store
Apache License 2.0
633 stars 153 forks source link

GetLastReceipt does not work for IOS6 #32

Closed cbonachera closed 7 years ago

cbonachera commented 8 years ago

Can you push this patch please? For IOS6, you forgot to push the latest receipt in the result.

  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'];
        }

        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('status', $jsonResponse)) {
      $this->_code = $jsonResponse['status'];
    } else {
      $this->_code = self::RESULT_DATA_MALFORMED;
    }
    return $this;
  }
aporat commented 8 years ago

I no longer support ios <= 6. however, if you can open a pull request with the changes, i'll gladly review it.