1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jenschude <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Request\Me; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Client\HttpMethod; |
9
|
|
|
use Commercetools\Core\Client\JsonRequest; |
10
|
|
|
use Commercetools\Core\Model\Common\Context; |
11
|
|
|
use Commercetools\Core\Request\AbstractApiRequest; |
12
|
|
|
use Commercetools\Core\Response\ResourceResponse; |
13
|
|
|
use Psr\Http\Message\ResponseInterface; |
14
|
|
|
use Commercetools\Core\Model\Customer\Customer; |
15
|
|
|
use Commercetools\Core\Response\ApiResponseInterface; |
16
|
|
|
use Commercetools\Core\Model\MapperInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @package Commercetools\Core\Request\Me |
20
|
|
|
* @link https://docs.commercetools.com/http-api-projects-me-profile.html#change-customers-password |
21
|
|
|
* @method Customer mapResponse(ApiResponseInterface $response) |
22
|
|
|
* @method Customer mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null) |
23
|
|
|
*/ |
24
|
|
|
class MePasswordChangeRequest extends AbstractApiRequest |
25
|
|
|
{ |
26
|
|
|
const ID = 'id'; |
27
|
|
|
const VERSION = 'version'; |
28
|
|
|
const CURRENT_PASSWORD = 'currentPassword'; |
29
|
|
|
const NEW_PASSWORD = 'newPassword'; |
30
|
|
|
|
31
|
|
|
protected $resultClass = Customer::class; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var int |
35
|
|
|
*/ |
36
|
|
|
protected $version; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $currentPassword; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected $newPassword; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param int $version |
50
|
|
|
* @param string $currentPassword |
51
|
|
|
* @param string $newPassword |
52
|
|
|
* @param Context $context |
53
|
|
|
*/ |
54
|
|
|
public function __construct($version, $currentPassword, $newPassword, Context $context = null) |
55
|
|
|
{ |
56
|
|
|
parent::__construct(MeEndpoint::endpoint(), $context); |
57
|
|
|
$this->setVersion($version); |
58
|
|
|
$this->currentPassword = $currentPassword; |
59
|
|
|
$this->newPassword = $newPassword; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return int |
64
|
|
|
*/ |
65
|
|
|
public function getVersion() |
66
|
|
|
{ |
67
|
|
|
return $this->version; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param int $version |
72
|
|
|
* @return $this |
73
|
|
|
*/ |
74
|
|
|
public function setVersion($version) |
75
|
|
|
{ |
76
|
|
|
$this->version = $version; |
77
|
|
|
|
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param int $version |
83
|
|
|
* @param string $currentPassword |
84
|
|
|
* @param string $newPassword |
85
|
|
|
* @param Context $context |
86
|
|
|
* @return static |
87
|
|
|
*/ |
88
|
|
|
public static function ofVersionAndPasswords( |
89
|
|
|
$version, |
90
|
|
|
$currentPassword, |
91
|
|
|
$newPassword, |
92
|
|
|
Context $context = null |
93
|
|
|
) { |
94
|
|
|
return new static($version, $currentPassword, $newPassword, $context); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return string |
99
|
|
|
* @internal |
100
|
|
|
*/ |
101
|
|
|
protected function getPath() |
102
|
|
|
{ |
103
|
|
|
return (string)$this->getEndpoint() . '/password' . $this->getParamString(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return JsonRequest |
108
|
|
|
* @internal |
109
|
|
|
*/ |
110
|
|
|
public function httpRequest() |
111
|
|
|
{ |
112
|
|
|
$payload = [ |
113
|
|
|
static::VERSION => $this->getVersion(), |
114
|
|
|
static::CURRENT_PASSWORD => $this->currentPassword, |
115
|
|
|
static::NEW_PASSWORD => $this->newPassword |
116
|
|
|
]; |
117
|
|
|
return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param ResponseInterface $response |
122
|
|
|
* @return ResourceResponse |
123
|
|
|
* @internal |
124
|
|
|
*/ |
125
|
|
|
public function buildResponse(ResponseInterface $response) |
126
|
|
|
{ |
127
|
|
|
return new ResourceResponse($response, $this, $this->getContext()); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|