Completed
Push — master ( 065035...4118ee )
by Songda
01:49
created

TransferGateway   A

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