新增了微信支付 关闭订单。在取消未支付订单中。

This commit is contained in:
2024-06-26 14:18:40 +08:00
parent 7d978c27bd
commit 914ddb5abf
3 changed files with 50 additions and 1 deletions
+43
View File
@@ -250,4 +250,47 @@ class WechatPay
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
}
}
/**
* 关闭订单
* @param string $out_trade_no 商户系统内部订单号
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function closeOrder(string $out_trade_no): array
{
$app = $this->createApp();
$options = [
"mchid" => $this->pay_config['mch_id'], // <---- 商户号
];
Log::getInstance()->info(json_encode($options,JSON_UNESCAPED_UNICODE));
try {
$url = "v3/pay/transactions/out-trade-no/" . $out_trade_no . "/close";
$response = $app->getClient()->postJson($url, $options);
if ($response->isFailed()) {
// 出错了,处理异常
$result = $response->toArray(false);
Log::getInstance()->info(json_encode($result,JSON_UNESCAPED_UNICODE));
if(empty($result)){
// 返回值为空
throw new BusinessException("发起支付失败");
}
if (!empty($result['code'])){
if ($result['code'] != 400){
throw new BusinessException($result['message']);
}
}else{
throw new BusinessException("关闭支付订单失败");
}
}
return $response->toArray(false);
} catch (\Exception $e) {
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
}
}
}