Exemplo n.º 1
0
 protected static function flushSandboxEntities()
 {
     $api = new Oauth2Api($clientId = getenv('API_CLIENT_ID'), $clientSecret = getenv('API_CLIENT_SECRET'), $refreshToken = getenv('API_REFRESH_TOKEN'), $sandbox = true);
     if (!$api->isSandbox()) {
         throw new Exception('Attempting to use this test suite on a live account will delete everything');
     }
     $api->connect();
     /** @var string[] $entities */
     $entities = ['invoice', 'project', 'contact', 'bankAccount'];
     /** @var string $entityName */
     foreach ($entities as $entityName) {
         /** @var AbstractEntity $entity */
         foreach ($api->{$entityName}()->query() as $entity) {
             if ($entity instanceof Invoice && !$entity->isDraft()) {
                 $entity->markAsDraft();
             }
             $entity->delete();
         }
     }
 }