diff --git a/src/Application/Controller/Admin/AdminOrder.php b/src/Application/Controller/Admin/AdminOrder.php
index 7173cf1..7f276c1 100644
--- a/src/Application/Controller/Admin/AdminOrder.php
+++ b/src/Application/Controller/Admin/AdminOrder.php
@@ -17,14 +17,13 @@ namespace D3\Linkmobility4OXID\Application\Controller\Admin;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
+use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
-use D3\Linkmobility4OXID\Application\Model\Sms;
use D3\LinkmobilityClient\Response\ResponseInterface;
use D3\LinkmobilityClient\ValueObject\Recipient;
use Exception;
use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
use OxidEsales\Eshop\Application\Model\Order;
-use OxidEsales\Eshop\Application\Model\Remark;
use OxidEsales\Eshop\Core\Registry;
class AdminOrder extends AdminController
@@ -86,7 +85,6 @@ class AdminOrder extends AdminController
try {
$sms = oxNew(Sms::class, $messageBody);
if ($sms->sendOrderMessage($order)) {
- $this->setRemark($sms->getRecipientsList(), $sms->getMessage());
Registry::getUtilsView()->addErrorToDisplay(
oxNew(successfullySentException::class, $sms->getResponse()->getSmsCount())
);
@@ -103,21 +101,4 @@ class AdminOrder extends AdminController
Registry::getUtilsView()->addErrorToDisplay($e);
}
}
-
- /**
- * @param $recipients
- * @param $messageBody
- *
- * @throws Exception
- */
- protected function setRemark($recipients, $messageBody)
- {
- $remark = oxNew(Remark::class);
- $remark->assign([
- 'oxtype' => AdminUser::REMARK_IDENT,
- 'oxparentid' => $this->order->getUser()->getId(),
- 'oxtext' => $recipients.PHP_EOL.$messageBody
- ]);
- $remark->save();
- }
}
diff --git a/src/Application/Controller/Admin/AdminUser.php b/src/Application/Controller/Admin/AdminUser.php
index ad659d2..e4a27b6 100644
--- a/src/Application/Controller/Admin/AdminUser.php
+++ b/src/Application/Controller/Admin/AdminUser.php
@@ -16,20 +16,17 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Application\Controller\Admin;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
-use D3\Linkmobility4OXID\Application\Model\Sms;
+use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\Linkmobility4OXID\Application\Model\UserRecipients;
use D3\LinkmobilityClient\Response\ResponseInterface;
use D3\LinkmobilityClient\ValueObject\Recipient;
use Exception;
use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
-use OxidEsales\Eshop\Application\Model\Remark;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry;
class AdminUser extends AdminController
{
- public const REMARK_IDENT = 'LMSMS';
-
protected $_sThisTemplate = 'd3adminuser.tpl';
/**
@@ -86,7 +83,6 @@ class AdminUser extends AdminController
$sms = oxNew(Sms::class, $messageBody);
if ($sms->sendUserAccountMessage($user)) {
- $this->setRemark($sms->getRecipientsList(), $sms->getMessage());
Registry::getUtilsView()->addErrorToDisplay(
sprintf(
Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'),
@@ -103,21 +99,4 @@ class AdminUser extends AdminController
);
}
}
-
- /**
- * @param $recipients
- * @param $messageBody
- *
- * @throws Exception
- */
- protected function setRemark($recipients, $messageBody)
- {
- $remark = oxNew(Remark::class);
- $remark->assign([
- 'oxtype' => AdminUser::REMARK_IDENT,
- 'oxparentid' => $this->getEditObjectId(),
- 'oxtext' => $recipients.PHP_EOL.$messageBody
- ]);
- $remark->save();
- }
}
diff --git a/src/Application/Model/Configuration.php b/src/Application/Model/Configuration.php
index 6bdd750..9da0a7c 100644
--- a/src/Application/Model/Configuration.php
+++ b/src/Application/Model/Configuration.php
@@ -58,7 +58,7 @@ class Configuration
$country = trim(Registry::getConfig()->getConfigParam('d3linkmobility_smsSenderCountry'));
$country = strlen($country) ? strtoupper($country) : null;
- Assert::that($country)->nullOr() || Assert::that($country)->string()->length(2);
+ Assert::that($country)->nullOr()->string()->length(2);
return $country;
}
diff --git a/src/Application/Model/MessageSender.php b/src/Application/Model/MessageSender.php
index 8d368e3..8aa7c18 100644
--- a/src/Application/Model/MessageSender.php
+++ b/src/Application/Model/MessageSender.php
@@ -15,10 +15,10 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Application\Model;
-use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
+use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
+use Exception;
use OxidEsales\Eshop\Application\Model\Order;
-use OxidEsales\Eshop\Application\Model\Remark;
use OxidEsales\Eshop\Core\Registry;
class MessageSender
@@ -26,6 +26,7 @@ class MessageSender
/**
* @param Order $order
* @param $messageBody
+ * @throws Exception
*/
public function sendOrderFinishedMessage(Order $order, $messageBody)
{
@@ -35,6 +36,7 @@ class MessageSender
/**
* @param Order $order
* @param $messageBody
+ * @throws Exception
*/
public function sendSendedNowMessage(Order $order, $messageBody)
{
@@ -44,6 +46,7 @@ class MessageSender
/**
* @param Order $order
* @param $messageBody
+ * @throws Exception
*/
public function sendCancelOrderMessage(Order $order, $messageBody)
{
@@ -54,6 +57,7 @@ class MessageSender
* @param $configParam
* @param Order $order
* @param $messageBody
+ * @throws Exception
*/
public function sendMessageByOrder($configParam, Order $order, $messageBody)
{
@@ -65,28 +69,8 @@ class MessageSender
try {
$sms = oxNew(Sms::class, $messageBody);
- if ($sms->sendOrderMessage($order)) {
- $this->setRemark($order->getId(), $sms->getRecipientsList(), $sms->getMessage());
- }
+ $sms->sendOrderMessage($order);
} catch (noRecipientFoundException $e) {
}
}
-
- /**
- * @param $orderId
- * @param $recipients
- * @param $message
- *
- * @throws \Exception
- */
- protected function setRemark($orderId, $recipients, $message)
- {
- $remark = oxNew(Remark::class);
- $remark->assign([
- 'oxtype' => AdminUser::REMARK_IDENT,
- 'oxparentid' => $orderId,
- 'oxtext' => $recipients.PHP_EOL.$message
- ]);
- $remark->save();
- }
}
diff --git a/src/Application/Model/MessageTypes/AbstractMessage.php b/src/Application/Model/MessageTypes/AbstractMessage.php
new file mode 100644
index 0000000..1bc8c70
--- /dev/null
+++ b/src/Application/Model/MessageTypes/AbstractMessage.php
@@ -0,0 +1,113 @@
+
+ * @link https://www.oxidmodule.com
+ */
+
+declare(strict_types=1);
+
+namespace D3\Linkmobility4OXID\Application\Model\MessageTypes;
+
+use D3\LinkmobilityClient\Response\ResponseInterface;
+use D3\LinkmobilityClient\ValueObject\Recipient;
+use Exception;
+use OxidEsales\Eshop\Application\Model\Remark;
+
+abstract class AbstractMessage
+{
+ const REMARK_IDENT = 'LINKMOB';
+
+ protected $message;
+ protected $removeLineBreaks = true;
+ protected $removeMultipleSpaces = true;
+
+ protected $response;
+ protected $recipients = [];
+
+ /**
+ * @param string $message
+ */
+ public function __construct(string $message)
+ {
+ $this->message = $this->sanitizeMessage($message);
+ }
+
+ /**
+ * @return string
+ */
+ public function getMessage(): string
+ {
+ return $this->message;
+ }
+
+ /**
+ * @param $userId
+ * @param $recipients
+ * @param $message
+ *
+ * @throws Exception
+ */
+ protected function setRemark($userId, $recipients, $message)
+ {
+ $remark = oxNew(Remark::class);
+ $remark->assign([
+ 'oxtype' => self::REMARK_IDENT,
+ 'oxparentid' => $userId,
+ 'oxtext' => $this->getTypeName().' -> '.$recipients.PHP_EOL.$message
+ ]);
+ $remark->save();
+ }
+
+ /**
+ * @return ResponseInterface|null
+ */
+ public function getResponse()
+ {
+ return $this->response;
+ }
+
+ /**
+ * @param array $recipients
+ * @return void
+ */
+ protected function setRecipients(array $recipients)
+ {
+ $this->recipients = $recipients;
+ }
+
+ /**
+ * @return string
+ */
+ public function getRecipientsList(): string
+ {
+ $list = [];
+ /** @var Recipient $recipient */
+ foreach ($this->recipients as $recipient) {
+ $list[] = $recipient->get();
+ }
+
+ return implode(', ', $list);
+ }
+
+ /**
+ * @param $message
+ *
+ * @return string
+ */
+ protected function sanitizeMessage($message): string
+ {
+ $message = trim(strip_tags($message));
+ $message = $this->removeLineBreaks ? str_replace(["\r", "\n"], ' ', $message) : $message;
+ $regexp = '/\s{2,}/m';
+ return $this->removeMultipleSpaces ? preg_replace($regexp, ' ', $message) : $message;
+ }
+
+ abstract public function getTypeName() : string;
+}
diff --git a/src/Application/Model/Sms.php b/src/Application/Model/MessageTypes/Sms.php
similarity index 75%
rename from src/Application/Model/Sms.php
rename to src/Application/Model/MessageTypes/Sms.php
index f6bd90d..acdb4a1 100644
--- a/src/Application/Model/Sms.php
+++ b/src/Application/Model/MessageTypes/Sms.php
@@ -13,46 +13,46 @@
declare(strict_types=1);
-namespace D3\Linkmobility4OXID\Application\Model;
+namespace D3\Linkmobility4OXID\Application\Model\MessageTypes;
+use D3\Linkmobility4OXID\Application\Model\Configuration;
use D3\Linkmobility4OXID\Application\Model\Exceptions\abortSendingExceptionInterface;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
+use D3\Linkmobility4OXID\Application\Model\MessageClient;
+use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
+use D3\Linkmobility4OXID\Application\Model\RequestFactory;
+use D3\Linkmobility4OXID\Application\Model\UserRecipients;
use D3\LinkmobilityClient\Exceptions\ApiException;
use D3\LinkmobilityClient\Request\RequestInterface;
-use D3\LinkmobilityClient\Response\ResponseInterface;
use D3\LinkmobilityClient\SMS\SmsRequestInterface;
-use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\LinkmobilityClient\ValueObject\Sender;
+use Exception;
use GuzzleHttp\Exception\GuzzleException;
use InvalidArgumentException;
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry;
-class Sms
+class Sms extends AbstractMessage
{
- private $response;
- private $recipients = [];
- private $message;
- protected $removeLineBreaks = true;
- protected $removeMultipleSpaces = true;
-
- public function __construct(string $message)
- {
- $this->message = $this->sanitizeMessage($message);
- }
-
/**
* @param User $user
*
* @return bool
+ * @throws Exception
*/
public function sendUserAccountMessage(User $user): bool
{
try {
- return $this->sendCustomRecipientMessage(
+ Registry::getLogger()->debug('startRequest', ['userId' => $user->getId()]);
+ $return = $this->sendCustomRecipientMessage(
[ oxNew(UserRecipients::class, $user)->getSmsRecipient() ]
);
+ if ($return) {
+ $this->setRemark($user->getId(), $this->getRecipientsList(), $this->getMessage());
+ }
+ Registry::getLogger()->debug('finishRequest', ['userId' => $user->getId()]);
+ return $return;
} catch (noRecipientFoundException $e) {
Registry::getLogger()->warning($e->getMessage());
Registry::getUtilsView()->addErrorToDisplay($e);
@@ -66,6 +66,7 @@ class Sms
*
* @return bool
* @throws noRecipientFoundException
+ * @throws Exception
*/
public function sendOrderMessage(Order $order): bool
{
@@ -74,6 +75,9 @@ class Sms
$return = $this->sendCustomRecipientMessage(
[ $this->getOrderRecipient($order) ]
);
+ if ($return) {
+ $this->setRemark($order->getOrderUser()->getId(), $this->getRecipientsList(), $this->getMessage());
+ }
Registry::getLogger()->debug('finishRequest', ['orderId' => $order->getId()]);
return $return;
} catch (noRecipientFoundException $e) {
@@ -148,44 +152,10 @@ class Sms
}
/**
- * @return ResponseInterface|null
- */
- public function getResponse()
- {
- return $this->response;
- }
-
- protected function setRecipients(array $recipients)
- {
- $this->recipients = $recipients;
- }
-
- public function getRecipientsList(): string
- {
- $list = [];
- /** @var Recipient $recipient */
- foreach ($this->recipients as $recipient) {
- $list[] = $recipient->get();
- }
-
- return implode(', ', $list);
- }
-
- /**
- * @param $message
- *
* @return string
*/
- protected function sanitizeMessage($message): string
+ public function getTypeName(): string
{
- $message = trim(strip_tags($message));
- $message = $this->removeLineBreaks ? str_replace(["\r", "\n"], ' ', $message) : $message;
- $regexp = '/\s{2,}/m';
- return $this->removeMultipleSpaces ? preg_replace($regexp, ' ', $message) : $message;
- }
-
- public function getMessage(): string
- {
- return $this->message;
+ return 'SMS';
}
}
diff --git a/src/Application/views/admin/de/d3Linkmobility_lang.php b/src/Application/views/admin/de/d3Linkmobility_lang.php
index f6f2379..092d4f1 100644
--- a/src/Application/views/admin/de/d3Linkmobility_lang.php
+++ b/src/Application/views/admin/de/d3Linkmobility_lang.php
@@ -30,13 +30,13 @@ $aLang = [
'SHOP_MODULE_GROUP_d3linkmobility_sms' => 'SMS-Versand',
'SHOP_MODULE_d3linkmobility_smsSenderNumber' => 'Sendernummer',
- 'HELP_SHOP_MODULE_d3linkmobility_smsSenderNumber' => 'Ihre Mobilfunknummer, die als Antwortziel verwendet werden kann., Bitte lassen Sie die gewünschte Telefonnummer in Ihrem Konto hinterlegen.',
+ 'HELP_SHOP_MODULE_d3linkmobility_smsSenderNumber' => 'Ihre Mobilfunknummer, die als Absender verwendet wird. Bitte lassen Sie die gewünschte Telefonnummer in Ihrem Konto hinterlegen. Ist dort nur eine Nummer hinterlegt, brauchen Sie hier keine Angabe machen. Dann wird automatisch die Telefonnummer aus Ihrem Konto verwendet.',
'SHOP_MODULE_d3linkmobility_smsSenderCountry' => 'Landeskürzel',
- 'HELP_SHOP_MODULE_d3linkmobility_smsSenderCountry' => 'Geben Sie hier das Landeskürzel (ISO-Alpha-2, z.B. DE, AT, FR) an, zu dem Ihre Mobilfunknummer zugeordnet ist.',
+ 'HELP_SHOP_MODULE_d3linkmobility_smsSenderCountry' => 'Geben Sie hier das Landeskürzel (ISO-Alpha-2, z.B. DE, AT, FR) an, zu dem Ihre Mobilfunknummer zugeordnet ist. Diese Angabe ist nur nötig, wenn Sie eine Sendernummer angegeben haben.',
'SHOP_MODULE_d3linkmobility_smsUserRecipientsFields'=> 'Felder des Benutzerkontos, die auf gültige Mobilfunknummern geprüft werden',
'HELP_SHOP_MODULE_d3linkmobility_smsUserRecipientsFields' => 'Die Felder werden in dieser Reihenfolge geprüft und das erste valide Vorkommen wird zum Senden der Nachricht verwendet. Ohne (gültige) Feldangabe werden die Felder "oxmobfon", "oxfon" und "oxprivfon" geprüft.',
'SHOP_MODULE_d3linkmobility_smsOrderRecipientsFields'=> 'Felder der Bestellung, die auf gültige Mobilfunknummern und zugehörige Länderident geprüft werden',
- 'HELP_SHOP_MODULE_d3linkmobility_smsOrderRecipientsFields' => 'Die Felder werden in dieser Reihenfolge geprüft und das erste valide Vorkommen wird zum Senden der Nachricht verwendet. Ohne (gültige) Feldangabe werden die Felder "oxdelfon", und "oxbillfon" geprüft. Zum Telefonnummernfeld ist die Angabe des dazugehörigen Landesidentfeldes erforderlich. Individuelle Angaben erfolgen in diesem Format: