1: <?php
2:
3: namespace mcfedr\Paypal;
4:
5: /**
6: * Describes the buyer of your product, this info is received in notifications
7: */
8: class Buyer {
9:
10: /**
11: * Unique id for this buyer
12: * @var string
13: */
14: public $id;
15:
16: /**
17: * First name
18: * @var string
19: */
20: public $firstName;
21:
22: /**
23: * Last name
24: * @var string
25: */
26: public $lastName;
27:
28: /**
29: * Email
30: * @var string
31: */
32: public $email;
33:
34: /**
35: * business name if has one
36: * @var string
37: */
38: public $business;
39:
40: /**
41: * contact phone
42: * @var string
43: */
44: public $phone;
45:
46: /**
47: * status, ie verified or not
48: * @var string
49: */
50: public $status;
51:
52: /**
53: * Code of country of residence
54: * @var string
55: */
56: public $residenceCountry;
57:
58: /**
59: * Country
60: * @var string
61: */
62: public $addressCountry;
63:
64: /**
65: * Country code ie gb or fr etc
66: * @var string
67: */
68: public $addressCountryCode;
69:
70: /**
71: * Zip code or similar
72: * @var string
73: */
74: public $addressZip;
75:
76: /**
77: * State
78: * @var string
79: */
80: public $addressState;
81:
82: /**
83: * City
84: * @var string
85: */
86: public $addressCity;
87:
88: /**
89: * Street
90: * @var string
91: */
92: public $addressStreet;
93:
94: /**
95: * Name to be used with address
96: * @var string
97: */
98: public $addressName;
99:
100: /**
101: * status of address, ie verifed or not
102: * @var string
103: */
104: public $addressStatus;
105:
106: /**
107: * Extract buyer info from the vars from notifications
108: * @param array $vars
109: */
110: public function __construct($vars) {
111: if (isset($vars['payer_id'])) {
112: $this->id = $vars['payer_id'];
113: }
114:
115: if (isset($vars['first_name'])) {
116: $this->firstName = $vars['first_name'];
117: }
118:
119: if (isset($vars['last_name'])) {
120: $this->lastName = $vars['last_name'];
121: }
122:
123: if (isset($vars['payer_email'])) {
124: $this->email = $vars['payer_email'];
125: }
126: else if (isset($vars['sender_email'])) {
127: $this->email = $vars['sender_email'];
128: }
129:
130: if (isset($vars['payer_business_name'])) {
131: $this->business = $vars['payer_business_name'];
132: }
133:
134: if (isset($vars['contact_phone'])) {
135: $this->phone = $vars['contact_phone'];
136: }
137:
138: if (isset($vars['payer_status'])) {
139: $this->status = $vars['payer_status'];
140: }
141:
142: if (isset($vars['residence_country'])) {
143: $this->residenceCountry = $vars['residence_country'];
144: }
145:
146: if (isset($vars['address_country'])) {
147: $this->addressCountry = $vars['address_country'];
148: }
149:
150: if (isset($vars['address_country_code'])) {
151: $this->addressCountryCode = $vars['address_country_code'];
152: }
153:
154: if (isset($vars['address_zip'])) {
155: $this->addressZip = $vars['address_zip'];
156: }
157:
158: if (isset($vars['address_state'])) {
159: $this->addressState = $vars['address_state'];
160: }
161:
162: if (isset($vars['address_city'])) {
163: $this->addressCity = $vars['address_city'];
164: }
165:
166: if (isset($vars['address_street'])) {
167: $this->addressStreet = $vars['address_street'];
168: }
169:
170: if (isset($vars['address_name'])) {
171: $this->addressName = $vars['address_name'];
172: }
173:
174: if (isset($vars['address_status'])) {
175: $this->addressStatus = $vars['address_status'];
176: }
177: }
178:
179: /**
180: * Set params in button for buyer
181: *
182: * @param array $params
183: */
184: public function setParams(&$params) {
185: if (!empty($this->email)) {
186: $params['email'] = $this->email;
187: }
188: if (!empty($this->firstName)) {
189: $params['first_name'] = $this->firstName;
190: }
191: if (!empty($this->lastName)) {
192: $params['last_name'] = $this->lastName;
193: }
194: //TODO: address fields
195: }
196:
197: }
198: