Skip to content

Commit

Permalink
Release 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vttn committed Jun 19, 2020
1 parent f0a365d commit 2d0438e
Show file tree
Hide file tree
Showing 80 changed files with 3,416 additions and 1,360 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# 1.0.0a
# 1.1.0
- Handle empty/default Settings values
- Save refunds to db, and reload order tab on changes

# 1.0.0
- First version of the Wallee integrations for Shopware 6
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"ext-json": "*",
"ext-mbstring": "*",
"php": ">=7.2",
"shopware/core": "~6.2",
"shopware/storefront": "~6.2",
"shopware/core": ">=6.2,<7",
"shopware/storefront": ">=6.2,<7",
"wallee/sdk": "2.1.*"
},
"type": "shopware-platform-plugin",
"version": "1.0.0"
"version": "1.1.0"
}
48 changes: 36 additions & 12 deletions src/Core/Api/Configuration/Controller/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
use Symfony\Component\{
HttpFoundation\JsonResponse,
HttpFoundation\Request,
HttpFoundation\Response,
Routing\Annotation\Route,};
Routing\Annotation\Route};
use WalleePayment\Core\{
Api\OrderDeliveryState\Service\OrderDeliveryStateService,
Api\PaymentMethodConfiguration\Service\PaymentMethodConfigurationService,
Api\WebHooks\Service\WebHooksService};
use WalleePayment\Util\PaymentMethodUtil;
Api\WebHooks\Service\WebHooksService,
Util\PaymentMethodUtil};

/**
* Class ConfigurationController
Expand All @@ -38,7 +38,7 @@ class ConfigurationController extends AbstractController {
protected $logger;

/**
* @var \WalleePayment\Util\PaymentMethodUtil
* @var \WalleePayment\Core\Util\PaymentMethodUtil
*/
private $paymentMethodUtil;

