1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the slince/shopify-api-php |
5
|
|
|
* |
6
|
|
|
* (c) Slince <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Slince\Shopify; |
13
|
|
|
|
14
|
|
|
use Psr\Http\Message\RequestInterface; |
15
|
|
|
|
16
|
|
|
class PrivateAppCredential implements CredentialInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $apiKey; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $password; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $sharedSecret; |
32
|
|
|
|
33
|
|
|
public function __construct($apiKey, $password, $sharedSecret) |
34
|
|
|
{ |
35
|
|
|
$this->apiKey = $apiKey; |
36
|
|
|
$this->password = $password; |
37
|
|
|
$this->sharedSecret = $sharedSecret; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public function getApiKey() |
44
|
|
|
{ |
45
|
|
|
return $this->apiKey; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $apiKey |
50
|
|
|
* |
51
|
|
|
* @return PrivateAppCredential |
52
|
|
|
*/ |
53
|
|
|
public function setApiKey($apiKey) |
54
|
|
|
{ |
55
|
|
|
$this->apiKey = $apiKey; |
56
|
|
|
|
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function getPassword() |
64
|
|
|
{ |
65
|
|
|
return $this->password; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $password |
70
|
|
|
* |
71
|
|
|
* @return PrivateAppCredential |
72
|
|
|
*/ |
73
|
|
|
public function setPassword($password) |
74
|
|
|
{ |
75
|
|
|
$this->password = $password; |
76
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function getSharedSecret() |
84
|
|
|
{ |
85
|
|
|
return $this->sharedSecret; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param string $sharedSecret |
90
|
|
|
* |
91
|
|
|
* @return PrivateAppCredential |
92
|
|
|
*/ |
93
|
|
|
public function setSharedSecret($sharedSecret) |
94
|
|
|
{ |
95
|
|
|
$this->sharedSecret = $sharedSecret; |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
|
|
public function applyToRequest(RequestInterface $request) |
104
|
|
|
{ |
105
|
|
|
return $request->withHeader('Authorization', 'Basic ' |
106
|
|
|
.base64_encode("{$this->apiKey}:{$this->password}")); |
107
|
|
|
} |
108
|
|
|
} |