Skip to content

Commit b51a484

Browse files
Checkout API header to v3 (#12)
1 parent 0bbb940 commit b51a484

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

examples/step1_checkout_create.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function createCheckoutPayload() {
174174
function createAplazameCheckout(Aplazame\Api\Client $aplazameApiClient, $payload)
175175
{
176176
try {
177-
return $aplazameApiClient->post('/checkout', $payload)['id'];
177+
return $aplazameApiClient->request('POST','/checkout', $payload, 3)['id'];
178178
} catch (Aplazame\Api\ApiCommunicationException $apiCommunicationException) {
179179
// A network error has occurred while sending the request or receiving the response.
180180

src/Api/ApiRequest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,22 @@ public static function createAcceptHeader($useSandbox, $apiVersion, $format)
4040

4141
/**
4242
* @param bool $useSandbox
43+
* @param int $apiVersion The API version of the request.
4344
* @param string $accessToken The Access Token of the request (Public API key or Private API key)
4445
* @param string $method The HTTP method of the request.
4546
* @param string $uri The URI of the request.
4647
* @param mixed $data The data of the request.
4748
*/
4849
public function __construct(
4950
$useSandbox,
51+
$apiVersion,
5052
$accessToken,
5153
$method,
5254
$uri,
5355
$data = null
5456
) {
5557
$headers = array(
56-
'Accept' => array(self::createAcceptHeader($useSandbox, 1, self::FORMAT_JSON)),
58+
'Accept' => array(self::createAcceptHeader($useSandbox, $apiVersion, self::FORMAT_JSON)),
5759
'Authorization' => array(self::createAuthorizationHeader($accessToken)),
5860
'User-Agent' => array(
5961
'Aplazame/' . self::SDK_VERSION,

src/Api/Client.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public function put($path, $data)
147147
* @param string $method The HTTP method of the request.
148148
* @param string $path The path of the request.
149149
* @param array|object|null $data The data of the request.
150+
* @param int $apiVersion The API version of the request.
150151
*
151152
* @return array The data of the response.
152153
*
@@ -155,11 +156,11 @@ public function put($path, $data)
155156
* @throws ApiServerException if server was not able to respond.
156157
* @throws ApiClientException if request is invalid.
157158
*/
158-
public function request($method, $path, $data = null)
159+
public function request($method, $path, $data = null, $apiVersion = 1)
159160
{
160161
$uri = $this->apiBaseUri . '/' . ltrim($path, '/');
161162

162-
$request = new ApiRequest($this->useSandbox, $this->accessToken, $method, $uri, $data);
163+
$request = new ApiRequest($this->useSandbox, $apiVersion, $this->accessToken, $method, $uri, $data);
163164
try {
164165
$response = $this->httpClient->send($request);
165166
} catch (RuntimeException $e) {

test/Api/ApiRequestTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,20 @@ public function authorizationHeaderProvider()
5151
/**
5252
* @dataProvider constructorProvider
5353
*/
54-
public function testConstructor($useSandbox, $accessToken, $expectedHeaders)
54+
public function testConstructor($useSandbox, $apiVersion, $accessToken, $expectedHeaders)
5555
{
56-
$helper = new ApiRequest($useSandbox, $accessToken, 'GET', 'http://api.example.com');
56+
$helper = new ApiRequest($useSandbox, $apiVersion, $accessToken, 'GET', 'http://api.example.com');
5757

5858
self::assertEquals($expectedHeaders, $helper->getHeaders(), 'getHeaders not match');
5959
}
6060

6161
public function constructorProvider()
6262
{
6363
return array(
64-
// Description => [useSandbox, accessToken, expectedHeader]
64+
// Description => [useSandbox, apiVersion, accessToken, expectedHeader]
6565
'foo' => array(
6666
'useSandbox' => true,
67+
'apiVersion' => 1,
6768
'accessToken' => 'foo',
6869
'expectedHeaders' => array(
6970
'Accept' => array('application/vnd.aplazame.sandbox.v1+json'),

0 commit comments

Comments
 (0)