private function getConnectionForTesting() { $this->container = []; $history = Middleware::history($this->container); $connection = new \Picqer\Financials\Moneybird\Connection(); $connection->insertMiddleWare($history); $connection->setClientId('testClientId'); $connection->setClientSecret('testClientSecret'); $connection->setAccessToken('testAccessToken'); $connection->setAuthorizationCode('testAuthorizationCode'); $connection->setRedirectUrl('testRedirectUrl'); $connection->setTesting(true); return $connection; }
/** * Function to connect to Moneybird, this creates the client and automatically retrieves oAuth tokens if needed * * @return \Picqer\Financials\Moneybird\Connection * @throws Exception */ function connect($redirectUrl, $clientId, $clientSecret) { $connection = new \Picqer\Financials\Moneybird\Connection(); $connection->setRedirectUrl($redirectUrl); $connection->setClientId($clientId); $connection->setClientSecret($clientSecret); // Retrieves authorizationcode from database if (getValue('authorizationcode')) { $connection->setAuthorizationCode(getValue('authorizationcode')); } // Retrieves accesstoken from database if (getValue('accesstoken')) { $connection->setAccessToken(getValue('accesstoken')); } // Make the client connect and exchange tokens try { $connection->connect(); } catch (\Exception $e) { throw new Exception('Could not connect to Moneybird: ' . $e->getMessage()); } // Save the new tokens for next connections setValue('accesstoken', $connection->getAccessToken()); return $connection; }