Skip to content

Commit

Permalink
ASW-500 merge release-3.5.0 into adyen/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bortefi committed Mar 30, 2022
2 parents 6b1f344 + f723bf3 commit ee986dd
Show file tree
Hide file tree
Showing 74 changed files with 3,070 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,22 @@

declare(strict_types=1);

namespace AdyenPayment\Components\Adyen;
namespace AdyenPayment\AdyenApi\HttpClient;

use Adyen\AdyenException;
use Adyen\Client;
use Adyen\Environment;
use AdyenPayment\Components\Configuration;
use AdyenPayment\Components\ConfigurationInterface;
use Psr\Log\LoggerInterface;
use Shopware\Models\Shop\Shop;

/**
* Class ApiFactory.
*/
class ApiFactory
final class ClientFactory implements ClientFactoryInterface
{
/**
* @var Configuration
*/
private $configuration;
private ConfigurationInterface $configuration;
private LoggerInterface $logger;

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

public function __construct(
Configuration $configuration,
LoggerInterface $logger
) {
public function __construct(ConfigurationInterface $configuration, LoggerInterface $logger)
{
$this->configuration = $configuration;
$this->logger = $logger;
}
Expand All @@ -47,8 +35,12 @@ public function provide(Shop $shop): Client
);
}

private function createClient(string $merchantAccount, string $apiKey, string $environment, ?string $prefix = null): Client
{
private function createClient(
string $merchantAccount,
string $apiKey,
string $environment,
?string $prefix = null
): Client {
$urlPrefix = Environment::LIVE === $environment ? $prefix : null;

$adyenClient = new Client();
Expand Down
13 changes: 13 additions & 0 deletions AdyenApi/HttpClient/ClientFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace AdyenPayment\AdyenApi\HttpClient;

use Adyen\Client;
use Shopware\Models\Shop\Shop;

interface ClientFactoryInterface
{
public function provide(Shop $shop): Client;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@

declare(strict_types=1);

namespace AdyenPayment\Components\Adyen;
namespace AdyenPayment\AdyenApi\HttpClient;

use Adyen\Client;
use Shopware\Models\Shop\Shop;

class ApiClientMap
final class ClientMemoise implements ClientMemoiseInterface
{
/**
* @var array<int|string, Client>
*/
private $memoisedClients = [];
private ClientFactoryInterface $factory;

/**
* @var ApiFactory
*/
private $factory;

public function __construct(ApiFactory $factory)
public function __construct(ClientFactoryInterface $factory)
{
$this->factory = $factory;
}
Expand Down
13 changes: 13 additions & 0 deletions AdyenApi/HttpClient/ClientMemoiseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace AdyenPayment\AdyenApi\HttpClient;

use Adyen\Client;
use Shopware\Models\Shop\Shop;

interface ClientMemoiseInterface
{
public function lookup(Shop $shop): Client;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,25 @@

declare(strict_types=1);

namespace AdyenPayment\Components\Adyen;
namespace AdyenPayment\AdyenApi\HttpClient;

use Adyen\AdyenException;
use Adyen\Service\Checkout;
use AdyenPayment\Components\Configuration;
use AdyenPayment\Components\ConfigurationInterface;
use AdyenPayment\Validator\ConstraintViolationFactory;
use Doctrine\Persistence\ObjectRepository;
use Shopware\Models\Shop\Shop;
use Symfony\Component\Validator\ConstraintViolationList;

class ApiConfigValidator
final class ConfigValidator implements ConfigValidatorInterface
{
/**
* @var ApiFactory
*/
private $adyenApiFactory;

/**
* @var Configuration
*/
private $configuration;

/**
* @var ObjectRepository
*/
private $shopRepository;
private ClientFactoryInterface $adyenApiFactory;
private ConfigurationInterface $configuration;
private ObjectRepository $shopRepository;

public function __construct(
ApiFactory $adyenApiFactory,
Configuration $configuration,
ClientFactoryInterface $adyenApiFactory,
ConfigurationInterface $configuration,
ObjectRepository $shopRepository
) {
$this->adyenApiFactory = $adyenApiFactory;
Expand All @@ -42,7 +31,7 @@ public function __construct(
public function validate(int $shopId): ConstraintViolationList
{
$shop = $this->shopRepository->find($shopId);
if (!$shop) {
if (null === $shop) {
return new ConstraintViolationList([
ConstraintViolationFactory::create('Shop not found for ID "'.$shopId.'".'),
]);
Expand Down
12 changes: 12 additions & 0 deletions AdyenApi/HttpClient/ConfigValidatorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace AdyenPayment\AdyenApi\HttpClient;

use Symfony\Component\Validator\ConstraintViolationList;

interface ConfigValidatorInterface
{
public function validate(int $shopId): ConstraintViolationList;
}
37 changes: 37 additions & 0 deletions AdyenApi/Model/ApiResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace AdyenPayment\AdyenApi\Model;

final class ApiResponse
{
private bool $success;
private string $message;

private function __construct(bool $success, string $message)
{
$this->success = $success;
$this->message = $message;
}

public static function create(bool $success, string $message): self
{
return new self($success, $message);
}

public static function empty(): self
{
return new self(false, 'Customer number not found.');
}

public function isSuccess(): bool
{
return $this->success;
}

public function message(): string
{
return $this->message;
}
}
55 changes: 55 additions & 0 deletions AdyenApi/Recurring/DisableTokenRequestHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace AdyenPayment\AdyenApi\Recurring;

use AdyenPayment\AdyenApi\Model\ApiResponse;
use AdyenPayment\AdyenApi\TransportFactoryInterface;
use AdyenPayment\Session\CustomerNumberProviderInterface;
use Shopware\Models\Shop\Shop;

final class DisableTokenRequestHandler implements DisableTokenRequestHandlerInterface
{
private TransportFactoryInterface $transportFactory;
private CustomerNumberProviderInterface $customerNumberProvider;

public function __construct(
TransportFactoryInterface $transportFactory,
CustomerNumberProviderInterface $customerNumberProvider
) {
$this->transportFactory = $transportFactory;
$this->customerNumberProvider = $customerNumberProvider;
}

public function disableToken(string $recurringTokenId, Shop $shop): ApiResponse
{
$customerNumber = ($this->customerNumberProvider)();
if ('' === $customerNumber) {
return ApiResponse::empty();
}
$recurringTransport = $this->transportFactory->recurring($shop);

$payload = [
'shopperReference' => $customerNumber,
'recurringDetailReference' => $recurringTokenId,
];

$result = $recurringTransport->disable($payload);

$response = (string) ($result['response'] ?? '');
$resultMessage = (string) ($result['message'] ?? '');
$isSuccessfullyDisabled = $this->isSuccessfullyDisabled($response);

return ApiResponse::create($isSuccessfullyDisabled, $resultMessage);
}

private function isSuccessfullyDisabled(string $response): bool
{
if (false === mb_strpos($response, 'successfully-disabled')) {
return false;
}

return true;
}
}
13 changes: 13 additions & 0 deletions AdyenApi/Recurring/DisableTokenRequestHandlerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace AdyenPayment\AdyenApi\Recurring;

use AdyenPayment\AdyenApi\Model\ApiResponse;
use Shopware\Models\Shop\Shop;

interface DisableTokenRequestHandlerInterface
{
public function disableToken(string $recurringTokenId, Shop $shop): ApiResponse;
}
34 changes: 34 additions & 0 deletions AdyenApi/TransportFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace AdyenPayment\AdyenApi;

use Adyen\Service\Checkout;
use Adyen\Service\Recurring;
use AdyenPayment\AdyenApi\HttpClient\ClientFactoryInterface;
use Shopware\Models\Shop\Shop;

final class TransportFactory implements TransportFactoryInterface
{
private ClientFactoryInterface $apiFactory;

public function __construct(ClientFactoryInterface $apiFactory)
{
$this->apiFactory = $apiFactory;
}

public function recurring(Shop $shop): Recurring
{
return new Recurring(
$this->apiFactory->provide($shop)
);
}

public function checkout(Shop $shop): Checkout
{
return new Checkout(
$this->apiFactory->provide($shop)
);
}
}
15 changes: 15 additions & 0 deletions AdyenApi/TransportFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace AdyenPayment\AdyenApi;

use Adyen\Service\Checkout;
use Adyen\Service\Recurring;
use Shopware\Models\Shop\Shop;

interface TransportFactoryInterface
{
public function recurring(Shop $shop): Recurring;
public function checkout(Shop $shop): Checkout;
}
2 changes: 2 additions & 0 deletions AdyenPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use AdyenPayment\Models\Enum\PaymentMethod\SourceType;
use AdyenPayment\Models\Notification;
use AdyenPayment\Models\PaymentInfo;
use AdyenPayment\Models\RecurringPayment\RecurringPaymentToken;
use AdyenPayment\Models\Refund;
use AdyenPayment\Models\TextNotification;
use AdyenPayment\Models\UserPreference;
Expand Down Expand Up @@ -171,6 +172,7 @@ private function getModelMetaData(): array
$entityManager->getClassMetadata(Refund::class),
$entityManager->getClassMetadata(TextNotification::class),
$entityManager->getClassMetadata(UserPreference::class),
$entityManager->getClassMetadata(RecurringPaymentToken::class),
];
}

Expand Down
6 changes: 3 additions & 3 deletions Components/Adyen/PaymentMethod/PaymentMethodsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Adyen\AdyenException;
use Adyen\Service\Checkout;
use AdyenPayment\AdyenApi\HttpClient\ClientFactory;
use AdyenPayment\Collection\Payment\PaymentMethodCollection;
use AdyenPayment\Components\Adyen\ApiFactory;
use AdyenPayment\Components\Adyen\PaymentMethodService;
use AdyenPayment\Components\Configuration;
use Psr\Log\LoggerInterface;
Expand All @@ -16,12 +16,12 @@
final class PaymentMethodsProvider implements PaymentMethodsProviderInterface
{
private Configuration $configuration;
private ApiFactory $adyenApiFactory;
private ClientFactory $adyenApiFactory;
private LoggerInterface $logger;

public function __construct(
Configuration $configuration,
ApiFactory $adyenApiFactory,
ClientFactory $adyenApiFactory,
LoggerInterface $logger
) {
$this->configuration = $configuration;
Expand Down
Loading

0 comments on commit ee986dd

Please sign in to comment.