Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
<?php
namespace Wgg\MailchimpBundle\Util;
use MailchimpMarketing\Api\ListsApi;
use MailchimpMarketing\Api\PingApi;
use MailchimpMarketing\ApiClient as BaseApiClient;
use function mb_strtolower;
use function md5;
/**
* @property ListsApi $lists
* @property PingApi $ping
*/
class ApiClient extends BaseApiClient
{
private ?array $listIds;
public function __construct(MailchimpConfiguration $configuration)
{
parent::__construct();
$config = $configuration->readConfig();
$this->setConfig([
'apiKey' => $config['api_key'],
'server' => $config['server_prefix'],
]);
$this->listIds = $config['list_id'];
}
public function getListIds(): ?array
{
return $this->listIds;
}
public function addListMember(string $listId, string $email, string $name, string $language): void
{
$subscriberHash = md5(mb_strtolower($email));
$this->lists->setListMember($listId,
$subscriberHash,
[
'email_address' => $email,
'status_if_new' => 'pending',
'status' => 'subscribed',
'language' => $language,
'merge_fields' => [
'NAME' => $name,
],
]);
}
}