Completed
Push — list_events_limit_parameter_an... ( 671774 )
by Vitaliy
05:09 queued 02:50
created

TokenRequest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 96.67%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 10
c 3
b 0
f 2
lcom 1
cbo 0
dl 0
loc 114
ccs 29
cts 30
cp 0.9667
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 4 1
A __construct() 0 5 1
A setUserEmail() 0 6 1
A setUserName() 0 6 1
A setCurrency() 0 6 1
A setCustomParameters() 0 6 1
A setExternalPaymentId() 0 6 1
A setPurchase() 0 7 1
A setSandboxMode() 0 10 2
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 3
    public function __construct($projectId, $userId)
17
    {
18 3
        $this->data['user']['id']['value'] = $userId;
19 3
        $this->data['settings']['project_id'] = $projectId;
20 3
    }
21
22
    /**
23
     * @param string $email
24
     *
25
     * @return self
26
     */
27 2
    public function setUserEmail($email)
28
    {
29 2
        $this->data['user']['email']['value'] = $email;
30
31 2
        return $this;
32
    }
33
34
    /**
35
     * @param string $name
36
     *
37
     * @return self
38
     */
39 2
    public function setUserName($name)
40
    {
41 2
        $this->data['user']['name']['value'] = $name;
42
43 2
        return $this;
44
    }
45
46
    /**
47
     * @param string $currencyIsoCode
48
     *
49
     * @return self
50
     */
51 2
    public function setCurrency($currencyIsoCode)
52
    {
53 2
        $this->data['settings']['currency'] = $currencyIsoCode;
54
55 2
        return $this;
56
    }
57
58
    /**
59
     * @param array $customParameters
60
     *
61
     * @return self
62
     */
63 2
    public function setCustomParameters(array $customParameters)
64
    {
65 2
        $this->data['custom_parameters'] = $customParameters;
66
67 2
        return $this;
68
    }
69
70
    /**
71
     * @param string $externalId
72
     *
73
     * @return self
74
     */
75 1
    public function setExternalPaymentId($externalId)
76
    {
77 1
        $this->data['settings']['external_id'] = $externalId;
78
79 1
        return $this;
80
    }
81
82
    /**
83
     * @param bool $isSandbox
84
     *
85
     * @return self
86
     */
87 3
    public function setSandboxMode($isSandbox = true)
88
    {
89 3
        if (true === $isSandbox) {
90 3
            $this->data['settings']['mode'] = 'sandbox';
91
        } else {
92
            unset($this->data['settings']['mode']);
93
        }
94
95 3
        return $this;
96
    }
97
98
    /**
99
     * @param  float  $amount
100
     * @param  string $currency
101
     * @return $this
102
     */
103 2
    public function setPurchase($amount, $currency)
104
    {
105 2
        $this->data['purchase']['checkout']['amount'] = $amount;
106 2
        $this->data['purchase']['checkout']['currency'] = $currency;
107
108 2
        return $this;
109
    }
110
111
    /**
112
     * @return array
113
     */
114 3
    public function toArray()
115
    {
116 3
        return $this->data;
117
    }
118
}
119