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#reset-customers-password |
21
|
|
|
* @method Customer mapResponse(ApiResponseInterface $response) |
22
|
|
|
* @method Customer mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null) |
23
|
|
|
*/ |
24
|
|
|
class MePasswordResetRequest extends AbstractApiRequest |
25
|
|
|
{ |
26
|
|
|
const TOKEN_VALUE = 'tokenValue'; |
27
|
|
|
const NEW_PASSWORD = 'newPassword'; |
28
|
|
|
|
29
|
|
|
protected $resultClass = Customer::class; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $token; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $newPassword; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $token |
43
|
|
|
* @param string $newPassword |
44
|
|
|
* @param Context $context |
45
|
|
|
*/ |
46
|
|
|
public function __construct($token, $newPassword, Context $context = null) |
47
|
|
|
{ |
48
|
|
|
parent::__construct(MeEndpoint::endpoint(), $context); |
49
|
|
|
$this->token = $token; |
50
|
|
|
$this->newPassword = $newPassword; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $token |
55
|
|
|
* @param string $newPassword |
56
|
|
|
* @param Context $context |
57
|
|
|
* @return static |
58
|
|
|
*/ |
59
|
|
|
public static function ofTokenAndPassword( |
60
|
|
|
$token, |
61
|
|
|
$newPassword, |
62
|
|
|
Context $context = null |
63
|
|
|
) { |
64
|
|
|
return new static($token, $newPassword, $context); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
* @internal |
70
|
|
|
*/ |
71
|
|
|
protected function getPath() |
72
|
|
|
{ |
73
|
|
|
return (string)$this->getEndpoint() . '/password/reset' . $this->getParamString(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return JsonRequest |
78
|
|
|
* @internal |
79
|
|
|
*/ |
80
|
|
|
public function httpRequest() |
81
|
|
|
{ |
82
|
|
|
$payload = [ |
83
|
|
|
static::TOKEN_VALUE => $this->token, |
84
|
|
|
static::NEW_PASSWORD => $this->newPassword |
85
|
|
|
]; |
86
|
|
|
return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param ResponseInterface $response |
91
|
|
|
* @return ResourceResponse |
92
|
|
|
* @internal |
93
|
|
|
*/ |
94
|
|
|
public function buildResponse(ResponseInterface $response) |
95
|
|
|
{ |
96
|
|
|
return new ResourceResponse($response, $this, $this->getContext()); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|