protected function check($receipt, $url = null)
 {
     $url = empty($url) ? self::PRODUCTION_API : $url;
     $request = new URLRequest($url);
     $response = $request->postJSON(array('receipt-data' => $receipt), false);
     if (isset($response->status) === false) {
         throw new NonFatalException('invalid receipt', 400);
     } else {
         if ($response->status != 0) {
             if ($response->status === 21007) {
                 $response = $this->check($receipt, self::SANDBOX_API);
             } else {
                 throw new NonFatalException('invalid receipt - ' . $response->status, 400);
             }
         }
     }
     return $response;
 }
 public function verify($id, $receipt)
 {
     $data = $this->decodeReceipt($receipt);
     if (empty($data->receipt) === true || empty($data->userId) === true) {
         throw new NonFatalException('missing receipt or userId');
     }
     $secret = Config::get('amazon.iap.secret');
     $suffix = "/version/2.0/verify/developer/{$secret}/user/{$data->userId}/purchaseToken/{$data->receipt}";
     $url = (Environment::is(Environment::PRODUCTION) ? self::PRODUCTION_API : self::SANDBOX_API) . $suffix;
     $request = new URLRequest($url);
     $response = $request->getJSON(false);
     if (empty($response) === true) {
         throw new Exception('invalid receipt', 400);
     }
     if (empty($response->message) === false) {
         throw new NonFatalException($response->message, $request->lastResponseCode);
     }
     $productId = empty($response->sku) ? null : $response->sku;
     return $id === $productId;
 }