-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed mostly stuff on external token callback (#740)
- Loading branch information
Showing
25 changed files
with
512 additions
and
173 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
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
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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\Models\List; | ||
|
||
use App\Actions\Models\List\ExternalProfile\StoreExternalProfileTokenAction; | ||
use App\Actions\Models\List\ExternalProfile\StoreExternalTokenAction; | ||
use App\Models\List\ExternalProfile; | ||
use Error; | ||
use Exception; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
/** | ||
* Class ExternalTokenCallbackAction. | ||
*/ | ||
class ExternalTokenCallbackAction | ||
{ | ||
/** | ||
* We should store the token, the profile and its entries. | ||
* | ||
* @param array $parameters | ||
* @return JsonResponse|ExternalProfile | ||
* | ||
* @throws Exception | ||
*/ | ||
public function store(array $parameters): JsonResponse|ExternalProfile | ||
{ | ||
try { | ||
DB::beginTransaction(); | ||
|
||
$action = new StoreExternalTokenAction(); | ||
|
||
$externalToken = $action->store($parameters); | ||
|
||
if ($externalToken === null) { | ||
throw new Error('Invalid Code', 400); | ||
} | ||
|
||
$profileAction = new StoreExternalProfileTokenAction(); | ||
|
||
$profile = $profileAction->findOrCreate($externalToken, $parameters); | ||
|
||
DB::commit(); | ||
|
||
return $profile; | ||
} catch (Exception $e) { | ||
Log::error($e->getMessage()); | ||
|
||
DB::rollBack(); | ||
|
||
return new JsonResponse([ | ||
'error' => $e->getMessage(), | ||
], $e->getCode()); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.