Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
13 changes: 13 additions & 0 deletions src/Contracts/ContactsV4Contract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

namespace Mailjet\LaravelMailjet\Contracts;

interface ContactsV4Contract
{
public function delete($id);
}
51 changes: 51 additions & 0 deletions src/Providers/ContactsServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Mailjet\LaravelMailjet\Providers;

use Illuminate\Support\ServiceProvider;
use Mailjet\LaravelMailjet\Contracts\ContactsV4Contract;
use Mailjet\LaravelMailjet\Services\ContactsV4Service;
use Mailjet\LaravelMailjet\Services\MailjetService;

class ContactsServiceProvider extends ServiceProvider
{
protected $defer = true;

/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{

}

/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->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];
}
}
43 changes: 43 additions & 0 deletions src/Services/ContactsV4Service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Mailjet\LaravelMailjet\Services;

use Mailjet\LaravelMailjet\Contracts\ContactsV4Contract;
use \Mailjet\Resources;
use Mailjet\LaravelMailjet\Exception\MailjetException;

/**
* https://dev.mailjet.com/email/guides/contact-management/#gdpr-delete-contacts
*/
class ContactsV4Service implements ContactsV4Contract
{
/**
* Mailjet client
* @var MailjetService
*/
protected $mailjet;

/**
* @param MailjetService $mailjet
*/
public function __construct(MailjetService $mailjet)
{
$this->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();
}
}