├── .gitignore ├── composer.json ├── config └── mailchimp.php ├── src └── MailchimpServiceProvider.php ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store 5 | /.idea -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "skovmand/mailchimp-laravel", 3 | "description": "A minimal service provider to set up and use the Mailchimp Api v2 PHP library in Laravel 5.*", 4 | "license": "MIT", 5 | "require": { 6 | "laravel/framework": "5.0 - 5.6", 7 | "mailchimp/mailchimp": "~2.0" 8 | }, 9 | "autoload": { 10 | "psr-4": { 11 | "Skovmand\\Mailchimp\\": "src/" 12 | } 13 | }, 14 | "abandoned": true 15 | } 16 | -------------------------------------------------------------------------------- /config/mailchimp.php: -------------------------------------------------------------------------------- 1 | env('MAILCHIMP_API_KEY') 15 | ]; 16 | -------------------------------------------------------------------------------- /src/MailchimpServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 21 | __DIR__ . '/../config/mailchimp.php' => config_path('mailchimp.php') 22 | ]); 23 | } 24 | 25 | /** 26 | * Register the Mailchimp Instance to be set up with the API-key. 27 | * Then, the IoC-container can be used to get a Mailchimp instance ready for use. 28 | * 29 | * @return void 30 | */ 31 | public function register() 32 | { 33 | $this->app->singleton('Mailchimp', function($app) { 34 | $config = $app['config']['mailchimp']; 35 | return new Mailchimp($config['apikey']); 36 | }); 37 | } 38 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2015 Physical Code ApS 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This package is abandoned. 2 | 3 | The Mailchimp API v2.0 was deprecated from jan 1st 2017. This package uses the v2 API, because it relies on the [Mailchimp PHP API Client](https://bitbucket.org/mailchimp/mailchimp-api-php.git), which uses the v2 API. 4 | 5 | This package will not recieve updates for future Laravel versions. 6 | 7 | Please use an api v3-compatible package instead, several are available on [Packagist](https://packagist.org/) 8 | 9 | 10 | # skovmand/mailchimp-laravel 11 | A minimal service provider to set up and use the Mailchimp API v2 PHP library in Laravel v5.* 12 | 13 | For Laravel v4 check https://packagist.org/packages/hugofirth/mailchimp 14 | 15 | 16 | ## How it works 17 | This package contains a service provider, which binds an instance of an initialized Mailchimp client to the IoC-container. 18 | 19 | You recieve the Mailchimp client through depencency injection already set up with your own API key. 20 | 21 | 22 | **Usage example** 23 | 24 | ```php 25 | class NewsletterManager 26 | { 27 | protected $mailchimp; 28 | protected $listId = '1234567890'; // Id of newsletter list 29 | 30 | /** 31 | * Pull the Mailchimp-instance from the IoC-container. 32 | */ 33 | public function __construct(\Mailchimp $mailchimp) 34 | { 35 | $this->mailchimp = $mailchimp; 36 | } 37 | 38 | /** 39 | * Access the mailchimp lists API 40 | */ 41 | public function addEmailToList($email) 42 | { 43 | try { 44 | $this->mailchimp 45 | ->lists 46 | ->subscribe( 47 | $this->listId, 48 | ['email' => $email] 49 | ); 50 | } catch (\Mailchimp_List_AlreadySubscribed $e) { 51 | // do something 52 | } catch (\Mailchimp_Error $e) { 53 | // do something 54 | } 55 | } 56 | } 57 | ``` 58 | 59 | Or you can manually instantiate the Mailchimp client by using: 60 | 61 | ```$mailchimp = app('Mailchimp');``` 62 | 63 | 64 | ## Setup 65 | **Step 1: Adding the dependency to composer.json** 66 | 67 | Add this to your composer.json in your Laravel folder. 68 | Note: Adding this dependency will automatically setup "mailchimp/mailchimp": "~2.0" too. 69 | 70 | ```json 71 | "require": { 72 | "skovmand/mailchimp-laravel": "1.*", 73 | } 74 | ``` 75 | 76 | **Step 2: Register the service provider** 77 | 78 | Register the service provider in ```config/app.php``` by inserting into the ```providers``` array 79 | 80 | ```php 81 | 'providers' => [ 82 | Skovmand\Mailchimp\MailchimpServiceProvider::class, 83 | ] 84 | ``` 85 | 86 | **Step 3: From the command-line run** 87 | 88 | ``` 89 | php artisan vendor:publish --provider="Skovmand\Mailchimp\MailchimpServiceProvider" 90 | ``` 91 | 92 | This will publish ```config/mailchimp.php``` to your config folder. 93 | 94 | **Step 4: Edit your .env file** 95 | 96 | ```php 97 | MAILCHIMP_API_KEY="your-api-key-here" 98 | ``` 99 | 100 | **Good to go!** 101 | --------------------------------------------------------------------------------