Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 9f84f79

Browse files
committed
feat(holder): add Holder resource and resolves Holder params
1 parent 24aa711 commit 9f84f79

File tree

8 files changed

+296
-17
lines changed

8 files changed

+296
-17
lines changed

src/Moip.php

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Moip\Resource\BankAccount;
88
use Moip\Resource\Customer;
99
use Moip\Resource\Entry;
10+
use Moip\Resource\Holder;
1011
use Moip\Resource\Keys;
1112
use Moip\Resource\Multiorders;
1213
use Moip\Resource\NotificationPreferences;
@@ -130,6 +131,16 @@ public function customers()
130131
return new Customer($this);
131132
}
132133

134+
/**
135+
* Create a new Holder instance.
136+
*
137+
* @return \Moip\Resource\Holder
138+
*/
139+
public function holders()
140+
{
141+
return new Holder($this);
142+
}
143+
133144
/**
134145
* Create a new Account instance.
135146
*

src/Resource/Customer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public function setEmail($email)
323323
*
324324
* @return $this
325325
*/
326-
public function setCreditCard($expirationMonth, $expirationYear, $number, $cvc, Customer $holder = null)
326+
public function setCreditCard($expirationMonth, $expirationYear, $number, $cvc, Holder $holder = null)
327327
{
328328
if ($holder === null) {
329329
$holder = $this;

src/Resource/Holder.php

+250
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
<?php
2+
3+
namespace Moip\Resource;
4+
5+
use stdClass;
6+
use UnexpectedValueException;
7+
8+
/**
9+
* Class Holder.
10+
*/
11+
class Holder extends MoipResource {
12+
13+
/**
14+
* Address Type.
15+
*
16+
* @const string
17+
*/
18+
const ADDRESS_BILLING = 'BILLING';
19+
20+
/**
21+
* Standard country .
22+
*
23+
* @const string
24+
*/
25+
const ADDRESS_COUNTRY = 'BRA';
26+
27+
/**
28+
* Standard document type.
29+
*
30+
* @const string
31+
*/
32+
const TAX_DOCUMENT = 'CPF';
33+
34+
/**
35+
* Initialize a new instance.
36+
*/
37+
public function initialize()
38+
{
39+
$this->data = new stdClass();
40+
}
41+
42+
/**
43+
* Add a new address to the holder.
44+
*
45+
* @param string $type Address type: BILLING.
46+
* @param string $street Street address.
47+
* @param string $number Number address.
48+
* @param string $district Neighborhood address.
49+
* @param string $city City address.
50+
* @param string $state State address.
51+
* @param string $zip The zip code billing address.
52+
* @param string $complement Address complement.
53+
* @param string $country Country ISO-alpha3 format, BRA example.
54+
*
55+
* @return $this
56+
*/
57+
public function setAddress($type = self::ADDRESS_BILLING, $street, $number, $district, $city, $state, $zip, $complement = null, $country = self::ADDRESS_COUNTRY)
58+
{
59+
$address = new stdClass();
60+
$address->street = $street;
61+
$address->streetNumber = $number;
62+
$address->complement = $complement;
63+
$address->district = $district;
64+
$address->city = $city;
65+
$address->state = $state;
66+
$address->country = $country;
67+
$address->zipCode = $zip;
68+
69+
$this->data->billingAddress = $address;
70+
71+
return $this;
72+
}
73+
74+
/**
75+
* Get holder address.
76+
*
77+
* @return \stdClass Holder's address.
78+
*/
79+
public function getBillingAddress()
80+
{
81+
return $this->getIfSet('billingAddress');
82+
}
83+
84+
/**
85+
* Get holser fullname.
86+
*
87+
* @return string Holder's full name.
88+
*/
89+
public function getFullname()
90+
{
91+
return $this->getIfSet('fullname');
92+
}
93+
94+
/**
95+
* Get birth date from holder.
96+
*
97+
* @return \DateTime|null Date of birth of the credit card holder.
98+
*/
99+
public function getBirthDate()
100+
{
101+
return $this->getIfSetDate('birthDate');
102+
}
103+
104+
/**
105+
* Get phone area code from holder.
106+
*
107+
* @return int DDD telephone.
108+
*/
109+
public function getPhoneAreaCode()
110+
{
111+
return $this->getIfSet('areaCode', $this->data->phone);
112+
}
113+
114+
/**
115+
* Get phone country code from holder.
116+
*
117+
* @return int Country code.
118+
*/
119+
public function getPhoneCountryCode()
120+
{
121+
return $this->getIfSet('countryCode', $this->data->phone);
122+
}
123+
124+
/**
125+
* Get phone number from holder.
126+
*
127+
* @return int Telephone number.
128+
*/
129+
public function getPhoneNumber()
130+
{
131+
return $this->getIfSet('number', $this->data->phone);
132+
}
133+
134+
/**
135+
* Get tax document type from holder.
136+
*
137+
* @return string Type of value: CPF and CNPJ
138+
*/
139+
public function getTaxDocumentType()
140+
{
141+
return $this->getIfSet('type', $this->data->taxDocument);
142+
}
143+
144+
/**
145+
* Get tax document number from holder.
146+
*
147+
* @return string Document Number.
148+
*/
149+
public function getTaxDocumentNumber()
150+
{
151+
return $this->getIfSet('number', $this->data->taxDocument);
152+
}
153+
154+
/**
155+
* Mount the buyer structure from holder.
156+
*
157+
* @param \stdClass $response
158+
*
159+
* @return Holder information.
160+
*/
161+
protected function populate(stdClass $response)
162+
{
163+
$holder = clone $this;
164+
$holder->data = new stdClass();
165+
$holder->data->fullname = $this->getIfSet('fullname', $response);
166+
$holder->data->phone = new stdClass();
167+
168+
$phone = $this->getIfSet('phone', $response);
169+
170+
$holder->data->phone->countryCode = $this->getIfSet('countryCode', $phone);
171+
$holder->data->phone->areaCode = $this->getIfSet('areaCode', $phone);
172+
$holder->data->phone->number = $this->getIfSet('number', $phone);
173+
$holder->data->birthDate = $this->getIfSet('birthDate', $response);
174+
$holder->data->taxDocument = new stdClass();
175+
$holder->data->taxDocument->type = $this->getIfSet('type', $this->getIfSet('taxDocument', $response));
176+
$holder->data->taxDocument->number = $this->getIfSet('number', $this->getIfSet('taxDocument', $response));
177+
//$holder->data->addresses = [];
178+
$holder->data->billingAddress = $this->getIfSet('billingAddress', $response);
179+
180+
return $holder;
181+
}
182+
183+
/**
184+
* Set fullname from holder.
185+
*
186+
* @param string $fullname Holder's full name.
187+
*
188+
* @return $this
189+
*/
190+
public function setFullname($fullname)
191+
{
192+
$this->data->fullname = $fullname;
193+
194+
return $this;
195+
}
196+
197+
/**
198+
* Set birth date from holder.
199+
*
200+
* @param \DateTime|string $birthDate Date of birth of the credit card holder.
201+
*
202+
* @return $this
203+
*/
204+
public function setBirthDate($birthDate)
205+
{
206+
if ($birthDate instanceof \DateTime) {
207+
$birthDate = $birthDate->format('Y-m-d');
208+
}
209+
210+
$this->data->birthDate = $birthDate;
211+
212+
return $this;
213+
}
214+
215+
/**
216+
* Set tax document from holder.
217+
*
218+
* @param string $number Document number.
219+
* @param string $type Document type.
220+
*
221+
* @return $this
222+
*/
223+
public function setTaxDocument($number, $type = self::TAX_DOCUMENT)
224+
{
225+
$this->data->taxDocument = new stdClass();
226+
$this->data->taxDocument->type = $type;
227+
$this->data->taxDocument->number = $number;
228+
229+
return $this;
230+
}
231+
232+
/**
233+
* Set phone from holder.
234+
*
235+
* @param int $areaCode DDD telephone.
236+
* @param int $number Telephone number.
237+
* @param int $countryCode Country code.
238+
*
239+
* @return $this
240+
*/
241+
public function setPhone($areaCode, $number, $countryCode = 55)
242+
{
243+
$this->data->phone = new stdClass();
244+
$this->data->phone->countryCode = $countryCode;
245+
$this->data->phone->areaCode = $areaCode;
246+
$this->data->phone->number = $number;
247+
248+
return $this;
249+
}
250+
}

src/Resource/Payment.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public function setBoleto($expirationDate, $logoUri, array $instructionLines = [
411411
*
412412
* @param \Moip\Resource\Customer $holder
413413
*/
414-
private function setCreditCardHolder(Customer $holder)
414+
private function setCreditCardHolder(Holder $holder)
415415
{
416416
$birthdate = $holder->getBirthDate();
417417
if ($birthdate instanceof \DateTime) {
@@ -439,7 +439,7 @@ private function setCreditCardHolder(Customer $holder)
439439
*
440440
* @return $this
441441
*/
442-
public function setCreditCardHash($hash, Customer $holder, $store = true)
442+
public function setCreditCardHash($hash, Holder $holder, $store = true)
443443
{
444444
$this->data->fundingInstrument->method = self::METHOD_CREDIT_CARD;
445445
$this->data->fundingInstrument->creditCard = new stdClass();
@@ -464,7 +464,7 @@ public function setCreditCardHash($hash, Customer $holder, $store = true)
464464
*
465465
* @return $this
466466
*/
467-
public function setCreditCard($expirationMonth, $expirationYear, $number, $cvc, Customer $holder, $store = true)
467+
public function setCreditCard($expirationMonth, $expirationYear, $number, $cvc, Holder $holder, $store = true)
468468
{
469469
$this->data->fundingInstrument->method = self::METHOD_CREDIT_CARD;
470470
$this->data->fundingInstrument->creditCard = new stdClass();

tests/Resource/EscrowTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function testShouldReleaseEscrow()
1313
$cc = '5555666677778884';
1414
$this->mockHttpSession($this->body_cc_pay_pci_escrow);
1515
$payment = $order->payments()
16-
->setCreditCard(5, 2018, $cc, 123, $this->createCustomer(), false)
16+
->setCreditCard(5, 2018, $cc, 123, $this->createHolder(), false)
1717
->setEscrow('teste de descricao')
1818
->execute();
1919
$this->mockHttpSession($this->body_release_escrow);

0 commit comments

Comments
 (0)