Skip to content

Commit

Permalink
fix: use json guzzle request option instead of form_params (#102)
Browse files Browse the repository at this point in the history
* fix: use json guzzle request option instead of form_params

* [test] assert using json in defer subscription:defer

---------

Co-authored-by: Mike Mellor <[email protected]>
Co-authored-by: imdhemy <[email protected]>
  • Loading branch information
3 people authored Dec 15, 2023
1 parent a227174 commit bb94f3b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Subscriptions/SubscriptionClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function defer(SubscriptionDeferralInfo $subscriptionDeferralInfo): Time
{
$uri = $this->getEndpoint(self::URI_DEFER);
$options = [
'form_params' => [
'json' => [
'deferralInfo' => $subscriptionDeferralInfo->toArray(),
],
];
Expand Down
7 changes: 2 additions & 5 deletions tests/Subscriptions/SubscriptionClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Imdhemy\GooglePlay\Subscriptions\SubscriptionPurchase;
use Imdhemy\GooglePlay\ValueObjects\EmptyResponse;
use Imdhemy\GooglePlay\ValueObjects\SubscriptionDeferralInfo;
use Imdhemy\GooglePlay\ValueObjects\Time;
use Tests\TestCase;

class SubscriptionClientTest extends TestCase
Expand Down Expand Up @@ -113,10 +112,8 @@ public function cancel()

/**
* @test
*
* @throws GuzzleException
*/
public function defer()
public function defer(): void
{
$desiredExpiryTimeMillis = $this->faker->dateTime->getTimestamp() * 1000;
$deferResponse = new Response(200, [], json_encode(['newExpiryTimeMillis' => $desiredExpiryTimeMillis]));
Expand All @@ -128,11 +125,11 @@ public function defer()
$deferralInfo = new SubscriptionDeferralInfo(0, $desiredExpiryTimeMillis);
$newExpiryTime = $subscriptionClient->defer($deferralInfo);

$this->assertInstanceOf(Time::class, $newExpiryTime);
$this->assertEquals($desiredExpiryTimeMillis, $newExpiryTime->getCarbon()->getTimestampMs());

/** @var Request $request */
$request = $transactions[0]['request'];
$this->assertEquals($deferralInfo->toArray(), json_decode($request->getBody()->getContents(), true)['deferralInfo']);
$uri = $this->getEndpoint(SubscriptionClient::URI_DEFER);
$this->assertEquals($uri, (string)$request->getUri());
}
Expand Down

0 comments on commit bb94f3b

Please sign in to comment.