Skip to content

Commit

Permalink
Merge pull request #26 from kernio/master
Browse files Browse the repository at this point in the history
Fix iTunes Response return types, adding test for latest receipt
  • Loading branch information
aporat committed Mar 24, 2016
2 parents 085f727 + 0d0d57a commit 2d53c4a
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/iTunes/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Response
*
* @var string
*/
protected $_bundle_id = null;
protected $_bundle_id;

/**
* receipt info
Expand All @@ -64,16 +64,16 @@ class Response
/**
* latest receipt (needs for auto-renewable subscriptions)
*
* @var array
* @var string
*/
protected $_latest_receipt = array();
protected $_latest_receipt;

/**
* latest receipt info (needs for auto-renewable subscriptions)
*
* @var string
* @var array
*/
protected $_latest_receipt_info = null;
protected $_latest_receipt_info;

/**
* purhcases info
Expand Down Expand Up @@ -160,7 +160,7 @@ public function getLatestReceipt()
/**
* Get the bundle id assoicated with the receipt
*
* @return array
* @return string
*/
public function getBundleId()
{
Expand All @@ -185,7 +185,9 @@ public function isValid()
* Parse JSON Response
*
* @param string $jsonResponse
* @return Message
*
* @return Response
* @throws RunTimeException
*/
public function parseJsonResponse($jsonResponse)
{
Expand Down
16 changes: 16 additions & 0 deletions tests/iTunes/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,20 @@ public function testValidReceipt()
$this->assertEquals(0, $response->getResultCode(), 'receipt result code must match');
}

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');
}
}
84 changes: 84 additions & 0 deletions tests/iTunes/fixtures/inAppPurchaseResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"environment": "Sandbox",
"latest_receipt": "MILFMwYJKoZIhvcNAQcCoILFJDCCxSACAQExCzAJBgUrDgMCGgUAMIK05AYJKoZIhvcNAQcBoIK01QSCtNExgrTNMAoCAQgCAQEEAhYAMAoCARICAQEEAhYAMAoCARMCAQEEAgwAMAoCARQCAQEEAgwAMAsCAQECAQEEAwIBADA",
"latest_receipt_info": [
{
"expires_date": "2014-03-12 10:18:05 Etc\/GMT",
"expires_date_ms": 1394619485000,
"expires_date_pst": "2014-03-12 03:18:05 America\/Los_Angeles",
"is_trial_period": false,
"original_purchase_date": "2014-03-12 10:15:06 Etc\/GMT",
"original_purchase_date_ms": 1394619306000,
"original_purchase_date_pst": "2014-03-12 03:15:06 America\/Los_Angeles",
"original_transaction_id": 1000000093384828,
"product_id": "myapp.1",
"purchase_date": "2014-03-25 12:21:23 Etc\/GMT",
"purchase_date_ms": 1395750083000,
"purchase_date_pst": "2014-03-25 05:21:23 America\/Los_Angeles",
"quantity": 1,
"transaction_id": 1000000104232856,
"web_order_line_item_id": 1000000027948608
},
{
"expires_date": "2013-11-14 10:23:43 Etc\/GMT",
"expires_date_ms": 1384424623000,
"expires_date_pst": "2013-11-14 02:23:43 America\/Los_Angeles",
"original_purchase_date": "2013-11-14 10:20:44 Etc\/GMT",
"original_purchase_date_ms": 1384424444000,
"original_purchase_date_pst": "2013-11-14 02:20:44 America\/Los_Angeles",
"original_transaction_id": 1000000093384828,
"product_id": "myapp.2",
"purchase_date": "2014-03-29 05:37:36 Etc\/GMT",
"purchase_date_ms": 1396071456569,
"purchase_date_pst": "2014-03-28 22:37:36 America\/Los_Angeles",
"quantity": 1,
"transaction_id": 1000000093384828,
"web_order_line_item_id": 1000000027562376
}
],
"receipt": {
"adam_id": 0,
"app_item_id": 0,
"application_version": 1,
"bundle_id": "com.myapp",
"download_id": 0,
"in_app": [
{
"is_trial_period": false,
"original_purchase_date": "2015-05-24 01:06:58 Etc\/GMT",
"original_purchase_date_ms": 1432429618000,
"original_purchase_date_pst": "2015-05-23 18:06:58 America\/Los_Angeles",
"original_transaction_id": 1000000156455961,
"product_id": "myapp.1",
"purchase_date": "2015-05-24 01:06:58 Etc\/GMT",
"purchase_date_ms": 1432429618000,
"purchase_date_pst": "2015-05-23 18:06:58 America\/Los_Angeles",
"quantity": 1,
"transaction_id": 1000000156455961
},
{
"is_trial_period": false,
"original_purchase_date": "2015-05-20 17:41:12 Etc\/GMT",
"original_purchase_date_ms": 1432143672000,
"original_purchase_date_pst": "2015-05-20 10:41:12 America\/Los_Angeles",
"original_transaction_id": 1000000156014803,
"product_id": "myapp.2",
"purchase_date": "2015-05-20 17:41:12 Etc\/GMT",
"purchase_date_ms": 1432143672000,
"purchase_date_pst": "2015-05-20 10:41:12 America\/Los_Angeles",
"quantity": 1,
"transaction_id": 1000000156014803
}
],
"original_application_version": "1.0",
"original_purchase_date": "2013-08-01 07:00:00 Etc\/GMT",
"original_purchase_date_ms": 1375340400000,
"original_purchase_date_pst": "2013-08-01 00:00:00 America\/Los_Angeles",
"receipt_type": "ProductionSandbox",
"request_date": "2015-05-24 16:31:18 Etc\/GMT",
"request_date_ms": 1432485078143,
"request_date_pst": "2015-05-24 09:31:18 America\/Los_Angeles",
"version_external_identifier": 0
},
"status": 0
}

0 comments on commit 2d53c4a

Please sign in to comment.