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

src/Gateways/Alipay/TransferGateway.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 View Code Duplication
class TransferGateway implements GatewayInterface
0 ignored issues
show
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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'] = $this->getMethod();
28
        $payload['biz_content'] = json_encode(array_merge(
29
            json_decode($payload['biz_content'], true),
30
            ['product_code' => $this->getProductCode()]
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
     * Get method config.
41
     *
42
     * @author yansongda <[email protected]>
43
     *
44
     * @return string
45
     */
46
    protected function getMethod(): string
47
    {
48
        return 'alipay.fund.trans.toaccount.transfer';
49
    }
50
51
    /**
52
     * Get productCode config.
53
     *
54
     * @author yansongda <[email protected]>
55
     *
56
     * @return string
57
     */
58
    protected function getProductCode(): string
59
    {
60
        return '';
61
    }
62
}
63