1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Omnipay\Heidelpay\Message; |
5
|
|
|
|
6
|
|
|
class CreateCustomerRequest extends AbstractRequest |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @return array|mixed |
10
|
|
|
*/ |
11
|
|
|
public function getData() |
12
|
|
|
{ |
13
|
|
|
$this->validate('card'); |
14
|
|
|
|
15
|
|
|
$data = [ |
16
|
|
|
'firstname' => $this->getCard()->getFirstName(), |
17
|
|
|
'lastname' => $this->getCard()->getLastName(), |
18
|
|
|
'birthDate' => $this->getCard()->getBirthday(), |
19
|
|
|
'email' => $this->getCard()->getEmail() |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
if ($this->getCard()->getPhone()) { |
23
|
|
|
$data['phone'] = $this->getCard()->getPhone(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
if ($this->getCard()->getBillingName()) { |
27
|
|
|
$data = array_merge($data, $this->getAddressData('Billing')); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if ($this->getCard()->getShippingName()) { |
31
|
|
|
$data = array_merge($data, $this->getAddressData('Shipping')); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return $data; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get either the billing or the shipping address from |
39
|
|
|
* the card object, mapped to Heidelpay field names. |
40
|
|
|
* |
41
|
|
|
* @param string $type 'Billing' or 'Shipping' |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
protected function getAddressData($type = 'Billing') |
45
|
|
|
{ |
46
|
|
|
$card = $this->getCard(); |
47
|
|
|
|
48
|
|
|
$mapping = [ |
49
|
|
|
'name' => 'Name', |
50
|
|
|
'street' => 'Address1', |
51
|
|
|
'city' => 'City', |
52
|
|
|
'zip' => 'Postcode', |
53
|
|
|
'state' => 'State', |
54
|
|
|
'country' => 'Country' |
55
|
|
|
]; |
56
|
|
|
|
57
|
|
|
$data = []; |
58
|
|
|
|
59
|
|
|
foreach ($mapping as $heidelpayName => $omnipayName) { |
60
|
|
|
$value = call_user_func([$card, 'get'.$type.$omnipayName]); |
61
|
|
|
if ($value !== null) { |
62
|
|
|
$data[strtolower($type) . 'Address.' . $heidelpayName] = $value; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
return $data; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getEndpoint() |
72
|
|
|
{ |
73
|
|
|
return parent::getEndpoint().'customers'; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
protected function createResponse($data) |
77
|
|
|
{ |
78
|
|
|
return $this->response = new Response($this, $data); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|