MiniGateway   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A pay() 0 13 2
1
<?php
2
3
namespace Yansongda\Pay\Gateways\Alipay;
4
5
use Yansongda\Pay\Contracts\GatewayInterface;
6
use Yansongda\Pay\Events;
7
use Yansongda\Pay\Exceptions\GatewayException;
8
use Yansongda\Pay\Exceptions\InvalidArgumentException;
9
use Yansongda\Pay\Exceptions\InvalidConfigException;
10
use Yansongda\Pay\Exceptions\InvalidSignException;
11
use Yansongda\Supports\Collection;
12
13
class MiniGateway implements GatewayInterface
14
{
15
    /**
16
     * Pay an order.
17
     *
18
     * @author xiaozan <[email protected]>
19
     *
20
     * @param string $endpoint
21
     * @param array  $payload
22
     *
23
     * @throws GatewayException
24
     * @throws InvalidArgumentException
25
     * @throws InvalidConfigException
26
     * @throws InvalidSignException
27
     *
28
     * @link https://docs.alipay.com/mini/introduce/pay
29
     *
30
     * @return Collection
31
     */
32
    public function pay($endpoint, array $payload): Collection
33
    {
34
        if (empty(json_decode($payload['biz_content'], true)['buyer_id'])) {
35
            throw new InvalidArgumentException('buyer_id required');
36
        }
37
38
        $payload['method'] = 'alipay.trade.create';
39
        $payload['sign'] = Support::generateSign($payload);
40
41
        Events::dispatch(new Events\PayStarted('Alipay', 'Mini', $endpoint, $payload));
42
43
        return Support::requestApi($payload);
44
    }
45
}
46