Skip to content

Commit

Permalink
MOL-1222: add POS payment method (#620)
Browse files Browse the repository at this point in the history
* MOL-1222: Payment Method POS Terminals

* NTR: Pos layout

* NTR: hide status change

* NTR: handle response

* NTR: add auto redirect again

---------

Co-authored-by: Vitalij Mik <[email protected]>
  • Loading branch information
boxblinkracer and Vitalij Mik authored Sep 21, 2023
1 parent c5f2ddd commit 817f3e0
Show file tree
Hide file tree
Showing 84 changed files with 2,246 additions and 634 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ src/Resources/public/administration/js/
/tests/Cypress/cypress/results
/src/Resources/app/administration/.stryker-tmp
/.phpunuhi/
/src/Resources/public/static
/src/Resources/public/static/css
/src/Resources/public/static/js
/src/Resources/public/js
/src/Resources/public/mollie-payments.js
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"config": {
"optimize-autoloader": true,
"allow-plugins": {
"infection/extension-installer": true
"infection/extension-installer": true,
"php-http/discovery": true
}
},
"autoload": {
Expand Down Expand Up @@ -64,7 +65,7 @@
"require": {
"php": ">=7.4",
"ext-curl": "*",
"mollie/mollie-api-php": "2.40.1"
"mollie/mollie-api-php": "2.61.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
Expand Down
1,150 changes: 615 additions & 535 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ clean: ## Cleans all dependencies and files
rm -rf ./src/Resources/app/storefront/node_modules/*
# ------------------------------------------------------
rm -rf ./src/Resources/app/storefront/dist/storefront
rm -rf ./src/Resources/public
# ------------------------------------------------------
rm -rf ./src/Resources/public/administration
rm -rf ./src/Resources/public/molllie-payments.js

build: ## Installs the plugin, and builds the artifacts using the Shopware build commands.
php switch-composer.php prod
Expand Down
13 changes: 10 additions & 3 deletions src/Controller/Api/Webhook/WebhookControllerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Kiener\MolliePayments\Controller\Storefront\Webhook\NotificationFacade;
use Kiener\MolliePayments\Repository\Order\OrderRepository;
use Kiener\MolliePayments\Repository\Order\OrderRepositoryInterface;
use Kiener\MolliePayments\Repository\OrderTransaction\OrderTransactionRepositoryInterface;
use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity;
use Shopware\Core\Framework\Context;
Expand Down Expand Up @@ -39,18 +40,25 @@ class WebhookControllerBase extends AbstractController
*/
private $logger;

/**
* @var OrderTransactionRepositoryInterface
*/
private $repoOrderTransactions;


/**
* @param NotificationFacade $notificationFacade
* @param SubscriptionManager $subscriptions
* @param OrderRepositoryInterface $repoOrders
* @param OrderTransactionRepositoryInterface $repoOrderTransactions
* @param LoggerInterface $logger
*/
public function __construct(NotificationFacade $notificationFacade, SubscriptionManager $subscriptions, OrderRepositoryInterface $repoOrders, LoggerInterface $logger)
public function __construct(NotificationFacade $notificationFacade, SubscriptionManager $subscriptions, OrderRepositoryInterface $repoOrders, OrderTransactionRepositoryInterface $repoOrderTransactions, LoggerInterface $logger)
{
$this->notificationFacade = $notificationFacade;
$this->subscriptions = $subscriptions;
$this->repoOrders = $repoOrders;
$this->repoOrderTransactions = $repoOrderTransactions;
$this->logger = $logger;
}

Expand Down Expand Up @@ -151,8 +159,7 @@ public function webhookSubscriptionAction(string $swSubscriptionId, Request $req
}

# now lets grab the latest order transaction of our new order
/** @var OrderTransactionEntity $latestTransaction */
$latestTransaction = $this->notificationFacade->getOrderTransactions($swOrder->getId(), $context)->last();
$latestTransaction = $this->repoOrderTransactions->getLatestOrderTransaction($swOrder->getId(), $context);

# now simply redirect to the official webhook
# that handles the full order, validates the payment and
Expand Down
89 changes: 89 additions & 0 deletions src/Controller/StoreApi/POS/PosControllerBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace Kiener\MolliePayments\Controller\StoreApi\POS;

use Kiener\MolliePayments\Controller\StoreApi\POS\Response\StoreTerminalResponse;
use Kiener\MolliePayments\Controller\StoreApi\POS\Response\TerminalsResponse;
use Kiener\MolliePayments\Gateway\MollieGatewayInterface;
use Kiener\MolliePayments\Service\CustomerService;
use Mollie\Api\Resources\Terminal;
use Shopware\Core\Checkout\Customer\CustomerEntity;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\SalesChannel\StoreApiResponse;
use Symfony\Component\Routing\Annotation\Route;

class PosControllerBase
{

/**
* @var CustomerService
*/
private $customerService;

/**
* @var MollieGatewayInterface
*/
private $mollieGateway;


/**
* @param CustomerService $customerService
* @param MollieGatewayInterface $mollieGateway
*/
public function __construct(CustomerService $customerService, MollieGatewayInterface $mollieGateway)
{
$this->customerService = $customerService;
$this->mollieGateway = $mollieGateway;
}


/**
* @Route("/store-api/mollie/pos/terminals", name="store-api.mollie.pos.terminals", methods={"GET"})
*
* @param SalesChannelContext $context
* @return StoreApiResponse
*/
public function getIssuers(SalesChannelContext $context): StoreApiResponse
{
$this->mollieGateway->switchClient($context->getSalesChannelId());

$terminalsArray = [];

$terminals = $this->mollieGateway->getPosTerminals();

foreach ($terminals as $terminal) {
$terminalsArray[] = [
'id' => $terminal->id,
'name' => $terminal->description,
];
}

return new TerminalsResponse($terminalsArray);
}

/**
* @Route("/store-api/mollie/pos/store-terminal/{customerId}/{terminalID}", name="store-api.mollie.pos.store-terminal", methods={"POST"})
*
* @param string $customerId
* @param string $terminalID
* @param SalesChannelContext $context
* @throws \Exception
* @return StoreApiResponse
*/
public function saveTerminalId(string $customerId, string $terminalID, SalesChannelContext $context): StoreApiResponse
{
$customer = $this->customerService->getCustomer($customerId, $context->getContext());

if (!$customer instanceof CustomerEntity) {
throw new \Exception('Customer with ID ' . $customerId . ' not found in Shopware');
}

$result = $this->customerService->setPosTerminal(
$customer,
$terminalID,
$context->getContext()
);

return new StoreTerminalResponse($result !== null);
}
}
29 changes: 29 additions & 0 deletions src/Controller/StoreApi/POS/Response/StoreTerminalResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Kiener\MolliePayments\Controller\StoreApi\POS\Response;

use Shopware\Core\Framework\Struct\ArrayStruct;
use Shopware\Core\System\SalesChannel\StoreApiResponse;

class StoreTerminalResponse extends StoreApiResponse
{
/**
* @var ArrayStruct<mixed, mixed>
*/
protected $object;

/**
* @param bool $success
*/
public function __construct(bool $success)
{
$this->object = new ArrayStruct(
[
'success' => $success,
],
'mollie_payments_pos_terminal_stored'
);

parent::__construct($this->object);
}
}
30 changes: 30 additions & 0 deletions src/Controller/StoreApi/POS/Response/TerminalsResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Kiener\MolliePayments\Controller\StoreApi\POS\Response;

use Shopware\Core\Framework\Struct\ArrayStruct;
use Shopware\Core\System\SalesChannel\StoreApiResponse;

class TerminalsResponse extends StoreApiResponse
{
/**
* @var ArrayStruct<mixed, mixed>
*/
protected $object;


/**
* @param array<mixed> $terminals
*/
public function __construct(array $terminals)
{
$this->object = new ArrayStruct(
[
'terminals' => $terminals,
],
'mollie_payments_pos_terminals'
);

parent::__construct($this->object);
}
}
13 changes: 13 additions & 0 deletions src/Controller/StoreApi/POS/Sw6/PosController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Kiener\MolliePayments\Controller\StoreApi\POS\Sw6;

use Kiener\MolliePayments\Controller\StoreApi\POS\PosControllerBase;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;

/**
* @RouteScope(scopes={"store-api"})
*/
class PosController extends PosControllerBase
{
}
13 changes: 13 additions & 0 deletions src/Controller/StoreApi/POS/Sw65/PosController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Kiener\MolliePayments\Controller\StoreApi\POS\Sw65;

use Kiener\MolliePayments\Controller\StoreApi\POS\PosControllerBase;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(defaults={"_routeScope"={"store-api"}})
*/
class PosController extends PosControllerBase
{
}
6 changes: 3 additions & 3 deletions src/Controller/StoreApi/iDEAL/Response/IssuersResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class IssuersResponse extends StoreApiResponse


/**
* @param array<mixed> $issuers
* @param array<mixed> $terminals
*/
public function __construct(array $issuers)
public function __construct(array $terminals)
{
$this->object = new ArrayStruct(
[
'issuers' => $issuers,
'issuers' => $terminals,
],
'mollie_payments_ideal_issuers'
);
Expand Down
Loading

0 comments on commit 817f3e0

Please sign in to comment.