You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							37 lines
						
					
					
						
							973 B
						
					
					
				
			
		
		
	
	
							37 lines
						
					
					
						
							973 B
						
					
					
				| <?php | |
|  | |
| namespace core\services\newsletter; | |
|  | |
| use RuntimeException; | |
|  | |
| class MailChimp implements Newsletter | |
| { | |
|     private \DrewM\MailChimp\MailChimp $client; | |
|     private string $listId; | |
|  | |
|     public function __construct(\DrewM\MailChimp\MailChimp $client, $listId) | |
|     { | |
|         $this->client = $client; | |
|         $this->listId = $listId; | |
|     } | |
|  | |
|     public function subscribe($email): void | |
|     { | |
|         $this->client->post('lists/' . $this->listId . '/members', [ | |
|             'email_address' => $email, | |
|             'status' => 'subscribed', | |
|         ]); | |
|         if ($error = $this->client->getLastError()) { | |
|             throw new RuntimeException($error); | |
|         } | |
|     } | |
|  | |
|     public function unsubscribe($email): void | |
|     { | |
|         $hash = $this->client->subscriberHash($email); | |
|         $this->client->delete('lists/' . $this->listId . '/members/' . $hash); | |
|         if ($error = $this->client->getLastError()) { | |
|             throw new RuntimeException($error); | |
|         } | |
|     } | |
| }
 | |
| 
 |