Skip to content

Commit

Permalink
Merge branch 'staging' into 'production'
Browse files Browse the repository at this point in the history
Staging

See merge request sezzle/shopware-5!18
  • Loading branch information
Dan Ross committed Jul 2, 2021
2 parents e2e553f + 55a5a33 commit d13c073
Show file tree
Hide file tree
Showing 123 changed files with 556 additions and 2,318 deletions.
Empty file modified CHANGELOG.md
100644 → 100755
Empty file.
Empty file modified Components/ApiBuilderInterface.php
100644 → 100755
Empty file.
Empty file modified Components/ApiBuilderParameters.php
100644 → 100755
Empty file.
Empty file modified Components/Backend/CaptureService.php
100644 → 100755
Empty file.
72 changes: 0 additions & 72 deletions Components/Backend/GatewayRegionService.php

This file was deleted.

Empty file modified Components/Backend/RefundService.php
100644 → 100755
Empty file.
Empty file modified Components/Backend/ReleaseService.php
100644 → 100755
Empty file.
14 changes: 12 additions & 2 deletions Components/DependencyProvider.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Shopware\Components\Cart\PaymentTokenService;
use Shopware\Components\DependencyInjection\Container as DIContainer;
use Shopware\Models\Shop\DetachedShop;
use Shopware\Models\Shop\Repository;
use Shopware\Models\Shop\Shop;
use Shopware_Components_Modules;

class DependencyProvider
{
Expand All @@ -27,8 +30,15 @@ public function getShop()
if ($this->container->has('shop')) {
return $this->container->get('shop');
}
return $this->getMainShop();
}

return null;
public function getMainShop()
{
/** @var Repository $shopRepository */
$shopRepository = Shopware()->Container()->get('models')->getRepository(Shop::class);
/** @noinspection PhpParamsInspection */
return DetachedShop::createFromShop($shopRepository->findOneBy(['default' => 1]));
}

