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
|
|
|
'phone' => $this->getCard()->getPhone(), |
21
|
|
|
]; |
22
|
|
|
$data['billingAddress'] = $this->getAddressData('Billing'); |
23
|
|
|
$data['shippingAddress'] = $this->getAddressData('Shipping'); |
24
|
|
|
|
25
|
|
|
return $data; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Get either the billing or the shipping address from |
30
|
|
|
* the card object, mapped to Heidelpay field names. |
31
|
|
|
* |
32
|
|
|
* @param string $type 'Billing' or 'Shipping' |
33
|
|
|
* @return array |
34
|
|
|
*/ |
35
|
|
|
protected function getAddressData($type = 'Billing') |
36
|
|
|
{ |
37
|
|
|
$card = $this->getCard(); |
38
|
|
|
|
39
|
|
|
$mapping = [ |
40
|
|
|
'firstname' => 'FirstName', |
41
|
|
|
'lastname' => 'LastName', |
42
|
|
|
'street' => 'Address1', |
43
|
|
|
'city' => 'City', |
44
|
|
|
'zip' => 'Postcode', |
45
|
|
|
'state' => 'State', |
46
|
|
|
'country' => 'Country' |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
$data = []; |
50
|
|
|
|
51
|
|
|
foreach ($mapping as $heidelpayName => $omnipayName) { |
52
|
|
|
$data[$heidelpayName] = call_user_func([$card, 'get'.$type.$omnipayName]); |
53
|
|
|
} |
54
|
|
|
return $data; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getEndpoint() |
61
|
|
|
{ |
62
|
|
|
return parent::getEndpoint().'customers'; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function createResponse($data) |
66
|
|
|
{ |
67
|
|
|
return $this->response = new CreateCustomerResponse($this, $data); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|