فهرست منبع

feat: 待支付订单继续支付

runphp 1 ماه پیش
والد
کامیت
c0069552f7
1فایلهای تغییر یافته به همراه15 افزوده شده و 4 حذف شده
  1. 15 4
      src/PaymentProvider.php

+ 15 - 4
src/PaymentProvider.php

@@ -59,16 +59,27 @@ class PaymentProvider implements PaymentProviderInterface
             'biz_type' => $bizType,
         ])->findOrEmpty();
         if (!$payment->isEmpty()) {
-            // todo 判断订单是否支付成功
+            // 判断订单是否支付成功
             // 支付时间结束关闭订单
             // 订单未支付可重新支付
             // 交易已关闭请重新下单
-            //订单已付款请勿重复操作
+            // 订单已付款请勿重复操作
             // 订单已退款请重新下单
-            //订单已撤销请重新下单
+            // 订单已撤销请重新下单
             // 订单支付中请稍后再试
             // 订单支付失败请重新下单
-            throw new \RuntimeException('开发测试中,请稍后再试');
+            try {
+                $paymentResult = $this->queryByOutTradeNo($payment['out_trade_no']);
+            } catch (ClientException $e) {
+                if ($e->getCode() === 404) {
+                    throw new NotFoundException(sprintf('订单%s不存在', $payment['out_trade_no']));
+                }
+                throw $e;
+            }
+            if ($paymentResult->trade_state !== 'NOTPAY') {
+                throw_logic_exception($paymentResult->trade_state_desc.',请重新下单');
+            }
+            return new PaymentResponse(orderNo: $payment->out_trade_no, type: self::PAYMENT_TYPE, raw: $payment->toArray());
         }
         $payment->transaction(function () use ($bizType, $order, $payment) {
             $payment->save([