add client factory, Sms wrapper, further configuration options
This commit is contained in:
parent
924d6640e2
commit
b4f7d1a1bd
66
src/Application/Model/Configuration.php
Normal file
66
src/Application/Model/Configuration.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\Linkmobility4OXID\Application\Model;
|
||||
|
||||
use Assert\Assert;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
class Configuration
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getApiToken(): string
|
||||
{
|
||||
$token = trim(Registry::getConfig()->getConfigParam('d3linkmobility_apitoken'));
|
||||
|
||||
Assert::that($token)->string()->notEmpty();
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getTestMode(): bool
|
||||
{
|
||||
return (bool) Registry::getConfig()->getConfigParam( 'd3linkmobility_debug');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSmsSenderNumber(): string
|
||||
{
|
||||
$number = trim(Registry::getConfig()->getConfigParam('d3linkmobility_smsSenderNumber'));
|
||||
|
||||
Assert::that($number)->string()->notEmpty();
|
||||
|
||||
return $number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSmsSenderCountry(): string
|
||||
{
|
||||
$country = trim(Registry::getConfig()->getConfigParam('d3linkmobility_smsSenderCountry'));
|
||||
|
||||
Assert::that($country)->string()->length(2);
|
||||
|
||||
return strtoupper($country);
|
||||
}
|
||||
}
|
32
src/Application/Model/MessageClient.php
Normal file
32
src/Application/Model/MessageClient.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\Linkmobility4OXID\Application\Model;
|
||||
|
||||
use D3\LinkmobilityClient\Client;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
class MessageClient
|
||||
{
|
||||
/**
|
||||
* @return Client
|
||||
*/
|
||||
public function getClient(): Client
|
||||
{
|
||||
$client = oxNew(Client::class, oxNew(Configuration::class)->getApiToken());
|
||||
$client->setLogger(Registry::getLogger());
|
||||
return $client;
|
||||
}
|
||||
}
|
53
src/Application/Model/Sms.php
Normal file
53
src/Application/Model/Sms.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\Linkmobility4OXID\Application\Model;
|
||||
|
||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||
use D3\LinkmobilityClient\SMS\RequestFactory;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
|
||||
class Sms
|
||||
{
|
||||
public function sendMessageToUser(User $user, $message)
|
||||
{
|
||||
$configuration = oxNew(Configuration::class);
|
||||
$client = oxNew(MessageClient::class)->getClient();
|
||||
|
||||
$request = oxNew(RequestFactory::class, $message, $client)->getSmsRequest();
|
||||
$request->setTestMode( $configuration->getTestMode())
|
||||
->setMethod(RequestInterface::METHOD_POST)
|
||||
->setSenderAddress(
|
||||
oxNew(Sender::class, $configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry())
|
||||
)
|
||||
->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL);
|
||||
|
||||
$recipientsList = $request->getRecipientsList();
|
||||
dumpvar($recipientsList);
|
||||
/*
|
||||
foreach (oxNew(UserRecipients::class)->getSmsRecipients() as $recipient) {
|
||||
$recipientsList->
|
||||
}
|
||||
*/
|
||||
/*
|
||||
->add(oxNew(Recipient::class, '+49(0)176-21164371', 'DE'))
|
||||
->add(oxNew(Recipient::class, '+49176 21164372', 'DE'))
|
||||
->add(oxNew(Recipient::class, '03721268090', 'DE'))
|
||||
->add(oxNew(Recipient::class, '0049176abc21164373', 'DE'));
|
||||
*/
|
||||
}
|
||||
}
|
58
src/Application/Model/UserRecipients.php
Normal file
58
src/Application/Model/UserRecipients.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\Linkmobility4OXID\Application\Model;
|
||||
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
|
||||
class UserRecipients
|
||||
{
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
private $user;
|
||||
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function getSmsRecipients()
|
||||
{
|
||||
dumpvar(array_map(
|
||||
function ($fieldName) {
|
||||
dumpvar($fieldName);
|
||||
},
|
||||
$this->getSmsRecipientFields()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSmsRecipientFields(): array
|
||||
{
|
||||
return [
|
||||
'oxmobfon',
|
||||
'oxfon',
|
||||
'oxprivfon'
|
||||
];
|
||||
}
|
||||
|
||||
public function getSmsCountry()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\Linkmobility4OXID\Modules\Application\Controller;
|
||||
namespace D3\Linkmobility4OXID\Application\Model;
|
||||
|
||||
use D3\LinkmobilityClient\Client;
|
||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||
|
@ -15,11 +15,13 @@
|
||||
|
||||
namespace D3\Linkmobility4OXID\Modules\Application\Controller;
|
||||
|
||||
use D3\Linkmobility4OXID\Application\Model\Sms;
|
||||
use D3\LinkmobilityClient\Client;
|
||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||
use D3\LinkmobilityClient\SMS\RequestFactory;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
class StartController extends StartController_parent
|
||||
@ -29,6 +31,11 @@ class StartController extends StartController_parent
|
||||
$message = "testMessagetestMessagetestMessagetestMessagetestMessagetestMessage";
|
||||
//$message = "test\tMessage\ttest\tMessage";
|
||||
|
||||
$user = oxNew(User::class);
|
||||
$user->load('oxdefaultadmin');
|
||||
$sms = oxNew(Sms::class)->sendMessageToUser($user, $message);
|
||||
die();
|
||||
|
||||
$lmClient = oxNew(Client::class, trim(Registry::getConfig()->getConfigParam('d3linkmobility_apitoken')));
|
||||
$lmClient->setLogger(Registry::getLogger());
|
||||
$request = oxNew(RequestFactory::class, $message, $lmClient)->getSmsRequest();
|
||||
@ -41,6 +48,7 @@ class StartController extends StartController_parent
|
||||
->add(oxNew(Recipient::class, '+49176 21164372', 'DE'))
|
||||
->add(oxNew(Recipient::class, '03721268090', 'DE'))
|
||||
->add(oxNew(Recipient::class, '0049176abc21164373', 'DE'));
|
||||
|
||||
try {
|
||||
$response = $lmClient->request( $request );
|
||||
} catch (\Exception $e) {
|
||||
@ -48,6 +56,7 @@ class StartController extends StartController_parent
|
||||
}
|
||||
|
||||
dumpvar($response->isSuccessful());
|
||||
dumpvar($response->getInternalStatus());
|
||||
dumpvar($response->getErrorMessage());
|
||||
dumpvar($response->getSmsCount());
|
||||
|
||||
|
@ -40,6 +40,18 @@ $aModule = [
|
||||
'name' => $sModuleId.'_apitoken',
|
||||
'type' => 'str',
|
||||
'value' => false
|
||||
],
|
||||
[
|
||||
'group' => $sModuleId.'_general',
|
||||
'name' => $sModuleId.'_smsSenderNumber',
|
||||
'type' => 'str',
|
||||
'value' => false
|
||||
],
|
||||
[
|
||||
'group' => $sModuleId.'_general',
|
||||
'name' => $sModuleId.'_smsSenderCountry',
|
||||
'type' => 'str',
|
||||
'value' => 'DE'
|
||||
]
|
||||
]
|
||||
];
|
Loading…
Reference in New Issue
Block a user