Completed
Push — master ( 867225...9deef3 )
by Songda
01:47
created

TransferGateway::getMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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