/**
  * @param \SubscribePro\Service\Subscription\SubscriptionInterface $subscription
  * @return \SubscribePro\Service\Subscription\SubscriptionInterface
  * @throws \SubscribePro\Exception\EntityInvalidDataException
  * @throws \SubscribePro\Exception\HttpException
  */
 public function saveSubscription(SubscriptionInterface $subscription)
 {
     if (!$subscription->isValid()) {
         throw new EntityInvalidDataException('Not all required fields are set.');
     }
     $url = $subscription->isNew() ? '/services/v2/subscription.json' : "/services/v2/subscriptions/{$subscription->getId()}.json";
     $response = $this->httpClient->post($url, [self::API_NAME_SUBSCRIPTION => $subscription->getFormData()]);
     return $this->retrieveItem($response, self::API_NAME_SUBSCRIPTION, $subscription);
 }
 /**
  * @param array $data
  * @param array $addressData
  * @param array $addressAsChildFormData
  * @param array $expectedData
  * @param bool $isNew
  * @dataProvider getFormDataProvider
  */
 public function testGetFormData($data, $addressData, $addressAsChildFormData, $expectedData, $isNew)
 {
     $this->paymentProfileMock->expects($this->once())->method('importData')->with([])->willReturnSelf();
     $this->shippingAddressMock->expects($this->once())->method('importData')->with($addressData)->willReturnSelf();
     $this->shippingAddressMock->expects($this->any())->method('getId')->willReturn(null);
     $this->shippingAddressMock->expects($this->once())->method('getAsChildFormData')->with($isNew)->willReturn($addressAsChildFormData);
     $this->subscription->importData($data);
     $this->assertEquals($expectedData, $this->subscription->getFormData());
 }