|
@@ -28,6 +28,7 @@ use yii\web\NotFoundHttpException;
|
|
|
class GuestDeclarationOrderService
|
|
class GuestDeclarationOrderService
|
|
|
{
|
|
{
|
|
|
private const DRAFT_TTL = 86400;
|
|
private const DRAFT_TTL = 86400;
|
|
|
|
|
+ private const PAYMENT_INITIALIZATION_TIMEOUT = 60;
|
|
|
|
|
|
|
|
public function createDraft(string $countryId): array
|
|
public function createDraft(string $countryId): array
|
|
|
{
|
|
{
|
|
@@ -140,7 +141,22 @@ class GuestDeclarationOrderService
|
|
|
throw new BadRequestHttpException('Guest order draft has expired.');
|
|
throw new BadRequestHttpException('Guest order draft has expired.');
|
|
|
}
|
|
}
|
|
|
if ($draft->STATUS === GuestDeclarationDraftStatus::PAYMENT_INITIALIZING) {
|
|
if ($draft->STATUS === GuestDeclarationDraftStatus::PAYMENT_INITIALIZING) {
|
|
|
- throw new BadRequestHttpException('Payment initialization is in progress.');
|
|
|
|
|
|
|
+ $recoveredStatus = $draft->PAYMENT_REFERENCE
|
|
|
|
|
+ ? GuestDeclarationDraftStatus::PENDING_PAYMENT
|
|
|
|
|
+ : GuestDeclarationDraftStatus::DRAFT;
|
|
|
|
|
+ GuestDeclarationDraft::updateAll(
|
|
|
|
|
+ ['STATUS' => $recoveredStatus, 'UPDATED_AT' => time()],
|
|
|
|
|
+ [
|
|
|
|
|
+ 'AND',
|
|
|
|
|
+ ['ID' => $draft->ID],
|
|
|
|
|
+ ['STATUS' => GuestDeclarationDraftStatus::PAYMENT_INITIALIZING],
|
|
|
|
|
+ ['<' , 'UPDATED_AT', time() - self::PAYMENT_INITIALIZATION_TIMEOUT],
|
|
|
|
|
+ ]
|
|
|
|
|
+ );
|
|
|
|
|
+ $draft->refresh();
|
|
|
|
|
+ if ($draft->STATUS === GuestDeclarationDraftStatus::PAYMENT_INITIALIZING) {
|
|
|
|
|
+ throw new BadRequestHttpException('Payment initialization is in progress.');
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (!in_array($draft->STATUS, [GuestDeclarationDraftStatus::DRAFT, GuestDeclarationDraftStatus::PAYMENT_FAILED, GuestDeclarationDraftStatus::PENDING_PAYMENT], true)) {
|
|
if (!in_array($draft->STATUS, [GuestDeclarationDraftStatus::DRAFT, GuestDeclarationDraftStatus::PAYMENT_FAILED, GuestDeclarationDraftStatus::PENDING_PAYMENT], true)) {
|
|
|
throw new BadRequestHttpException('Guest order draft cannot be submitted in its current state.');
|
|
throw new BadRequestHttpException('Guest order draft cannot be submitted in its current state.');
|