Completed
Push — master ( 00553d...119d3b )
by Songda
01:42
created

src/Gateways/Alipay/AppGateway.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 Symfony\Component\HttpFoundation\Response;
6
use Yansongda\Pay\Contracts\GatewayInterface;
7
use Yansongda\Pay\Log;
8
9 View Code Duplication
class AppGateway 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\InvalidArgumentException
20
     * @throws \Yansongda\Pay\Exceptions\InvalidConfigException
21
     *
22
     * @return Response
23
     */
24
    public function pay($endpoint, array $payload): Response
25
    {
26
        $payload['method'] = $this->getMethod();
27
        $payload['biz_content'] = json_encode(array_merge(
28
            json_decode($payload['biz_content'], true),
29
            ['product_code' => $this->getProductCode()]
30
        ));
31
        $payload['sign'] = Support::generateSign($payload);
32
33
        Log::info('Starting To Pay An Alipay App Order', [$endpoint, $payload]);
34
35
        return Response::create(http_build_query($payload));
36
    }
37
38
    /**
39
     * Get method config.
40
     *
41
     * @author yansongda <[email protected]>
42
     *
43
     * @return string
44
     */
45
    protected function getMethod(): string
46
    {
47
        return 'alipay.trade.app.pay';
48
    }
49
50
    /**
51
     * Get productCode method.
52
     *
53
     * @author yansongda <[email protected]>
54
     *
55
     * @return string
56
     */
57
    protected function getProductCode(): string
58
    {
59
        return 'QUICK_MSECURITY_PAY';
60
    }
61
}
62