PosGateway   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pay() 0 10 1
A getTradeType() 0 4 1
1
<?php
2
3
namespace Yansongda\Pay\Gateways\Wechat;
4
5
use Yansongda\Pay\Events;
6
use Yansongda\Pay\Exceptions\GatewayException;
7
use Yansongda\Pay\Exceptions\InvalidArgumentException;
8
use Yansongda\Pay\Exceptions\InvalidSignException;
9
use Yansongda\Supports\Collection;
10
11
class PosGateway extends Gateway
12
{
13
    /**
14
     * Pay an order.
15
     *
16
     * @author yansongda <[email protected]>
17
     *
18
     * @param string $endpoint
19
     * @param array  $payload
20
     *
21
     * @throws GatewayException
22
     * @throws InvalidArgumentException
23
     * @throws InvalidSignException
24
     *
25
     * @return Collection
26
     */
27
    public function pay($endpoint, array $payload): Collection
28
    {
29
        unset($payload['trade_type'], $payload['notify_url']);
30
31
        $payload['sign'] = Support::generateSign($payload);
32
33
        Events::dispatch(new Events\PayStarted('Wechat', 'Pos', $endpoint, $payload));
34
35
        return Support::requestApi('pay/micropay', $payload);
36
    }
37
38
    /**
39
     * Get trade type config.
40
     *
41
     * @author yansongda <[email protected]>
42
     *
43
     * @return string
44
     */
45
    protected function getTradeType(): string
46
    {
47
        return 'MICROPAY';
48
    }
49
}
50