/** * @param array $data * @param array $billingData * @param bool $isValid * @param bool $isAsChildValid * @dataProvider isValidDataProvider */ public function testIsValid($data, $billingData, $isValid, $isAsChildValid) { $this->billingAddressMock->expects($this->atLeastOnce())->method('importData')->with($billingData)->willReturnSelf(); if (null === $isAsChildValid) { $this->billingAddressMock->expects($this->never())->method('isAsChildValid'); } else { $this->billingAddressMock->expects($this->atLeastOnce())->method('isAsChildValid')->willReturn($isAsChildValid); } $this->paymentProfile->importData($data); $this->assertEquals($isValid, $this->paymentProfile->isValid()); }
/** * @param \SubscribePro\Service\PaymentProfile\PaymentProfileInterface $paymentProfile * @return \SubscribePro\Service\PaymentProfile\PaymentProfileInterface * @throws \SubscribePro\Exception\EntityInvalidDataException * @throws \SubscribePro\Exception\HttpException */ public function saveProfile(PaymentProfileInterface $paymentProfile) { if (!$paymentProfile->isValid()) { throw new EntityInvalidDataException('Not all required fields are set.'); } $postData = [self::API_NAME_PROFILE => $paymentProfile->getFormData()]; $response = $paymentProfile->isNew() ? $this->httpClient->post('/services/v1/vault/paymentprofile.json', $postData) : $this->httpClient->put("/services/v1/vault/paymentprofiles/{$paymentProfile->getId()}.json", $postData); return $this->retrieveItem($response, self::API_NAME_PROFILE, $paymentProfile); }