PaymentUIScriptRenderer::render()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 0
cts 22
cp 0
rs 9.552
c 0
b 0
f 0
cc 2
nc 1
nop 2
crap 6
1
<?php
2
3
namespace Xsolla\SDK\API\PaymentUI;
4
5
/**
6
 * @see https://github.com/xsolla/paystation-embed
7
 */
8
class PaymentUIScriptRenderer
9
{
10
    /**
11
     * @param string     $token
12
     * @param bool|false $isSandbox
13
     */
14
    public static function send($token, $isSandbox = false)
15
    {
16
        echo self::render($token, $isSandbox);
17
    }
18
19
    /**
20
     * @param  string     $token
21
     * @param  bool|false $isSandbox
22
     * @return string
23
     */
24
    public static function render($token, $isSandbox = false)
25
    {
26
        $template =
27
<<<'EOF'
28
<script>
29
    var options = {
30
        access_token: '%s',
31
        sandbox: %s
32
    };
33
    var s = document.createElement('script');
34
    s.type = "text/javascript";
35
    s.async = true;
36
    s.src = "//static.xsolla.com/embed/paystation/1.0.7/widget.min.js";
37
    s.addEventListener('load', function (e) {
38
        XPayStationWidget.init(options);
39
    }, false);
40
    var head = document.getElementsByTagName('head')[0];
41
    head.appendChild(s);
42
</script>
43
EOF;
44
45
        return sprintf($template, $token, $isSandbox ? 'true' : 'false');
46
    }
47
}
48