Completed
Push — master ( 4a5840...1f0278 )
by
unknown
11s
created

CustomerCreditCard::getBrand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Moip\Resource;
4
5
use stdClass;
6
7
/**
8
 * Class CustomerFunding.
9
 *
10
 * Add a credit card.
11
 * Through this API you can add one or more credit cards to a Customer.
12
 */
13
class CustomerCreditCard extends MoipResource
14
{
15
    /**
16
     * Path funding instruments.
17
     *
18
     * @const
19
     */
20
    const PATH_POST = 'customers/%s/fundinginstruments';
21
22
    /**
23
     * Delete a credit card.
24
     *
25
     * @const
26
     */
27
    const PATH_DELETE = 'fundinginstruments/%s';
28
29
    /**
30
     * @const sting
31
     */
32
    const METHOD_CREDIT_CARD = 'CREDIT_CARD';
33
34
    /**
35
     * Initialize a new instance.
36
     */
37
    protected function initialize()
38
    {
39
        $this->data = new stdClass();
40
        $this->data->method = self::METHOD_CREDIT_CARD;
41
        $this->data->creditCard = new stdClass();
42
        $this->data->creditCard->holder = new stdClass();
43
        $this->data->creditCard->holder->taxDocument = new stdClass();
44
        $this->data->creditCard->holder->phone = new stdClass();
45
    }
46
47
    /**
48
     * Mount information of a determined object.
49
     *
50
     * @param \stdClass $response
51
     *
52
     * @return mixed
53
     */
54
    protected function populate(stdClass $response)
55
    {
56
        $funding = clone $this;
57
        $funding->data->method = self::METHOD_CREDIT_CARD;
58
        $funding->data->creditCard = new stdClass();
59
        $funding->data->creditCard->id = $response->creditCard->id;
60
        $funding->data->creditCard->brand = $response->creditCard->brand;
61
        $funding->data->creditCard->first6 = $response->creditCard->first6;
62
        $funding->data->creditCard->last4 = $response->creditCard->last4;
63
        $funding->data->creditCard->store = $response->creditCard->store;
64
        $funding->data->card = new stdClass();
65
        $funding->data->card->brand = $response->card->brand;
66
        $funding->data->card->store = $response->card->store;
67
68
        return $funding;
69
    }
70
71
    /**
72
     * Create.
73
     *
74
     * @param $customer_id
75
     *
76
     * @return stdClass
77
     */
78
    public function create($customer_id)
79
    {
80
        return $this->createResource(sprintf('%s/%s', MoipResource::VERSION, sprintf(self::PATH_POST, $customer_id)));
81
    }
82
83
    /**
84
     * Delete.
85
     *
86
     * @param $creditcard_id
87
     *
88
     * @return mixed
89
     */
90
    public function delete($creditcard_id)
91
    {
92
        return $this->deleteByPath(sprintf('%s/%s', MoipResource::VERSION, sprintf(self::PATH_DELETE, $creditcard_id)));
93
    }
94
95
    /**
96
     * Mês de expiração do cartão.
97
     * Necessário estar dentro do escopo PCI para enviar esse campo sem criptografia.
98
     *
99
     * @param int $expiration_month
100
     *
101
     * @return $this
102
     */
103
    public function setExpirationMonth($expiration_month)
104
    {
105
        $this->data->creditCard->expirationMonth = $expiration_month;
106
107
        return $this;
108
    }
109
110
    /**
111
     * Ano de expiração do cartão.
112
     * Necessário estar dentro do escopo PCI para enviar esse campo sem criptografia.
113
     *
114
     * @param int $expiration_year
115
     *
116
     * @return $this
117
     */
118
    public function setExpirationYear($expiration_year)
119
    {
120
        $this->data->creditCard->expirationYear = $expiration_year;
121
122
        return $this;
123
    }
124
125
    /**
126
     * Número do cartão de crédito.
127
     * Necessário estar dentro do escopo PCI para enviar esse campo sem criptografia.
128
     *
129
     * @param $number
130
     *
131
     * @return $this
132
     */
133
    public function setNumber($number)
134
    {
135
        $this->data->creditCard->number = $number;
136
137
        return $this;
138
    }
139
140
    /**
141
     * Código de segurança do cartão.
142
     * Necessário estar dentro do escopo PCI para enviar esse campo sem criptografia.
143
     *
144
     * @param string $cvc
145
     *
146
     * @return $this
147
     */
148
    public function setCvc($cvc)
149
    {
150
        $this->data->creditCard->cvc = $cvc;
151
152
        return $this;
153
    }
154
155
    /**
156
     * Nome do portador impresso no cartão.
157
     *
158
     * @param $fullname
159
     *
160
     * @return $this
161
     */
162
    public function setFullname($fullname)
163
    {
164
        $this->data->creditCard->holder->fullname = $fullname;
165
166
        return $this;
167
    }
168
169
    /**
170
     * Data de nascimento do cliente. date(AAAA-MM-DD),.
171
     *
172
     * @param $birthdate
173
     *
174
     * @return $this
175
     */
176
    public function setBirthdate($birthdate)
177
    {
178
        $this->data->creditCard->holder->birthdate = $birthdate;
179
180
        return $this;
181
    }
182
183
    /**
184
     * Documento fiscal.
185
     *
186
     * @param string $type   Tipo do documento. Valores possíveis: CPF.
187
     * @param string $number Número do documento.
188
     *
189
     * @return $this
190
     */
191
    public function setTaxDocument($type, $number)
192
    {
193
        $this->data->creditCard->holder->taxDocument->type = $type;
194
        $this->data->creditCard->holder->taxDocument->number = $number;
195
196
        return $this;
197
    }
198
199
    /**
200
     * Telefone do cliente.
201
     *
202
     * @param int $country_code DDI (código internacional) do telefone. Valores possíveis: 55.
203
     * @param int $area_code    Código de área do cliente. Limite de caracteres: (2).
204
     * @param int $number       Número de telefone do cliente. Limite de caracteres: 9
205
     *
206
     * @return $this
207
     */
208 View Code Duplication
    public function setPhone($country_code, $area_code, $number)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
209
    {
210
        $this->data->creditCard->holder->phone->countryCode = $country_code;
211
        $this->data->creditCard->holder->phone->areaCode = $area_code;
212
        $this->data->creditCard->holder->phone->number = $number;
213
214
        return $this;
215
    }
216
217
    /**
218
     * Get credit card id.
219
     *
220
     * @return string
221
     */
222
    public function getId()
223
    {
224
        return $this->data->creditCard->id;
225
    }
226
227
    /**
228
     * Get brand.
229
     *
230
     * @return string
231
     */
232
    public function getBrand()
233
    {
234
        return $this->data->creditCard->brand;
235
    }
236
237
    /**
238
     * Get first 6 characters from credit card.
239
     *
240
     * @return string
241
     */
242
    public function getFirst6()
243
    {
244
        return $this->data->creditCard->first6;
245
    }
246
247
    /**
248
     * Get last 4 characters from credit card.
249
     *
250
     * @return string
251
     */
252
    public function getLast4()
253
    {
254
        return $this->data->creditCard->last4;
255
    }
256
257
    /**
258
     * Get if a credit card was stored or not.
259
     *
260
     * @return bool
261
     */
262
    public function getStore()
263
    {
264
        return $this->data->creditCard->store;
265
    }
266
}
267