|
|
@@ -20,6 +20,7 @@ use SixShop\Payment\Enum\RefundStatusEnum;
|
|
|
use SixShop\Payment\Event\PaymentSuccessEvent;
|
|
|
use SixShop\Payment\Event\RefundSuccessEvent;
|
|
|
use SixShop\Wechat\Facade\WechatUser;
|
|
|
+use SixShop\WechatPay\Entity\WechatpayTransferBillEntity;
|
|
|
use SixShop\WechatPay\Job\QueryRefundJob;
|
|
|
use SixShop\WechatPay\Service\NotifyService;
|
|
|
use SixShop\WechatPay\Trait\ApiTrait;
|
|
|
@@ -43,6 +44,7 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
public function __construct(
|
|
|
private readonly ExtensionPaymentEntity $extensionPaymentEntity,
|
|
|
private readonly ExtensionRefundEntity $extensionRefundEntity,
|
|
|
+ private readonly WechatpayTransferBillEntity $wechatpayTransferBillEntity,
|
|
|
private readonly NotifyService $notifyService,
|
|
|
)
|
|
|
{
|
|
|
@@ -107,36 +109,41 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
{
|
|
|
$inBody = $request['inBody'];
|
|
|
$data = $this->notifyService->transactionSuccess($request['headers'], json_encode($request['inBody']));
|
|
|
- if ($inBody['event_type'] !== 'TRANSACTION.SUCCESS') {
|
|
|
- Log::warning('Not implemented: ' . $inBody['event_type']. ' ' . json_encode($data));
|
|
|
- throw_logic_exception('Not implemented: ' . $inBody['event_type']);
|
|
|
- }
|
|
|
- Log::debug(__METHOD__ . json_encode($data));
|
|
|
- $payment = $this->extensionPaymentEntity->where([
|
|
|
- 'out_trade_no' => $data['out_trade_no'],
|
|
|
- ])->findOrEmpty();
|
|
|
- if ($payment->isEmpty()) {
|
|
|
- throw new \RuntimeException('订单不存在或已结束');
|
|
|
+ if ($inBody['event_type'] == 'TRANSACTION.SUCCESS') {
|
|
|
+ // 交易成功
|
|
|
+ Log::debug(__METHOD__ . json_encode($data));
|
|
|
+ $payment = $this->extensionPaymentEntity->where([
|
|
|
+ 'out_trade_no' => $data['out_trade_no'],
|
|
|
+ ])->findOrEmpty();
|
|
|
+ if ($payment->isEmpty()) {
|
|
|
+ throw new \RuntimeException('订单不存在或已结束');
|
|
|
+ }
|
|
|
+ // 验签有问题,暂时叫个支付查询处理 todo 待完善
|
|
|
+ $queryResult = $this->query($payment['id']);
|
|
|
+ return new PaymentNotifyResult(
|
|
|
+ orderNo: $queryResult->orderNo,
|
|
|
+ transactionId: $data['transaction_id'],
|
|
|
+ amount: $queryResult->amount,
|
|
|
+ status: $queryResult->status,
|
|
|
+ raw: $data
|
|
|
+ );
|
|
|
+ } else if ($inBody['event_type'] == 'MCHTRANSFER.BILL.FINISHED') {
|
|
|
+ // 转账完成
|
|
|
+ $transferBill = $this->wechatpayTransferBillEntity->where('out_bill_no', $data['out_bill_no'])->findOrEmpty();
|
|
|
+ if ($transferBill->isEmpty()) {
|
|
|
+ throw new \RuntimeException('转账单不存在');
|
|
|
+ }
|
|
|
+ $this->wechatpayTransferBillEntity->refreshTransferBill($transferBill->id);
|
|
|
+ return new PaymentNotifyResult(
|
|
|
+ orderNo: $transferBill['out_bill_no'],
|
|
|
+ transactionId: $transferBill['transfer_bill_no'],
|
|
|
+ amount: round($transferBill['transfer_amount'] / 100, 2),
|
|
|
+ status: PaymentStatusEnum::SUCCESS,
|
|
|
+ raw: $data
|
|
|
+ );
|
|
|
}
|
|
|
- // 验签有问题,暂时叫个支付查询处理 todo 待完善
|
|
|
- $queryResult = $this->query($payment['id']);
|
|
|
- return new PaymentNotifyResult(
|
|
|
- orderNo: $queryResult->orderNo,
|
|
|
- transactionId: $data['transaction_id'],
|
|
|
- amount: $queryResult->amount,
|
|
|
- status: $queryResult->status,
|
|
|
- raw: $data
|
|
|
- );
|
|
|
- // data 数据
|
|
|
- //{
|
|
|
- //"mchid":"1730970813",
|
|
|
- //"appid":"wx2c4a7d3d5d5aef0b",
|
|
|
- //"out_trade_no":"20251030094337050576",
|
|
|
- //"transaction_id":"4200002881202510302655663850","trade_type":"JSAPI",
|
|
|
- //"trade_state":"SUCCESS","trade_state_desc":"\u652f\u4ed8\u6210\u529f","bank_type":"OTHERS","attach":"actor",
|
|
|
- //"success_time":"2025-10-30T09:43:50+08:00","payer":{"openid":"oPuRO19YQD4Tc2w2Vak4U83-Liys"},"amount":{"total":100,"payer_total":100,"currency":"CNY","payer_currency":"CNY"}
|
|
|
- //}
|
|
|
-
|
|
|
+ Log::warning('Not implemented: ' . $inBody['event_type']. ' ' . json_encode($data));
|
|
|
+ throw_logic_exception('Not implemented: ' . $inBody['event_type']);
|
|
|
}
|
|
|
|
|
|
public function query(int $recordID): PaymentQueryResult
|