/**
Expand All @@ -39,7 +49,7 @@ public function getShop()
*/
public function getModule($moduleName)
{
/** @var \Shopware_Components_Modules $modules */
/** @var Shopware_Components_Modules $modules */
$modules = $this->container->get('modules');

return $modules->getModule($moduleName);
Expand Down
Empty file modified Components/ErrorCodes.php
100644 → 100755
Empty file.
9 changes: 6 additions & 3 deletions Components/Exception/OrderNotFoundException.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

namespace SezzlePayment\Components\Exception;

class OrderNotFoundException extends \RuntimeException
use RuntimeException;
use Throwable;

class OrderNotFoundException extends RuntimeException
{
/**
* OrderNotFoundException constructor.
* @param string $parameter
* @param string $value
* @param int $code
* @param \Throwable|null $previous
* @param Throwable|null $previous
*/
public function __construct($parameter, $value, $code = 0, \Throwable $previous = null)
public function __construct($parameter, $value, $code = 0, Throwable $previous = null)
{
$message = sprintf('Could not find order with search parameter "%s" and value "%s"', $parameter, $value);
parent::__construct($message, $code, $previous);
Expand Down
4 changes: 3 additions & 1 deletion Components/Exception/SezzleApiException.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace SezzlePayment\Components\Exception;

class SezzleApiException extends \Exception
use Exception;

class SezzleApiException extends Exception
{
/**
* @var string
Expand Down
5 changes: 3 additions & 2 deletions Components/ExceptionHandlerServiceInterface.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace SezzlePayment\Components;

use Exception;
use SezzlePayment\Components\Exception\SezzleApiException;

interface ExceptionHandlerServiceInterface
{
/**
* @param \Exception $e
* @param Exception $e
* @param string $currentAction
*
* @return SezzleApiException The error message and name extracted from the exception
*/
public function handle(\Exception $e, $currentAction);
public function handle(Exception $e, $currentAction);
}
69 changes: 54 additions & 15 deletions Components/PaymentMethodProvider.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SezzlePayment\Components;

use Doctrine\DBAL\Connection;
use Exception;
use Shopware\Components\Model\ModelManager;
use Shopware\Models\Payment\Payment;

Expand All @@ -12,6 +12,8 @@ class PaymentMethodProvider
* The technical name of the sezzle payment method.
*/
const SEZZLE_PAYMENT_METHOD_NAME = 'Sezzle';
const SEZZLE_LOGO = 'https://d34uoa9py2cgca.cloudfront.net/branding/sezzle-logos/png/sezzle-logo-sm-100w.png'; //TODO check if this is valid for all time (use local?)
const SEZZLE_ADDITIONAL_DESCRIPTION = ''; //'Pay later with 0% interest'; //TODO german (add translation?)

/**
* @var ModelManager
Expand All @@ -21,7 +23,7 @@ class PaymentMethodProvider
/**
* @param ModelManager $modelManager
*/
public function __construct(ModelManager $modelManager = null)
public function __construct(ModelManager $modelManager)
{
$this->modelManager = $modelManager;
}
Expand All @@ -43,48 +45,85 @@ public function getPaymentMethodModel()

/**
* @param bool $active
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @see PaymentMethodProvider::SEZZLE_PAYMENT_METHOD_NAME
*/
public function setPaymentMethodActiveFlag($active)
{
$paymentMethod = $this->getPaymentMethodModel();
if ($paymentMethod) {
$paymentMethod->setActive($active);
try {
$paymentMethod = $this->getPaymentMethodModel();
if ($paymentMethod) {
$paymentMethod->setActive($active);
$this->modelManager->persist($paymentMethod);
$this->modelManager->flush($paymentMethod);
}
}catch (Exception $e){

$this->modelManager->persist($paymentMethod);
$this->modelManager->flush($paymentMethod);
}
}

/**
* @param Connection $connection
* @return bool
* @see PaymentMethodProvider::SEZZLE_PAYMENT_METHOD_NAME
*
*/
public function getPaymentMethodActiveFlag(Connection $connection)
public function getPaymentMethodActiveFlag()
{
$sql = 'SELECT `active` FROM s_core_paymentmeans WHERE `name`=:paymentName';

return (bool) $connection->fetchColumn($sql, [
return (bool)$this->modelManager->getConnection()->fetchColumn($sql, [
':paymentName' => self::SEZZLE_PAYMENT_METHOD_NAME,
]);
}

/**
* @param Connection $connection
* @return int
* @see PaymentMethodProvider::SEZZLE_PAYMENT_METHOD_NAME
*
*/
public function getPaymentId(Connection $connection)
public function getPaymentId()
{
$sql = 'SELECT `id` FROM s_core_paymentmeans WHERE `name`=:paymentName';

return (int) $connection->fetchColumn($sql, [
return (int)$this->modelManager->getConnection()->fetchColumn($sql, [
':paymentName' => self::SEZZLE_PAYMENT_METHOD_NAME,
]);
}

public function createPaymentMethod()
{
if ($this->getPaymentId()) {
return;
}

$payment = new Payment();
$payment->setActive(false);
$payment->setPosition(-100);
$payment->setName(PaymentMethodProvider::SEZZLE_PAYMENT_METHOD_NAME);
$payment->setDescription('Sezzle');
$payment->setAdditionalDescription($this->getAdditionalDescription());
$payment->setAction('Sezzle');

$this->modelManager->persist($payment);
$this->modelManager->flush($payment);

}


/**
* @return string
*/
/*
private function getUnifiedPaymentLogo()
{
return '<img src="' . self::SEZZLE_LOGO . '" alt="Logo Sezzle" class="sezzle-payment-logo" />';
}
*/

/**
* @return string
*/
private function getAdditionalDescription()
{
return self::SEZZLE_ADDITIONAL_DESCRIPTION;
}
}
7 changes: 3 additions & 4 deletions Components/Services/ApiBuilderService.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SezzlePayment\Components\DependencyProvider;
use SezzlePayment\Components\ApiBuilderInterface;
use SezzlePayment\Components\ApiBuilderParameters;
use SezzlePayment\SezzleBundle\Components\SettingsServiceInterface;
use SezzlePayment\SezzleBundle\Structs\CustomerOrder;
use SezzlePayment\SezzleBundle\Structs\Order\Capture;
use SezzlePayment\SezzleBundle\Structs\Session;
Expand All @@ -26,7 +25,7 @@ class ApiBuilderService implements ApiBuilderInterface
protected $router;

/**
* @var SettingsServiceInterface
* @var SettingsService
*/
protected $settings;

Expand Down Expand Up @@ -78,13 +77,13 @@ class ApiBuilderService implements ApiBuilderInterface
/**
* ApiBuilderService constructor.
* @param RouterInterface $router
* @param SettingsServiceInterface $settingsService
* @param SettingsService $settingsService
* @param SnippetManager $snippetManager
* @param DependencyProvider $dependencyProvider
*/
public function __construct(
RouterInterface $router,
SettingsServiceInterface $settingsService,
SettingsService $settingsService,
SnippetManager $snippetManager,
DependencyProvider $dependencyProvider
) {
Expand Down
8 changes: 3 additions & 5 deletions Components/Services/BasketDataService.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace SezzlePayment\Components\Services;

use Doctrine\DBAL\Connection;
use SezzlePayment\SezzleBundle\Components\SettingsServiceInterface;
use SezzlePayment\SezzleBundle\PaymentType;

class BasketDataService
Expand All @@ -14,18 +13,18 @@ class BasketDataService
private $dbalConnection;

/**
* @var SettingsServiceInterface
* @var SettingsService
*/
private $settingsService;

/**
* BasketDataService constructor.
* @param Connection $dbalConnection
* @param SettingsServiceInterface $settingsService
* @param SettingsService $settingsService
*/
public function __construct(
Connection $dbalConnection,
SettingsServiceInterface $settingsService
SettingsService $settingsService
) {
$this->dbalConnection = $dbalConnection;
$this->settingsService = $settingsService;
Expand Down Expand Up @@ -57,7 +56,6 @@ public function applyOrderUuidAttribute($basketId, $orderUuid)
*/
public function getValueByKey($basket, $key)
{
echo "<pre>";
$attribute = sprintf("sezzle_%s", $key);
$basketId = function ($basket) {
foreach ($basket['content'] as $lineItem) {
Expand Down
7 changes: 3 additions & 4 deletions Components/Services/ExceptionHandlerService.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Shopware\Components\HttpClient\RequestException;
use SezzlePayment\Components\Exception\SezzleApiException;
use SezzlePayment\Components\ExceptionHandlerServiceInterface;
use SezzlePayment\SezzleBundle\Components\LoggerServiceInterface;
use SezzlePayment\SezzleBundle\Structs\ErrorResponse;

class ExceptionHandlerService implements ExceptionHandlerServiceInterface
Expand All @@ -16,15 +15,15 @@ class ExceptionHandlerService implements ExceptionHandlerServiceInterface
const LOG_MESSAGE = 'Could not %s due to a communication failure';

/**
* @var LoggerServiceInterface
* @var LoggerService
*/
private $loggerService;

/**
* ExceptionHandlerService constructor.
* @param LoggerServiceInterface $loggerService
* @param LoggerService $loggerService
*/
public function __construct(LoggerServiceInterface $loggerService)
public function __construct(LoggerService$loggerService)
{
$this->loggerService = $loggerService;
}
Expand Down
Loading

0 comments on commit d13c073

Please sign in to comment.