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

PrepayPlugin::getService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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