config = $this->resolveOptions($options); } /** * @throws ApiClientException */ public function getProfile(string $email, string $password): NotificationResponse|ProfileResponse { $data = [ 'anfrage' => [ 'user' => $this->config['bpn_username'], 'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], static::TYPE_CUSTOMER_DATA), 'satz' => ['@typ' => static::TYPE_CUSTOMER_DATA], 'art' => 'Adressdaten', 'email' => $email, 'passwort' => $password, ], ]; return $this->sendRequest(static::TYPE_CUSTOMER_DATA, $data); } /** * @throws ApiClientException */ public function updateProfile(User $user, string $password): NotificationResponse|ProfileResponse { if (null === $teamer = $user->getTeamer()) { throw new ApiClientException('Invalid argument'); } $data = [ 'anfrage' => [ 'user' => $this->config['bpn_username'], 'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], static::TYPE_CUSTOMER_DATA), 'satz' => ['@typ' => static::TYPE_CUSTOMER_DATA], 'art' => 'Adressdaten_Ändern', 'email' => $user->getEmail(), 'passwort' => $password, 'idadresse' => $user->getBusProAddressId(), 'adressdaten' => $teamer->toPayload(), ], ]; return $this->sendRequest(static::TYPE_CUSTOMER_DATA, $data); } /** * @throws ApiClientException */ public function resetPassword(string $email): NotificationResponse { $data = [ 'anfrage' => [ 'user' => $this->config['bpn_username'], 'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], static::TYPE_CUSTOMER_DATA), 'satz' => ['@typ' => static::TYPE_CUSTOMER_DATA], 'art' => 'Passwort_Anfrage', 'email' => $email, ], ]; return $this->sendRequest(static::TYPE_CUSTOMER_DATA, $data); } /** * @throws ApiClientException */ public function getCrmAttributes(string $email, string $password): NotificationResponse|CrmAttributesResponse { $data = [ 'anfrage' => [ 'user' => $this->config['bpn_username'], 'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], static::TYPE_CUSTOMER_DATA), 'satz' => ['@typ' => static::TYPE_CUSTOMER_DATA], 'art' => 'SelektionCRM', 'email' => $email, 'passwort' => $password, ], ]; return $this->sendRequest(static::TYPE_CUSTOMER_DATA, $data); } /** * @throws ApiClientException */ public function getBaseData(string $type): NotificationResponse|BaseDataResponse { $data = [ 'anfrage' => [ 'user' => $this->config['bpn_username'], 'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], $type), 'satz' => ['@typ' => $type], ], ]; return $this->sendRequest($type, $data); } /** * @throws ApiClientException */ private function sendRequest(string $type, array $data): mixed { $body = $this ->serializer ->serialize($data, 'xml') ; try { $response = $this->httpClient->request('GET', $this->config['bpn_url'], [ 'query' => [ 'operation' => $body, ] ]); $xml = $response->getContent(); return $this->responseParser->parseXmlString($type, $xml); } catch (\Throwable $e) { } $this->logger->error('API error', ['error' => $e->getMessage()]); throw new ApiClientException($e->getMessage()); } private function createKey(string $username, string $password, string $type): string { $date = (new \DateTimeImmutable())->format('Ymd'); return md5($username.$password.$date.$type); } private function resolveOptions(array $options): array { $optionsResolver = new OptionsResolver(); $optionsResolver->setRequired(['bpn_url', 'bpn_username', 'bpn_password']); return $optionsResolver->resolve($options); } }