Completed
Pull Request — master (#37)
by Vitaliy
06:49 queued 04:18
created

TokenRequest::setSandboxMode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Xsolla\SDK\API\PaymentUI;
4
5
class TokenRequest
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $data = array();
11
12
    /**
13
     * @param int    $projectId
14
     * @param string $userId
15
     */
16
    public function __construct($projectId, $userId)
17
    {
18
        $this->data['user']['id']['value'] = $userId;
19
        $this->data['settings']['project_id'] = $projectId;
20
    }
21
22
    /**
23
     * @param string $email
24
     *
25
     * @return self
26
     */
27
    public function setUserEmail($email)
28
    {
29
        $this->data['user']['email']['value'] = $email;
30
31
        return $this;
32
    }
33
34
    /**
35
     * @param string $name
36
     *
37
     * @return self
38
     */
39
    public function setUserName($name)
40
    {
41
        $this->data['user']['name']['value'] = $name;
42
43
        return $this;
44
    }
45
46
    /**
47
     * @param string $currencyIsoCode
48
     *
49
     * @return self
50
     */
51
    public function setCurrency($currencyIsoCode)
52
    {
53
        $this->data['settings']['currency'] = $currencyIsoCode;
54
55
        return $this;
56
    }
57
58
    /**
59
     * @param array $customParameters
60
     *
61
     * @return self
62
     */
63
    public function setCustomParameters(array $customParameters)
64
    {
65
        $this->data['custom_parameters'] = $customParameters;
66
67
        return $this;
68
    }
69
70
    /**
71
     * @param string $externalId
72
     *
73
     * @return self
74
     */
75
    public function setExternalPaymentId($externalId)
76
    {
77
        $this->data['settings']['external_id'] = $externalId;
78
79
        return $this;
80
    }
81
82
    /**
83
     * @param bool $isSandbox
84
     *
85
     * @return self
86
     */
87
    public function setSandboxMode($isSandbox = true)
88
    {
89
        if (true === $isSandbox) {
90
            $this->data['settings']['mode'] = 'sandbox';
91
        } else {
92
            unset($this->data['settings']['mode']);
93
        }
94
95
        return $this;
96
    }
97
98
    /**
99
     * @param  float  $amount
100
     * @param  string $currency
101
     * @return $this
102
     */
103
    public function setPurchase($amount, $currency)
104
    {
105
        $this->data['purchase']['checkout']['amount'] = $amount;
106
        $this->data['purchase']['checkout']['currency'] = $currency;
107
108
        return $this;
109
    }
110
111
    /**
112
     * @return array
113
     */
114
    public function toArray()
115
    {
116
        return $this->data;
117
    }
118
}
119