-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from shopware/next-37028/iaf-filter-gateway
NEXT-37028 - IAP Filter Gateway
- Loading branch information
Showing
6 changed files
with
242 additions
and
22 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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopware\App\SDK\Context\Gateway\InAppFeatures; | ||
|
||
use Shopware\App\SDK\Context\ActionSource; | ||
use Shopware\App\SDK\Framework\Collection; | ||
use Shopware\App\SDK\Shop\ShopInterface; | ||
|
||
class FilterAction | ||
{ | ||
/** | ||
* Use this action to filter in-app purchases to be *available* to buy for the customer. | ||
* In the ActionSource you can find any *active* purchases. | ||
* | ||
* @param Collection<string> $purchases - The list of purchases to filter for | ||
*/ | ||
public function __construct( | ||
public readonly ShopInterface $shop, | ||
public readonly ActionSource $source, | ||
public readonly Collection $purchases, | ||
) { | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopware\App\SDK\Response; | ||
|
||
use Http\Discovery\Psr17Factory; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Shopware\App\SDK\Framework\Collection; | ||
|
||
class InAppPurchasesResponse | ||
{ | ||
/** | ||
* @param Collection<string> $purchases | ||
*/ | ||
public static function filter(Collection $purchases): ResponseInterface | ||
{ | ||
return self::createResponse(['purchases' => $purchases->all()]); | ||
} | ||
|
||
/** | ||
* @param array<mixed> $data | ||
*/ | ||
private static function createResponse(array $data): ResponseInterface | ||
{ | ||
$psr = new Psr17Factory(); | ||
|
||
return $psr->createResponse(200) | ||
->withHeader('Content-Type', 'application/json') | ||
->withBody($psr->createStream(\json_encode($data, \JSON_THROW_ON_ERROR))); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopware\App\SDK\Tests\Context\Gateway\InAppFeatures; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use Shopware\App\SDK\Context\ActionSource; | ||
use Shopware\App\SDK\Context\Gateway\InAppFeatures\FilterAction; | ||
use Shopware\App\SDK\Framework\Collection; | ||
use Shopware\App\SDK\Test\MockShop; | ||
|
||
#[CoversClass(FilterAction::class)] | ||
class FilterActionTest extends TestCase | ||
{ | ||
public function testConstruct(): void | ||
{ | ||
$purchases = new Collection(['purchase-1', 'purchase-2', 'purchase-3']); | ||
|
||
$shop = new MockShop('foo', 'https://example.com', 'secret'); | ||
$source = new ActionSource('https://example.com', '1.0.0', new Collection()); | ||
|
||
$action = new FilterAction($shop, $source, $purchases); | ||
|
||
static::assertSame($shop, $action->shop); | ||
static::assertSame($source, $action->source); | ||
static::assertSame($purchases, $action->purchases); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopware\App\SDK\Tests\Response; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use Shopware\App\SDK\Framework\Collection; | ||
use Shopware\App\SDK\Response\InAppPurchasesResponse; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(InAppPurchasesResponse::class)] | ||
class InAppPurchasesResponseTest extends TestCase | ||
{ | ||
public function testPaid(): void | ||
{ | ||
$purchases = new Collection(['foo', 'bar']); | ||
$response = InAppPurchasesResponse::filter($purchases); | ||
|
||
static::assertSame(200, $response->getStatusCode()); | ||
static::assertSame('application/json', $response->getHeaderLine('Content-Type')); | ||
static::assertSame('{"purchases":["foo","bar"]}', $response->getBody()->getContents()); | ||
} | ||
} |