Completed
Push — master ( c3ded3...e46555 )
by Songda
13s
created

PosGateway::pay()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 2
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 PosGateway implements GatewayInterface
0 ignored issues
show
Duplication introduced by
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
            [
32
                'product_code' => $this->getProductCode(),
33
                'scene'        => 'bar_code',
34
            ]
35
        ));
36
        $payload['sign'] = Support::generateSign($payload);
37
38
        Log::info('Starting To Pay An Alipay Pos Order', [$endpoint, $payload]);
39
40
        return Support::requestApi($payload);
41
    }
42
43
    /**
44
     * Get method config.
45
     *
46
     * @author yansongda <[email protected]>
47
     *
48
     * @return string
49
     */
50
    protected function getMethod(): string
51
    {
52
        return 'alipay.trade.pay';
53
    }
54
55
    /**
56
     * Get productCode config.
57
     *
58
     * @author yansongda <[email protected]>
59
     *
60
     * @return string
61
     */
62
    protected function getProductCode(): string
63
    {
64
        return 'FACE_TO_FACE_PAYMENT';
65
    }
66
}
67