Completed
Push — master ( 00553d...119d3b )
by Songda
01:42
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\Log;
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\InvalidArgumentException
21
     * @throws \Yansongda\Pay\Exceptions\InvalidConfigException
22
     * @throws \Yansongda\Pay\Exceptions\InvalidSignException
23
     *
24
     * @return Collection
25
     */
26
    public function pay($endpoint, array $payload): Collection
27
    {
28
        $payload['method'] = $this->getMethod();
29
        $payload['biz_content'] = json_encode(array_merge(
30
            json_decode($payload['biz_content'], true),
31
            ['product_code' => $this->getProductCode()]
32
        ));
33
        $payload['sign'] = Support::generateSign($payload);
34
35
        Log::info('Starting To Pay An Alipay Transfer Order', [$endpoint, $payload]);
36
37
        return Support::requestApi($payload);
38
    }
39
40
    /**
41
     * Get method config.
42
     *
43
     * @author yansongda <[email protected]>
44
     *
45
     * @return string
46
     */
47
    protected function getMethod(): string
48
    {
49
        return 'alipay.fund.trans.toaccount.transfer';
50
    }
51
52
    /**
53
     * Get productCode config.
54
     *
55
     * @author yansongda <[email protected]>
56
     *
57
     * @return string
58
     */
59
    protected function getProductCode(): string
60
    {
61
        return '';
62
    }
63
}
64