diff --git a/src/Amazon/PurchaseItem.php b/src/Amazon/PurchaseItem.php index c89d9ec..bc039a9 100644 --- a/src/Amazon/PurchaseItem.php +++ b/src/Amazon/PurchaseItem.php @@ -28,6 +28,13 @@ class PurchaseItem */ protected $_product_id; + /** + * transaction_id + * + * @var string + */ + protected $_transaction_id; + /** * purchase_date * @@ -66,6 +73,14 @@ public function getProductId() return $this->_product_id; } + /** + * @return string + */ + public function getTransactionId() + { + return $this->_transaction_id; + } + /** * @return Carbon */ diff --git a/tests/Amazon/ResponseTest.php b/tests/Amazon/ResponseTest.php new file mode 100644 index 0000000..5c39860 --- /dev/null +++ b/tests/Amazon/ResponseTest.php @@ -0,0 +1,41 @@ +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'); + } + +} \ No newline at end of file