/** * @param \SubscribePro\Service\Customer\CustomerInterface $customer * @return \SubscribePro\Service\Customer\CustomerInterface * @throws \SubscribePro\Exception\EntityInvalidDataException * @throws \SubscribePro\Exception\HttpException */ public function saveCustomer(CustomerInterface $customer) { if (!$customer->isValid()) { throw new EntityInvalidDataException('Not all required fields are set.'); } $url = $customer->isNew() ? '/services/v2/customer.json' : "/services/v2/customers/{$customer->getId()}.json"; $response = $this->httpClient->post($url, [self::API_NAME_CUSTOMER => $customer->getFormData()]); return $this->retrieveItem($response, self::API_NAME_CUSTOMER, $customer); }