Completed
Push — master ( 8787ba...721c87 )
by wannanbigpig
05:01 queued 11s
created

Client::query()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 13
ccs 0
cts 11
cp 0
crap 6
rs 9.9666
1
<?php
2
/*
3
 * This file is part of the wannanbigpig/alipay.
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 WannanBigPig\Alipay\Payment\Refund;
12
13
use WannanBigPig\Alipay\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 \WannanBigPig\Alipay\Kernel\Exceptions\InvalidSignException
35
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
36
     */
37
    public function query(string $tradeNo, string $outTradeNo = null, string $outRequestNo = null, string $orgPid = null)
38
    {
39
        $params = array_filter([
40
            'trade_no' => $tradeNo,
41
            'out_trade_no' => $outTradeNo,
42
            'out_request_no' => $outRequestNo ?: $outTradeNo,
43
            'orgPid' => $orgPid,
44
        ], function ($value) {
45
            return !($this->checkEmpty($value));
46
        });
47
48
        return $this->request('alipay.trade.fastpay.refund.query', [
49
            '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 1
    public function page(string $tradeNo, $amount, string $outRequestNo, string $outTradeNo = null, array $params = [], string $httpMethod = 'POST')
68
    {
69 1
        $method = 'alipay.trade.page.refund';
70 1
        $params = array_merge(array_filter([
71 1
            'trade_no' => $tradeNo,
72 1
            'out_trade_no' => $outTradeNo,
73 1
            'refund_amount' => $amount,
74 1
            'out_request_no' => $outRequestNo,
75 1
        ], function ($value) {
76 1
            return !($this->checkEmpty($value));
77 1
        }), $params);
78 1
        $this->app->setEndpointConfig($method, [
79 1
            'return_url' => $this->app['config']->get('return_url'),
80
        ]);
81
82 1
        return $this->pageExecute($method, [
83 1
            'biz_content' => $params,
84 1
        ], $httpMethod);
85
    }
86
}
87