laowu 2 dagen geleden
bovenliggende
commit
b5ec47ebf4
2 gewijzigde bestanden met toevoegingen van 36 en 0 verwijderingen
  1. 18 0
      app/Http/logic/api/PayPlusLogic.php
  2. 18 0
      tests/Unit/PayPlusLogicTest.php

+ 18 - 0
app/Http/logic/api/PayPlusLogic.php

@@ -228,6 +228,8 @@ class PayPlusLogic extends BaseApiLogic
                 $order->GiftsID,
                 $orderSn,
             ]);
+        } elseif ($this->isCompletedButNotSuccessfulPayment($post)) {
+            $body['remarks'] = $this->resolveNotifyErrorMessage($post);
         } else {
             return 'success';
         }
@@ -272,6 +274,22 @@ class PayPlusLogic extends BaseApiLogic
         return (int) ($data['order_status'] ?? 0) === 3;
     }
 
+    public function isCompletedButNotSuccessfulPayment(array $post)
+    {
+        return ($post['event'] ?? '') === 'PAYMENT.CAPTURE.COMPLETED'
+            && !$this->isSuccessfulPayment($post);
+    }
+
+    public function resolveNotifyErrorMessage(array $post)
+    {
+        $data = $post['data'] ?? [];
+
+        return $this->stringOrDefault(
+            $data['error_message'] ?? ($post['error_message'] ?? null),
+            json_encode($post, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
+        );
+    }
+
     public function isFailedPayment(array $post)
     {
         $event = $post['event'] ?? '';

+ 18 - 0
tests/Unit/PayPlusLogicTest.php

@@ -107,6 +107,24 @@ class PayPlusLogicTest extends TestCase
             ],
         ]));
     }
+
+    /** @test */
+    public function it_marks_completed_event_with_non_success_status_as_failed_notify()
+    {
+        $logic = new PayPlusLogic(new PayPlus([]));
+
+        $post = [
+            'event' => 'PAYMENT.CAPTURE.COMPLETED',
+            'event_detail_name' => 'payment_declined',
+            'data' => [
+                'order_status' => 4,
+                'error_message' => 'card declined',
+            ],
+        ];
+
+        $this->assertTrue($logic->isCompletedButNotSuccessfulPayment($post));
+        $this->assertSame('card declined', $logic->resolveNotifyErrorMessage($post));
+    }
 }
 
 class FakePayPlusForPayinQuery extends PayPlus