Skip to content

Commit

Permalink
Release 1.5.1 (#57)
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

* Only send mail after succesful payment (#46)

* Only send mail after succesful payment

* Fixes #12 Tabs to spaces

* Fix indentation

* Fix indentation

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

* #54 cronjobs not running (#55)

Add missing service registration

* add redirect  data to payments request (#56)

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

* 1.5.1 changelog

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 30, 2020
1 parent 4371f95 commit 85530d1
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 8 deletions.
13 changes: 13 additions & 0 deletions AdyenPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Shopware\Components\Plugin\Context\DeactivateContext;
use Shopware\Components\Plugin\Context\InstallContext;
use Shopware\Components\Plugin\Context\UninstallContext;
use Shopware\Components\Plugin\Context\UpdateContext;
use Shopware\Components\Plugin\PaymentInstaller;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -36,6 +37,7 @@ class AdyenPayment extends Plugin
const SESSION_ADYEN_PAYMENT = 'adyenPayment';
const SESSION_ADYEN_PAYMENT_VALID = 'adyenPaymentValid';
const SESSION_ADYEN_PAYMENT_DATA = 'adyenPaymentData';
const SESSION_ADYEN_RESTRICT_EMAILS = 'adyenRestrictEmail';

/**
* @return bool
Expand Down Expand Up @@ -95,6 +97,17 @@ public function install(InstallContext $context)
$tool->updateSchema($classes, true);
}

public function update(UpdateContext $context)
{
$this->installAttributes();

$tool = new SchemaTool($this->container->get('models'));
$classes = $this->getModelMetaData();
$tool->updateSchema($classes, true);

parent::update($context);
}

/**
* @param UninstallContext $context
* @throws Exception
Expand Down
60 changes: 60 additions & 0 deletions Components/OrderMailService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace AdyenPayment\Components;

use Shopware\Components\Model\ModelManager;

class OrderMailService
{
/**
* @var ModelManager
*/
private $modelManager;
/**
* @var BasketService
*/
private $basketService;

public function __construct(
ModelManager $modelManager,
BasketService $basketService
) {
$this->modelManager = $modelManager;
$this->basketService = $basketService;
}

/**
* Sends the mail after a payment is confirmed
*
* @param \Shopware\Models\Order\Order $order
*/
public function sendOrderConfirmationMail($orderNumber)
{
$order = $this->basketService->getOrderByOrderNumber($orderNumber);
if (!$order) {
return;
}

$paymentInfoRepository = $this->modelManager->getRepository(\AdyenPayment\Models\PaymentInfo::class);
/** @var \AdyenPayment\Models\PaymentInfo $paymentInfo */
$paymentInfo = $paymentInfoRepository->findOneBy([
'orderId' => $order->getId()
]);

if (!$paymentInfo) {
return;
}

$variables = json_decode($paymentInfo->getOrdermailVariables(), true);

if (is_array($variables)) {
$sOrder = Shopware()->Modules()->Order();
$sOrder->sUserData = $variables;
$sOrder->sendMail($variables);
}

$paymentInfo->setOrdermailVariables(null);
$this->modelManager->persist($paymentInfo);
$this->modelManager->flush($paymentInfo);
}
}
4 changes: 3 additions & 1 deletion Components/Payload/Providers/ApplicationInfoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ public function provide(PaymentContext $context): array
'executeThreeD' => true,
'allow3DS2' => true,
],
"channel" => Channel::WEB,
'channel' => Channel::WEB,
'origin' => $context->getOrigin(),
'redirectFromIssuerMethod' => 'GET',
'redirectToIssuerMethod' => 'POST',
'returnUrl' => $returnUrl,
'merchantAccount' => $this->configuration->getMerchantAccount(),
'applicationInfo' => [
Expand Down
4 changes: 2 additions & 2 deletions Components/Payload/Providers/OrderInfoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function provide(PaymentContext $context): array

return [
'amount' => [
"currency" => $currencyCode,
"value" => $adyenCurrency->sanitize($context->getOrder()->getInvoiceAmount(), $currencyCode),
'currency' => $currencyCode,
'value' => $adyenCurrency->sanitize($context->getOrder()->getInvoiceAmount(), $currencyCode),
],
'reference' => $context->getOrder()->getNumber(),
];
Expand Down
7 changes: 6 additions & 1 deletion Controllers/Frontend/Adyen.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use AdyenPayment\AdyenPayment;
use AdyenPayment\Components\Adyen\PaymentMethodService;
use AdyenPayment\Components\BasketService;
use AdyenPayment\Components\Calculator\PriceCalculationService;
Expand Down Expand Up @@ -199,7 +200,7 @@ private function prepareTransaction()
}

/**
* @param $transaction
* @param PaymentInfo $transaction
* @return Order
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
Expand All @@ -208,13 +209,17 @@ private function prepareOrder($transaction)
{
$signature = $this->persistBasket();

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

$orderNumber = $this->saveOrder(
$transaction->getId(),
$signature,
Status::PAYMENT_STATE_OPEN,
false
);

Shopware()->Session()->offsetSet(AdyenPayment::SESSION_ADYEN_RESTRICT_EMAILS, false);

/** @var Order $order */
$order = $this->getModelManager()->getRepository(Order::class)->findOneBy([
'number' => $orderNumber
Expand Down
11 changes: 10 additions & 1 deletion Controllers/Frontend/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ class Shopware_Controllers_Frontend_Process extends Shopware_Controllers_Fronten
*/
private $basketService;

/**
* @var \AdyenPayment\Components\OrderMailService
*/
private $orderMailService;

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


/**
* Whitelist notifyAction
*/
Expand All @@ -41,12 +47,12 @@ public function getWhitelistedCSRFActions()
return ['return'];
}


public function preDispatch()
{
$this->adyenManager = $this->get('adyen_payment.components.manager.adyen_manager');
$this->adyenCheckout = $this->get('adyen_payment.components.adyen.payment.method');
$this->basketService = $this->get('adyen_payment.components.basket_service');
$this->orderMailService = $this->get('adyen_payment.components.order_mail_service');
$this->logger = $this->get('adyen_payment.logger');
}

Expand All @@ -67,6 +73,9 @@ public function returnAction()
case PaymentResultCodes::AUTHORISED:
case PaymentResultCodes::PENDING:
case PaymentResultCodes::RECEIVED:
if (!empty($result['merchantReference'])) {
$this->orderMailService->sendOrderConfirmationMail($result['merchantReference']);
}
$this->redirect([
'controller' => 'checkout',
'action' => 'finish',
Expand Down
24 changes: 23 additions & 1 deletion Models/PaymentInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ class PaymentInfo extends ModelEntity
private $resultCode;

/**
* PaymenntInfo constructor
* @var string
*
* @ORM\Column(name="ordermail_variables", type="text", nullable=true)
*/
private $ordermailVariables;

public function __construct()
{
$this->setCreatedAt(new \DateTime('now'));
Expand Down Expand Up @@ -195,4 +199,22 @@ public function setResultCode(string $resultCode)
$this->resultCode = $resultCode;
return $this;
}

/**
* @return string|null
*/
public function getOrdermailVariables()
{
return $this->ordermailVariables;
}

/**
* @param string|null $ordermailVariables
* @return $this
*/
public function setOrdermailVariables($ordermailVariables)
{
$this->ordermailVariables = $ordermailVariables;
return $this;
}
}
6 changes: 6 additions & 0 deletions Resources/services/components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<argument type="service" id="shopware.plugin.cached_config_reader"/>
<argument type="service" id="dbal_connection"/>
</service>
<service id="adyen_payment.components.order_mail_service" class="AdyenPayment\Components\OrderMailService">
<argument type="service" id="models"/>
<argument type="service" id="adyen_payment.components.basket_service"/>
</service>
<service id="adyen_payment.components.adyen.apifactory" class="AdyenPayment\Components\Adyen\ApiFactory">
<argument type="service" id="models"/>
<argument type="service" id="adyen_payment.components.configuration"/>
Expand Down Expand Up @@ -80,6 +84,7 @@
<argument type="service" id="adyen_payment.logger.notifications"/>
<argument type="service" id="events"/>
<argument type="service" id="adyen_payment.components.payment_status_update"/>
<argument type="service" id="models"/>
</service>
<service id="adyen_payment.components.notification_processor.cancellation"
class="AdyenPayment\Components\NotificationProcessor\Cancellation">
Expand All @@ -94,6 +99,7 @@
<argument type="service" id="adyen_payment.logger.notifications"/>
<argument type="service" id="events"/>
<argument type="service" id="adyen_payment.components.payment_status_update"/>
<argument type="service" id="models"/>
</service>
<service id="adyen_payment.components.notification_processor.capture_failed"
class="AdyenPayment\Components\NotificationProcessor\CaptureFailed">
Expand Down
5 changes: 5 additions & 0 deletions Resources/services/subscribers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<argument type="service" id="models"/>
<argument type="service" id="adyen_payment.components.notification_manager"/>
</service>
<service id="adyen_payment.subscriber.order_email_subscriber" class="AdyenPayment\Subscriber\OrderEmailSubscriber">
<tag name="shopware.event_subscriber"/>
<argument type="service" id="models"/>
<argument type="service" id="adyen_payment.components.order_mail_service"/>
</service>
<service id="adyen_payment.subscriber.checkout" class="AdyenPayment\Subscriber\CheckoutSubscriber">
<tag name="shopware.event_subscriber"/>
<argument type="service" id="adyen_payment.components.configuration"/>
Expand Down
96 changes: 96 additions & 0 deletions Subscriber/OrderEmailSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php declare(strict_types=1);

namespace AdyenPayment\Subscriber;

use AdyenPayment\AdyenPayment;
use AdyenPayment\Components\NotificationManager;
use AdyenPayment\Components\OrderMailService;
use AdyenPayment\Models\PaymentInfo;
use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ORM\EntityRepository;
use Enlight\Event\SubscriberInterface;
use Enlight_Event_EventArgs;
use MollieShopware\Models\Transaction;
use Shopware\Components\HttpClient\Response;
use Shopware\Components\Model\ModelManager;
use Shopware_Controllers_Frontend_Checkout;

class OrderEmailSubscriber implements SubscriberInterface
{
/**
* @var ModelManager
*/
private $modelManager;

/**
* @var ObjectRepository|EntityRepository
*/
private $paymentInfoRepository;
/**
* @var OrderMailService
*/
private $orderMailService;

public function __construct(
ModelManager $modelManager,
OrderMailService $orderMailService
) {
$this->modelManager = $modelManager;
$this->paymentInfoRepository = $this->modelManager->getRepository(PaymentInfo::class);
$this->orderMailService = $orderMailService;
}

public static function getSubscribedEvents()
{
return [
'Shopware_Modules_Order_SendMail_Send' => 'shouldStopEmailSending',
'Enlight_Controller_Action_PostDispatch_Frontend_Checkout' => 'onCheckoutDispatch'
];
}

public function shouldStopEmailSending(Enlight_Event_EventArgs $args)
{
$orderId = $args->get('orderId');
$variables = $args->get('variables');

if ($variables['additional']['payment']['name'] === AdyenPayment::ADYEN_GENERAL_PAYMENT_METHOD &&
Shopware()->Session()->get(AdyenPayment::SESSION_ADYEN_RESTRICT_EMAILS, true) === false) {
Shopware()->Session()->offsetSet(AdyenPayment::SESSION_ADYEN_RESTRICT_EMAILS, true);

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

if ($paymentInfo && empty($paymentInfo->getOrdermailVariables())) {
$paymentInfo->setOrdermailVariables(json_encode($variables));

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

return false;
}

return null;
}

public function onCheckoutDispatch(Enlight_Event_EventArgs $args)
{

/** @var Shopware_Controllers_Frontend_Checkout $subject */
$subject = $args->getSubject();

if ($subject->Request()->getActionName() !== 'finish') {
return;
}

$data = $subject->View()->getAssign();

if (!$data['sOrderNumber']) {
return;
}

$this->orderMailService->sendOrderConfirmationMail($data['sOrderNumber']);
}
}
19 changes: 17 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

<label>Adyen Shopware Plugin</label>
<label lang="de">Adyen Shopware Plugin</label>

<version>1.5.0</version>
<version>1.5.1</version>
<copyright>Adyen</copyright>
<author>Adyen</author>
<link>https://adyen.com</link>
Expand Down Expand Up @@ -52,4 +51,20 @@
Live/Test config values
</changes>
</changelog>
<changelog version="1.5.1">
<changes lang="de">
Fixes:
Only send mail after successful payment
Adding N/A to houseNumberOrName
Cronjobs not running fix
Add redirect data to payments request
</changes>
<changes lang="en">
Fixes:
Only send mail after successful payment
Adding N/A to houseNumberOrName
Cronjobs not running fix
Add redirect data to payments request
</changes>
</changelog>
</plugin>

0 comments on commit 85530d1

Please sign in to comment.