-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding missing getTransactionId to amazon purchase item
- Loading branch information
Adar Porat
committed
Jan 25, 2017
1 parent
52c6eb8
commit 44eddef
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
|
||
} |