Completed
Push — master ( 01cd01...a1188f )
by Jean C.
02:23
created

CustomerCreditCard::populate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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