|
|
@@ -139,13 +139,10 @@ class GuestDeclarationOrderService
|
|
|
$draft->transitionTo(GuestDeclarationDraftStatus::EXPIRED);
|
|
|
throw new BadRequestHttpException('Guest order draft has expired.');
|
|
|
}
|
|
|
- if ($draft->STATUS === GuestDeclarationDraftStatus::PENDING_PAYMENT) {
|
|
|
- return $this->paymentResponse($draft);
|
|
|
- }
|
|
|
if ($draft->STATUS === GuestDeclarationDraftStatus::PAYMENT_INITIALIZING) {
|
|
|
throw new BadRequestHttpException('Payment initialization is in progress.');
|
|
|
}
|
|
|
- if (!in_array($draft->STATUS, [GuestDeclarationDraftStatus::DRAFT, GuestDeclarationDraftStatus::PAYMENT_FAILED], 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.');
|
|
|
}
|
|
|
|
|
|
@@ -253,9 +250,10 @@ class GuestDeclarationOrderService
|
|
|
$input['password'] = Yii::$app->security->generatePasswordHash((string) $input['password']);
|
|
|
$input['payPassword'] = Yii::$app->security->generatePasswordHash((string) $input['payPassword']);
|
|
|
$storedPayload = json_encode($input, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
|
+ $previousStatus = $draft->STATUS;
|
|
|
$reserved = GuestDeclarationDraft::updateAll(
|
|
|
['STATUS' => GuestDeclarationDraftStatus::PAYMENT_INITIALIZING, 'UPDATED_AT' => time()],
|
|
|
- ['AND', ['ID' => $draft->ID], ['STATUS' => $draft->STATUS], ['>' , 'EXPIRES_AT', time()]]
|
|
|
+ ['AND', ['ID' => $draft->ID], ['STATUS' => $previousStatus], ['>' , 'EXPIRES_AT', time()]]
|
|
|
);
|
|
|
if ($reserved !== 1) {
|
|
|
$draft->refresh();
|
|
|
@@ -277,7 +275,7 @@ class GuestDeclarationOrderService
|
|
|
);
|
|
|
if (empty($init['status']) || empty($init['data']['reference']) || empty($init['data']['authorization_url'])) {
|
|
|
GuestDeclarationDraft::updateAll(
|
|
|
- ['STATUS' => GuestDeclarationDraftStatus::DRAFT, 'UPDATED_AT' => time()],
|
|
|
+ ['STATUS' => $previousStatus, 'UPDATED_AT' => time()],
|
|
|
['AND', ['ID' => $draft->ID], ['STATUS' => GuestDeclarationDraftStatus::PAYMENT_INITIALIZING]]
|
|
|
);
|
|
|
throw new \RuntimeException('Unable to initialize payment. Please retry.');
|