Expand All @@ -50,7 +50,7 @@ class ConfigurationController extends AbstractController {
/**
* ConfigurationController constructor.
*
* @param \WalleePayment\Util\PaymentMethodUtil $paymentMethodUtil
* @param \WalleePayment\Core\Util\PaymentMethodUtil $paymentMethodUtil
* @param \WalleePayment\Core\Api\PaymentMethodConfiguration\Service\PaymentMethodConfigurationService $paymentMethodConfigurationService
* @param \WalleePayment\Core\Api\WebHooks\Service\WebHooksService $webHooksService
* @param \Psr\Log\LoggerInterface $logger
Expand All @@ -62,32 +62,33 @@ public function __construct(
LoggerInterface $logger
)
{
$this->paymentMethodUtil = $paymentMethodUtil;
$this->webHooksService = $webHooksService;
$this->logger = $logger;
$this->webHooksService = $webHooksService;
$this->paymentMethodUtil = $paymentMethodUtil;

$this->paymentMethodConfigurationService = $paymentMethodConfigurationService;
$this->logger = $logger;
}

/**
* Set WalleePayment as the default payment for a give sales channel
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Shopware\Core\Framework\Context $context
* @return \Symfony\Component\HttpFoundation\Response
* @return \Symfony\Component\HttpFoundation\JsonResponse
*
* @Route(
* "/api/v{version}/_action/wallee/configuration/set-wallee-as-sales-channel-payment-default",
* name="api.action.wallee.configuration.set-wallee-as-sales-channel-payment-default",
* methods={"POST"}
* )
*/
public function setWalleeAsSalesChannelPaymentDefault(Request $request, Context $context): Response
public function setWalleeAsSalesChannelPaymentDefault(Request $request, Context $context): JsonResponse
{
$salesChannelId = $request->request->get('salesChannelId');
$salesChannelId = ($salesChannelId == 'null') ? null : $salesChannelId;

$this->paymentMethodUtil->setWalleeAsDefaultPaymentMethod($context, $salesChannelId);
return new Response(null, Response::HTTP_NO_CONTENT);
return new JsonResponse([]);
}

/**
Expand Down Expand Up @@ -140,4 +141,27 @@ public function synchronizePaymentMethodConfiguration(Request $request, Context

return new JsonResponse(['result' => $result]);
}

/**
* Install OrderDeliveryStates
*
* @param \Shopware\Core\Framework\Context $context
* @return \Symfony\Component\HttpFoundation\JsonResponse
*
* @Route(
* "/api/v{version}/_action/wallee/configuration/install-order-delivery-states",
* name="api.action.wallee.configuration.install-order-delivery-states",
* methods={"POST"}
* )
*/
public function installOrderDeliveryStates(Context $context): JsonResponse
{
/**
* @var \WalleePayment\Core\Api\OrderDeliveryState\Service\OrderDeliveryStateService $orderDeliveryStateService
*/
$orderDeliveryStateService = $this->container->get(OrderDeliveryStateService::class);
$orderDeliveryStateService->install($context);

return new JsonResponse([]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php declare(strict_types=1);

namespace WalleePayment\Core\Api\OrderDeliveryState\Handler;

use Shopware\Core\{
Checkout\Order\Aggregate\OrderDelivery\OrderDeliveryDefinition,
Framework\Context,
System\StateMachine\StateMachineRegistry,
System\StateMachine\Transition};

/**
* Class OrderDeliveryStateHandler
*
* @package WalleePayment\Core\Api\OrderDeliveryState\Handler
*/
class OrderDeliveryStateHandler {

public const STATE_HOLD = 'hold';
public const ACTION_HOLD = 'hold';
public const ACTION_UNHOLD = 'unhold';

/**
* @var \Shopware\Core\System\StateMachine\StateMachineRegistry
*/
private $stateMachineRegistry;

/**
* OrderDeliveryStateHandler constructor.
*
* @param \Shopware\Core\System\StateMachine\StateMachineRegistry $stateMachineRegistry
*/
public function __construct(StateMachineRegistry $stateMachineRegistry)
{
$this->stateMachineRegistry = $stateMachineRegistry;
}

/**
* @param string $entityId
* @param \Shopware\Core\Framework\Context $context
*/
public function hold(string $entityId, Context $context): void
{
$this->stateMachineRegistry->transition(
new Transition(
OrderDeliveryDefinition::ENTITY_NAME,
$entityId,
self::ACTION_HOLD,
'stateId'
),
$context
);
}

/**
* @param string $entityId
* @param \Shopware\Core\Framework\Context $context
*/
public function unhold(string $entityId, Context $context): void
{
$this->stateMachineRegistry->transition(
new Transition(
OrderDeliveryDefinition::ENTITY_NAME,
$entityId,
self::ACTION_UNHOLD,
'stateId'
),
$context
);
}
}
187 changes: 187 additions & 0 deletions src/Core/Api/OrderDeliveryState/Service/OrderDeliveryStateService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<?php declare(strict_types=1);

namespace WalleePayment\Core\Api\OrderDeliveryState\Service;

use Psr\Container\ContainerInterface;
use Shopware\Core\{
Checkout\Order\Aggregate\OrderDelivery\OrderDeliveryStates,
Framework\Context,
Framework\DataAbstractionLayer\Search\Criteria,
Framework\DataAbstractionLayer\Search\Filter\EqualsFilter,
Framework\Uuid\Uuid};
use WalleePayment\Core\Api\OrderDeliveryState\Handler\OrderDeliveryStateHandler;

/**
* Class OrderDeliveryStateService
*
* @package WalleePayment\Core\Api\OrderDeliveryState\Service
*/
class OrderDeliveryStateService {

/**
* @var \Psr\Container\ContainerInterface
*/
protected $container;

/**
* OrderDeliveryStateHandler constructor.
*
* @param \Psr\Container\ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}

/**
* @param \Shopware\Core\Framework\Context $context
*/
public function install(Context $context): void
{
$stateMachineId = $this->getStateMachineEntity($context);
$holdStateId = $this->getHoldStateId($stateMachineId, $context);
$openStateId = $this->getOpenStateId($stateMachineId, $context);

$this->upsertHoldTransition($stateMachineId, $openStateId, $holdStateId, $context);
$this->upsertUnholdTransition($stateMachineId, $holdStateId, $openStateId, $context);

}

/**
* @param \Shopware\Core\Framework\Context $context
* @return \Shopware\Core\System\StateMachine\StateMachineEntity
*/
protected function getStateMachineEntity(Context $context): string
{
$stateMachineCriteria = (new Criteria())
->addFilter(new EqualsFilter('technicalName', OrderDeliveryStates::STATE_MACHINE));
$stateMachineEntity = $this->container->get('state_machine.repository')->search($stateMachineCriteria, $context)->first();
return $stateMachineEntity->getId();
}

/**
* @param string $stateMachineId
* @param \Shopware\Core\Framework\Context $context
* @return string
*/
protected function getHoldStateId(string $stateMachineId, Context $context): string
{
$stateMachineStateRepository = $this->container->get('state_machine_state.repository');

$holdStateMachineStateCriteria = (new Criteria())
->addFilter(
new EqualsFilter('technicalName', OrderDeliveryStateHandler::STATE_HOLD),
new EqualsFilter('stateMachineId', $stateMachineId)
);

$holdStateMachineStateEntity = $stateMachineStateRepository->search($holdStateMachineStateCriteria, $context)->first();

$holdStateId = is_null($holdStateMachineStateEntity) ? Uuid::randomHex() : $holdStateMachineStateEntity->getId();

if (is_null($holdStateMachineStateEntity)) {
$data = [
'id' => $holdStateId,
'technicalName' => OrderDeliveryStateHandler::STATE_HOLD,
'stateMachineId' => $stateMachineId,
'translations' => [
'en-GB' => [
'name' => 'Hold',
],
'de-DE' => [
'name' => 'Halten',
],
],
];
$stateMachineStateRepository->upsert([$data], $context);
}

return $holdStateId;
}

/**
* @param string $stateMachineId
* @param \Shopware\Core\Framework\Context $context
* @return string
*/
protected function getOpenStateId(string $stateMachineId, Context $context): string
{
$stateMachineStateRepository = $this->container->get('state_machine_state.repository');

$stateMachineStateCriteria = (new Criteria())
->addFilter(
new EqualsFilter('technicalName', OrderDeliveryStates::STATE_OPEN),
new EqualsFilter('stateMachineId', $stateMachineId)
);

$stateMachineStateEntity = $stateMachineStateRepository->search($stateMachineStateCriteria, $context)->first();
return $stateMachineStateEntity->getId();
}

/**
* @param string $stateMachineId
* @param string $openStateId
* @param string $holdStateId
* @param \Shopware\Core\Framework\Context $context
*/
protected function upsertHoldTransition(string $stateMachineId, string $openStateId, string $holdStateId, Context $context)
{
$translations = [
'en-GB' => [
'name' => 'Hold',
],
'de-DE' => [
'name' => 'Halten',
],
];

$this->upsertTransition(OrderDeliveryStateHandler::ACTION_HOLD, $stateMachineId, $openStateId, $holdStateId, $translations, $context);
}

protected function upsertTransition(string $actionName, string $stateMachineId, string $fromStateId, string $toStateId, array $translations, Context $context): void
{
$stateMachineTransitionRepository = $this->container->get('state_machine_transition.repository');
$criteria = (new Criteria())
->addFilter(
new EqualsFilter('actionName', $actionName),
new EqualsFilter('stateMachineId', $stateMachineId),
new EqualsFilter('fromStateId', $fromStateId),
new EqualsFilter('toStateId', $toStateId)
);

$stateMachineTransitionEntity = $stateMachineTransitionRepository->search($criteria, $context)->first();
$transitionId = is_null($stateMachineTransitionEntity) ? Uuid::randomHex() : $stateMachineTransitionEntity->getId();

if (is_null($stateMachineTransitionEntity)) {
$data = [
'id' => $transitionId,
'actionName' => $actionName,
'stateMachineId' => $stateMachineId,
'fromStateId' => $fromStateId,
'toStateId' => $toStateId,
'translations' => $translations,
];
$stateMachineTransitionRepository->upsert([$data], $context);
}

}

/**
* @param string $stateMachineId
* @param string $openStateId
* @param string $holdStateId
* @param \Shopware\Core\Framework\Context $context
*/
protected function upsertUnholdTransition(string $stateMachineId, string $holdStateId, string $openStateId, Context $context)
{
$translations = [
'en-GB' => [
'name' => 'Unhold',
],
'de-DE' => [
'name' => 'Aufheben',
],
];

$this->upsertTransition(OrderDeliveryStateHandler::ACTION_UNHOLD, $stateMachineId, $holdStateId, $openStateId, $translations, $context);
}
}

0 comments on commit 2d0438e

Please sign in to comment.