diff --git a/README.md b/README.md index 909a2ad..662358b 100644 --- a/README.md +++ b/README.md @@ -81,13 +81,23 @@ MAIL_FROM_NAME=YOU_FROM_NAME 'call' => true, 'secured' => true ] - ] + ], + 'v4' => [ + 'call' => true, + 'options' => [ + 'url' => 'api.mailjet.com', + 'version' => 'v4', + 'call' => true, + 'secured' => true + ] + ], ] ``` You can pass settings to [MailjetClient](https://github.com/mailjet/mailjet-apiv3-php#new--version-120-of-the-php-wrapper-). * `transactional`: settings to sendAPI client * `common`: setting to MailjetClient accessible throught the Facade Mailjet +* `v4`: setting used for some DataProvider`s ## Mail driver configuration @@ -137,6 +147,26 @@ All method return `Mailjet\Response` or throw a `MailjetException` in case of AP You can also get the Mailjet API client with the method `getClient()` and make your own custom request to Mailjet API. +If you need to delete a contact, you need to register ContactsServiceProvider: +* In the providers array: + +```php +'providers' => [ + ... + \Mailjet\LaravelMailjet\Providers\ContactsServiceProvider::class, + ... +] +``` + +and use it: +```php +public function handle(ContactsV4Service $contactsV4Service) +{ + $response = $contactsV4Service->delete(351406781); + ... +} +``` + ## ToDo * Add additional unit tests to increase code coverage. diff --git a/src/Contracts/ContactsV4Contract.php b/src/Contracts/ContactsV4Contract.php new file mode 100644 index 0000000..9b1a351 --- /dev/null +++ b/src/Contracts/ContactsV4Contract.php @@ -0,0 +1,13 @@ +app->bind(ContactsV4Service::class, function($app) { + $config = $this->app['config']->get('services.mailjet', []); + $call = $this->app['config']->get('services.mailjet.v4.call', true); + $options = $this->app['config']->get('services.mailjet.v4.options', []); + + $mailjetService = new MailjetService($config['key'], $config['secret'], $call, $options); + + return new ContactsV4Service($mailjetService); + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return [ContactsV4Service::class]; + } +} \ No newline at end of file diff --git a/src/Services/ContactsV4Service.php b/src/Services/ContactsV4Service.php new file mode 100644 index 0000000..709bfcf --- /dev/null +++ b/src/Services/ContactsV4Service.php @@ -0,0 +1,43 @@ +mailjet = $mailjet; + } + + /** + * Delete a Contact + * @param int $id + * @return bool + */ + public function delete($id) + { + $response = $this->mailjet->delete(['contacts', ''], ['id' => $id]); + + if (!$response->success()) { + throw new MailjetException(0, "ContactsV4Service:delete() failed", $response); + } + + return 200 === $response->getStatus(); + } +} \ No newline at end of file