-
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 branch 'main' into next-36521/in-app-purchases
- Loading branch information
Showing
58 changed files
with
2,208 additions
and
283 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
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
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,97 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopware\App\SDK\Adapter\DynamoDB; | ||
|
||
use AsyncAws\DynamoDb\DynamoDbClient; | ||
use AsyncAws\DynamoDb\Input\DeleteItemInput; | ||
use AsyncAws\DynamoDb\Input\GetItemInput; | ||
use AsyncAws\DynamoDb\Input\PutItemInput; | ||
use Shopware\App\SDK\Shop\ShopInterface; | ||
use Shopware\App\SDK\Shop\ShopRepositoryInterface; | ||
|
||
/** | ||
* @implements ShopRepositoryInterface<DynamoDBShop> | ||
*/ | ||
class DynamoDBRepository implements ShopRepositoryInterface | ||
{ | ||
public function __construct(private readonly DynamoDbClient $client, private readonly string $tableName) | ||
{ | ||
} | ||
|
||
public function createShopStruct(string $shopId, string $shopUrl, string $shopSecret): ShopInterface | ||
{ | ||
return new DynamoDBShop($shopId, $shopUrl, $shopSecret); | ||
} | ||
|
||
public function createShop(ShopInterface $shop): void | ||
{ | ||
$this->client->putItem(new PutItemInput([ | ||
'TableName' => $this->tableName, | ||
'Item' => [ | ||
'id' => ['S' => $shop->getShopId()], | ||
'active' => ['BOOL' => $shop->isShopActive() ? '1' : '0'], | ||
'url' => ['S' => $shop->getShopUrl()], | ||
'secret' => ['S' => $shop->getShopSecret()], | ||
'clientId' => ['S' => (string) $shop->getShopClientId()], | ||
'clientSecret' => ['S' => (string) $shop->getShopClientSecret()], | ||
], | ||
])); | ||
} | ||
|
||
public function getShopFromId(string $shopId): ShopInterface|null | ||
{ | ||
$item = $this->client->getItem(new GetItemInput([ | ||
'TableName' => $this->tableName, | ||
'Key' => [ | ||
'id' => ['S' => $shopId], | ||
], | ||
]))->getItem(); | ||
|
||
if (!$item) { | ||
return null; | ||
} | ||
|
||
$shopClientId = $item['clientId']->getS(); | ||
$shopClientSecret = $item['clientSecret']->getS(); | ||
|
||
if ($shopClientSecret === '') { | ||
$shopClientSecret = null; | ||
} | ||
|
||
if ($shopClientId === '') { | ||
$shopClientId = null; | ||
} | ||
|
||
$active = $item['active']->getBool(); | ||
|
||
if ($active === null) { | ||
$active = false; | ||
} | ||
|
||
return new DynamoDBShop( | ||
$item['id']->getS() ?? '', | ||
$item['url']->getS() ?? '', | ||
$item['secret']->getS() ?? '', | ||
$shopClientId, | ||
$shopClientSecret, | ||
$active, | ||
); | ||
} | ||
|
||
public function updateShop(ShopInterface $shop): void | ||
{ | ||
$this->createShop($shop); | ||
} | ||
|
||
public function deleteShop(string $shopId): void | ||
{ | ||
$this->client->deleteItem(new DeleteItemInput([ | ||
'TableName' => $this->tableName, | ||
'Key' => [ | ||
'id' => ['S' => $shopId], | ||
], | ||
])); | ||
} | ||
} |
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,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopware\App\SDK\Adapter\DynamoDB; | ||
|
||
use Shopware\App\SDK\Shop\ShopInterface; | ||
|
||
class DynamoDBShop implements ShopInterface | ||
{ | ||
public function __construct(public string $shopId, public string $shopUrl, public string $shopSecret, public ?string $shopClientId = null, public ?string $shopClientSecret = null, public bool $active = false) | ||
{ | ||
} | ||
|
||
public function isShopActive(): bool | ||
{ | ||
return $this->active; | ||
} | ||
|
||
public function getShopId(): string | ||
{ | ||
return $this->shopId; | ||
} | ||
|
||
public function getShopUrl(): string | ||
{ | ||
return $this->shopUrl; | ||
} | ||
|
||
public function getShopSecret(): string | ||
{ | ||
return $this->shopSecret; | ||
} | ||
|
||
public function getShopClientId(): ?string | ||
{ | ||
return $this->shopClientId; | ||
} | ||
|
||
public function getShopClientSecret(): ?string | ||
{ | ||
return $this->shopClientSecret; | ||
} | ||
|
||
public function setShopApiCredentials(string $clientId, string $clientSecret): ShopInterface | ||
{ | ||
$this->shopClientId = $clientId; | ||
$this->shopClientSecret = $clientSecret; | ||
|
||
return $this; | ||
} | ||
|
||
public function setShopUrl(string $url): ShopInterface | ||
{ | ||
$this->shopUrl = $url; | ||
|
||
return $this; | ||
} | ||
|
||
public function setShopActive(bool $active): ShopInterface | ||
{ | ||
$this->active = $active; | ||
|
||
return $this; | ||
} | ||
} |
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
Oops, something went wrong.