Passed
Pull Request — master (#1002)
by
unknown
02:10
created

PrepayPlugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doSomethingBefore() 0 15 3
A getService() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Epay\Pay\Scan;
6
7
use Yansongda\Artful\Exception\ContainerException;
8
use Yansongda\Artful\Exception\InvalidConfigException;
9
use Yansongda\Artful\Exception\ServiceNotFoundException;
10
use Yansongda\Artful\Rocket;
11
use Yansongda\Pay\Exception\Exception;
12
use Yansongda\Pay\Plugin\Epay\GeneralPlugin;
13
14
use function Yansongda\Pay\get_provider_config;
15
16
class PrepayPlugin extends GeneralPlugin
17
{
18
    protected function getService(): string
19
    {
20
        return 'atPay';
21
    }
22
23
    /**
24
     * @throws ServiceNotFoundException
25
     * @throws ContainerException
26
     */
27
    protected function doSomethingBefore(Rocket $rocket): void
28
    {
29
        if (!empty($rocket->getPayload()['notify_url'])) {
30
            return;
31
        }
32
33
        $params = $rocket->getParams();
34
        $config = get_provider_config('epay', $params);
35
36
        $backUrl = $config['notify_url'] ?? null;
37
        if (!$backUrl) {
38
            throw new InvalidConfigException(Exception::CONFIG_EPAY_INVALID, 'Missing Epay Config -- [notify_url]');
39
        }
40
        $rocket->mergePayload([
41
            'backUrl' => $backUrl,
42
        ]);
43
    }
44
}
45