Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class AmoCRMAdapter implements CRMAdapterInterface
- {
- private AmoCRMApiClient $apiClient;
- public function __construct(
- private readonly string $clientId,
- private readonly string $clientSecret,
- private readonly string $redirectUri,
- private readonly string $domain,
- private readonly AmoCRMTokenStorage $tokenStorage,
- private readonly LoggerInterface $amoCrmLogger
- ) {
- $this->apiClient = new AmoCRMApiClient($this->clientId, $this->clientSecret, $this->redirectUri);
- }
- public function getAccessTokenByCode(string $code): void
- {
- try {
- $accessToken = $this->apiClient->getOAuthClient()->getAccessTokenByCode($code);
- } catch (\Exception $e) {
- throw new AmoCRMCannotGetTokenException($e->getMessage());
- }
- $this->tokenStorage->setToken($accessToken);
- }
- public function getToken(): AccessTokenInterface
- {
- return $this->tokenStorage->getToken();
- }
- public function getDomain(): string
- {
- return $this->domain;
- }
- public function getClientId(): string
- {
- return $this->clientId;
- }
- private function auth(): void
- {
- $accessToken = $this->tokenStorage->getToken();
- $tokenStorage = $this->tokenStorage;
- $saveTokenCallback = static function (AccessTokenInterface $accessToken, string $baseDomain) use ($tokenStorage): void {
- $tokenStorage->setToken($accessToken);
- };
- $this->apiClient
- ->setAccessToken($accessToken)
- ->setAccountBaseDomain($this->domain)
- ->onAccessTokenRefresh($saveTokenCallback);
- }
- public function createLead(CRMUserDto $user): void
- {
- $this->auth();
- // TODO: Implement createLead() method.
- }
- public function updateLead(CRMUserDto $user): void
- {
- $this->auth();
- // TODO: Implement updateLead() method.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement