TransferGateway   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 47
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 7 2
A pay() 0 13 1
1
<?php
2
3
namespace Yansongda\Pay\Gateways\Alipay;
4
5
use Yansongda\Pay\Contracts\GatewayInterface;
6
use Yansongda\Pay\Events;
7
use Yansongda\Pay\Exceptions\GatewayException;
8
use Yansongda\Pay\Exceptions\InvalidConfigException;
9
use Yansongda\Pay\Exceptions\InvalidSignException;
10
use Yansongda\Supports\Collection;
11
12
class TransferGateway implements GatewayInterface
13
{
14
    /**
15
     * Pay an order.
16
     *
17
     * @author yansongda <[email protected]>
18
     *
19
     * @param string $endpoint
20
     * @param array  $payload
21
     *
22
     * @throws GatewayException
23
     * @throws InvalidConfigException
24
     * @throws InvalidSignException
25
     *
26
     * @return Collection
27
     */
28
    public function pay($endpoint, array $payload): Collection
29
    {
30
        $payload['method'] = 'alipay.fund.trans.toaccount.transfer';
31
        $payload['biz_content'] = json_encode(array_merge(
32
            json_decode($payload['biz_content'], true),
33
            ['product_code' => '']
34
        ));
35
        $payload['sign'] = Support::generateSign($payload);
36
37
        Events::dispatch(new Events\PayStarted('Alipay', 'Transfer', $endpoint, $payload));
38
39
        return Support::requestApi($payload);
40
    }
41
42
    /**
43
     * Find.
44
     *
45
     * @author yansongda <[email protected]>
46
     *
47
     * @param $order
48
     *
49
     * @return array
50
     */
51
    public function find($order): array
52
    {
53
        return [
54
            'method'      => 'alipay.fund.trans.order.query',
55
            'biz_content' => json_encode(is_array($order) ? $order : ['out_biz_no' => $order]),
56
        ];
57
    }
58
}
59