|
|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
|
+
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
namespace SixShop\WechatPay;
|
|
|
@@ -8,7 +9,6 @@ use SixShop\Core\Exception\NotFoundException;
|
|
|
use SixShop\Payment\Contracts\PaymentNotifyResult;
|
|
|
use SixShop\Payment\Contracts\PaymentProviderInterface;
|
|
|
use SixShop\Payment\Contracts\PaymentQueryResult;
|
|
|
-use SixShop\Payment\Contracts\PaymentRefundQueryResult;
|
|
|
use SixShop\Payment\Contracts\PaymentRefundRequest;
|
|
|
use SixShop\Payment\Contracts\PaymentRefundResult;
|
|
|
use SixShop\Payment\Contracts\PaymentResponse;
|
|
|
@@ -30,25 +30,25 @@ use SixShop\WechatPay\Trait\PaymentParamsTrait;
|
|
|
use think\facade\Db;
|
|
|
use think\facade\Event;
|
|
|
use think\facade\Log;
|
|
|
+
|
|
|
use function SixShop\Core\throw_logic_exception;
|
|
|
|
|
|
class PaymentProvider implements PaymentProviderInterface
|
|
|
{
|
|
|
- private const string PAYMENT_TYPE = 'wechatpay';
|
|
|
use ApiTrait;
|
|
|
use MiniAppTrait {
|
|
|
uploadShippingInfo as private uploadShippingInfoAPI;
|
|
|
waybillToken as private waybillTokenAPI;
|
|
|
}
|
|
|
use PaymentParamsTrait;
|
|
|
+ private const string PAYMENT_TYPE = 'wechatpay';
|
|
|
|
|
|
public function __construct(
|
|
|
private readonly ExtensionPaymentEntity $extensionPaymentEntity,
|
|
|
private readonly ExtensionRefundEntity $extensionRefundEntity,
|
|
|
private readonly WechatpayTransferBillEntity $wechatpayTransferBillEntity,
|
|
|
private readonly NotifyService $notifyService,
|
|
|
- )
|
|
|
- {
|
|
|
+ ) {
|
|
|
}
|
|
|
|
|
|
public function create(array $order, PaymentBizEnum $bizType): PaymentResponse
|
|
|
@@ -68,7 +68,7 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
//订单已撤销请重新下单
|
|
|
// 订单支付中请稍后再试
|
|
|
// 订单支付失败请重新下单
|
|
|
- throw new \RuntimeException('开发测试中,请稍后再试');
|
|
|
+ throw new \RuntimeException('开发测试中,请稍后再试');
|
|
|
}
|
|
|
$payment->transaction(function () use ($bizType, $order, $payment) {
|
|
|
$payment->save([
|
|
|
@@ -117,8 +117,8 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
'out_trade_no' => $data['out_trade_no'],
|
|
|
])->findOrEmpty();
|
|
|
if ($payment->isEmpty()) {
|
|
|
- Log::warning(__METHOD__ . '订单不存在{out_trade_no}', ['out_trade_no' => $data['out_trade_no']] );
|
|
|
- throw_logic_exception('订单不存在或已结束',httpCode: 404);
|
|
|
+ Log::warning(__METHOD__ . '订单不存在{out_trade_no}', ['out_trade_no' => $data['out_trade_no']]);
|
|
|
+ throw_logic_exception('订单不存在或已结束', httpCode: 404);
|
|
|
}
|
|
|
$queryResult = $this->query($payment['id']);
|
|
|
return new PaymentNotifyResult(
|
|
|
@@ -128,11 +128,11 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
status: $queryResult->status,
|
|
|
raw: $data
|
|
|
);
|
|
|
- } else if ($inBody['event_type'] == 'MCHTRANSFER.BILL.FINISHED') {
|
|
|
+ } elseif ($inBody['event_type'] == 'MCHTRANSFER.BILL.FINISHED') {
|
|
|
// 转账完成
|
|
|
$transferBill = $this->wechatpayTransferBillEntity->where('out_bill_no', $data['out_bill_no'])->findOrEmpty();
|
|
|
if ($transferBill->isEmpty()) {
|
|
|
- Log::warning(__METHOD__ . '订单不存在{out_trade_no}', ['out_trade_no' => $data['out_trade_no']] );
|
|
|
+ Log::warning(__METHOD__ . '订单不存在{out_trade_no}', ['out_trade_no' => $data['out_trade_no']]);
|
|
|
throw_logic_exception('转账单不存在', httpCode: 404);
|
|
|
}
|
|
|
$this->wechatpayTransferBillEntity->refreshTransferBill($transferBill->id);
|
|
|
@@ -185,7 +185,7 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
$payment = $this->extensionPaymentEntity->find($recordID);
|
|
|
// todo 订单分多次退款未实现
|
|
|
$refund = ExtensionRefundModel::where(
|
|
|
- ['order_sn' => $payment->out_trade_no, 'status' =>RefundStatusEnum::SUCCESS]
|
|
|
+ ['order_sn' => $payment->out_trade_no, 'status' => RefundStatusEnum::SUCCESS]
|
|
|
)->findOrEmpty();
|
|
|
if (!$refund->isEmpty()) {
|
|
|
return new PaymentRefundResult($refund);
|
|
|
@@ -234,12 +234,14 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
$refund->status = RefundStatusEnum::SUCCESS;
|
|
|
$refund->status_desc = '成功退款到' . $result->user_received_account;
|
|
|
$refund->success_time = strtotime($result->success_time);
|
|
|
- Event::trigger(new RefundSuccessEvent(
|
|
|
+ Event::trigger(
|
|
|
+ new RefundSuccessEvent(
|
|
|
$refund->model(),
|
|
|
$refund->payment,
|
|
|
- new PaymentRefundRequest($refund->amount, $refund->reason, $refund->refund_param))
|
|
|
+ new PaymentRefundRequest($refund->amount, $refund->reason, $refund->refund_param)
|
|
|
+ )
|
|
|
);
|
|
|
- } else if ($result->status === 'PROCESSING') {
|
|
|
+ } elseif ($result->status === 'PROCESSING') {
|
|
|
QueryRefundJob::dispatch($refund->id)->delay(10);
|
|
|
}
|
|
|
$refund->save();
|
|
|
@@ -251,7 +253,7 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
/**
|
|
|
* 发货信息录入
|
|
|
* @param int $orderID 订单ID
|
|
|
- * @param int $bizType 业务类型
|
|
|
+ * @param int $bizType 业务类型
|
|
|
* @param string $itemDesc 商品描述
|
|
|
* @param string $trackingNo 运单号
|
|
|
* @param string $expressCompany 快递公司ID
|
|
|
@@ -268,8 +270,7 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
string $receiverContact = '',
|
|
|
int $logisticsType = 1,
|
|
|
bool $failException = true,
|
|
|
- ): array
|
|
|
- {
|
|
|
+ ): array {
|
|
|
$order = $this->extensionPaymentEntity->where([
|
|
|
'order_id' => $orderID,
|
|
|
'biz_type' => $bizType,
|
|
|
@@ -293,8 +294,7 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
string $deliveryID,
|
|
|
array $detailList,
|
|
|
bool $failException = true
|
|
|
- ): array
|
|
|
- {
|
|
|
+ ): array {
|
|
|
$order = $this->extensionPaymentEntity->where([
|
|
|
'order_id' => $orderID,
|
|
|
'biz_type' => 1,
|
|
|
@@ -306,4 +306,4 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
}
|
|
|
return $this->waybillTokenAPI($order->user_id, $receiverPhone, $waybillID, $deliveryID, $detailList, $failException);
|
|
|
}
|
|
|
-}
|
|
|
+}
|