forked from Adyen/adyen-shopware5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into Adyen#54-cronjobs-not-running
* develop: (21 commits) Only send mail after succesful payment (Adyen#46) Adding N/A to houseNumberOrName in Components/Payload/Providers/ShopperInfoProvider.php 1.5.0 version bump Fixing changelog Changing API test error code from 500 to 400 (Adyen#52) Feature/change refund function (Adyen#48) Localizing changelog (Adyen#49) Fixes Adyen#13 PW-2748 Add event to order restore (Adyen#42) PW-2505 Distinquish fields of test and live (Adyen#44) PW-2565 Make paymentsmethod cache configurable (Adyen#43) PW-2804 Save form before test (Adyen#36) Fixes Adyen#18 PW-2600 Catch exception during backend Test (Adyen#38) Fixes Adyen#15 Handle offer_closed notification (Adyen#39) Improve exception logging (Adyen#37) Fixing Yandex logo (Adyen#40) PW-2603 remove customer id from shopperinfo payload (Adyen#33) Fix Adyen#22 PW-2743 Show error on 404 (Adyen#35) Fix Adyen#19 PW-2601 Update completed state (Adyen#34) Update composer.json (Adyen#31) [PW-2562] Adjustments for phpcs (Adyen#9) ... # Conflicts: # plugin.xml
- Loading branch information
Showing
9 changed files
with
219 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters