Skip to content

Commit

Permalink
Release 6.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrososa committed Jun 24, 2024
1 parent 0f61d85 commit 41cd180
Show file tree
Hide file tree
Showing 38 changed files with 404 additions and 122 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 6.1.5
- Support for Shopware 6.6.3.1 and Vue 3

# 6.1.4
- Improved plugin's settings form
- Support for Shopware 6.6.2.0
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 6.1.5
- Unterstützung von Shopware 6.6.3.1 und Vue 3

# 6.1.4
- Das Einstellungsformular des Plugins wurde verbessert
- Unterstützung von Shopware 6.6.2.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ tail -f var/log/postfinancecheckout_payment*.log

## Documentation

[Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/shopware-6/6.1.4/docs/en/documentation.html)
[Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/shopware-6/6.1.5/docs/en/documentation.html)

## License

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@
"postfinancecheckout/sdk": "4.2.0"
},
"type": "shopware-platform-plugin",
"version": "6.1.4"
"version": "6.1.5"
}
2 changes: 1 addition & 1 deletion docs/en/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2>Documentation</h2> </div>
</a>
</li>
<li>
<a href="https://github.com/pfpayments/shopware-6/releases/tag/6.1.4/">
<a href="https://github.com/pfpayments/shopware-6/releases/tag/6.1.5/">
Source
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use Psr\Log\LoggerInterface;
use Shopware\Core\{
Framework\Context,
Framework\Log\Package,};
Framework\Log\Package};
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\{
HttpFoundation\JsonResponse,
HttpFoundation\Request,
HttpFoundation\Response,
Routing\Annotation\Route};
Routing\Attribute\Route};
use PostFinanceCheckoutPayment\Core\{
Api\OrderDeliveryState\Service\OrderDeliveryStateService,
Api\PaymentMethodConfiguration\Service\PaymentMethodConfigurationService,
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Api/Refund/Controller/RefundController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\{
HttpFoundation\Request,
HttpFoundation\Response,
Routing\Annotation\Route,};
Routing\Attribute\Route,};
use PostFinanceCheckoutPayment\Core\{
Api\Refund\Service\RefundService,
Settings\Service\SettingsService};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
HttpFoundation\JsonResponse,
HttpFoundation\Request,
HttpFoundation\Response,
Routing\Annotation\Route};
Routing\Attribute\Route};
use PostFinanceCheckout\Sdk\{
Model\TransactionState};
use PostFinanceCheckoutPayment\Core\Settings\Service\SettingsService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
HttpFoundation\JsonResponse,
HttpFoundation\Request,
HttpFoundation\Response,
Routing\Annotation\Route};
Routing\Attribute\Route};
use PostFinanceCheckoutPayment\{
Core\Api\Transaction\Service\TransactionService,
Core\Settings\Service\SettingsService};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
HttpFoundation\JsonResponse,
HttpFoundation\Request,
HttpFoundation\Response,
Routing\Annotation\Route};
Routing\Attribute\Route};
use PostFinanceCheckout\Sdk\{
Model\TransactionState};
use PostFinanceCheckoutPayment\Core\Settings\Service\SettingsService;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Api/WebHooks/Controller/WebHookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
HttpFoundation\ParameterBag,
HttpFoundation\Request,
HttpFoundation\Response,
Routing\Annotation\Route};
Routing\Attribute\Route};
use PostFinanceCheckout\Sdk\{
Model\RefundState,
Model\Transaction,
Expand Down
189 changes: 189 additions & 0 deletions src/Core/Settings/Command/CreateMerchantCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?php declare(strict_types=1);

namespace PostFinanceCheckoutPayment\Core\Settings\Command;

use Symfony\Component\{
Console\Command\Command,
Console\Attribute\AsCommand,
Console\Input\InputInterface,
Console\Input\InputArgument,
Console\Input\InputOption,
Console\Output\OutputInterface,
PasswordHasher\Hasher\UserPasswordHasherInterface};
use Shopware\Core\Framework\{
DataAbstractionLayer\EntityRepository,
DataAbstractionLayer\EntityRepositoryInterface,
DataAbstractionLayer\Search\Criteria,
DataAbstractionLayer\Search\Filter\EqualsFilter,
Uuid\Uuid,
Context};
use PostFinanceCheckoutPayment\Core\{
Settings\Options\Integration,
Settings\Service\SettingsService};

/**
* Class CreateMerchantCommand
* @internal
* @package PostFinanceCheckoutPayment\Core\Settings\Command
*/
#[AsCommand(name: 'postfinancecheckout:settings:create-merchant')]
class CreateMerchantCommand extends Command {

/**
* @var EntityRepositoryInterface Repository for user entities
*/
private $userRepository;

/**
* @var EntityRepositoryInterface Repository for user role entities
*/
private $userRoleRepository;

/**
* @var EntityRepositoryInterface Repository for locale entities
*/
private $localeRepository;

/**
* CreateMerchantUserCommand constructor.
*
* @param EntityRepositoryInterface $userRepository
* @param EntityRepositoryInterface $userRoleRepository
* @param EntityRepositoryInterface $localeRepository
*/
public function __construct(
EntityRepository $userRepository,
EntityRepository $userRoleRepository,
EntityRepository $localeRepository,
) {
parent::__construct();
$this->userRepository = $userRepository;
$this->userRoleRepository = $userRoleRepository;
$this->localeRepository = $localeRepository;
}

/**
* Executes the command to create a new merchant user with a specific role.
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int Command::SUCCESS on success, Command::FAILURE on failure
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('Creating PostFinanceCheckoutPayment merchant with custom role...');

$firstName = $input->getOption('firstName');
$lastName = $input->getOption('lastName');
$email = $input->getOption('email') ?? '[email protected]';
$password = $input->getOption('password') ?? 'merchant123';

$context = Context::createDefaultContext();

// Check if user already exists
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('email', $email));
$existingUser = $this->userRepository->search($criteria, $context)->first();

if ($existingUser) {
$output->writeln('User already exists.');
return Command::SUCCESS;
}

// Create role if it doesn't exist
$roleId = $this->getOrCreateRoleId('PostFinanceCheckout viewer', $context);

// Create user if it doesn't exist
$this->userRepository->create([
[
'id' => Uuid::randomHex(),
'username' => $email,
'email' => $email,
'firstName' => $firstName,
'lastName' => $lastName,
'password' => $password,
'admin' => false,
'localeId' => $this->getLocaleId($context),
'aclRoles' => [
[
'id' => $roleId
]
],
]
], $context);

$output->writeln('Merchant user created successfully.');

return Command::SUCCESS;
}

/**
* Fetches the default locale ID.
*
* @param Context $context
* @return string Locale ID
* @throws \RuntimeException If the default locale is not found
*/
private function getLocaleId(Context $context): string
{
// Fetch the default locale id
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('code', 'en-GB'));
$localeId = $this->localeRepository->searchIds($criteria, $context)->firstId();

if (!$localeId) {
throw new \RuntimeException('Default locale not found');
}

return $localeId;
}

/**
* Fetches the role ID for a given role name or creates the role if it does not exist.
*
* @param string $roleName
* @param Context $context
* @return string Role ID
* @throws \RuntimeException If the role cannot be created or found
*/
private function getOrCreateRoleId(string $roleName, Context $context): string
{
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('name', $roleName));
$roleId = $this->userRoleRepository->searchIds($criteria, $context)->firstId();

if (!$roleId) {
$roleId = Uuid::randomHex();
$this->userRoleRepository->create([
[
'id' => $roleId,
'name' => $roleName,
'privileges' => [
'postfinancecheckout.viewer',
'postfinancecheckout_sales_channel:read',
'postfinancecheckout_sales_channel_run:read',
'postfinancecheckout_sales_channel_run_log:read',
'language:read',
'locale:read',
'system_config:read'
]
]
], $context);
}

return $roleId;
}

