├── .styleci.yml ├── CHANGELOG.md ├── .editorconfig ├── src ├── LobServiceProvider.php ├── LobChannel.php ├── LobPostcard.php └── LobAddress.php ├── LICENSE.md ├── composer.json ├── CONTRIBUTING.md └── README.md /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `lob` will be documented in this file 4 | 5 | ## 1.1.0 - 2019-10-06 6 | 7 | - support laravel 5.5+ and 6.0 8 | - drop support for php < 7.1 9 | - bump lob to v3 10 | 11 | ## 1.0.0 12 | 13 | - initial release 14 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | ; This file is for unifying the coding style for different editors and IDEs. 2 | ; More information at http://editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | indent_size = 4 9 | indent_style = space 10 | end_of_line = lf 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /src/LobServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->when(LobChannel::class) 16 | ->needs(Lob::class) 17 | ->give(function () { 18 | $config = config('services.lob'); 19 | 20 | return new Lob( 21 | $config['api_key'] 22 | ); 23 | }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/LobChannel.php: -------------------------------------------------------------------------------- 1 | lob = $lob; 19 | } 20 | 21 | /** 22 | * Send the given notification. 23 | * 24 | * @param mixed $notifiable 25 | * @param \Illuminate\Notifications\Notification $notification 26 | */ 27 | public function send($notifiable, Notification $notification) 28 | { 29 | $message = $notification->toLobPostcard($notifiable); 30 | 31 | $messageContent = $message->toArray(); 32 | 33 | if (($address = $notifiable->routeNotificationFor('Lob')) && ! isset($messageContent['to'])) { 34 | $messageContent['to'] = $address; 35 | } 36 | 37 | $this->lob->{$message->type}()->create($messageContent); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) :author_name <:author_email> 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel-notification-channels/lob", 3 | "description": "Lob.com notifications channel for Laravel 5.3", 4 | "homepage": "https://github.com/laravel-notification-channels/lob", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Mohamed Said", 9 | "email": "themsaid@gmail.com", 10 | "homepage": "http://themsaid.com", 11 | "role": "Developer" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=7.2.5", 16 | "illuminate/notifications": "~5.5 || ~6.0 || ~7.0", 17 | "illuminate/support": "~5.5 || ~6.0 || ~7.0", 18 | "illuminate/queue": "~5.5 || ~6.0 || ~7.0", 19 | "lob/lob-php": "^3.0" 20 | }, 21 | "require-dev": { 22 | "mockery/mockery": "^1.0", 23 | "phpunit/phpunit": "~8.0" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "NotificationChannels\\Lob\\": "src" 28 | } 29 | }, 30 | "autoload-dev": { 31 | "psr-4": { 32 | "NotificationChannels\\Lob\\Test\\": "tests" 33 | } 34 | }, 35 | "scripts": { 36 | "test": "vendor/bin/phpunit" 37 | }, 38 | "config": { 39 | "sort-packages": true 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/LobPostcard.php: -------------------------------------------------------------------------------- 1 | message = $message; 41 | } 42 | 43 | /** 44 | * @param string|LobAddress $value 45 | * 46 | * @return $this 47 | */ 48 | public function fromAddress($value) 49 | { 50 | $this->fromAddress = is_string($value) ? $value : $value->toArray(); 51 | 52 | return $this; 53 | } 54 | 55 | /** 56 | * @param string|LobAddress $value 57 | * 58 | * @return $this 59 | */ 60 | public function toAddress($value) 61 | { 62 | $this->toAddress = is_string($value) ? $value : $value->toArray(); 63 | 64 | return $this; 65 | } 66 | 67 | /** 68 | * @param mixed $front 69 | * 70 | * @return $this 71 | */ 72 | public function front($front) 73 | { 74 | $this->front = $front; 75 | 76 | return $this; 77 | } 78 | 79 | /** 80 | * @param string $message 81 | * 82 | * @return $this 83 | */ 84 | public function message($message) 85 | { 86 | $this->message = $message; 87 | 88 | return $this; 89 | } 90 | 91 | /** 92 | * @param string $size 93 | * 94 | * @return $this 95 | */ 96 | public function size($size) 97 | { 98 | $this->size = $size; 99 | 100 | return $this; 101 | } 102 | 103 | /** 104 | * @return $this 105 | */ 106 | public function size4x6() 107 | { 108 | $this->size = '4x6'; 109 | 110 | return $this; 111 | } 112 | 113 | /** 114 | * @return $this 115 | */ 116 | public function size6x11() 117 | { 118 | $this->size = '6x11'; 119 | 120 | return $this; 121 | } 122 | 123 | /** 124 | * Get an array representation of the message. 125 | * 126 | * @return array 127 | */ 128 | public function toArray() 129 | { 130 | return array_filter([ 131 | 'to' => $this->toAddress, 132 | 'from' => $this->fromAddress, 133 | 'front' => $this->front, 134 | 'message' => $this->message, 135 | 'size' => $this->size, 136 | ]); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/LobAddress.php: -------------------------------------------------------------------------------- 1 | line1 = $line1; 46 | 47 | $this->country = $country; 48 | } 49 | 50 | /** 51 | * @param string $line2 52 | * 53 | * @return $this 54 | */ 55 | public function line2($line2) 56 | { 57 | $this->line2 = $line2; 58 | 59 | return $this; 60 | } 61 | 62 | /** 63 | * @param string $country 64 | * 65 | * @return $this 66 | */ 67 | public function country($country) 68 | { 69 | $this->country = $country; 70 | 71 | return $this; 72 | } 73 | 74 | /** 75 | * @param string $city 76 | * 77 | * @return $this 78 | */ 79 | public function city($city) 80 | { 81 | $this->city = $city; 82 | 83 | return $this; 84 | } 85 | 86 | /** 87 | * @param string $state 88 | * 89 | * @return $this 90 | */ 91 | public function state($state) 92 | { 93 | $this->state = $state; 94 | 95 | return $this; 96 | } 97 | 98 | /** 99 | * @param string $zip 100 | * 101 | * @return $this 102 | */ 103 | public function zip($zip) 104 | { 105 | $this->zip = $zip; 106 | 107 | return $this; 108 | } 109 | 110 | /** 111 | * @param string $name 112 | * 113 | * @return $this 114 | */ 115 | public function name($name) 116 | { 117 | $this->name = $name; 118 | 119 | return $this; 120 | } 121 | 122 | /** 123 | * Get an array representation of the address. 124 | * 125 | * @return array 126 | */ 127 | public function toArray() 128 | { 129 | return array_filter([ 130 | 'address_line1' => $this->line1, 131 | 'address_country' => $this->country, 132 | 'address_line2' => $this->line2, 133 | 'address_city' => $this->city, 134 | 'address_state' => $this->state, 135 | 'address_zip' => $this->zip, 136 | 'name' => $this->name, 137 | ]); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lob.com notifications channel for Laravel 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/lob.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/lob) 4 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 5 | [![Build Status](https://img.shields.io/travis/laravel-notification-channels/lob/master.svg?style=flat-square)](https://travis-ci.org/laravel-notification-channels/lob) 6 | [![StyleCI](https://styleci.io/repos/65659860/shield)](https://styleci.io/repos/65659860) 7 | [![SensioLabsInsight](https://img.shields.io/sensiolabs/i/d6b5e386-7830-4623-afd4-2ee6a6eb65a1.svg?style=flat-square)](https://insight.sensiolabs.com/projects/d6b5e386-7830-4623-afd4-2ee6a6eb65a1) 8 | [![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/lob.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/lob) 9 | [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/lob/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/lob/?branch=master) 10 | [![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/lob.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/lob) 11 | 12 | 13 | This package makes it easy to send notifications using [Lob.com](https://lob.com/) with Laravel 5.5, 6.x and 7.x 14 | 15 | ## Contents 16 | 17 | - [Installation](#installation) 18 | - [Setting up the lob.com](#setting-up-lob) 19 | - [Usage](#usage) 20 | - [Available Message methods](#available-message-methods) 21 | - [Changelog](#changelog) 22 | - [Testing](#testing) 23 | - [Security](#security) 24 | - [Contributing](#contributing) 25 | - [Credits](#credits) 26 | - [License](#license) 27 | 28 | 29 | ## Installation 30 | 31 | You can install the package via composer: 32 | 33 | ``` bash 34 | composer require laravel-notification-channels/lob 35 | ``` 36 | 37 | You must install the service provider: 38 | 39 | ```php 40 | // config/app.php 41 | 'providers' => [ 42 | ... 43 | NotificationChannels\Lob\LobServiceProvider::class, 44 | ], 45 | ``` 46 | 47 | ### Setting up lob 48 | 49 | - Register a new account on [Lob.com](https://lob.com) 50 | - Check for [you API keys](https://dashboard.lob.com/#/settings/keys) 51 | - Finally add your API key to your `config/services.php` 52 | 53 | ```php 54 | // config/services.php 55 | ... 56 | 'lob' => [ 57 | 'api_key' => env('LOB_API_KEY'), 58 | ], 59 | ... 60 | ``` 61 | 62 | ## Usage 63 | 64 | Now you can use the channel in your `via()` method inside the notification: 65 | 66 | ```php 67 | use NotificationChannels\Lob\LobChannel; 68 | use NotificationChannels\Lob\LobPostcard; 69 | use NotificationChannels\Lob\LobAddress; 70 | use Illuminate\Notifications\Notification; 71 | 72 | class AccountApproved extends Notification 73 | { 74 | public function via($notifiable) 75 | { 76 | return [LobChannel::class]; 77 | } 78 | 79 | public function toLobPostcard($notifiable) 80 | { 81 | return LobPostcard::create() 82 | ->toAddress( 83 | LobAddress::create('300 BOYLSTON AVE E') 84 | ->name('John Smith') 85 | ->city('SEATTLE') 86 | ->state('WA') 87 | ->zip('98002'); 88 | ) 89 | ->front('https://path.to/my/image/postcardfront.png') 90 | ->message('Wishing you a wonderful weekend!'); 91 | } 92 | } 93 | ``` 94 | 95 | ### Available Postcard methods 96 | 97 | - `fromAddress()` Address of the sender. 98 | - `toAddress()` Address of the receiver. 99 | - `country()` Set the country. `US` is default. 100 | - `city()` required if country is `US`. 101 | - `state()` required if country is `US`. 102 | - `zip()` required if country is `US`. 103 | - `front()` A 4.25"x6.25" or 6.25"x11.25" image to use as the front of the postcard. 104 | - `message()` The message at the back of the card. 105 | 106 | ## Changelog 107 | 108 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. 109 | 110 | ## Testing 111 | 112 | ``` bash 113 | $ composer test 114 | ``` 115 | 116 | ## Security 117 | 118 | If you discover any security related issues, please email themsaid@gmail.com instead of using the issue tracker. 119 | 120 | ## Contributing 121 | 122 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 123 | 124 | ## Credits 125 | 126 | - [Mohamed Said](https://github.com/themsaid) 127 | - [All Contributors](../../contributors) 128 | 129 | ## License 130 | 131 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 132 | --------------------------------------------------------------------------------