Skip to content

Commit

Permalink
Add v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mkielb committed Feb 9, 2024
1 parent 898ab6b commit cbe7791
Show file tree
Hide file tree
Showing 25 changed files with 118 additions and 429 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "PayU integration for Shopware 6",
"type": "shopware-platform-plugin",
"license": "proprietary",
"version": "1.1.5",
"version": "2.0.0",
"authors": [
{
"name": "Crehler Sp. z o. o.",
Expand Down Expand Up @@ -40,8 +40,8 @@
}
},
"require": {
"shopware/core": "^6.4",
"shopware/storefront": "^6.4",
"shopware/core": "^6.5",
"shopware/storefront": "^6.5",
"openpayu/openpayu": "^2.2"
},
"minimum-stability": "RC"
Expand Down
43 changes: 6 additions & 37 deletions src/Controller/Api/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,18 @@
use Symfony\Component\Routing\Annotation\Route;

/**
* @RouteScope(scopes={"api"})
* @Route(defaults={"_routeScope"={"api"}})
*/
class ConfigurationController extends AbstractController
{
/** @var LoggerInterface */
private $logger;

/** @var ConfigurationService */
private $settingsService;

/** @var PayuMethodFinder */
private $methodFinder;

private SystemConfigService $systemConfigService;

public function __construct(
LoggerInterface $logger,
ConfigurationService $settingsService,
PayuMethodFinder $methodFinder,
SystemConfigService $systemConfigService
) {
$this->logger = $logger;
$this->settingsService = $settingsService;
$this->methodFinder = $methodFinder;
$this->systemConfigService = $systemConfigService;
public function __construct(private readonly LoggerInterface $logger, private readonly ConfigurationService $settingsService, private readonly PayuMethodFinder $methodFinder, private readonly SystemConfigService $systemConfigService)
{
}

/**
* @Route(
* "/api/crehler/payu/sales-channel-payment-configuration-notification",
* name="api.crehler.payu.sales-channel-payment-configuration-notification",
* methods={"POST"}
* )
*
* @param Request $request
* @param Context $context
* @return JsonResponse
*/
#[Route(path: '/api/crehler/payu/sales-channel-payment-configuration-notification', name: 'api.crehler.payu.sales-channel-payment-configuration-notification', methods: ['POST'])]
public function salesChannelPaymentConfigurationNotification(Request $request, Context $context): JsonResponse
{
$paymentMethodIds = $request->get('paymentMethodIds');
Expand All @@ -77,21 +51,16 @@ public function salesChannelPaymentConfigurationNotification(Request $request, C
}

/**
* @Route(
* "/api/crehler/payu/check-credentials",
* name="api.crehler.payu.check-credentials",
* methods={"POST"}
* )
*
* @param Request $request
*
* @return JsonResponse
*/
#[Route(path: '/api/crehler/payu/check-credentials', name: 'api.crehler.payu.check-credentials', methods: ['POST'])]
public function checkCredentials(Request $request): JsonResponse
{
try {
$result = $this->settingsService->checkRequestCredentials($request);
} catch (\Exception $e) {
} catch (\Exception) {
$result = false;
}

Expand Down
15 changes: 3 additions & 12 deletions src/Controller/Api/PayUDetailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,23 @@
use Symfony\Component\Routing\Annotation\Route;

/**
* @RouteScope(scopes={"api"})
* @Route(defaults={"_routeScope"={"api"}})
*/
class PayUDetailController extends AbstractController
{
/** @var TransactionDetails */
private $transactionDetails;

/**
* PayUDetailController constructor.
*
* @param TransactionDetails $transactionDetails
*/
public function __construct(TransactionDetails $transactionDetails)
public function __construct(private readonly TransactionDetails $transactionDetails)
{
$this->transactionDetails = $transactionDetails;
}

/**
* @Route("/api/crehler/payu/detail/{id}", name="api.action.crehler.payu.detail", methods={"GET"})
*
* @param string $id
* @param Request $request
* @param Context $context
*
* @return JsonResponse
*/
#[Route(path: '/api/crehler/payu/detail/{id}', name: 'api.action.crehler.payu.detail', methods: ['GET'])]
public function getDetailInfo(string $id, Request $request, Context $context): JsonResponse
{
$data = $this->transactionDetails->getData($id, $context);
Expand Down
34 changes: 3 additions & 31 deletions src/Controller/Storefront/PayUNotifyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,18 @@
/**
* Class PayUNotifyController
*
* @RouteScope(scopes={"storefront"})
* @Route(defaults={"_routeScope"={"storefront"}})
*/
class PayUNotifyController extends StorefrontController
{
/** @var FinalizeTokenGenerator */
private $finalizeTokenGenerator;

/** @var PayUPayment */
private $payUPayment;

/** @var LoggerInterface */
private $logger;

/**
* PayUNotifyController constructor.
*
* @param FinalizeTokenGenerator $finalizeTokenGenerator
* @param PayUPayment $payUPayment
* @param LoggerInterface $logger
*/
public function __construct(
FinalizeTokenGenerator $finalizeTokenGenerator,
PayUPayment $payUPayment,
LoggerInterface $logger
)
public function __construct(private readonly FinalizeTokenGenerator $finalizeTokenGenerator, private readonly PayUPayment $payUPayment, private readonly LoggerInterface $logger)
{
$this->finalizeTokenGenerator = $finalizeTokenGenerator;
$this->payUPayment = $payUPayment;
$this->logger = $logger;
}

/**
* @Route(
* "/crehler/payu/notify",
* name="action.crehler.payu.notify",
* options={"seo"="false"},
* methods={"POST"},
* defaults={"csrf_protected"=false}
* )
*/
#[Route(path: '/crehler/payu/notify', name: 'action.crehler.payu.notify', options: ['seo' => 'false'], methods: ['POST'], defaults: ['csrf_protected' => false])]
public function notifyAction(
Request $request,
SalesChannelContext $salesChannelContext): JsonResponse
Expand Down
76 changes: 19 additions & 57 deletions src/Core/Checkout/Payment/PayUPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

namespace Crehler\PayU\Core\Checkout\Payment;

use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
use Shopware\Core\System\StateMachine\Exception\StateMachineNotFoundException;
use Shopware\Core\System\StateMachine\Exception\StateMachineStateNotFoundException;
use Crehler\PayU\Entity\OrderTransactionRepository;
use Crehler\PayU\Service\PayU\OrderCreate;
use Crehler\PayU\Service\PayU\UpdateStatus;
Expand All @@ -21,7 +25,6 @@
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStateHandler;
use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct;
use Shopware\Core\Checkout\Payment\Cart\PaymentHandler\AsynchronousPaymentHandlerInterface;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand All @@ -32,53 +35,23 @@
*/
class PayUPayment implements AsynchronousPaymentHandlerInterface
{
/**
* @var OrderTransactionStateHandler
*/
private $transactionStateHandler;

/**
* @var OrderCreate
*/
private $orderCreate;

/** @var EntityRepositoryInterface */
/** @var EntityRepository */
private $orderTransactionRepository;

/** @var UpdateStatus */
private $updateStatus;

/** @var LoggerInterface */
private $logger;

/**
* PayUPayment constructor.
*
* @param OrderTransactionStateHandler $transactionStateHandler
* @param OrderCreate $orderCreate
* @param EntityRepositoryInterface $orderTransactionRepository
* @param UpdateStatus $updateStatus
* @param LoggerInterface $logger
*/
public function __construct(
OrderTransactionStateHandler $transactionStateHandler,
OrderCreate $orderCreate,
EntityRepositoryInterface $orderTransactionRepository,
UpdateStatus $updateStatus,
LoggerInterface $logger
private readonly OrderTransactionStateHandler $transactionStateHandler,
private readonly OrderCreate $orderCreate,
EntityRepository $orderTransactionRepository,
private readonly UpdateStatus $updateStatus,
private readonly LoggerInterface $logger
) {
$this->transactionStateHandler = $transactionStateHandler;
$this->orderCreate = $orderCreate;
$this->orderTransactionRepository = $orderTransactionRepository;
$this->updateStatus = $updateStatus;
$this->logger = $logger;
}

/**
* @param AsyncPaymentTransactionStruct $transaction
* @param RequestDataBag $dataBag
* @param SalesChannelContext $salesChannelContext
*
* @throws OpenPayU_Exception
*
* @return RedirectResponse
Expand All @@ -102,9 +75,6 @@ public function pay(AsyncPaymentTransactionStruct $transaction, RequestDataBag $
}

/**
* @param AsyncPaymentTransactionStruct $transaction
* @param Request $request
* @param SalesChannelContext $salesChannelContext
*
* @throws \Exception
*/
Expand All @@ -114,14 +84,11 @@ public function finalize(AsyncPaymentTransactionStruct $transaction, Request $re
}

/**
* @param AsyncPaymentTransactionStruct $transaction
* @param Request $request
* @param SalesChannelContext $salesChannelContext
*
* @throws OpenPayU_Exception
* @throws \Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException
* @throws \Shopware\Core\System\StateMachine\Exception\StateMachineNotFoundException
* @throws \Shopware\Core\System\StateMachine\Exception\StateMachineStateNotFoundException
* @throws InconsistentCriteriaIdsException
* @throws StateMachineNotFoundException
* @throws StateMachineStateNotFoundException
*
* @return bool
*/
Expand All @@ -137,17 +104,12 @@ public function notify(AsyncPaymentTransactionStruct $transaction, Request $requ
if ($order->getStatus() == OpenPayU_Order::SUCCESS) {
$this->logger->info('PayU - Paid status: ' . $paymentStatus . ' for order: ' . $shopOrderId);

switch ($paymentStatus) {
case OpenPayuOrderStatus::STATUS_COMPLETED:
$this->transactionStateHandler->paid($transaction->getOrderTransaction()->getId(), $salesChannelContext->getContext());
break;
case OpenPayuOrderStatus::STATUS_CANCELED:
$this->transactionStateHandler->cancel($transaction->getOrderTransaction()->getId(), $salesChannelContext->getContext());
break;
case OpenPayuOrderStatus::STATUS_WAITING_FOR_CONFIRMATION:
$this->updateStatus->complete($orderID);
break;
}
match ($paymentStatus) {
OpenPayuOrderStatus::STATUS_COMPLETED => $this->transactionStateHandler->paid($transaction->getOrderTransaction()->getId(), $salesChannelContext->getContext()),
OpenPayuOrderStatus::STATUS_CANCELED => $this->transactionStateHandler->cancel($transaction->getOrderTransaction()->getId(), $salesChannelContext->getContext()),
OpenPayuOrderStatus::STATUS_WAITING_FOR_CONFIRMATION => $this->updateStatus->complete($orderID),
default => true,
};

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/OrderTransactionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
*/
class OrderTransactionRepository
{
const PAYU_EXTERNAL_ID = 'crehler_payu_external_id';
const PAYU_PAY_URL = 'crehler_payu_pay_url';
final const PAYU_EXTERNAL_ID = 'crehler_payu_external_id';
final const PAYU_PAY_URL = 'crehler_payu_pay_url';
}
Loading

0 comments on commit cbe7791

Please sign in to comment.