-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from DrH97/dev-dr
Dev dr
- Loading branch information
Showing
13 changed files
with
243 additions
and
180 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace DrH\Tanda\Console; | ||
|
||
use DrH\Tanda\Repositories\Tanda; | ||
use Illuminate\Console\Command; | ||
|
||
class RequestStatusCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'tanda:query_status'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Check the status of all missing transactions.'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
*/ | ||
public function __construct(private Tanda $tanda) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
*/ | ||
public function handle() | ||
{ | ||
$results = $this->tanda->queryRequestStatus(); | ||
|
||
if (count($results['successful'])) { | ||
$this->info("Successful queries: "); | ||
|
||
foreach ($results['successful'] as $reference => $message) { | ||
$this->comment(" * $reference ---> $message"); | ||
} | ||
} | ||
|
||
if (count($results['errors'])) { | ||
$this->info("Failed queries: "); | ||
|
||
foreach ($results['errors'] as $reference => $message) { | ||
$this->comment(" * $reference ---> $message"); | ||
} | ||
} | ||
|
||
if (empty($results['successful']) && empty($results['errors'])) { | ||
$this->comment("Nothing to query... all transactions seem to be ok."); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,73 @@ | ||
<?php | ||
|
||
namespace DrH\Tanda\Repositories; | ||
|
||
use Carbon\Carbon; | ||
use DrH\Tanda\Events\TandaRequestFailedEvent; | ||
use DrH\Tanda\Events\TandaRequestSuccessEvent; | ||
use DrH\Tanda\Exceptions\TandaException; | ||
use DrH\Tanda\Library\BaseClient; | ||
use DrH\Tanda\Library\Utility; | ||
use DrH\Tanda\Models\TandaRequest; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use JetBrains\PhpStorm\ArrayShape; | ||
|
||
class Tanda | ||
{ | ||
private Utility $utility; | ||
|
||
public function __construct(BaseClient $baseClient) | ||
{ | ||
$this->utility = new Utility($baseClient); | ||
} | ||
|
||
#[ArrayShape(['successful' => "array", 'errors' => "array"])] | ||
public function queryRequestStatus(): array | ||
{ | ||
/** @var TandaRequest[] $tandaRequests */ | ||
$tandaRequests = TandaRequest::whereStatus(000001)->get(); | ||
$success = $errors = []; | ||
|
||
foreach ($tandaRequests as $request) { | ||
try { | ||
$result = $this->utility->requestStatus($request->request_id); | ||
|
||
$success[$request->request_id] = $result['message']; | ||
|
||
$data = [ | ||
'status' => $result['status'], | ||
'message' => $result['message'], | ||
'receipt_number' => $result['receiptNumber'], | ||
'result' => $result['resultParameters'], | ||
'last_modified' => Carbon::parse($result['datetimeLastModified'])->utc(), | ||
]; | ||
|
||
$transaction = TandaRequest::updateOrCreate( | ||
['request_id' => $result['id']], | ||
$data | ||
); | ||
|
||
$this->fireTandaEvent($transaction); | ||
} catch (TandaException | GuzzleException $e) { | ||
$errors[$request->request_id] = $e->getMessage(); | ||
} | ||
} | ||
|
||
return ['successful' => $success, 'errors' => $errors]; | ||
} | ||
|
||
/** | ||
* @param TandaRequest $request | ||
* @return void | ||
*/ | ||
private static function fireTandaEvent(TandaRequest $request): void | ||
{ | ||
if ($request->status == 000001) { | ||
return; | ||
} | ||
|
||
$request->status == 000000 | ||
? TandaRequestSuccessEvent::dispatch($request) | ||
: TandaRequestFailedEvent::dispatch($request); | ||
} | ||
} |
Oops, something went wrong.