/** * @param \SubscribePro\Service\Address\AddressInterface $address * @return \SubscribePro\Service\Address\AddressInterface * @throws \SubscribePro\Exception\EntityInvalidDataException * @throws \SubscribePro\Exception\HttpException */ public function findOrSave(AddressInterface $address) { if (!$address->isValid()) { throw new EntityInvalidDataException('Not all required fields are set.'); } $response = $this->httpClient->post('/services/v2/address/find-or-create.json', [self::API_NAME_ADDRESS => $address->getFormData()]); return $this->retrieveItem($response, self::API_NAME_ADDRESS, $address); }
/** * @param \SubscribePro\Service\Address\AddressInterface $address * @return array */ public function getTokenFormData(AddressInterface $address = null) { $tokenFormData = array_intersect_key($this->data, $this->createTokenFields); if ($address) { $tokenFormData[self::BILLING_ADDRESS] = $address->getAsChildFormData(true); } return $tokenFormData; }
/** * @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()); }
/** * @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); }
/** * @param array $data * @dataProvider getAsChildFormDataProvider */ public function testGetAsChildFormData($data) { $expectedData = [AddressInterface::CITY => 'city', AddressInterface::COUNTRY => 'country', AddressInterface::COMPANY => 'company', AddressInterface::FIRST_NAME => 'first name', AddressInterface::LAST_NAME => 'last name', AddressInterface::MIDDLE_NAME => 'middle name', AddressInterface::PHONE => 'phone', AddressInterface::POSTCODE => 'postcode', AddressInterface::REGION => 'region', AddressInterface::STREET1 => 'street1', AddressInterface::STREET2 => 'street2']; $this->address->importData($data); $this->assertEquals($expectedData, $this->address->getFormData()); }