Client::page()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 6
dl 0
loc 18
ccs 15
cts 15
cp 1
crap 1
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the wannanbigpig/alipay-sdk-php.
4
 *
5
 * (c) wannanbigpig <[email protected]>
6
 *
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace EasyAlipay\Payment\Refund;
12
13
use EasyAlipay\Payment\Kernel\BaseClient;
14
15
/**
16
 * Class Client
17
 *
18
 * @author   liuml  <[email protected]>
19
 * @DateTime 2019-07-24  14:24
20
 */
21
class Client extends BaseClient
22
{
23
    /**
24
     * alipay.trade.fastpay.refund.query(统一收单交易退款查询).
25
     *
26
     * @param string      $tradeNo
27
     * @param string|null $outTradeNo
28
     * @param string|null $outRequestNo
29
     * @param string|null $orgPid
30
     *
31
     * @return array|object|\Psr\Http\Message\ResponseInterface|\WannanBigPig\Supports\Collection|\WannanBigPig\Supports\Http\Response
32
     *
33
     * @throws \GuzzleHttp\Exception\GuzzleException
34
     * @throws \EasyAlipay\Kernel\Exceptions\InvalidSignException
35
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
36
     */
37 2
    public function query(string $tradeNo, string $outTradeNo = null, string $outRequestNo = null, string $orgPid = null)
38
    {
39 2
        $params = array_filter([
40 2
            'trade_no' => $tradeNo,
41 2
            'out_trade_no' => $outTradeNo,
42 2
            'out_request_no' => $outRequestNo ?: $outTradeNo,
43 2
            'orgPid' => $orgPid,
44 2
        ], function ($value) {
45 2
            return !($this->checkEmpty($value));
46 2
        });
47
48 2
        return $this->request('alipay.trade.fastpay.refund.query', [
49 2
            'biz_content' => $params,
50
        ]);
51
    }
52
53
    /**
54
     * alipay.trade.page.refund(统一收单退款页面接口).
55
     *
56
     * @param string      $tradeNo
57
     * @param             $amount
58
     * @param string      $outRequestNo
59
     * @param string|null $outTradeNo
60
     * @param array       $params
61
     * @param string      $httpMethod
62
     *
63
     * @return string
64
     *
65
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
66
     */
67 2
    public function page(string $tradeNo, $amount, string $outRequestNo, string $outTradeNo = null, array $params = [], string $httpMethod = 'POST')
68
    {
69 2
        $method = 'alipay.trade.page.refund';
70 2
        $params = array_merge(array_filter([
71 2
            'trade_no' => $tradeNo,
72 2
            'out_trade_no' => $outTradeNo,
73 2
            'refund_amount' => $amount,
74 2
            'out_request_no' => $outRequestNo,
75 2
        ], function ($value) {
76 2
            return !($this->checkEmpty($value));
77 2
        }), $params);
78 2
        $this->app->setEndpointConfig($method, [
79 2
            'return_url' => $this->app['config']->get('return_url'),
80
        ]);
81
82 2
        return $this->pageExecute($method, [
83 2
            'biz_content' => $params,
84 2
        ], $httpMethod);
85
    }
86
}
87