Skip to content

Commit

Permalink
Release 1.5.0 (#53)
Browse files Browse the repository at this point in the history
* [PW-2473]: Shopware review fixes and remove 3DS2 image size (#7)

* Shopware review fixes and remove 3DS2 image size

* Indentation fixes

* Hardcode 3DS image size

* Revert hardcode 3DS image size

* [PW-2562] Adjustments for phpcs (#9)

* Fixes and removing phpcs exclude patterns in favor of specific rules suppression

* New phpcs version and ignore/disable sniffs

* Adjusting copyright comment

* Update composer.json (#31)

To correctly install the plugin via composer, the module directory needs to be renamed to 'AdyenPayment'.

* Fix #19 PW-2601 Update completed state (#34)

* Fix #22 PW-2743 Show error on 404 (#35)

Shows error message when 404 is returned from Test button. This means the plugin is not active.

* PW-2603 remove customer id from shopperinfo payload (#33)

Co-authored-by: Wanne Van Camp <[email protected]>

* Fixing Yandex logo (#40)

* Improve exception logging (#37)

Fix #23 PW-2747

* Fixes #15 Handle offer_closed notification (#39)

* Fixes #15 Handle offer_closed notification

* PW-2748 Tabs -> spaces

* Fixes #18 PW-2600 Catch exception during backend Test (#38)

* Fixes #18 PW-2600 Catch exception during backend Test

* PW-2600 Tabs to spaces

* PW-2804 Save form before test (#36)

Saves the config before the test is ran.

Fix #24

* PW-2565 Make paymentsmethod cache configurable (#43)

Adds configuration option to make caching of /paymentmethods call configurable.

Co-authored-by: Ángel Campos <[email protected]>

Fixes #26

* PW-2505 Distinquish fields of test and live (#44)

* PW-2505 Distinquish fields of test and live

* PW-2505 Remove debug lines

* Improve labels

Co-authored-by: Ángel Campos <[email protected]>

Co-authored-by: Marcos Garcia <[email protected]>
Co-authored-by: Ángel Campos <[email protected]>

* Fixes #13 PW-2748 Add event to order restore (#42)

* Localizing changelog (#49)

* Feature/change refund function (#48)

* Save successful psp reference to PaymentInfo

* Fixes #17 Use succesfull notification for refunds

* Changing API test error code from 500 to 400 (#52)

* Fixing changelog

* 1.5.0 version bump

* Adding N/A to houseNumberOrName in Components/Payload/Providers/ShopperInfoProvider.php

Co-authored-by: maxwellpowers <[email protected]>
Co-authored-by: Rune Laenen <[email protected]>
Co-authored-by: Wanne Van Camp <[email protected]>
Co-authored-by: Wanne Van Camp <[email protected]>
Co-authored-by: Rune Laenen <[email protected]>
Co-authored-by: Marcos Garcia <[email protected]>
  • Loading branch information
7 people authored Sep 10, 2020
1 parent 042857e commit 4371f95
Show file tree
Hide file tree
Showing 38 changed files with 428 additions and 219 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run PHP Code Sniffer
run: vendor/bin/phpcs --ignore=*vendor/ --ignore=AdyenPayment.php --ignore=Controllers --standard=PSR2 .
run: vendor/bin/phpcs .

- name: Make sure project files are compilable
run: find -L . -path ./vendor -prune -o -path ./tests -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l
5 changes: 4 additions & 1 deletion AdyenPayment.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

//phpcs:disable PSR1.Files.SideEffects

namespace AdyenPayment;

use Doctrine\Common\Cache\Cache;
Expand Down Expand Up @@ -40,7 +42,7 @@ class AdyenPayment extends Plugin
*/
public static function isPackage(): bool
{
return file_exists(self::getPackageVendorAutoload());
return file_exists(static::getPackageVendorAutoload());
}

/**
Expand Down Expand Up @@ -236,3 +238,4 @@ private function rebuildAttributeModels()
if (AdyenPayment::isPackage()) {
require_once AdyenPayment::getPackageVendorAutoload();
}
//phpcs:enable PSR1.Files.SideEffects
9 changes: 8 additions & 1 deletion Components/Adyen/PaymentMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function getPaymentMethods(
$locale = null,
$cache = true
): array {
$cache = $cache && $this->configuration->isPaymentmethodsCacheEnabled();
$cacheKey = $this->getCacheKey($countryCode ?? '', $currency ?? '', (string)$value ?? '');
if ($cache && isset($this->cache[$cacheKey])) {
return $this->cache[$cacheKey];
Expand All @@ -88,7 +89,13 @@ public function getPaymentMethods(
try {
$paymentMethods = $checkout->paymentMethods($requestParams);
} catch (AdyenException $e) {
$this->logger->critical($e);
$this->logger->critical('Adyen Exception', [
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'errorType' => $e->getErrorType(),
'status' => $e->getStatus()
]);
return [];
}

Expand Down
20 changes: 19 additions & 1 deletion Components/Adyen/RefundService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Adyen\AdyenException;
use Adyen\Service\Modification;
use AdyenPayment\Components\NotificationManager;
use AdyenPayment\Models\PaymentInfo;
use AdyenPayment\Models\Refund;
use Shopware\Components\Model\ModelManager;
use Shopware\Models\Order\Order;
Expand All @@ -27,6 +28,10 @@ class RefundService
* @var NotificationManager
*/
private $notificationManager;
/**
* @var \Doctrine\Common\Persistence\ObjectRepository|\Doctrine\ORM\EntityRepository
*/
private $paymentInfoRepository;

/**
* PaymentMethodService constructor.
Expand All @@ -42,6 +47,7 @@ public function __construct(
$this->apiFactory = $apiFactory;
$this->modelManager = $modelManager;
$this->notificationManager = $notificationManager;
$this->paymentInfoRepository = $modelManager->getRepository(PaymentInfo::class);
}

/**
Expand All @@ -53,11 +59,23 @@ public function __construct(
*/
public function doRefund(int $orderId): Refund
{
/** @var Order $order */
$order = $this->modelManager->find(Order::class, $orderId);
$apiClient = $this->apiFactory->create($order->getShop());
$modification = new Modification($apiClient);

$notification = $this->notificationManager->getLastNotificationForOrderId($orderId);
/** @var PaymentInfo $paymentInfo */
$paymentInfo = $this->paymentInfoRepository->findOneBy([
'orderId' => $orderId
]);

if ($paymentInfo && !empty($paymentInfo->getPspReference())) {
$notification = $this->notificationManager->getLastNotificationForPspReference(
$paymentInfo->getPspReference()
);
} else {
$notification = $this->notificationManager->getLastNotificationForOrderId($orderId);
}

$request = [
'originalReference' => $notification->getPspReference(),
Expand Down
5 changes: 5 additions & 0 deletions Components/BasketService.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public function restoreFromOrder(Order $order)
foreach ($orderDetails as $orderDetail) {
$this->processOrderDetail($order, $orderDetail);
}

$this->events->notify(Event::BASKET_RESTORE_FROM_ORDER, [
'order' => $order
]);

$this->sBasket->sRefreshBasket();
}

Expand Down
49 changes: 33 additions & 16 deletions Components/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ public function __construct(
* @param bool $shop
* @return string
*/
public function getEnvironment($shop = false): string
public function getEnvironment($shop = false, $lowercase = false): string
{
$environment = Environment::TEST;
if ($this->getConfig('environment', $shop) === self::ENV_LIVE) {
return Environment::LIVE;
$environment = Environment::LIVE;
}

return Environment::TEST;
if ($lowercase) {
return strtolower($environment);
}

return $environment;
}

/**
Expand Down Expand Up @@ -97,22 +102,16 @@ public function getConfig($key = null, $shop = false)
return null;
}

/**
* @param bool|Shop $shop
* @return string
*/
public function getJsComponents3DS2ChallengeImageSize($shop = false): string
{
return (string)$this->getConfig('js_components_3DS2_challenge_image_size', $shop);
}

/**
* @param bool|Shop $shop
* @return string
*/
public function getApiKey($shop = false): string
{
return (string)$this->getConfig('api_key', $shop);
return (string)$this->getConfig(
'api_key_' . $this->getEnvironment($shop, true),
$shop
);
}

/**
Expand All @@ -139,7 +138,10 @@ public function getOriginKey($shop = false): string
*/
public function getNotificationHmac($shop = false): string
{
return (string)$this->getConfig('notification_hmac', $shop);
return (string)$this->getConfig(
'notification_hmac_' . $this->getEnvironment($shop, true),
$shop
);
}

/**
Expand All @@ -148,7 +150,10 @@ public function getNotificationHmac($shop = false): string
*/
public function getNotificationAuthUsername($shop = false): string
{
return (string)$this->getConfig('notification_auth_username', $shop);
return (string)$this->getConfig(
'notification_auth_username_' . $this->getEnvironment($shop, true),
$shop
);
}

/**
Expand All @@ -157,7 +162,10 @@ public function getNotificationAuthUsername($shop = false): string
*/
public function getNotificationAuthPassword($shop = false): string
{
return (string)$this->getConfig('notification_auth_password', $shop);
return (string)$this->getConfig(
'notification_auth_password_' . $this->getEnvironment($shop, true),
$shop
);
}

/**
Expand All @@ -169,6 +177,15 @@ public function getGoogleMerchantId($shop = false): string
return (string)$this->getConfig('google_merchant_id', $shop);
}

/**
* @param bool $shop
* @return bool
*/
public function isPaymentmethodsCacheEnabled($shop = false): bool
{
return (bool)$this->getConfig('paymentmethods_cache', $shop);
}

/**
* @return string
*/
Expand Down
21 changes: 21 additions & 0 deletions Components/NotificationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,25 @@ public function getLastNotificationForOrderId(int $orderId)
return null;
}
}

/**
* @param string $pspReference
* @return mixed|null
* @throws NonUniqueResultException
*/
public function getLastNotificationForPspReference(string $pspReference)
{
try {
$lastNotification = $this->notificationRepository->createQueryBuilder('n')
->where('n.pspReference = :pspReference')
->setMaxResults(1)
->orderBy('n.createdAt', 'ASC')
->setParameter('pspReference', $pspReference)
->getQuery()
->getSingleResult();
return $lastNotification;
} catch (NoResultException $ex) {
return null;
}
}
}
6 changes: 5 additions & 1 deletion Components/NotificationProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ private function process(Notification $notification)
} catch (\Exception $exception) {
$status = NotificationStatus::STATUS_FATAL;
$this->logger->notice('General Exception', [
'exception' => $exception,
'exception' => [
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine()
],
'notificationId' => $notification->getId()
]);
yield new NotificationProcessorFeedback(
Expand Down
28 changes: 26 additions & 2 deletions Components/NotificationProcessor/Authorisation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
use AdyenPayment\Components\PaymentStatusUpdate;
use AdyenPayment\Models\Event;
use AdyenPayment\Models\Notification;
use AdyenPayment\Models\PaymentInfo;
use Psr\Log\LoggerInterface;
use Shopware\Components\ContainerAwareEventManager;
use Shopware\Components\Model\ModelManager;
use Shopware\Models\Order\Status;

/**
Expand All @@ -29,6 +31,14 @@ class Authorisation implements NotificationProcessorInterface
* @var PaymentStatusUpdate
*/
private $paymentStatusUpdate;
/**
* @var ModelManager
*/
private $modelManager;
/**
* @var \Doctrine\Common\Persistence\ObjectRepository|\Doctrine\ORM\EntityRepository
*/
private $paymentInfoRepository;

/**
* Authorisation constructor.
Expand All @@ -39,11 +49,14 @@ class Authorisation implements NotificationProcessorInterface
public function __construct(
LoggerInterface $logger,
ContainerAwareEventManager $eventManager,
PaymentStatusUpdate $paymentStatusUpdate
PaymentStatusUpdate $paymentStatusUpdate,
ModelManager $modelManager
) {
$this->logger = $logger;
$this->eventManager = $eventManager;
$this->paymentStatusUpdate = $paymentStatusUpdate->setLogger($this->logger);
$this->modelManager = $modelManager;
$this->paymentInfoRepository = $modelManager->getRepository(PaymentInfo::class);
}

/**
Expand Down Expand Up @@ -78,9 +91,20 @@ public function process(Notification $notification)
);

$status = $notification->isSuccess() ?
Status::PAYMENT_STATE_THE_CREDIT_HAS_BEEN_ACCEPTED :
Status::PAYMENT_STATE_COMPLETELY_PAID :
Status::PAYMENT_STATE_THE_PROCESS_HAS_BEEN_CANCELLED;

$this->paymentStatusUpdate->updatePaymentStatus($order, $status);

if ($notification->isSuccess()) {
/** @var PaymentInfo $paymentInfo */
$paymentInfo = $this->paymentInfoRepository->findOneBy([
'orderId' => $order->getId()
]);

$paymentInfo->setPspReference($notification->getPspReference());
$this->modelManager->persist($paymentInfo);
$this->modelManager->flush($paymentInfo);
}
}
}
26 changes: 24 additions & 2 deletions Components/NotificationProcessor/Capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AdyenPayment\Components\NotificationProcessor;

use AdyenPayment\Models\PaymentInfo;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\TransactionRequiredException;
Expand All @@ -11,6 +12,7 @@
use AdyenPayment\Models\Notification;
use Psr\Log\LoggerInterface;
use Shopware\Components\ContainerAwareEventManager;
use Shopware\Components\Model\ModelManager;
use Shopware\Models\Order\Status;

/**
Expand All @@ -33,6 +35,14 @@ class Capture implements NotificationProcessorInterface
* @var PaymentStatusUpdate
*/
private $paymentStatusUpdate;
/**
* @var ModelManager
*/
private $modelManager;
/**
* @var \Doctrine\Common\Persistence\ObjectRepository|\Doctrine\ORM\EntityRepository
*/
private $paymentInfoRepository;


/**
Expand All @@ -44,11 +54,14 @@ class Capture implements NotificationProcessorInterface
public function __construct(
LoggerInterface $logger,
ContainerAwareEventManager $eventManager,
PaymentStatusUpdate $paymentStatusUpdate
PaymentStatusUpdate $paymentStatusUpdate,
ModelManager $modelManager
) {
$this->logger = $logger;
$this->eventManager = $eventManager;
$this->paymentStatusUpdate = $paymentStatusUpdate->setLogger($this->logger);
$this->modelManager = $modelManager;
$this->paymentInfoRepository = $modelManager->getRepository(PaymentInfo::class);
}

/**
Expand Down Expand Up @@ -85,8 +98,17 @@ public function process(Notification $notification)
if ($notification->isSuccess()) {
$this->paymentStatusUpdate->updatePaymentStatus(
$order,
Status::PAYMENT_STATE_THE_CREDIT_HAS_BEEN_ACCEPTED
Status::PAYMENT_STATE_COMPLETELY_PAID
);

/** @var PaymentInfo $paymentInfo */
$paymentInfo = $this->paymentInfoRepository->findOneBy([
'orderId' => $order->getId()
]);

$paymentInfo->setPspReference($notification->getPspReference());
$this->modelManager->persist($paymentInfo);
$this->modelManager->flush($paymentInfo);
}
}
}
Loading

0 comments on commit 4371f95

Please sign in to comment.