Skip to content

Commit

Permalink
Adding missing getTransactionId to amazon purchase item
Browse files Browse the repository at this point in the history
  • Loading branch information
Adar Porat committed Jan 25, 2017
1 parent 52c6eb8 commit 44eddef
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Amazon/PurchaseItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class PurchaseItem
*/
protected $_product_id;

/**
* transaction_id
*
* @var string
*/
protected $_transaction_id;

/**
* purchase_date
*
Expand Down Expand Up @@ -66,6 +73,14 @@ public function getProductId()
return $this->_product_id;
}

/**
* @return string
*/
public function getTransactionId()
{
return $this->_transaction_id;
}

/**
* @return Carbon
*/
Expand Down
41 changes: 41 additions & 0 deletions tests/Amazon/ResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
use ReceiptValidator\Amazon\Response;

/**
* @group library
*/
class AmazonResponseTest extends PHPUnit_Framework_TestCase
{

public function testInvalidOptionsToConstructor()
{
$this->setExpectedException("ReceiptValidator\\RuntimeException", "Response must be a scalar value");

new Response(Response::RESULT_OK, 'invalid');
}

public function testInvalidReceipt()
{
$response = new Response(Response::RESULT_INTERNAL_ERROR, array(''));

$this->assertFalse($response->isValid(), 'receipt must be invalid');
}

public function testValidReceipt()
{
$receipt = json_decode('{"betaProduct":false,"cancelDate":null,"parentProductId":null,"productId":"pack_100","productType":"CONSUMABLE","purchaseDate":1485359133060,"quantity":1,"receiptId":"M3qQCAiytxUzm3G05OworddJDiSi6ijXQGRFSK#AD=:1:11","renewalDate":null,"term":null,"termSku":null,"testTransaction":false}', true);

$response = new Response(Response::RESULT_OK, $receipt);

$this->assertTrue($response->isValid(), 'receipt must be valid');
$this->assertEquals(Response::RESULT_OK, $response->getResultCode(), 'receipt result code must match');

$this->assertCount(1, $response->getPurchases(), 'receipt must have single purchase');

$purchase = $response->getPurchases()[0];
$this->assertEquals('pack_100', $purchase->getProductId(), 'productId does not match');
$this->assertEquals('M3qQCAiytxUzm3G05OworddJDiSi6ijXQGRFSK#AD=:1:11', $purchase->getTransactionId(), 'transactionId does not match');
$this->assertEquals(1, $purchase->getQuantity(), 'quantity does not match');
}

}

0 comments on commit 44eddef

Please sign in to comment.