|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yansongda\Pay\Plugin\Wechat\Marketing\ECommerceRefund; |
|
6
|
|
|
|
|
7
|
|
|
use Closure; |
|
8
|
|
|
use Yansongda\Pay\Contract\PluginInterface; |
|
9
|
|
|
use Yansongda\Pay\Exception\ContainerException; |
|
10
|
|
|
use Yansongda\Pay\Exception\Exception; |
|
11
|
|
|
use Yansongda\Pay\Exception\InvalidParamsException; |
|
12
|
|
|
use Yansongda\Pay\Exception\ServiceNotFoundException; |
|
13
|
|
|
use Yansongda\Pay\Logger; |
|
14
|
|
|
use Yansongda\Pay\Rocket; |
|
15
|
|
|
|
|
16
|
|
|
use function Yansongda\Pay\get_wechat_config; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @see https://pay.weixin.qq.com/docs/partner/apis/ecommerce-refund/refunds/query-refund-by-out-refund-no.html |
|
20
|
|
|
*/ |
|
21
|
|
|
class QueryPlugin implements PluginInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @throws ContainerException |
|
25
|
|
|
* @throws InvalidParamsException |
|
26
|
|
|
* @throws ServiceNotFoundException |
|
27
|
|
|
*/ |
|
28
|
|
|
public function assembly(Rocket $rocket, Closure $next): Rocket |
|
29
|
|
|
{ |
|
30
|
|
|
Logger::debug('[Wechat][Marketing][ECommerceRefund][QueryPlugin] 插件开始装载', ['rocket' => $rocket]); |
|
31
|
|
|
|
|
32
|
|
|
$params = $rocket->getParams(); |
|
33
|
|
|
$payload = $rocket->getPayload(); |
|
34
|
|
|
$config = get_wechat_config($params); |
|
35
|
|
|
$outRefundNo = $payload?->get('out_refund_no') ?? null; |
|
36
|
|
|
|
|
37
|
|
|
if (is_null($outRefundNo)) { |
|
38
|
|
|
throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 平台收付通(退款)-查询单笔退款(按商户退款单号),缺少必要参数 `out_refund_no`'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$rocket->setPayload([ |
|
42
|
|
|
'_method' => 'GET', |
|
43
|
|
|
'_service_url' => 'v3/ecommerce/refunds/out-refund-no/'.$outRefundNo.'?sub_mchid='.$payload->get('sub_mchid', $config['sub_mch_id']), |
|
44
|
|
|
]); |
|
45
|
|
|
|
|
46
|
|
|
Logger::info('[Wechat][Marketing][ECommerceRefund][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]); |
|
47
|
|
|
|
|
48
|
|
|
return $next($rocket); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|