-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Hotrush\QuickBooksManager\Commands; | ||
|
||
use Hotrush\QuickBooksManager\QuickBooksManager; | ||
use Hotrush\QuickBooksManager\QuickBooksToken; | ||
use Illuminate\Console\Command; | ||
use QuickBooksOnline\API\Exception\ServiceException; | ||
|
||
class RefreshTokensCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'qbm:refresh-tokens'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Refresh access tokens.'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @param QuickBooksManager $manager | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle(QuickBooksManager $manager) | ||
{ | ||
$tokens = QuickBooksToken::where('refresh_at','<=',now())->where('refresh_expire_at','>',now())->get(); | ||
|
||
if (!$tokens->count()) { | ||
return; | ||
} | ||
|
||
foreach ($tokens as $token) { | ||
try { | ||
$manager->connection($token->connection)->refreshToken(); | ||
} catch (ServiceException $e) { | ||
$this->error(sprintf('Error refreshing token for connection "%s": %s', $token->connection, $e->getMessage())); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters