Exemplo n.º 1
0
 public function testAddOrUpdateMultipleSubscribers()
 {
     $subscribers = new SubscriberCollection();
     $subscriber = new Subscriber();
     $subscriber->setEmailAddress('*****@*****.**')->setSourceId(1);
     $subscribers->addSubscriber($subscriber);
     // add orders, order items, custom fields, etc...
     $subscribersResource = new Subscribers($this->connection);
     $subscribersResource->addOrUpdateMultiple($subscribers);
 }
Exemplo n.º 2
0
 public function addOrUpdateMultiple(SubscriberCollection $subscriberCollection)
 {
     $payload = $subscriberCollection->toPost();
     $response = $this->connection->post('/Import/AddOrUpdate', $payload);
     $body = $response->getBody();
     $subscriberResponse = null;
     if (!empty($body['ErrorCode'])) {
         $subscriberResponse = (new ErrorResponse())->setErrorCode($body['ErrorCode'])->setMessage($body['Message'])->setIsError(true);
     } else {
         $subscriberResponse = new SubscriberResponse();
         if (!empty($body['Failures'])) {
             foreach ($body['Failures'] as $failure) {
                 $subscriberError = (new SubscriberError())->setEmailAddress($failure['EmailAddress'])->setErrorCode($failure['ErrorCode'])->setMessage($failure['Message']);
                 $subscriberResponse->addError($subscriberError);
             }
         }
         $subscriberResponse->setContactsSubmitted($body['ContactsSubmitted'])->setSuccesses($body['Successes']);
     }
     return $subscriberResponse;
 }