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\ApiResponseInterface; |
13
|
|
|
use Commercetools\Core\Model\Customer\Customer; |
14
|
|
|
use Commercetools\Core\Response\ResourceResponse; |
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
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#verify-customers-email |
21
|
|
|
* @method Customer mapResponse(ApiResponseInterface $response) |
22
|
|
|
* @method Customer mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null) |
23
|
|
|
*/ |
24
|
|
|
class MeEmailConfirmRequest extends AbstractApiRequest |
25
|
|
|
{ |
26
|
|
|
protected $resultClass = Customer::class; |
27
|
|
|
|
28
|
|
|
const TOKEN_VALUE = 'tokenValue'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $tokenValue; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $tokenValue |
37
|
|
|
* @param Context $context |
38
|
|
|
*/ |
39
|
|
|
public function __construct($tokenValue, Context $context = null) |
40
|
|
|
{ |
41
|
|
|
parent::__construct(MeEndpoint::endpoint(), $context); |
42
|
|
|
$this->tokenValue = $tokenValue; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $tokenValue |
47
|
|
|
* @param Context $context |
48
|
|
|
* @return static |
49
|
|
|
*/ |
50
|
|
|
public static function ofToken($tokenValue, Context $context = null) |
51
|
|
|
{ |
52
|
|
|
return new static($tokenValue, $context); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string |
57
|
|
|
* @internal |
58
|
|
|
*/ |
59
|
|
|
protected function getPath() |
60
|
|
|
{ |
61
|
|
|
return (string)$this->getEndpoint() . '/email/confirm' . $this->getParamString(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return JsonRequest |
66
|
|
|
* @internal |
67
|
|
|
*/ |
68
|
|
|
public function httpRequest() |
69
|
|
|
{ |
70
|
|
|
$payload = [ |
71
|
|
|
static::TOKEN_VALUE => $this->tokenValue, |
72
|
|
|
]; |
73
|
|
|
return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function buildResponse(ResponseInterface $response) |
77
|
|
|
{ |
78
|
|
|
return new ResourceResponse($response, $this, $this->getContext()); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|