ryan 2 недель назад
Родитель
Сommit
f0d6664e73

+ 1 - 1
common/helpers/GuestDeclarationDraftStatus.php

@@ -15,7 +15,7 @@ final class GuestDeclarationDraftStatus
 
     private const TRANSITIONS = [
         self::DRAFT => [self::PAYMENT_INITIALIZING, self::EXPIRED],
-        self::PENDING_PAYMENT => [self::PROCESSING, self::PAYMENT_FAILED, self::EXPIRED, self::MANUAL_REVIEW],
+        self::PENDING_PAYMENT => [self::PROCESSING, self::PAYMENT_FAILED, self::PAYMENT_INITIALIZING, self::EXPIRED, self::MANUAL_REVIEW],
         self::PAYMENT_INITIALIZING => [self::DRAFT, self::PENDING_PAYMENT, self::MANUAL_REVIEW],
         self::PROCESSING => [self::COMPLETED, self::MANUAL_REVIEW],
         self::PAYMENT_FAILED => [self::PAYMENT_INITIALIZING, self::EXPIRED],

+ 4 - 6
common/services/GuestDeclarationOrderService.php

@@ -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.');

+ 1 - 0
common/tests/standalone/guest-declaration-draft-status.php

@@ -9,6 +9,7 @@ $checks = [
     'payment initialization can become pending' => GuestDeclarationDraftStatus::canTransition('payment_initializing', 'pending_payment'),
     'payment initialization can enter manual review' => GuestDeclarationDraftStatus::canTransition('payment_initializing', 'manual_review'),
     'pending payment can be claimed' => GuestDeclarationDraftStatus::canTransition('pending_payment', 'processing'),
+    'pending payment can be resubmitted with updated details' => GuestDeclarationDraftStatus::canTransition('pending_payment', 'payment_initializing'),
     'pending payment can enter manual review' => GuestDeclarationDraftStatus::canTransition('pending_payment', 'manual_review'),
     'failed payment can be retried' => GuestDeclarationDraftStatus::canTransition('payment_failed', 'payment_initializing'),
     'processing can complete' => GuestDeclarationDraftStatus::canTransition('processing', 'completed'),