public function testReceiptWithLatestReceiptInfo() { $jsonResponseString = file_get_contents(__DIR__ . '/fixtures/inAppPurchaseResponse.json'); $jsonResponseArray = json_decode($jsonResponseString, true); $response = new Response($jsonResponseArray); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $response->getLatestReceiptInfo()); $this->assertEquals($jsonResponseArray['latest_receipt_info'], $response->getLatestReceiptInfo(), 'latest receipt info must match'); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $response->getLatestReceipt()); $this->assertEquals($jsonResponseArray['latest_receipt'], $response->getLatestReceipt(), 'latest receipt must match'); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $response->getBundleId()); $this->assertEquals($jsonResponseArray['receipt']['bundle_id'], $response->getBundleId(), 'receipt bundle id must match'); }
public function testValidReceipt() { $response = new Response(array('status' => 0, 'receipt' => array())); $this->assertTrue($response->isValid(), 'receipt must be valid'); $this->assertEquals(0, $response->getResultCode(), 'receipt result code must match'); }
/** * validate the receipt data * * @param string $receiptData * * @return Response */ public function validate($receiptData = null, $iStoreSharedSecret = null) { if ($receiptData != null) { $this->setReceiptData($receiptData); } if ($iStoreSharedSecret != null) { $this->setIStoreSharedSecret($receiptData); } $httpResponse = $this->getClient()->post(null, null, $this->encodeRequest(), array('verify' => false))->send(); if ($httpResponse->getStatusCode() != 200) { throw new RunTimeException('Unable to get response from itunes server'); } $response = new Response($httpResponse->json()); // on a 21007 error retry the request in the sandbox environment (if the current environment is Production) // these are receipts from apple review team if ($this->_endpoint == self::ENDPOINT_PRODUCTION && $response->getResultCode() == Response::RESULT_SANDBOX_RECEIPT_SENT_TO_PRODUCTION) { $client = new GuzzleClient(self::ENDPOINT_SANDBOX); $httpResponse = $client->post(null, null, $this->encodeRequest(), array('verify' => false))->send(); if ($httpResponse->getStatusCode() != 200) { throw new RunTimeException('Unable to get response from itunes server'); } $response = new Response($httpResponse->json()); } return $response; }
public function testValidReceipt() { $response = new Response(array('status' => 0, 'receipt' => [])); $this->assertTrue($response->isValid(), 'receipt must be valid'); }