|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Omnipay\PaypalRest\Message; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @author Ivan Kerin <[email protected]> |
|
7
|
|
|
* @copyright 2014, Clippings Ltd. |
|
8
|
|
|
* @license http://spdx.org/licenses/BSD-3-Clause |
|
9
|
|
|
*/ |
|
10
|
|
|
class UpdateCardRequest extends AbstractPaypalRequest |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @return string |
|
14
|
|
|
*/ |
|
15
|
|
|
public function getEndpoint() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->validate('cardReference'); |
|
18
|
|
|
|
|
19
|
|
|
return '/vault/credit-card/'.$this->getCardReference(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @return string |
|
24
|
|
|
*/ |
|
25
|
|
|
public function getHttpMethod() |
|
26
|
|
|
{ |
|
27
|
|
|
return 'PATCH'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param mixed $data |
|
32
|
|
|
* @return UpdateCardResponse |
|
33
|
|
|
*/ |
|
34
|
|
|
public function sendData($data) |
|
35
|
|
|
{ |
|
36
|
|
|
$httpResponse = $this->sendHttpRequest($data); |
|
37
|
|
|
|
|
38
|
|
|
return $this->response = new UpdateCardResponse( |
|
39
|
|
|
$this, |
|
40
|
|
|
$httpResponse->json(), |
|
41
|
|
|
$httpResponse->getStatusCode() |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return array |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getData() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->validate('card'); |
|
51
|
|
|
$card = $this->getCard(); |
|
52
|
|
|
|
|
53
|
|
|
$cardFields = array( |
|
54
|
|
|
'expire_month' => $card->getExpiryMonth(), |
|
55
|
|
|
'expire_year' => $card->getExpiryYear(), |
|
56
|
|
|
'first_name' => $card->getFirstName(), |
|
57
|
|
|
'last_name' => $card->getLastName(), |
|
58
|
|
|
'billing_address' => array( |
|
59
|
|
|
'line1' => $card->getAddress1(), |
|
60
|
|
|
'line2' => $card->getAddress2(), |
|
61
|
|
|
'city' => $card->getCity(), |
|
62
|
|
|
'state' => $card->getState(), |
|
63
|
|
|
'postal_code' => $card->getPostcode(), |
|
64
|
|
|
'country_code' => strtoupper($card->getCountry()), |
|
65
|
|
|
) |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
$data = array(); |
|
69
|
|
|
|
|
70
|
|
|
foreach ($cardFields as $field => $value) { |
|
71
|
|
|
$data []= array( |
|
72
|
|
|
'path' => "/$field", |
|
73
|
|
|
'op' => 'add', |
|
74
|
|
|
'value' => $value |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $data; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|