Skip to content

Commit

Permalink
orange sms notification
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Apr 17, 2018
0 parents commit a78fd79
Show file tree
Hide file tree
Showing 8 changed files with 350 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2018 Blackbird Agency

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Orange Sms Notification

[![Latest Stable Version](https://img.shields.io/packagist/v/blackbird/orange-sms-notification.svg?style=flat-square)](https://packagist.org/packages/blackbird/orange-sms-notification)
[![License: MIT](https://img.shields.io/github/license/blackbird-agency/magento-2-orange-sms-notification.svg?style=flat-square)](./LICENSE)

This module is a free connector for the SmsNotification and the OrangeSms modules.
The free source is available at the [github repository](https://github.com/blackbird-agency/magento-2-orange-sms-notification).

These modules are available on our [store](https://store.bird.eu/).

## Setup

The module is available on packagist, so you can install the module through composer:

```
composer require blackbird/orange-sms-notification
```

Then, run the following magento command:

```
php bin/magento setup:upgrade
```

**If you are in production mode, do not forget to recompile and redeploy the static resources.**

## Settings

This module add the capability to enable or disable this adapter connector.
The setting is available at the Orange Sms config section.

Now, your Orange Sms connector is available in the field list of Sms Notification adapters.
Select `Orange Sms` and apply the changes. Now, your notification are sent through Orange Sms.

## Support

- If you have any issue with this code, feel free to [open an issue](https://github.com/blackbird-agency/magento-2-orange-sms-notification/issues/new).
- If you wan to contribute to this project, feel free to [create a pull request](https://github.com/blackbird-agency/magento-2-orange-sms-notification/compare).

## Authors

- **Thomas Klein** - *Initial work* - [It's me!](https://github.com/thomas-blackbird)
- **Blackbird Team** - *Contributor* - [They're awesome!](https://github.com/blackbird-agency)

## Licence

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

***That's all folks!***

117 changes: 117 additions & 0 deletions Service/OrangeSmsAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
/**
* Blackbird Orange SMS Notification Module
*
* NOTICE OF LICENSE
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to contact@bird.eu so we can send you a copy immediately.
*
* @category Blackbird
* @package Blackbird_OrangeSmsNotification
* @copyright Copyright (c) 2018 Blackbird (https://black.bird.eu)
* @author Blackbird Team
* @license https://store.bird.eu/license/
* @support help@bird.eu
*/
declare(strict_types=1);

namespace Blackbird\OrangeSmsNotification\Service;

use Blackbird\OrangeSms\Api\Data\SmsInterfaceFactory;
use Blackbird\OrangeSms\Api\SmsManagementInterface;
use Blackbird\OrangeSms\Exception\OrangeSmsSendException;
use Blackbird\SmsNotification\Exception\SendNotificationException;
use Blackbird\SmsNotification\Model\Notification\AdapterInterface;
use Blackbird\SmsNotification\Model\Notification\MessageInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Phrase;
use Magento\Store\Model\ScopeInterface;

/**
* Class OrangeSmsAdapter, connector to SmsNotification adapters
*/
class OrangeSmsAdapter implements AdapterInterface
{
const CODE = 'orange_sms';

/**#@+
* Orange Sms Notifications General Config Paths
*/
const XML_PATH_ORANGE_SMS_ENABLED = 'orange_sms/general/enabled';
/**#@-*/

/**
* @var \Blackbird\OrangeSms\Api\Data\SmsInterfaceFactory
*/
private $smsFactory;

/**
* @var \Blackbird\OrangeSms\Api\SmsManagementInterface
*/
private $smsManagement;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $scopeConfig;

/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Blackbird\OrangeSms\Api\Data\SmsInterfaceFactory $smsFactory
* @param \Blackbird\OrangeSms\Api\SmsManagementInterface $smsManagement
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
SmsInterfaceFactory $smsFactory,
SmsManagementInterface $smsManagement
) {
$this->smsFactory = $smsFactory;
$this->smsManagement = $smsManagement;
$this->scopeConfig = $scopeConfig;
}

/**
* {@inheritdoc}
*/
public function getCode(): string
{
return self::CODE;
}

/**
* {@inheritdoc}
*/
public function getLabel(): string
{
return (new Phrase('Orange SMS'))->render();
}

/**
* {@inheritdoc}
*/
public function isEnabled(): bool
{
return $this->scopeConfig->isSetFlag(self::XML_PATH_ORANGE_SMS_ENABLED, ScopeInterface::SCOPE_STORE);
}

/**
* {@inheritdoc}
*/
public function sendMessage(MessageInterface $message): bool
{
/** @var \Blackbird\OrangeSms\Api\Data\SmsInterface $sms */
$sms = $this->smsFactory->create();
$sms->setTo($message->getTo());
$sms->setFrom($message->getFrom());
$sms->setMessage($message->getText());

try {
$this->smsManagement->send($sms);
} catch (OrangeSmsSendException $e) {
throw new SendNotificationException(new Phrase('Impossible to send the message.'), $e);
}

return true;
}
}
50 changes: 50 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "blackbird/orange-sms-notification",
"description": "Orange Sms connector to the Sms Notificaiton module adapters.",
"keywords": [
"php",
"magento",
"magento2",
"orange",
"sms",
"notification"
],
"homepage": "https://github.com/blackbird-agency/magento-2-orange-sms-notification",
"authors": [
{
"name": "Thomas Klein",
"email": "thomas@bird.eu",
"homepage": "https://www.linkedin.com/in/thomas-klein/",
"role": "lead"
},
{
"name": "Blackbird Team",
"email": "hello@bird.eu",
"homepage": "https://black.bird.eu/",
"role": "contributor"
}
],
"support": {
"source": "https://github.com/blackbird-agency/magento-2-orange-sms-notification",
"issues": "https://github.com/blackbird-agency/magento-2-orange-sms-notification/issues"
},
"require": {
"magento/magento-composer-installer": "*",
"magento/framework": ">=100.0",
"magento/module-backend": ">=100.0",
"magento/module-config": ">=100.0",
"blackbird/sms-notification": ">=0.1.0",
"blackbird/orange-sms": ">=0.1.0"
},
"type": "magento2-module",
"version": "0.1.0",
"license": "MIT",
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Blackbird\\OrangeSmsNotification\\": ""
}
}
}
35 changes: 35 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<!--
/**
* Blackbird Orange SMS Notification Module
*
* NOTICE OF LICENSE
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to contact@bird.eu so we can send you a copy immediately.
*
* @category Blackbird
* @package Blackbird_OrangeSmsNotification
* @copyright Copyright (c) 2018 Blackbird (https://black.bird.eu)
* @author Blackbird Team
* @license https://store.bird.eu/license/
* @support help@bird.eu
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="orange_sms">
<group id="general">
<field id="enabled" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Enable Orange SMS</label>
<source_model>Magento\Config\Model\Config\Source\Enabledisable</source_model>
<requires>
<field id="orange_sms/general/client_id" />
<field id="orange_sms/general/client_secret" />
</requires>
<config_path>orange_sms/general/enabled</config_path>
</field>
</group>
</section>
</system>
</config>
27 changes: 27 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<!--
/**
* Blackbird Orange SMS Notification Module
*
* NOTICE OF LICENSE
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to contact@bird.eu so we can send you a copy immediately.
*
* @category Blackbird
* @package Blackbird_OrangeSmsNotification
* @copyright Copyright (c) 2018 Blackbird (https://black.bird.eu)
* @author Blackbird Team
* @license https://store.bird.eu/license/
* @support help@bird.eu
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Blackbird\SmsNotification\Model\Notification\AdapterPool">
<arguments>
<argument name="adapters" xsi:type="array">
<item name="orange_sms" xsi:type="object">Blackbird\OrangeSmsNotification\Service\OrangeSmsAdapter</item>
</argument>
</arguments>
</type>
</config>
28 changes: 28 additions & 0 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<!--
/**
* Blackbird Orange SMS Notification Module
*
* NOTICE OF LICENSE
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to contact@bird.eu so we can send you a copy immediately.
*
* @category Blackbird
* @package Blackbird_OrangeSmsNotification
* @copyright Copyright (c) 2018 Blackbird (https://black.bird.eu)
* @author Blackbird Team
* @license https://store.bird.eu/license/
* @support help@bird.eu
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Blackbird_OrangeSmsNotification" setup_version="0.1.0">
<sequence>
<module name="Magento_Backend" />
<module name="Magento_Config" />
<module name="Blackbird_OrangeSms" />
<module name="Blackbird_SmsNotification" />
</sequence>
</module>
</config>
22 changes: 22 additions & 0 deletions registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Blackbird Orange SMS Notification Module
*
* NOTICE OF LICENSE
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to contact@bird.eu so we can send you a copy immediately.
*
* @category Blackbird
* @package Blackbird_OrangeSmsNotification
* @copyright Copyright (c) 2018 Blackbird (https://black.bird.eu)
* @author Blackbird Team
* @license https://store.bird.eu/license/
* @support help@bird.eu
*/

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Blackbird_OrangeSmsNotification',
__DIR__
);

0 comments on commit a78fd79

Please sign in to comment.