Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.5.1 #57

Merged
merged 25 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d84dfa8
[PW-2473]: Shopware review fixes and remove 3DS2 image size (#7)
acampos1916 Jun 22, 2020
d8fe558
[PW-2562] Adjustments for phpcs (#9)
acampos1916 Jul 14, 2020
3ae870e
Update composer.json (#31)
maxwellpowers Aug 12, 2020
093ef96
Fix #19 PW-2601 Update completed state (#34)
runelaenen Aug 12, 2020
dbff888
Fix #22 PW-2743 Show error on 404 (#35)
runelaenen Aug 12, 2020
f3b7384
PW-2603 remove customer id from shopperinfo payload (#33)
wannevancamp Aug 12, 2020
c61c8ad
Fixing Yandex logo (#40)
acampos1916 Aug 12, 2020
43093d1
Improve exception logging (#37)
Aug 13, 2020
d52b19d
Fixes #15 Handle offer_closed notification (#39)
Aug 17, 2020
e66ce44
Fixes #18 PW-2600 Catch exception during backend Test (#38)
Aug 18, 2020
fdd9b42
PW-2804 Save form before test (#36)
Aug 20, 2020
59ea28b
PW-2565 Make paymentsmethod cache configurable (#43)
Aug 21, 2020
44a8568
PW-2505 Distinquish fields of test and live (#44)
Aug 28, 2020
5ac6600
Fixes #13 PW-2748 Add event to order restore (#42)
Aug 28, 2020
3b7729f
Localizing changelog (#49)
acampos1916 Aug 28, 2020
7d100b4
Feature/change refund function (#48)
Sep 3, 2020
3ff627f
Changing API test error code from 500 to 400 (#52)
acampos1916 Sep 7, 2020
3bac36b
Fixing changelog
acampos1916 Sep 9, 2020
d6c38ee
1.5.0 version bump
acampos1916 Sep 9, 2020
03f2c3b
Adding N/A to houseNumberOrName in Components/Payload/Providers/Shopp…
acampos1916 Sep 10, 2020
8c3b08f
Only send mail after succesful payment (#46)
Sep 11, 2020
ab7044b
#54 cronjobs not running (#55)
wannevancamp Sep 25, 2020
5a08719
add redirect data to payments request (#56)
wannevancamp Sep 30, 2020
d6ca466
Merge branch 'master' into develop
acampos1916 Sep 30, 2020
43fcedc
1.5.1 changelog
acampos1916 Sep 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>