示例#1
0
 /**
  * Method for receipts data verification
  * @param string $receipt base64 encoded receipt
  * @return Status|RenewableStatus|ResponsePayload iTunes status for receipt
  */
 public function verifyReceipt($receipt)
 {
     $Request = $this->getRequest($this->getEndpointUrl());
     $Request->addPostField('receipt-data', $receipt)->addPostField('password', $this->getPassword());
     $data = $Request->send();
     try {
         return ResponsePayload::initializeByString($data);
     } catch (InvalidArgumentException $Ex) {
         try {
             return RenewableStatus::initializeByString($data);
         } catch (InvalidArgumentException $ex) {
             return Status::initializeByString($data);
         }
     }
 }
 /**
  * @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);
     }
 }