├── .gitattributes ├── .github └── FUNDING.yml ├── CHANGELOG.md ├── Observer └── SendOrderNotification.php ├── README.md ├── composer.json ├── etc ├── acl.xml ├── adminhtml │ └── system.xml ├── config.xml ├── events.xml └── module.xml └── registration.php /.gitattributes: -------------------------------------------------------------------------------- 1 | /docs export-ignore 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: markshust 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 7 | 8 | ## [1.0.2] - 2019-10-18 9 | 10 | ### Fixed 11 | - Updated composer version constraints to support newer versions of Magento. 12 | 13 | ## [1.0.1] - 2019-05-10 14 | 15 | ### Fixed 16 | - Fixes suggested by Magento Coding Standard. 17 | 18 | ## [1.0.0] - 2019-02-12 19 | 20 | ### Added 21 | - Initial release. 22 | -------------------------------------------------------------------------------- /Observer/SendOrderNotification.php: -------------------------------------------------------------------------------- 1 | clientFactory = $clientFactory; 44 | $this->logger = $logger; 45 | $this->scopeConfig = $scopeConfig; 46 | $this->encryptor = $encryptor; 47 | } 48 | 49 | /** 50 | * Send an order notification in response to an observer object containing an 'order' property. 51 | * 52 | * @param Observer $observer 53 | */ 54 | public function execute(Observer $observer) 55 | { 56 | if (!$this->getGeneralConfig('enabled')) { 57 | return; 58 | } 59 | 60 | $order = $observer->getData('order'); 61 | $client = $this->clientFactory->create([ 62 | 'username' => $this->getGeneralConfig('account_sid'), 63 | 'password' => $this->encryptor->decrypt($this->getGeneralConfig('auth_token')), 64 | ]); 65 | $params = [ 66 | 'from' => $this->getGeneralConfig('send_from_number'), 67 | 'body' => $this->getBody($order), 68 | ]; 69 | 70 | try { 71 | $client->messages->create($this->getGeneralConfig('send_to_number'), $params); 72 | } catch (\Exception $e) { 73 | $this->logger->critical('Error message', ['exception' => $e]); 74 | } 75 | } 76 | 77 | /** 78 | * Construct the message of the body to send from a given order object. 79 | * 80 | * @param $order 81 | * @return string 82 | */ 83 | public function getBody($order) 84 | { 85 | $incrementId = $order->getData('increment_id'); 86 | $shippingDescription = $order->getData('shipping_description'); 87 | $result = "New order: #$incrementId" . PHP_EOL; 88 | $result .= PHP_EOL; 89 | $result .= "Shipping method: $shippingDescription" . PHP_EOL; 90 | $result .= PHP_EOL; 91 | 92 | foreach ($order->getData('items') as $item) { 93 | $qty = $item->getData('qty_ordered'); 94 | $sku = $item->getData('sku'); 95 | $name = $item->getData('name'); 96 | $result .= "[$qty x $sku] $name" . PHP_EOL; 97 | } 98 | 99 | return $result; 100 | } 101 | 102 | /** 103 | * Get the scoped config value. 104 | * 105 | * @param $value 106 | * @return mixed 107 | */ 108 | public function getGeneralConfig($value) 109 | { 110 | return $this->scopeConfig->getValue( 111 | "markshust_twilio/general/$value", 112 | ScopeInterface::SCOPE_STORE 113 | ); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

MarkShust_Twilio

2 | 3 |
4 |

Sends SMS messages in response to Magento events

5 | 6 | Supported Magento Versions 7 | Latest Stable Version 8 | Composer Downloads 9 | Maintained - Yes 10 | 11 | 12 |
13 | 14 | ## Table of contents 15 | 16 | - [Summary](#summary) 17 | - [Installation](#installation) 18 | - [Usage](#usage) 19 | - [License](#license) 20 | 21 | ## Summary 22 | 23 | There may be situations where you would like to be notified by SMS when a specific action happens within Magento. This module integrates with Twilio to provide that ability. 24 | 25 | Currently implemented is a "pick & pack" SMS order notification which is sent in response to an order that has been placed. 26 | 27 | ## Installation 28 | 29 | ``` 30 | composer require markshust/magento2-module-twilio 31 | bin/magento module:enable MarkShust_Twilio 32 | bin/magento setup:upgrade 33 | ``` 34 | 35 | Retrieve your Account SID and Auth Token from the Twilio Console Account Dashboard. 36 | 37 | Enable the module and add Twilio credentials at Admin > Stores > Configuration > Twilio > General Configuration. 38 | 39 | ## Usage 40 | 41 | Placing an order will result in an SMS message being sent: 42 | 43 | ![Screenshot](https://raw.githubusercontent.com/markshust/magento2-module-twilio/master/docs/demo.png) 44 | 45 | ## License 46 | 47 | [MIT](https://opensource.org/licenses/MIT) 48 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "markshust/magento2-module-twilio", 3 | "description": "The Twilio module sends SMS messages in response to Magento events.", 4 | "require": { 5 | "php": "^7.1", 6 | "magento/framework": "^101" 7 | }, 8 | "type": "magento2-module", 9 | "version": "1.0.0", 10 | "license": [ 11 | "MIT" 12 | ], 13 | "autoload": { 14 | "files": [ 15 | "registration.php" 16 | ], 17 | "psr-4": { 18 | "MarkShust\\Twilio\\": "" 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /etc/acl.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /etc/adminhtml/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | markshust_twilio 10 | MarkShust_Twilio::general 11 | 12 | 13 | 14 | 15 | Twilio Console.]]> 16 | Magento\Config\Model\Config\Source\Yesno 17 | 18 | 19 | 20 | 21 | 1 22 | 23 | 24 | 25 | 26 | Magento\Config\Model\Config\Backend\Encrypted 27 | 28 | 1 29 | 30 | 31 | 32 | 33 | Send notifications from this number (must be number registered to Twilio account). Format: +12165551212 34 | 35 | 1 36 | 37 | 38 | 39 | 40 | Send notifications to this number. Format: +12165551212 41 | 42 | 1 43 | 44 | 45 | 46 |
47 |
48 |
49 | -------------------------------------------------------------------------------- /etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /etc/events.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /registration.php: -------------------------------------------------------------------------------- 1 |