linkmobility4oxid/src/Application/Model/MessageSender.php

95 lines
2.5 KiB
PHP
Raw Normal View History

2022-07-04 16:33:49 +02:00
<?php
/**
2022-07-13 13:21:52 +02:00
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
2022-07-04 16:33:49 +02:00
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
2022-07-13 13:21:52 +02:00
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link https://www.oxidmodule.com
2022-07-04 16:33:49 +02:00
*/
2022-07-13 13:21:52 +02:00
declare(strict_types=1);
2022-07-04 16:33:49 +02:00
namespace D3\Linkmobility4OXID\Application\Model;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use Exception;
2022-07-04 16:33:49 +02:00
use OxidEsales\Eshop\Application\Model\Order;
class MessageSender
{
/**
* @param Order $order
2022-07-27 09:27:59 +02:00
* @param string $messageBody
* @return void
* @throws Exception
2022-07-04 16:33:49 +02:00
*/
2022-07-27 09:27:59 +02:00
public function sendOrderFinishedMessage(Order $order, string $messageBody): void
2022-07-04 16:33:49 +02:00
{
2023-01-05 23:33:29 +01:00
if ($this->getConfiguration()->sendOrderFinishedMessage()) {
2022-07-27 08:47:20 +02:00
$this->sendMessageByOrder($order, $messageBody);
2022-07-18 00:27:49 +02:00
}
}
/**
* @param Order $order
2022-07-27 09:27:59 +02:00
* @param string $messageBody
* @return void
* @throws Exception
*/
2022-07-27 09:27:59 +02:00
public function sendSendedNowMessage(Order $order, string $messageBody): void
{
2023-01-05 23:33:29 +01:00
if ($this->getConfiguration()->sendOrderSendedNowMessage()) {
2022-07-18 00:27:49 +02:00
$this->sendMessageByOrder($order, $messageBody);
}
}
/**
* @param Order $order
2022-07-27 09:27:59 +02:00
* @param string $messageBody
* @return void
* @throws Exception
*/
2022-07-27 09:27:59 +02:00
public function sendCancelOrderMessage(Order $order, string $messageBody): void
{
2023-01-05 23:33:29 +01:00
if ($this->getConfiguration()->sendOrderCanceledMessage()) {
2022-07-18 00:27:49 +02:00
$this->sendMessageByOrder($order, $messageBody);
}
}
2022-07-12 16:06:19 +02:00
/**
* @param Order $order
2022-07-27 09:27:59 +02:00
* @param string $messageBody
* @return void
* @throws Exception
2022-07-12 16:06:19 +02:00
*/
2022-07-27 09:27:59 +02:00
public function sendMessageByOrder(Order $order, string $messageBody): void
{
2023-01-10 23:35:52 +01:00
if ((bool) strlen(trim($messageBody)) === false) {
2022-07-04 16:33:49 +02:00
return;
2023-01-10 23:35:52 +01:00
}
2022-07-04 16:33:49 +02:00
try {
2023-01-05 23:33:29 +01:00
d3GetOxidDIC()->setParameter(Sms::class.'.args.message', $messageBody);
/** @var Sms $sms */
$sms = d3GetOxidDIC()->get(Sms::class);
$sms->sendOrderMessage($order);
2022-07-13 13:23:48 +02:00
} catch (noRecipientFoundException $e) {
}
2022-07-04 16:33:49 +02:00
}
2023-01-05 23:33:29 +01:00
/**
* @return Configuration
*/
protected function getConfiguration(): Configuration
{
/** @var Configuration $configuration */
$configuration = d3GetOxidDIC()->get(Configuration::class);
return $configuration;
}
2022-07-13 13:23:48 +02:00
}