Skip to content

Commit ec66a45

Browse files
chore(monetization): implement ConvertedPrice (#260)
Co-authored-by: Dhemy <[email protected]>
1 parent edaab20 commit ec66a45

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Imdhemy\GooglePlay\Monetization\Domain;
6+
7+
use Imdhemy\GooglePlay\ValueObjects\RegionsVersion;
8+
9+
/**
10+
* represents the response of the convertRegionPrices method in the monetization API.
11+
*
12+
* @see https://developers.google.com/android-publisher/api-ref/rest/v3/monetization/convertRegionPrices#response-body
13+
*/
14+
final readonly class ConvertedPrices
15+
{
16+
/**
17+
* @param array<string, ConvertedRegionPrice> $convertedRegionPrices
18+
*/
19+
public function __construct(
20+
public array $convertedRegionPrices,
21+
public ConvertedOtherRegionsPrice $convertedOtherRegionsPrice,
22+
public RegionsVersion $regionVersion,
23+
) {
24+
}
25+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Monetization\Domain;
6+
7+
use Imdhemy\GooglePlay\Monetization\Domain\ConvertedOtherRegionsPrice;
8+
use Imdhemy\GooglePlay\Monetization\Domain\ConvertedPrices;
9+
use Imdhemy\GooglePlay\Monetization\Domain\ConvertedRegionPrice;
10+
use Imdhemy\GooglePlay\ValueObjects\Money;
11+
use Imdhemy\GooglePlay\ValueObjects\RegionsVersion;
12+
use Tests\TestCase;
13+
14+
final class ConvertedPricesTest extends TestCase
15+
{
16+
/** @test */
17+
public function instantiate(): void
18+
{
19+
$data = [
20+
'convertedRegionPrices' => [
21+
'DE' => [
22+
'regionCode' => 'DE',
23+
'price' => [
24+
'currencyCode' => 'EUR',
25+
'units' => '10',
26+
'nanos' => 990000000,
27+
],
28+
'taxAmount' => [
29+
'currencyCode' => 'EUR',
30+
'units' => '1',
31+
'nanos' => 760000000,
32+
],
33+
],
34+
'JP' => [
35+
'regionCode' => 'JP',
36+
'price' => [
37+
'currencyCode' => 'JPY',
38+
'units' => '1480',
39+
'nanos' => 0,
40+
],
41+
'taxAmount' => [
42+
'currencyCode' => 'JPY',
43+
'units' => '135',
44+
'nanos' => 0,
45+
],
46+
],
47+
],
48+
'convertedOtherRegionsPrice' => [
49+
'usdPrice' => [
50+
'currencyCode' => 'USD',
51+
'units' => '9',
52+
'nanos' => 990000000,
53+
],
54+
'eurPrice' => [
55+
'currencyCode' => 'EUR',
56+
'units' => '9',
57+
'nanos' => 490000000,
58+
],
59+
],
60+
'regionVersion' => [
61+
'version' => '2024/02',
62+
],
63+
];
64+
65+
$actual = $this->normalizer->normalize($data, ConvertedPrices::class);
66+
67+
$this->assertInstanceOf(ConvertedPrices::class, $actual);
68+
$convertedRegionPrices = [
69+
'DE' => new ConvertedRegionPrice(
70+
regionCode: 'DE',
71+
price: new Money(currencyCode: 'EUR', units: '10', nanos: 990000000),
72+
taxAmount: new Money(currencyCode: 'EUR', units: '1', nanos: 760000000),
73+
),
74+
'JP' => new ConvertedRegionPrice(
75+
regionCode: 'JP',
76+
price: new Money(currencyCode: 'JPY', units: '1480', nanos: 0),
77+
taxAmount: new Money(currencyCode: 'JPY', units: '135', nanos: 0),
78+
),
79+
];
80+
$convertedOtherRegionsPrice = new ConvertedOtherRegionsPrice(
81+
usdPrice: new Money(currencyCode: 'USD', units: '9', nanos: 990000000),
82+
eurPrice: new Money(currencyCode: 'EUR', units: '9', nanos: 490000000),
83+
);
84+
$regionVersion = new RegionsVersion(version: '2024/02');
85+
$this->assertEquals($convertedRegionPrices, $actual->convertedRegionPrices);
86+
$this->assertEquals($convertedOtherRegionsPrice, $actual->convertedOtherRegionsPrice);
87+
$this->assertEquals($regionVersion, $actual->regionVersion);
88+
}
89+
}

0 commit comments

Comments
 (0)