Completed
Pull Request — master (#995)
by mingyoung
01:35
created

Client::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 3
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyWeChat\Payment\Bill;
13
14
use EasyWeChat\Kernel\Http\StreamResponse;
15
use EasyWeChat\Payment\Kernel\BaseClient;
16
17
class Client extends BaseClient
18
{
19
    /**
20
     * Download bill history as a table file.
21
     *
22
     * @param string $date
23
     * @param string $type
24
     *
25
     * @return \EasyWeChat\Kernel\Http\StreamResponse|\Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
26
     */
27
    public function get(string $date, string $type = 'ALL', array $optional = [])
28
    {
29
        $params = [
30
            'bill_date' => $date,
31
            'bill_type' => $type,
32
        ] + $optional;
33
34
        $response = $this->requestRaw('pay/downloadbill', $params);
35
36
        if (strpos($response->getBody()->getContents(), '<xml>') === 0) {
37
            return $this->resolveResponse($response, $this->app['config']->get('response_type', 'array'));
38
        }
39
40
        return StreamResponse::buildFromPsrResponse($response);
41
    }
42
}
43