/**
  * @param string $token
  * @param \SubscribePro\Service\Transaction\TransactionInterface $transaction
  * @param \SubscribePro\Service\Address\AddressInterface|null $address
  * @return \SubscribePro\Service\Token\TokenInterface
  * @throws \SubscribePro\Exception\EntityInvalidDataException
  * @throws \SubscribePro\Exception\HttpException
  */
 public function purchaseByToken($token, TransactionInterface $transaction, AddressInterface $address = null)
 {
     if (!$transaction->isTokenDataValid()) {
         throw new EntityInvalidDataException('Not all required Transaction fields are set.');
     }
     if ($address && !$address->isAsChildValid(true)) {
         throw new EntityInvalidDataException('Not all required Address fields are set.');
     }
     $response = $this->httpClient->post("/services/v1/vault/tokens/{$token}/purchase.json", [self::API_NAME_TRANSACTION => $transaction->getTokenFormData($address)]);
     return $this->retrieveItem($response, self::API_NAME_TRANSACTION, $transaction);
 }
Пример #2
0
 /**
  * @param array $data
  * @param bool $isNew
  * @param bool $isValid
  * @dataProvider isAsChildValidDataProvider
  */
 public function testIsAsChildValid($data, $isNew, $isValid)
 {
     $this->address->importData($data);
     $this->assertEquals($isValid, $this->address->isAsChildValid($isNew));
 }