/**
* Configures the current command.
*/
protected function configure(): void
{
$this
->setDescription('Creates a new merchant user with specific roles.')
->addOption('firstName', null, InputOption::VALUE_OPTIONAL, 'First name of the merchant user', 'Merchant')
->addOption('lastName', null, InputOption::VALUE_OPTIONAL, 'Last name of the merchant user', 'Merchant')
->addOption('email', null, InputOption::VALUE_OPTIONAL, 'Email of the merchant user')
->addOption('password', null, InputOption::VALUE_OPTIONAL, 'Password of the merchant user');
}
}
8 changes: 0 additions & 8 deletions src/Core/Settings/Command/SettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
SettingsService::CONFIG_APPLICATION_KEY => $input->getOption(SettingsService::CONFIG_APPLICATION_KEY),
SettingsService::CONFIG_EMAIL_ENABLED => $input->getOption(SettingsService::CONFIG_EMAIL_ENABLED),
SettingsService::CONFIG_INTEGRATION => $input->getOption(SettingsService::CONFIG_INTEGRATION),
SettingsService::CONFIG_IS_SHOWCASE => $input->getOption(SettingsService::CONFIG_IS_SHOWCASE),
SettingsService::CONFIG_LINE_ITEM_CONSISTENCY_ENABLED => $input->getOption(SettingsService::CONFIG_LINE_ITEM_CONSISTENCY_ENABLED),
SettingsService::CONFIG_SPACE_ID => $input->getOption(SettingsService::CONFIG_SPACE_ID),
SettingsService::CONFIG_SPACE_VIEW_ID => $input->getOption(SettingsService::CONFIG_SPACE_VIEW_ID),
Expand Down Expand Up @@ -98,13 +97,6 @@ protected function configure()
SettingsService::CONFIG_INTEGRATION,
Integration::IFRAME
)
->addOption(
SettingsService::CONFIG_IS_SHOWCASE,
SettingsService::CONFIG_IS_SHOWCASE,
InputOption::VALUE_OPTIONAL,
SettingsService::CONFIG_IS_SHOWCASE,
false
)
->addOption(
SettingsService::CONFIG_LINE_ITEM_CONSISTENCY_ENABLED,
SettingsService::CONFIG_LINE_ITEM_CONSISTENCY_ENABLED,
Expand Down
1 change: 0 additions & 1 deletion src/Core/Settings/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class SettingsService {
public const CONFIG_APPLICATION_KEY = 'applicationKey';
public const CONFIG_EMAIL_ENABLED = 'emailEnabled';
public const CONFIG_INTEGRATION = 'integration';
public const CONFIG_IS_SHOWCASE = 'isShowcase';
public const CONFIG_LINE_ITEM_CONSISTENCY_ENABLED = 'lineItemConsistencyEnabled';
public const CONFIG_SPACE_ID = 'spaceId';
public const CONFIG_SPACE_VIEW_ID = 'spaceViewId';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
HttpFoundation\HeaderUtils,
HttpFoundation\RequestStack,
HttpFoundation\Response,
Routing\Annotation\Route,
Routing\Attribute\Route,
Security\Core\Exception\AccessDeniedException};
use PostFinanceCheckoutPayment\Core\{
Api\Transaction\Service\TransactionService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use Symfony\Component\{
HttpFoundation\Request,
HttpFoundation\Response,
Routing\Annotation\Route,
Routing\Attribute\Route,
Routing\Generator\UrlGeneratorInterface
};
use PostFinanceCheckout\Sdk\{
Expand Down
Loading

0 comments on commit 41cd180

Please sign in to comment.