Skip to content

Commit

Permalink
Merge pull request #94 from Adyen/develop
Browse files Browse the repository at this point in the history
Release 1.6.0
  • Loading branch information
acampos1916 committed Dec 3, 2020
2 parents 85530d1 + 513e9b1 commit f02b085
Show file tree
Hide file tree
Showing 18 changed files with 274 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Make sure we are using composer v1
run: sudo composer self-update --1 && sudo chown $USER $HOME/.composer

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

Expand Down
8 changes: 7 additions & 1 deletion Components/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use AdyenPayment\AdyenPayment;
use Shopware\Components\Plugin\CachedConfigReader;
use Shopware\Models\Shop\Shop;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

/**
* Class Configuration
Expand Down Expand Up @@ -86,7 +87,12 @@ public function getMerchantAccount($shop = false): string
public function getConfig($key = null, $shop = false)
{
if (!$shop) {
$shop = null;
try {
$shop = Shopware()->Shop();
} catch (ServiceNotFoundException $exception) {
//The Shop service is not available in the context (i.e. getting the config from the Backend)
$shop = null;
}
}

$config = $this->cachedConfigReader->getByPluginName(AdyenPayment::NAME, $shop);
Expand Down
3 changes: 1 addition & 2 deletions Components/OrderMailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public function __construct(

/**
* Sends the mail after a payment is confirmed
*
* @param \Shopware\Models\Order\Order $order
* @param string|int $orderNumber
*/
public function sendOrderConfirmationMail($orderNumber)
{
Expand Down
6 changes: 2 additions & 4 deletions Components/Payload/Providers/ApplicationInfoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function __construct(Configuration $configuration)
public function provide(PaymentContext $context): array
{
$returnUrl = Shopware()->Router()->assemble([
'controller' => 'process',
'action' => 'return',
'controller' => 'transparent',
'action' => 'redirect',
]);

$plugin = $this->modelManager->getRepository(Plugin::class)->findOneBy(['name' => AdyenPayment::NAME]);
Expand All @@ -51,8 +51,6 @@ public function provide(PaymentContext $context): array
],
'channel' => Channel::WEB,
'origin' => $context->getOrigin(),
'redirectFromIssuerMethod' => 'GET',
'redirectToIssuerMethod' => 'POST',
'returnUrl' => $returnUrl,
'merchantAccount' => $this->configuration->getMerchantAccount(),
'applicationInfo' => [
Expand Down
28 changes: 27 additions & 1 deletion Components/PaymentStatusUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace AdyenPayment\Components;

use AdyenPayment\Models\Event;
use Psr\Log\LoggerInterface;
use Shopware\Components\ContainerAwareEventManager;
use Shopware\Components\Model\ModelManager;
use Shopware\Models\Order\Order;
use Shopware\Models\Order\Status;
Expand All @@ -21,14 +23,22 @@ class PaymentStatusUpdate
*/
private $logger;

/**
* @var ContainerAwareEventManager
*/
private $eventManager;

/**
* PaymentStatusUpdate constructor.
* @param ModelManager $modelManager
* @param ContainerAwareEventManager $eventManager
*/
public function __construct(
ModelManager $modelManager
ModelManager $modelManager,
ContainerAwareEventManager $eventManager
) {
$this->modelManager = $modelManager;
$this->eventManager = $eventManager;
}

/**
Expand All @@ -50,6 +60,14 @@ public function updateOrderStatus(Order $order, int $statusId)
]);
}

$this->eventManager->notify(
Event::ORDER_STATUS_CHANGED,
[
'order' => $order,
'newStatus' => $orderStatus
]
);

$order->setOrderStatus($orderStatus);
$this->modelManager->persist($order);
$this->modelManager->flush();
Expand All @@ -74,6 +92,14 @@ public function updatePaymentStatus(Order $order, int $statusId)
]);
}

$this->eventManager->notify(
Event::ORDER_PAYMENT_STATUS_CHANGED,
[
'order' => $order,
'newStatus' => $paymentStatus
]
);

$order->setPaymentStatus($paymentStatus);
$this->modelManager->persist($order);
$this->modelManager->flush();
Expand Down
5 changes: 4 additions & 1 deletion Controllers/Frontend/Adyen.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ private function prepareOrder($transaction)
{
$signature = $this->persistBasket();

Shopware()->Session()->offsetSet(AdyenPayment::SESSION_ADYEN_RESTRICT_EMAILS, $transaction->getId());
Shopware()->Session()->offsetSet(
AdyenPayment::SESSION_ADYEN_RESTRICT_EMAILS,
(bool) (0 < $transaction->getId())
);

$orderNumber = $this->saveOrder(
$transaction->getId(),
Expand Down
6 changes: 3 additions & 3 deletions Controllers/Frontend/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class Shopware_Controllers_Frontend_Notification extends Shopware_Controllers_Fr
private $incomingNotificationsManager;

/**
* POST: /notification
* POST: /notification/adyen
* @throws Enlight_Event_Exception
* @throws AdyenException
*/
public function indexAction()
public function adyenAction()
{
if (!$this->checkAuthentication()) {
$this->View()->assign('[Invalid or missing auth]');
Expand Down Expand Up @@ -109,7 +109,7 @@ private function saveNotifications(array $notifications)
*/
public function getWhitelistedCSRFActions()
{
return ['index'];
return ['adyen'];
}

/**
Expand Down
64 changes: 64 additions & 0 deletions Controllers/Frontend/Transparent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

use Shopware\Components\CSRFWhitelistAware;
use Shopware\Components\Logger;

// phpcs:ignore PSR1.Classes.ClassDeclaration.MissingNamespace, Squiz.Classes.ValidClassName.NotCamelCaps, Generic.Files.LineLength.TooLong
class Shopware_Controllers_Frontend_Transparent extends Shopware_Controllers_Frontend_Payment implements CSRFWhitelistAware
{

const ALLOWED_PARAMS = ['MD', 'PaRes'];
/**
* @var Logger
*/
private $logger;

public function preDispatch()
{
$this->logger = $this->get('adyen_payment.logger');
}

public function getWhitelistedCSRFActions()
{
return ['redirect'];
}

/**
* Transparent redirect to solve 3DS1 issue same site cookie policy issue
* Used to fetch POST return data and redirect locally to allow session usage
* https://github.com/Adyen/adyen-shopware5/issues/72
*/
public function redirectAction()
{
$redirectUrl = Shopware()->Router()->assemble([
'controller' => 'process',
'action' => 'return',
]);

$redirectParams = $this->retrieveParams();
$this->View()->assign('redirectUrl', $redirectUrl);
$this->View()->assign('redirectParams', $redirectParams);
$this->logger->debug('Forward incoming POST response to process/return', [
'POST and GET parameter keys' => array_keys($redirectParams)
]);
}

private function retrieveParams(): array
{
$request = $this->Request();

//Getting all GET parameters except for Shopware's action, controller and module
$getParams = $request->getQuery();
unset($getParams['action'], $getParams['controller'], $getParams['module']);

//Filtering allowed POST parameters
$fullPostParams = $request->getParams();
$postParams = [];
foreach (self::ALLOWED_PARAMS as $allowedParam) {
if (isset($fullPostParams[$allowedParam])) {
$postParams[$allowedParam] = $fullPostParams[$allowedParam];
}
}
return array_merge($getParams, $postParams);
}
}
3 changes: 3 additions & 0 deletions Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Event
const NOTIFICATION_PROCESS_CHARGEBACK = 'Adyen_Notification_Process_Chargeback';
const NOTIFICATION_PROCESS_CHARGEBACK_REVERSED = 'Adyen_Notification_Process_ChargebackReversed';

const ORDER_STATUS_CHANGED = 'Adyen_Order_Status_Changed';
const ORDER_PAYMENT_STATUS_CHANGED= 'Adyen_Order_Payment_Status_Changed';

const BASKET_RESTORE_FROM_ORDER = 'Adyen_Basket_RestoreFromOrder';
const BASKET_BEFORE_PROCESS_ORDER_DETAIL = 'Adyen_Basket_Before_ProcessOrderDetail';
const BASKET_STOPPED_PROCESS_ORDER_DETAIL = 'Adyen_Basket_Stopped_ProcessOrderDetail';
Expand Down
21 changes: 12 additions & 9 deletions Resources/frontend/js/jquery.adyen-confirm-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
case 'ChallengeShopper':
me.handlePaymentDataChallengeShopper(data);
break;
case 'Pending':
case 'RedirectShopper':
me.handlePaymentDataRedirectShopper(data);
break;
Expand Down Expand Up @@ -146,9 +147,9 @@
},
});
},
onError: function (error) {
console.error(error);
}
onError: function (error) {
console.error(error);
}
})
.mount('#AdyenIdentifyShopperThreeDS2');
},
Expand Down Expand Up @@ -176,17 +177,19 @@
},
});
},
onError: function (error) {
console.log(error);
}
onError: function (error) {
console.log(error);
}
})
.mount('#AdyenChallengeShopperThreeDS2');
},

handlePaymentDataRedirectShopper: function (data) {
var me = this;
if (data.action.type === 'redirect') {
me.adyenCheckout.createFromAction(data.action).mount(me.opts.mountRedirectSelector);
const me = this;
if ('redirect' === data.action.type || 'qrCode' === data.action.type) {
me.adyenCheckout
.createFromAction(data.action)
.mount(me.opts.mountRedirectSelector);
}
},

Expand Down
Loading

0 comments on commit f02b085

Please sign in to comment.