Skip to content

Commit

Permalink
[google-play] support product consume (#362)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
lolitototo and imdhemy authored Sep 19, 2023
1 parent 3c30e52 commit 4471f5d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"ext-json": "*",
"ext-openssl": "*",
"imdhemy/appstore-iap": "^1.6",
"imdhemy/google-play-billing": "^1.4",
"imdhemy/google-play-billing": "^1.5",
"laravel/framework": ">=8.0"
},
"require-dev": {
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ public function acknowledge(?string $developerPayload = null): EmptyResponse
return $this->createProduct()->acknowledge($developerPayload);
}

/**
* @throws GuzzleException
*/
public function consume(): EmptyResponse
{
return $this->createProduct()->consume();
}

/**
* @throws GuzzleException|InvalidReceiptException
*/
Expand Down
18 changes: 18 additions & 0 deletions tests/Facades/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
namespace Imdhemy\Purchases\Tests\Facades;

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Imdhemy\AppStore\Exceptions\InvalidReceiptException;
use Imdhemy\AppStore\Receipts\ReceiptResponse;
use Imdhemy\GooglePlay\ClientFactory;
use Imdhemy\GooglePlay\Products\ProductClient;
use Imdhemy\GooglePlay\Products\ProductPurchase;
use Imdhemy\GooglePlay\ValueObjects\EmptyResponse;
use Imdhemy\Purchases\Facades\Product;
Expand Down Expand Up @@ -79,4 +81,20 @@ public function test_facade_can_verify_product_receipt()
$this->assertInstanceOf(ReceiptResponse::class, $receiptResponse);
$this->assertEquals($status, $receiptResponse->getStatus()->getValue());
}

/** @test */
public function facade_can_consume_google_play_product(): void
{
$history = [];
$response = new Response(200, [], '[]');
$client = ClientFactory::mock($response, $history);

Product::googlePlay($client)->id($this->itemId)->token($this->token)->consume();

$this->assertCount(1, $history);
/** @var Request $request */
$request = $history[0]['request'];
$expectedUri = sprintf(ProductClient::URI_CONSUME, 'com.some.thing', $this->itemId, $this->token);
$this->assertEquals($expectedUri, $request->getUri()->__toString());
}
}

0 comments on commit 4471f5d

Please sign in to comment.