Преглед изворни кода

refactor(payment): 添加BeforePayEvent

runphp пре 6 месеци
родитељ
комит
35c23eda3f

+ 18 - 0
src/Contracts/PaymentNotifyResult.php

@@ -0,0 +1,18 @@
+<?php
+declare(strict_types=1);
+
+namespace SixShop\Payment\Contracts;
+
+class PaymentNotifyResult
+{
+
+    public function __construct(
+        public string $orderNo,
+        public string $transactionId,
+        public float  $amount,
+        public string $status,
+        public array  $raw
+    )
+    {
+    }
+}

+ 1 - 35
src/Contracts/PaymentProviderInterface.php

@@ -1,44 +1,10 @@
 <?php
 declare(strict_types=1);
+
 namespace SixShop\Payment\Contracts;
 
 use SixShop\Payment\Enum\PaymentBizEnum;
 
-class PaymentResponse {
-    public function __construct(public string $orderNo, public string $type, public array $raw)
-    {
-    }
-}
-
-class PaymentNotifyResult {
-    public string $orderNo;
-    public string $transactionId;
-    public float  $amount;
-    public string $status;          // success/fail
-    public array  $raw;
-}
-
-class PaymentQueryResult {
-    public string $orderNo;
-    public string $status;          // paid/unpaid/closed
-    public float  $amount;
-    public array  $raw;
-}
-
-class PaymentRefundResult {
-    public string $refundNo;
-    public string $orderNo;
-    public float  $refundAmount;
-    public string $status;          // success/fail
-    public array  $raw;
-}
-
-class PaymentRefundQueryResult {
-    public string $refundNo;
-    public string $status;          // success/fail/processing
-    public array  $raw;
-}
-
 interface PaymentProviderInterface
 {
     /**

+ 16 - 0
src/Contracts/PaymentQueryResult.php

@@ -0,0 +1,16 @@
+<?php
+declare(strict_types=1);
+
+namespace SixShop\Payment\Contracts;
+
+class PaymentQueryResult
+{
+    public function __construct(
+        public string $orderNo,
+        public string $status,
+        public float  $amount,
+        public array  $raw
+    )
+    {
+    }
+}

+ 15 - 0
src/Contracts/PaymentRefundQueryResult.php

@@ -0,0 +1,15 @@
+<?php
+declare(strict_types=1);
+
+namespace SixShop\Payment\Contracts;
+
+class PaymentRefundQueryResult
+{
+    public function __construct(
+        public string $refundNo,
+        public string $status,
+        public array  $raw
+    )
+    {
+    }
+}

+ 17 - 0
src/Contracts/PaymentRefundResult.php

@@ -0,0 +1,17 @@
+<?php
+declare(strict_types=1);
+
+namespace SixShop\Payment\Contracts;
+
+class PaymentRefundResult
+{
+    public function __construct(
+        public string $refundNo,
+        public string $orderNo,
+        public float  $refundAmount,
+        public string $status,
+        public array  $raw
+    )
+    {
+    }
+}

+ 11 - 0
src/Contracts/PaymentResponse.php

@@ -0,0 +1,11 @@
+<?php
+declare(strict_types=1);
+
+namespace SixShop\Payment\Contracts;
+
+class PaymentResponse
+{
+    public function __construct(public string $orderNo, public string $type, public array $raw)
+    {
+    }
+}

+ 27 - 0
src/Event/BeforePayEvent.php

@@ -0,0 +1,27 @@
+<?php
+declare(strict_types=1);
+namespace SixShop\Payment\Event;
+
+use SixShop\Payment\Enum\PaymentBizEnum;
+
+class BeforePayEvent
+{
+    public function __construct(
+        protected array $order,
+        protected string $paymentId,
+        protected PaymentBizEnum $bizType,
+    ) {
+    }
+    public function getOrder(): array
+    {
+        return $this->order;
+    }
+    public function getPaymentId(): string
+    {
+        return $this->paymentId;
+    }
+    public function getBizType(): PaymentBizEnum
+    {
+        return $this->bizType;
+    }
+}

+ 2 - 0
src/PaymentManager.php

@@ -5,6 +5,7 @@ namespace SixShop\Payment;
 use SixShop\Payment\Contracts\PaymentResponse;
 use SixShop\Payment\Entity\ExtensionPaymentEntity;
 use SixShop\Payment\Enum\PaymentBizEnum;
+use SixShop\Payment\Event\BeforePayEvent;
 use SixShop\Payment\Event\GatheringPaymentEvent;
 use SixShop\System\ExtensionManager;
 use SixShop\System\Model\ExtensionModel;
@@ -46,6 +47,7 @@ readonly class PaymentManager
     public function create($paymentId,  array $order, PaymentBizEnum $bizType = PaymentBizEnum::ORDER_PAY):  PaymentResponse
     {
         $extension = $this->extensionManager->getExtension($paymentId);
+        Event::trigger(new BeforePayEvent($order, $paymentId, $bizType));
         return $extension->getPaymentProvider()->create($order, $bizType);
     }