Skip to content

Commit 4471f5d

Browse files
lolitototoimdhemy
andauthored
[google-play] support product consume (#362)
* Update Product.php with consume * [deps] update google play billing * [cicd] fix styling * [google-play] add test for product consume --------- Co-authored-by: imdhemy <[email protected]>
1 parent 3c30e52 commit 4471f5d

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"ext-json": "*",
2222
"ext-openssl": "*",
2323
"imdhemy/appstore-iap": "^1.6",
24-
"imdhemy/google-play-billing": "^1.4",
24+
"imdhemy/google-play-billing": "^1.5",
2525
"laravel/framework": ">=8.0"
2626
},
2727
"require-dev": {

composer.lock

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Product.php

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ public function acknowledge(?string $developerPayload = null): EmptyResponse
9696
return $this->createProduct()->acknowledge($developerPayload);
9797
}
9898

99+
/**
100+
* @throws GuzzleException
101+
*/
102+
public function consume(): EmptyResponse
103+
{
104+
return $this->createProduct()->consume();
105+
}
106+
99107
/**
100108
* @throws GuzzleException|InvalidReceiptException
101109
*/

tests/Facades/ProductTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
namespace Imdhemy\Purchases\Tests\Facades;
66

77
use GuzzleHttp\Exception\GuzzleException;
8+
use GuzzleHttp\Psr7\Request;
89
use GuzzleHttp\Psr7\Response;
910
use Imdhemy\AppStore\Exceptions\InvalidReceiptException;
1011
use Imdhemy\AppStore\Receipts\ReceiptResponse;
1112
use Imdhemy\GooglePlay\ClientFactory;
13+
use Imdhemy\GooglePlay\Products\ProductClient;
1214
use Imdhemy\GooglePlay\Products\ProductPurchase;
1315
use Imdhemy\GooglePlay\ValueObjects\EmptyResponse;
1416
use Imdhemy\Purchases\Facades\Product;
@@ -79,4 +81,20 @@ public function test_facade_can_verify_product_receipt()
7981
$this->assertInstanceOf(ReceiptResponse::class, $receiptResponse);
8082
$this->assertEquals($status, $receiptResponse->getStatus()->getValue());
8183
}
84+
85+
/** @test */
86+
public function facade_can_consume_google_play_product(): void
87+
{
88+
$history = [];
89+
$response = new Response(200, [], '[]');
90+
$client = ClientFactory::mock($response, $history);
91+
92+
Product::googlePlay($client)->id($this->itemId)->token($this->token)->consume();
93+
94+
$this->assertCount(1, $history);
95+
/** @var Request $request */
96+
$request = $history[0]['request'];
97+
$expectedUri = sprintf(ProductClient::URI_CONSUME, 'com.some.thing', $this->itemId, $this->token);
98+
$this->assertEquals($expectedUri, $request->getUri()->__toString());
99+
}
82100
}

0 commit comments

Comments
 (0)